Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed Aug 18, 2023
1 parent 89eeb20 commit c607cf7
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ interface CDSFeatures {
}

export class CanonicalGeneGlyph extends Glyph {
/**
* Returns features as rows (Array of all child features and the parent feature at the end).
* ex:
* [ [ UTR/CDS/exon, UTR/CDS/exon, . . . , UTR/CDS/exon, mRNA/transcript ],
* [ UTR/CDS/exon, UTR/CDS/exon, . . . , UTR/CDS/exon, mRNA/transcript ] ]
*
* @param feature - Parent feature (ex: gene)
* @returns returns features for selected row
*/
featuresForRow(feature: AnnotationFeatureI): AnnotationFeature[][] {
const cdsFeatures: CDSFeatures[] = []
feature.children?.forEach((child: AnnotationFeatureI) => {
Expand Down Expand Up @@ -107,7 +98,7 @@ export class CanonicalGeneGlyph extends Glyph {
return features
}

getRowCount(feature: AnnotationFeatureI, _bpPerPx: number): number {
getRowCount(feature: AnnotationFeatureI, _bpPerPx?: number): number {
let cdsCount = 0
feature.children?.forEach((child: AnnotationFeatureI) => {
child.children?.forEach((grandchild: AnnotationFeatureI) => {
Expand Down Expand Up @@ -265,6 +256,50 @@ export class CanonicalGeneGlyph extends Glyph {
currentCDS += 1
})
})
if (apolloSelectedFeature) {
if (feature._id === apolloSelectedFeature._id) {
const widthPx = feature.length / bpPerPx
const startPx = reversed ? xOffset - widthPx : xOffset
const top = row * rowHeight
const height = this.getRowCount(feature) * rowHeight
ctx.fillStyle = theme?.palette.action.selected ?? 'rgba(0,0,0,0.08)'
ctx.fillRect(startPx, top, widthPx, height)
} else {
let featureEntry: AnnotationFeatureI | undefined
let featureRow: number | undefined
let i = 0
feature.children?.forEach((f: AnnotationFeatureI) => {
if (f._id === apolloSelectedFeature?._id) {
featureEntry = f
featureRow = i
}
i++
})

if (featureEntry === undefined || featureRow === undefined) {
return
}
let cdsCount = 0
featureEntry.children?.forEach((cf: AnnotationFeatureI) => {
if (
cf.discontinuousLocations &&
cf.discontinuousLocations.length > 0
) {
cdsCount++
}
})
let height = rowHeight
if (cdsCount > 1) {
height = height * cdsCount
}
const widthPx = featureEntry.length / bpPerPx
const offsetPx = (featureEntry.start - feature.min) / bpPerPx
const startPx = reversed ? xOffset - widthPx : xOffset + offsetPx
const top = (row + featureRow) * rowHeight
ctx.fillStyle = theme?.palette.action.selected ?? 'rgba(0,0,0,08)'
ctx.fillRect(startPx, top, widthPx, height)
}
}
}

drawHover(stateModel: LinearApolloDisplay, ctx: CanvasRenderingContext2D) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,38 @@ export class ImplicitExonGeneGlyph extends Glyph {
})
currentMRNA += 1
})

if (apolloSelectedFeature) {
if (feature._id === apolloSelectedFeature._id) {
const widthPx = feature.length / bpPerPx
const startPx = reversed ? xOffset - widthPx : xOffset
const top = row * rowHeight
const height = this.getRowCount(feature) * rowHeight
ctx.fillStyle = theme?.palette.action.selected ?? 'rgba(0,0,0,0.08)'
ctx.fillRect(startPx, top, widthPx, height)
} else {
let featureEntry: AnnotationFeatureI | undefined
let featureRow: number | undefined
let i = 0
feature.children?.forEach((f: AnnotationFeatureI) => {
if (f._id === apolloSelectedFeature?._id) {
featureEntry = f
featureRow = i
}
i++
})

if (featureEntry === undefined || featureRow === undefined) {
return
}
const widthPx = featureEntry.length / bpPerPx
const offsetPx = (featureEntry.start - feature.min) / bpPerPx
const startPx = reversed ? xOffset - widthPx : xOffset + offsetPx
const top = (row + featureRow) * rowHeight
ctx.fillStyle = theme?.palette.action.selected ?? 'rgba(0,0,0,08)'
ctx.fillRect(startPx, top, widthPx, rowHeight)
}
}
}

drawHover(stateModel: LinearApolloDisplay, ctx: CanvasRenderingContext2D) {
Expand Down

0 comments on commit c607cf7

Please sign in to comment.