11// -------
22// IMPORTS
33// -------
4- import React , { FC , useEffect , useLayoutEffect , useState } from 'react'
4+ import React , { FC , useEffect , useState } from 'react'
55
6- import { useCollections , useGeneticElements } from '@eplant/state'
6+ import { useCollections } from '@eplant/state'
77import { Unstable_Popup as Popup } from '@mui/base/Unstable_Popup'
88import ArrowLeft from '@mui/icons-material/ArrowLeft'
99import Box from '@mui/material/Box'
@@ -17,28 +17,32 @@ import {
1717 GeneAnnotationItem ,
1818 GeneRange ,
1919} from '../types'
20-
21- import GeneAnnotation from './GeneAnnotation'
22- import GeneList from './GeneList'
2320import {
2421 getChromosomeSvg ,
2522 getChromosomeXCoordinate ,
26- getGeneAnnotation ,
2723 pixelToBp ,
28- } from './utilities'
24+ } from '../utilities'
25+
26+ import GeneAnnotation from './GeneAnnotation'
27+ import GeneList from './GeneList'
2928
3029//----------
3130// TYPES
3231//----------
3332interface ChromosomeProps {
34- scale : number
3533 chromosome : ChromosomeItem
34+ annotations : GeneAnnotationItem [ ]
35+ scale : number
3636}
3737
3838//----------
3939// COMPONENT
4040//----------
41- const Chromosome : FC < ChromosomeProps > = ( { scale, chromosome } ) => {
41+ const Chromosome : FC < ChromosomeProps > = ( {
42+ chromosome,
43+ annotations,
44+ scale,
45+ } ) => {
4246 // State
4347 const [ isHovered , setIsHovered ] = useState < boolean > ( false )
4448 const [ anchorOrigin , setAnchorOrigin ] = useState < number [ ] > ( [ ] )
@@ -47,13 +51,7 @@ const Chromosome: FC<ChromosomeProps> = ({ scale, chromosome }) => {
4751 start : 0 ,
4852 end : 0 ,
4953 } )
50- // Gene Annotation drawing
51- const [ geneAnnotationArray , setGeneAnnotationArray ] = useState <
52- GeneAnnotationItem [ ]
53- > ( [ ] )
5454
55- // Global State
56- const [ geneticElements ] = useGeneticElements ( )
5755 const [ collections ] = useCollections ( )
5856 const theme = useTheme ( )
5957
@@ -73,45 +71,6 @@ const Chromosome: FC<ChromosomeProps> = ({ scale, chromosome }) => {
7371 // Gene List popover variables
7472 const openPopup = Boolean ( anchorEl )
7573
76- // Fire before paint, converts geneticElements into geneAnnotationArray
77- useLayoutEffect ( ( ) => {
78- // TODO: move this to top level to prevent uneccessary api calls
79- const poplar = false
80- const species = poplar ? 'Populus_trichocarpa' : 'Arabidopsis_thaliana'
81- let newGeneAnnotationArray : GeneAnnotationItem [ ] = [ ]
82- geneticElements . map ( ( gene ) => {
83- // for each item in geneticElements, fetch it's gene information to add to it's geneAnnotation
84- fetch (
85- `https://bar.utoronto.ca/eplant${
86- poplar ? '_poplar' : ''
87- } /cgi-bin/querygene.cgi?species=${ species } &term=${ gene . id } `
88- )
89- . then ( ( response ) => response . json ( ) )
90- . then ( ( geneItem ) => {
91- if ( geneItem . chromosome === chromosome . id ) {
92- newGeneAnnotationArray = geneAnnotationArray
93- const geneAnnotation : GeneAnnotationItem =
94- getGeneAnnotation ( geneItem )
95-
96- // Make sure new geneAnnotation is not already in geneAnnotationArray
97- const isDuplicate = newGeneAnnotationArray . some ( ( gene ) => {
98- if ( gene . id === geneAnnotation . id ) {
99- return true
100- }
101- return false
102- } )
103- if ( ! isDuplicate ) {
104- newGeneAnnotationArray . push ( geneAnnotation )
105- setGeneAnnotationArray ( newGeneAnnotationArray )
106- }
107- }
108- } )
109- . catch ( ( err ) => {
110- console . log ( err )
111- } )
112- } )
113- } , [ ] )
114-
11574 // Execute on first render, after paint
11675 useEffect ( ( ) => {
11776 const svg : HTMLElement & SVGSVGElement = getChromosomeSvg ( chromosome . id )
@@ -288,7 +247,7 @@ const Chromosome: FC<ChromosomeProps> = ({ scale, chromosome }) => {
288247 </ g >
289248 { /* GENES ANNOTATION TAGS */ }
290249 < g id = { `${ chromosome . id } _geneAnnotationTags` } >
291- { geneAnnotationArray . map ( ( gene , i ) => {
250+ { annotations . map ( ( gene , i ) => {
292251 // Flatten collections into array of gene IDs - important for not drawing removed gene annotations
293252 const flatGeneCollection = collections . flatMap (
294253 ( collection ) => collection . genes
0 commit comments