diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts index afd48bf4b..d379b8ac6 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts @@ -76,6 +76,9 @@ interface ExonCDSRelation { } export class CanonicalGeneGlyph extends Glyph { + /** + * Return list of all the features (exons/cds) for each row for a given feature + */ featuresForRow( feature: AnnotationFeatureNew, ): CanonicalGeneAnnotationFeature[][] { @@ -96,7 +99,7 @@ export class CanonicalGeneGlyph extends Glyph { } } - console.log('cdsFeatures', cdsFeatures) + // console.log('cdsFeatures', cdsFeatures) const features: CanonicalGeneAnnotationFeature[][] = [] for (const f of cdsFeatures) { @@ -106,6 +109,7 @@ export class CanonicalGeneGlyph extends Glyph { continue } + // Add all cds locations if ( cf.type === 'CDS' && f.cdsDiscontinuousLocs && @@ -121,12 +125,14 @@ export class CanonicalGeneGlyph extends Glyph { }) } } else { + // Add all exons childFeatures.push({ annotationFeature: cf, parent: f.parent, }) } } + // Add parent(mRNA) feature childFeatures.push({ annotationFeature: f.parent, }) @@ -381,8 +387,9 @@ export class CanonicalGeneGlyph extends Glyph { const cdsLocs = this.getDiscontinuousLocations(parentFeature, feature) const { cdsLocations } = parentFeature - console.log('parentFeature type', parentFeature.type) + // console.log('parentFeature type', parentFeature.type) console.log('cdsLocations', cdsLocations) + console.log('cdsLocs', cdsLocs) for (const cdsLoc of cdsLocs) { this.drawShadeForFeature( diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts index c0c3c5940..717f2eada 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts @@ -119,45 +119,77 @@ export abstract class Glyph { parentFeature: AnnotationFeatureNew, cdsFeature: AnnotationFeatureNew, ): CDSDiscontinuousLocation[] { - const exons: AnnotationFeatureNew[] = [] + // const exons: AnnotationFeatureNew[] = [] - for (const [, child] of parentFeature.children ?? new Map()) { - if (child.type === 'exon') { - exons.push(child) - } - } + // for (const [, child] of parentFeature.children ?? new Map()) { + // if (child.type === 'exon') { + // exons.push(child) + // } + // } + + // const cdsDLs: CDSDiscontinuousLocation[] = [] + // for (const exon of exons) { + // if (exon.min > cdsFeature.max || exon.max < cdsFeature.min) { + // continue + // } + + // let cdsMin, cdsMax + // if (exon.min > cdsFeature.min && exon.max < cdsFeature.max) { + // cdsMin = exon.min + // cdsMax = exon.max + // } else if ( + // exon.min <= cdsFeature.min && + // cdsFeature.min < exon.max && + // exon.max < cdsFeature.max + // ) { + // cdsMin = cdsFeature.min + // cdsMax = exon.max + // } else if ( + // exon.min < cdsFeature.max && + // cdsFeature.max <= exon.max && + // exon.min > cdsFeature.min + // ) { + // cdsMin = exon.min + // cdsMax = cdsFeature.max + // } else { + // continue + // } + // cdsDLs.push({ + // start: cdsMin, + // end: cdsMax, + // phase: undefined, + // }) + // } const cdsDLs: CDSDiscontinuousLocation[] = [] - for (const exon of exons) { - if (exon.min > cdsFeature.max || exon.max < cdsFeature.min) { - continue - } - let cdsMin, cdsMax - if (exon.min > cdsFeature.min && exon.max < cdsFeature.max) { - cdsMin = exon.min - cdsMax = exon.max - } else if ( - exon.min <= cdsFeature.min && - cdsFeature.min < exon.max && - exon.max < cdsFeature.max - ) { - cdsMin = cdsFeature.min - cdsMax = exon.max - } else if ( - exon.min < cdsFeature.max && - cdsFeature.max <= exon.max && - exon.min > cdsFeature.min - ) { - cdsMin = exon.min - cdsMax = cdsFeature.max - } else { - continue + if (parentFeature?.type !== 'mRNA') { + return cdsDLs + } + + const { cdsLocations, children } = parentFeature + + let i = 0 + for (const [, child] of children ?? new Map()) { + if (cdsFeature._id === child._id) { + break } + if (child.type === 'CDS') { + i++ + } + } + + const cdsLocation = cdsLocations[i] + + if (!cdsLocation) { + return cdsDLs + } + + for (const { max, min, phase } of cdsLocation) { cdsDLs.push({ - start: cdsMin, - end: cdsMax, - phase: undefined, + start: min, + end: max, + phase, }) } @@ -216,7 +248,7 @@ export abstract class Glyph { const cdsLocs = this.getDiscontinuousLocations(parentFeature, feature) let start: number, end: number, length: number let location = 'Loc: ' - if (cdsLocs && cdsLocs.length > 0) { + if (feature.type === 'CDS' && cdsLocs && cdsLocs.length > 0) { const lastLoc = cdsLocs.at(-1) if (!lastLoc) { return