-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
100 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
3 changes: 3 additions & 0 deletions
3
plugins/alignments/src/CramAdapter/__snapshots__/util.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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`cram read features 1`] = `[]`; |
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,7 @@ | ||
import { readFeaturesToMismatches } from './util' | ||
|
||
test('cram read features', () => { | ||
expect( | ||
readFeaturesToMismatches([{ code: 'i', pos: 5, refPos: 5, data: 'x' }], 0), | ||
).toMatchSnapshot() | ||
}) |
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,120 @@ | ||
import { CramRecord } from '@gmod/cram' | ||
|
||
type ReadFeatures = CramRecord['readFeatures'] | ||
|
||
export interface Mismatch { | ||
qual?: number | ||
start: number | ||
length: number | ||
type: string | ||
base: string | undefined | ||
altbase?: string | ||
seq?: string | ||
cliplen?: number | ||
} | ||
|
||
export function readFeaturesToMismatches( | ||
readFeatures: ReadFeatures, | ||
start: number, | ||
qual?: number[] | null, | ||
) { | ||
if (!readFeatures) { | ||
return [] | ||
} | ||
const mismatches: Mismatch[] = new Array(readFeatures.length) | ||
let j = 0 | ||
let insLen = 0 | ||
|
||
let refPos = 0 | ||
let sublen = 0 | ||
let lastPos = start | ||
|
||
for (let i = 0; i < readFeatures.length; i++) { | ||
const f = readFeatures[i] | ||
const { code, pos, data, sub, ref } = f | ||
sublen = refPos - lastPos | ||
lastPos = refPos | ||
|
||
if (sublen && insLen > 0) { | ||
mismatches[j++] = { | ||
start: refPos, | ||
type: 'insertion', | ||
base: `${insLen}`, | ||
length: 0, | ||
} | ||
insLen = 0 | ||
} | ||
refPos = f.refPos - 1 - start | ||
|
||
if (code === 'X') { | ||
// substitution | ||
mismatches[j++] = { | ||
start: refPos, | ||
length: 1, | ||
base: sub, | ||
qual: qual?.[pos], | ||
altbase: ref, | ||
type: 'mismatch', | ||
} | ||
} else if (code === 'I') { | ||
// insertion | ||
mismatches[j++] = { | ||
start: refPos, | ||
type: 'insertion', | ||
base: `${data.length}`, | ||
length: 0, | ||
} | ||
} else if (code === 'N') { | ||
// reference skip | ||
mismatches[j++] = { | ||
type: 'skip', | ||
length: data, | ||
start: refPos, | ||
base: 'N', | ||
} | ||
} else if (code === 'S') { | ||
// soft clip | ||
const len = data.length | ||
mismatches[j++] = { | ||
start: refPos, | ||
type: 'softclip', | ||
base: `S${len}`, | ||
cliplen: len, | ||
length: 1, | ||
} | ||
} else if (code === 'P') { | ||
// padding | ||
} else if (code === 'H') { | ||
// hard clip | ||
const len = data | ||
mismatches[j++] = { | ||
start: refPos, | ||
type: 'hardclip', | ||
base: `H${len}`, | ||
cliplen: len, | ||
length: 1, | ||
} | ||
} else if (code === 'D') { | ||
// deletion | ||
mismatches[j++] = { | ||
type: 'deletion', | ||
length: data, | ||
start: refPos, | ||
base: '*', | ||
} | ||
} else if (code === 'b') { | ||
// stretch of bases | ||
} else if (code === 'q') { | ||
// stretch of qual scores | ||
} else if (code === 'B') { | ||
// a pair of [base, qual] | ||
} else if (code === 'i') { | ||
// single-base insertion | ||
// insertion | ||
insLen++ | ||
} else if (code === 'Q') { | ||
// single quality value | ||
} | ||
} | ||
return mismatches.slice(0, j) | ||
} |