-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce some work the BAM parser has to do
- Loading branch information
Showing
14 changed files
with
620 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
plugins/alignments/src/MismatchParser/__snapshots__/index.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`more skip 1`] = ` | ||
[ | ||
{ | ||
"altbase": "G", | ||
"base": "A", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 6, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"altbase": "C", | ||
"base": "A", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 11, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"base": "1", | ||
"length": 0, | ||
"start": 31, | ||
"type": "insertion", | ||
}, | ||
{ | ||
"altbase": "G", | ||
"base": "C", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 32, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"altbase": "A", | ||
"base": "C", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 34, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"altbase": "C", | ||
"base": "C", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 40, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"altbase": "A", | ||
"base": "C", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 46, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"base": "*", | ||
"length": 1, | ||
"start": 48, | ||
"type": "deletion", | ||
}, | ||
{ | ||
"altbase": "A", | ||
"base": "G", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 52, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"altbase": "G", | ||
"base": "G", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 68, | ||
"type": "mismatch", | ||
}, | ||
{ | ||
"altbase": "G", | ||
"base": "G", | ||
"length": 1, | ||
"qual": undefined, | ||
"start": 70, | ||
"type": "mismatch", | ||
}, | ||
] | ||
`; |
98 changes: 98 additions & 0 deletions
98
plugins/alignments/src/MismatchParser/cigarToMismatches.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Mismatch } from '../shared/types' | ||
import type { Buffer } from 'buffer' | ||
|
||
export function cigarToMismatches( | ||
ops: string[], | ||
seq?: string, | ||
ref?: string, | ||
qual?: Buffer, | ||
) { | ||
let roffset = 0 // reference offset | ||
let soffset = 0 // seq offset | ||
const mismatches: Mismatch[] = [] | ||
const hasRefAndSeq = ref && seq | ||
for (let i = 0; i < ops.length; i += 2) { | ||
const len = +ops[i]! | ||
const op = ops[i + 1]! | ||
|
||
if (op === 'M' || op === '=' || op === 'E') { | ||
if (hasRefAndSeq) { | ||
for (let j = 0; j < len; j++) { | ||
if ( | ||
// @ts-ignore in the full yarn build of the repo, this says that | ||
// object is possibly undefined for some reason, ignored | ||
seq[soffset + j].toUpperCase() !== ref[roffset + j].toUpperCase() | ||
) { | ||
mismatches.push({ | ||
start: roffset + j, | ||
type: 'mismatch', | ||
base: seq[soffset + j]!, | ||
altbase: ref[roffset + j]!, | ||
length: 1, | ||
}) | ||
} | ||
} | ||
} | ||
soffset += len | ||
} | ||
if (op === 'I') { | ||
mismatches.push({ | ||
start: roffset, | ||
type: 'insertion', | ||
base: `${len}`, | ||
length: 0, | ||
}) | ||
soffset += len | ||
} else if (op === 'D') { | ||
mismatches.push({ | ||
start: roffset, | ||
type: 'deletion', | ||
base: '*', | ||
length: len, | ||
}) | ||
} else if (op === 'N') { | ||
mismatches.push({ | ||
start: roffset, | ||
type: 'skip', | ||
base: 'N', | ||
length: len, | ||
}) | ||
} else if (op === 'X') { | ||
const r = seq?.slice(soffset, soffset + len) || [] | ||
const q = qual?.subarray(soffset, soffset + len) || [] | ||
|
||
for (let j = 0; j < len; j++) { | ||
mismatches.push({ | ||
start: roffset + j, | ||
type: 'mismatch', | ||
base: r[j]!, | ||
qual: q[j]!, | ||
length: 1, | ||
}) | ||
} | ||
soffset += len | ||
} else if (op === 'H') { | ||
mismatches.push({ | ||
start: roffset, | ||
type: 'hardclip', | ||
base: `H${len}`, | ||
cliplen: len, | ||
length: 1, | ||
}) | ||
} else if (op === 'S') { | ||
mismatches.push({ | ||
start: roffset, | ||
type: 'softclip', | ||
base: `S${len}`, | ||
cliplen: len, | ||
length: 1, | ||
}) | ||
soffset += len | ||
} | ||
|
||
if (op !== 'I' && op !== 'S' && op !== 'H') { | ||
roffset += len | ||
} | ||
} | ||
return mismatches | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// get relative reference sequence positions for positions given relative to | ||
// the read sequence | ||
export function getNextRefPos(cigarOps: string[], positions: number[]) { | ||
let readPos = 0 | ||
let refPos = 0 | ||
let currPos = 0 | ||
const ret = [] | ||
for (let i = 0; i < cigarOps.length && currPos < positions.length; i += 2) { | ||
const len = +cigarOps[i]! | ||
const op = cigarOps[i + 1]! | ||
if (op === 'S' || op === 'I') { | ||
for (let i = 0; i < len && currPos < positions.length; i++) { | ||
if (positions[currPos] === readPos + i) { | ||
currPos++ | ||
} | ||
} | ||
readPos += len | ||
} else if (op === 'D' || op === 'N') { | ||
refPos += len | ||
} else if (op === 'M' || op === 'X' || op === '=') { | ||
for (let i = 0; i < len && currPos < positions.length; i++) { | ||
if (positions[currPos] === readPos + i) { | ||
ret.push({ | ||
ref: refPos + i, | ||
idx: currPos, | ||
}) | ||
currPos++ | ||
} | ||
} | ||
readPos += len | ||
refPos += len | ||
} | ||
} | ||
return ret | ||
} |
Oops, something went wrong.