Skip to content

Commit

Permalink
sequence highlighting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed May 23, 2024
1 parent 5b51404 commit 134ab83
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,6 @@ export class CanonicalGeneGlyph extends Glyph {
if (feature.type === 'CDS') {
const parentFeature = this.getParentFeature(feature, topLevelFeature)
const cdsLocs = this.getDiscontinuousLocations(parentFeature, feature)
const { cdsLocations } = parentFeature

// console.log('parentFeature type', parentFeature.type)
console.log('cdsLocations', cdsLocations)
console.log('cdsLocs', cdsLocs)

for (const cdsLoc of cdsLocs) {
this.drawShadeForFeature(
stateModel,
Expand Down Expand Up @@ -712,8 +706,8 @@ export class CanonicalGeneGlyph extends Glyph {
const dl = exonCDSRelation.cdsDL
if (
cdsDL.start === dl?.start &&
cdsDL.end === dl.end
// && cdsDL.phase === dl.phase
cdsDL.end === dl.end &&
cdsDL.phase === dl.phase
) {
idx = i
break
Expand Down Expand Up @@ -754,7 +748,7 @@ export class CanonicalGeneGlyph extends Glyph {
? {
start: cdsDLForExon.start,
end: cdsDLForExon.end,
phase: undefined,
phase: cdsDLForExon.phase,
}
: undefined,
})
Expand Down Expand Up @@ -967,8 +961,8 @@ export class CanonicalGeneGlyph extends Glyph {
for (const f of featuresForRow) {
if (
f.start !== undefined &&
f.end !== undefined
// && f.phase !== undefined
f.end !== undefined &&
f.phase !== undefined
) {
if (bp >= f.start && bp <= f.end && f.parent) {
featureFromLayout = f.annotationFeature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,48 +119,6 @@ export abstract class Glyph {
parentFeature: AnnotationFeatureNew,
cdsFeature: AnnotationFeatureNew,
): CDSDiscontinuousLocation[] {
// const exons: AnnotationFeatureNew[] = []

// 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[] = []

if (parentFeature?.type !== 'mRNA') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,24 @@ function getMousePosition(
return { x, y, refName, bp, regionNumber }
}

/* function getSeqRow(feature: AnnotationFeatureNew, bpPerPx: number) {
function getSeqRow(
feature: AnnotationFeatureNew,
bpPerPx: number,
phase?: number,
) {
const rowOffset = bpPerPx <= 1 ? 5 : 3
if (feature.type === 'CDS' && feature.phase !== undefined) {
if (feature.type === 'CDS' && phase !== undefined) {
return feature.strand === -1
? ((feature.max - feature.phase) % 3) + rowOffset
: Math.abs(((feature.min + feature.phase) % 3) - 2)
? ((feature.max - phase) % 3) + rowOffset
: Math.abs(((feature.min + phase) % 3) - 2)
}

if (bpPerPx <= 1) {
return feature.strand === -1 ? 4 : 3
}

return
} */
}

function highlightSeq(
seqTrackOverlayctx: CanvasRenderingContext2D,
Expand Down Expand Up @@ -222,60 +226,67 @@ export function mouseEventsSeqHightlightModelFactory(
if (!apolloHover) {
return
}
const { feature, mousePosition } = apolloHover
if (!feature || !mousePosition) {
const { feature, glyph, mousePosition, topLevelFeature } =
apolloHover
if (!feature || !mousePosition || !glyph) {
return
}

// for (const [idx, region] of regions.entries()) {
// const row = getSeqRow(feature, lgv.bpPerPx)
// if (
// feature.discontinuousLocations &&
// feature.discontinuousLocations.length > 0
// ) {
// for (const dl of feature.discontinuousLocations) {
// const offset =
// (lgv.bpToPx({
// refName: region.refName,
// coord: dl.start,
// regionNumber: idx,
// })?.offsetPx ?? 0) - lgv.offsetPx
// const widthPx = (dl.end - dl.start) / lgv.bpPerPx
// const startPx = displayedRegions[idx].reversed
// ? offset - widthPx
// : offset
for (const [idx, region] of regions.entries()) {
if (feature.type === 'CDS') {
const parentFeature = glyph.getParentFeature(
feature,
topLevelFeature,
)
const cdsLocs = glyph.getDiscontinuousLocations(
parentFeature,
feature,
)
for (const dl of cdsLocs) {
const row = getSeqRow(feature, lgv.bpPerPx, dl.phase)
const offset =
(lgv.bpToPx({
refName: region.refName,
coord: dl.start,
regionNumber: idx,
})?.offsetPx ?? 0) - lgv.offsetPx
const widthPx = (dl.end - dl.start) / lgv.bpPerPx
const startPx = displayedRegions[idx].reversed
? offset - widthPx
: offset

// highlightSeq(
// seqTrackOverlayctx,
// theme,
// startPx,
// sequenceRowHeight,
// row,
// widthPx,
// )
// }
// } else {
// const offset =
// (lgv.bpToPx({
// refName: region.refName,
// coord: feature.min,
// regionNumber: idx,
// })?.offsetPx ?? 0) - lgv.offsetPx
// const widthPx = feature.length / lgv.bpPerPx
// const startPx = displayedRegions[idx].reversed
// ? offset - widthPx
// : offset
highlightSeq(
seqTrackOverlayctx,
theme,
startPx,
sequenceRowHeight,
row,
widthPx,
)
}
} else {
const row = getSeqRow(feature, lgv.bpPerPx)
const offset =
(lgv.bpToPx({
refName: region.refName,
coord: feature.min,
regionNumber: idx,
})?.offsetPx ?? 0) - lgv.offsetPx
const widthPx = feature.length / lgv.bpPerPx
const startPx = displayedRegions[idx].reversed
? offset - widthPx
: offset

// highlightSeq(
// seqTrackOverlayctx,
// theme,
// startPx,
// sequenceRowHeight,
// row,
// widthPx,
// )
// }
// }
highlightSeq(
seqTrackOverlayctx,
theme,
startPx,
sequenceRowHeight,
row,
widthPx,
)
}
}
},
{ name: 'LinearApolloDisplayRenderSeqHighlight' },
),
Expand Down

0 comments on commit 134ab83

Please sign in to comment.