import React, { useMemo, useRef, useEffect } from 'react'; import { v1 as uuidv1 } from 'uuid'; import { SquishBamProps, BamRect } from './types'; import { xtransform } from '../../../utils/coordinates'; import { ClipPath } from '../../clippath'; import { renderSquishBamData } from './utils'; /** * Represents a Bam track rendered in squish mode as at UCSC. A squished Bam renders genomic regions * of interest as narrow rectangles packed into an optimal number of rows so overlapping regions * are distinguishable from one another. */ const SquishBam: React.FC = props => { const uuid = useRef(uuidv1()); const x = xtransform(props.domain, props.width); const color = props.color || "#000000"; const rendered: BamRect[][] = useMemo( () => renderSquishBamData(props.data!, x, props.domain), [ props.data, props.domain, props.width ] ); const height = props.rowHeight * rendered.length; const id = props.id || uuid.current.toString(); useEffect( () => { props.onHeightChanged && props.onHeightChanged(height); }, [ rendered, props.rowHeight, props.onHeightChanged ]); return ( { rendered.map( (group, i) => ( {group.map( (rect, j) => { let cgRects = rect.cigarOps.map((cg,k)=>{ let ops; if(cg.op==='S') { ops = } else if(cg.op==='I') { ops = Insertion } else if(cg.op==='D' || cg.op==='N') { ops = } else { ops = } return ops; }) return ( {cgRects} {props.domain.end - props.domain.start <= 200 && rect.seq && ( {rect.seq} )} ) })} ))} ); } export default SquishBam;