Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed May 23, 2024
1 parent dee2219 commit 5b51404
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[][] {
Expand All @@ -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) {
Expand All @@ -106,6 +109,7 @@ export class CanonicalGeneGlyph extends Glyph {
continue
}

// Add all cds locations
if (
cf.type === 'CDS' &&
f.cdsDiscontinuousLocs &&
Expand All @@ -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,
})
Expand Down Expand Up @@ -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)

Check warning on line 391 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
console.log('cdsLocs', cdsLocs)

Check warning on line 392 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement

for (const cdsLoc of cdsLocs) {
this.drawShadeForFeature(
Expand Down
100 changes: 66 additions & 34 deletions packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b51404

Please sign in to comment.