Skip to content

Commit

Permalink
Add more places where feature.get('seq') can return undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 4, 2023
1 parent 0761e0c commit 82371cb
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 76 deletions.
20 changes: 14 additions & 6 deletions plugins/alignments/src/LinearPileupDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,23 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
* #getter
*/
get rendererConfig() {
const configBlob =
getConf(self, ['renderers', self.rendererTypeName]) || {}
const {
featureHeight,
noSpacing,
trackMaxHeight,
mismatchAlpha,
rendererTypeName,
} = self
const configBlob = getConf(self, ['renderers', rendererTypeName]) || {}
return self.rendererType.configSchema.create(
{
...configBlob,
height: self.featureHeight,
noSpacing: self.noSpacing,
maxHeight: self.trackMaxHeight,
mismatchAlpha: self.mismatchAlpha,
...(featureHeight !== undefined ? { height: featureHeight } : {}),
...(noSpacing !== undefined ? { noSpacing } : {}),
...(mismatchAlpha !== undefined ? { mismatchAlpha } : {}),
...(trackMaxHeight !== undefined
? { maxHeight: trackMaxHeight }
: {}),
},
getEnv(self),
)
Expand Down
15 changes: 11 additions & 4 deletions plugins/alignments/src/PileupRenderer/PileupRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class PileupRenderer extends BoxRendererType {
// Expand the start and end of feature when softclipping enabled
if (showSoftClip) {
const mismatches = feature.get('mismatches') as Mismatch[] | undefined
const seq = feature.get('seq') as string
const seq = feature.get('seq') as string | undefined
if (seq && mismatches) {
for (let i = 0; i < mismatches.length; i += 1) {
const { type, start, cliplen = 0 } = mismatches[i]
Expand Down Expand Up @@ -454,9 +454,12 @@ export default class PileupRenderer extends BoxRendererType {

const cigar = feature.get('CIGAR')
const start = feature.get('start')
const seq = feature.get('seq')
const seq = feature.get('seq') as string | undefined
const strand = feature.get('strand')
const cigarOps = parseCigar(cigar)
if (!seq) {
return
}

const modifications = getModificationPositions(mm, seq, strand)

Expand Down Expand Up @@ -524,10 +527,14 @@ export default class PileupRenderer extends BoxRendererType {
const cigar = feature.get('CIGAR')
const fstart = feature.get('start')
const fend = feature.get('end')
const seq = feature.get('seq')
const seq = feature.get('seq') as string | undefined
const strand = feature.get('strand')
const cigarOps = parseCigar(cigar)

if (!seq) {
return
}

const methBins = new Array(region.end - region.start).fill(0)
const modifications = getModificationPositions(mm, seq, strand)
for (let i = 0; i < modifications.length; i++) {
Expand Down Expand Up @@ -1038,7 +1045,7 @@ export default class PileupRenderer extends BoxRendererType {
const [region] = regions
const minFeatWidth = readConfObject(config, 'minSubfeatureWidth')
const mismatches = feature.get('mismatches') as Mismatch[] | undefined
const seq = feature.get('seq')
const seq = feature.get('seq') as string | undefined
const { charWidth, charHeight } = this.getCharWidthHeight()
const { bases } = theme.palette
const colorForBase: { [key: string]: string } = {
Expand Down
113 changes: 58 additions & 55 deletions plugins/alignments/src/SNPCoverageAdapter/generateCoverageBins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,30 @@ export default async function generateCoverageBins(
}

if (colorBy?.type === 'modifications') {
const seq = feature.get('seq') as string
const seq = feature.get('seq') as string | undefined
const mm = (getTagAlt(feature, 'MM', 'Mm') as string) || ''
const ops = parseCigar(feature.get('CIGAR'))
const fend = feature.get('end')

getModificationPositions(mm, seq, fstrand).forEach(
({ type, positions }) => {
const mod = `mod_${type}`
for (const pos of getNextRefPos(ops, positions)) {
const epos = pos + fstart - region.start
if (epos >= 0 && epos < bins.length && pos + fstart < fend) {
const bin = bins[epos]
if (bin) {
inc(bin, fstrand, 'cov', mod)
} else {
console.warn(
'Undefined position in modifications snpcoverage encountered',
)
if (seq) {
getModificationPositions(mm, seq, fstrand).forEach(
({ type, positions }) => {
const mod = `mod_${type}`
for (const pos of getNextRefPos(ops, positions)) {
const epos = pos + fstart - region.start
if (epos >= 0 && epos < bins.length && pos + fstart < fend) {
const bin = bins[epos]
if (bin) {
inc(bin, fstrand, 'cov', mod)
} else {
console.warn(
'Undefined position in modifications snpcoverage encountered',
)
}
}
}
}
},
)
},
)
}
}

// methylation based coloring takes into account both reference
Expand All @@ -142,49 +143,51 @@ export default async function generateCoverageBins(
'no region sequence detected, need sequenceAdapter configuration',
)
}
const seq = feature.get('seq')
const seq = feature.get('seq') as string | undefined
const mm = getTagAlt(feature, 'MM', 'Mm') || ''
const methBins = new Array(region.end - region.start).fill(0)
const ops = parseCigar(feature.get('CIGAR'))

getModificationPositions(mm, seq, fstrand).forEach(
({ type, positions }) => {
// we are processing methylation
if (type === 'm') {
for (const pos of getNextRefPos(ops, positions)) {
const epos = pos + fstart - region.start
if (epos >= 0 && epos < methBins.length) {
methBins[epos] = 1
if (seq) {
getModificationPositions(mm, seq, fstrand).forEach(
({ type, positions }) => {
// we are processing methylation
if (type === 'm') {
for (const pos of getNextRefPos(ops, positions)) {
const epos = pos + fstart - region.start
if (epos >= 0 && epos < methBins.length) {
methBins[epos] = 1
}
}
}
}
},
)

for (let j = fstart; j < fend; j++) {
const i = j - region.start
if (i >= 0 && i < bins.length - 1) {
const l1 = regionSeq[i].toLowerCase()
const l2 = regionSeq[i + 1].toLowerCase()
const bin = bins[i]
const bin1 = bins[i + 1]

// color
if (l1 === 'c' && l2 === 'g') {
if (methBins[i] || methBins[i + 1]) {
inc(bin, fstrand, 'cov', 'meth')
inc(bin1, fstrand, 'cov', 'meth')
bins[i].ref--
bins[i][fstrand]--
bins[i + 1].ref--
bins[i + 1][fstrand]--
} else {
inc(bin, fstrand, 'cov', 'unmeth')
inc(bin1, fstrand, 'cov', 'unmeth')
bins[i].ref--
bins[i][fstrand]--
bins[i + 1].ref--
bins[i + 1][fstrand]--
},
)

for (let j = fstart; j < fend; j++) {
const i = j - region.start
if (i >= 0 && i < bins.length - 1) {
const l1 = regionSeq[i].toLowerCase()
const l2 = regionSeq[i + 1].toLowerCase()
const bin = bins[i]
const bin1 = bins[i + 1]

// color
if (l1 === 'c' && l2 === 'g') {
if (methBins[i] || methBins[i + 1]) {
inc(bin, fstrand, 'cov', 'meth')
inc(bin1, fstrand, 'cov', 'meth')
bins[i].ref--
bins[i][fstrand]--
bins[i + 1].ref--
bins[i + 1][fstrand]--
} else {
inc(bin, fstrand, 'cov', 'unmeth')
inc(bin1, fstrand, 'cov', 'unmeth')
bins[i].ref--
bins[i][fstrand]--
bins[i + 1].ref--
bins[i + 1][fstrand]--
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default function ReadVsRefDialog({
})
features.sort((a, b) => a.clipPos - b.clipPos)

const featSeq = feature.get('seq') as string
const featSeq = feature.get('seq') as string | undefined

// the config feature store includes synthetic mate features
// mapped to the read assembly
Expand Down
15 changes: 5 additions & 10 deletions plugins/wiggle/src/LinearWiggleDisplay/models/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,6 @@ function stateModelFactory(
* #getter
*/
get rendererConfig() {
const configBlob =
getConf(self, ['renderers', self.rendererTypeName]) || {}

const {
color,
displayCrossHatches,
Expand All @@ -355,8 +352,9 @@ function stateModelFactory(
posColor,
summaryScoreMode,
scaleType,
rendererTypeName,
} = self

const configBlob = getConf(self, ['renderers', rendererTypeName]) || {}
return self.rendererType.configSchema.create(
{
...configBlob,
Expand All @@ -382,15 +380,13 @@ function stateModelFactory(
* #getter
*/
get filled() {
const { fill, rendererConfig: conf } = self
return fill ?? readConfObject(conf, 'filled')
return readConfObject(self.rendererConfig, 'filled')
},
/**
* #getter
*/
get summaryScoreModeSetting() {
const { summaryScoreMode, rendererConfig: conf } = self
return summaryScoreMode ?? readConfObject(conf, 'summaryScoreMode')
return readConfObject(self.rendererConfig, 'summaryScoreMode')
},
/**
* #getter
Expand Down Expand Up @@ -460,8 +456,7 @@ function stateModelFactory(
* #getter
*/
get displayCrossHatchesSetting() {
const { displayCrossHatches: hatches, rendererConfig: conf } = self
return hatches ?? readConfObject(conf, 'displayCrossHatches')
return readConfObject(self.rendererConfig, 'displayCrossHatches')
},
}
})
Expand Down

0 comments on commit 82371cb

Please sign in to comment.