Skip to content

Commit

Permalink
More refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 10, 2024
1 parent 071d8cb commit 93e1086
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5540,
"flags": 16,
"id": "test-10158054",
"name": "ctgA_5060_5540_1:0:0_3:1:0_15a3",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -36,7 +35,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5541,
"flags": 16,
"id": "test-10158322",
"name": "ctgA_4973_5541_1:0:0_1:0:0_1569",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -66,7 +64,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5544,
"flags": 0,
"id": "test-10158581",
"name": "ctgA_5445_5947_3:1:0_2:0:0_2b9",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -96,7 +93,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5553,
"flags": 0,
"id": "test-10158847",
"name": "ctgA_5454_5906_0:1:0_2:0:0_d8a",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -126,7 +122,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5554,
"flags": 0,
"id": "test-12607066",
"name": "ctgA_5455_5964_2:0:0_2:0:0_23e2",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -156,7 +151,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5559,
"flags": 16,
"id": "test-12607328",
"name": "ctgA_5153_5559_3:0:0_1:1:0_11ac",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -186,7 +180,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5560,
"flags": 0,
"id": "test-12607590",
"name": "ctgA_5461_5986_1:1:0_3:0:0_200e",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -216,7 +209,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5568,
"flags": 0,
"id": "test-12607851",
"name": "ctgA_5469_5932_0:0:0_2:0:0_6f8",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -246,7 +238,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5594,
"flags": 16,
"id": "test-12608107",
"name": "ctgA_5079_5594_1:0:0_2:0:0_d64",
"next_pos": undefined,
"next_ref": undefined,
Expand Down Expand Up @@ -276,7 +267,6 @@ exports[`adapter can fetch features from volvox.bam 1`] = `
"CIGAR": "100M",
"end": 5596,
"flags": 0,
"id": "test-12608367",
"name": "ctgA_5497_6082_1:0:0_2:0:0_b2",
"next_pos": undefined,
"next_ref": undefined,
Expand Down
23 changes: 14 additions & 9 deletions plugins/alignments/src/CramAdapter/CramSlightlyLazyFeature.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
Feature,
SimpleFeatureSerialized,
} from '@jbrowse/core/util/simpleFeature'
import { Feature, SimpleFeatureSerialized } from '@jbrowse/core/util'
import { CramRecord } from '@gmod/cram'

// locals
import CramAdapter from './CramAdapter'
import { readFeaturesToCIGAR, readFeaturesToMismatches } from './util'
import { mdToMismatches, parseCigar } from '../MismatchParser'

export default class CramSlightlyLazyFeature implements Feature {
// uses parameter properties to automatically create fields on the class
Expand All @@ -28,10 +26,6 @@ export default class CramSlightlyLazyFeature implements Feature {
return this.start + (this.record.lengthOnRef ?? 1)
}

get type() {
return 'match'
}

get score() {
return this.record.mappingQuality
}
Expand Down Expand Up @@ -122,11 +116,22 @@ export default class CramSlightlyLazyFeature implements Feature {
}

get mismatches() {
return readFeaturesToMismatches(
const mismatches = readFeaturesToMismatches(
this.record.readFeatures,
this.start,
this.qualRaw,
)
return this.tags.MD && this.seq
? mismatches.concat(
mdToMismatches(
this.tags.MD,
parseCigar(this.CIGAR),
mismatches,
this.seq,
this.qualRaw,
),
)
: mismatches
}

get fields(): SimpleFeatureSerialized {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
[
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5540,
"flags": 16,
"is_paired": false,
"name": "ctgA_5060_5540_1:0:0_3:1:0_15a3",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -29,11 +31,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5541,
"flags": 16,
"is_paired": false,
"name": "ctgA_4973_5541_1:0:0_1:0:0_1569",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -54,11 +58,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5544,
"flags": 0,
"is_paired": false,
"name": "ctgA_5445_5947_3:1:0_2:0:0_2b9",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -79,11 +85,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5553,
"flags": 0,
"is_paired": false,
"name": "ctgA_5454_5906_0:1:0_2:0:0_d8a",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -104,11 +112,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5554,
"flags": 0,
"is_paired": false,
"name": "ctgA_5455_5964_2:0:0_2:0:0_23e2",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -129,11 +139,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5559,
"flags": 16,
"is_paired": false,
"name": "ctgA_5153_5559_3:0:0_1:1:0_11ac",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -154,11 +166,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5560,
"flags": 0,
"is_paired": false,
"name": "ctgA_5461_5986_1:1:0_3:0:0_200e",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -179,11 +193,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5568,
"flags": 0,
"is_paired": false,
"name": "ctgA_5469_5932_0:0:0_2:0:0_6f8",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -204,11 +220,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5594,
"flags": 16,
"is_paired": false,
"name": "ctgA_5079_5594_1:0:0_2:0:0_d64",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand All @@ -229,11 +247,13 @@ exports[`adapter can fetch features from volvox-sorted.cram 1`] = `
},
{
"CIGAR": "100M",
"clipPos": 0,
"end": 5596,
"flags": 0,
"is_paired": false,
"name": "ctgA_5497_6082_1:0:0_2:0:0_b2",
"next_pos": undefined,
"next_ref": undefined,
"next_segment_position": undefined,
"pair_orientation": undefined,
"qual": "17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17",
"refName": "ctgA",
"score": 37,
Expand Down
14 changes: 2 additions & 12 deletions plugins/alignments/src/CramAdapter/util.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { CramRecord } from '@gmod/cram'
import { Mismatch } from '../shared/types'

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,
Expand Down Expand Up @@ -48,7 +38,7 @@ export function readFeaturesToMismatches(
mismatches[j++] = {
start: refPos,
length: 1,
base: sub,
base: sub!,
qual: qual?.[pos - 1],
altbase: ref?.toUpperCase(),
type: 'mismatch',
Expand Down
13 changes: 2 additions & 11 deletions plugins/alignments/src/MismatchParser/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { Feature } from '@jbrowse/core/util'
import type { Buffer } from 'buffer'
import { Mismatch } from '../shared/types'

export interface Mismatch {
qual?: number
start: number
length: number
type: string
base: string
altbase?: string
seq?: string
cliplen?: number
}
const mdRegex = new RegExp(/(\d+|\^[a-z]+|[a-z])/gi)
const cigarRegex = new RegExp(/([MIDNSHPX=])/)
const startClip = new RegExp(/(\d+)[SH]$/)
Expand Down Expand Up @@ -125,7 +116,7 @@ export function mdToMismatches(
ops: string[],
cigarMismatches: Mismatch[],
seq: string,
qual?: Buffer,
qual?: Buffer | number[] | null,
) {
let curr: Mismatch = { start: 0, base: '', length: 0, type: 'mismatch' }
let lastCigar = 0
Expand Down
2 changes: 1 addition & 1 deletion plugins/alignments/src/PileupRenderer/layoutFeature.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bpSpanPx, Feature, Region } from '@jbrowse/core/util'
import { BaseLayout } from '@jbrowse/core/util/layouts'
import { Mismatch } from '../shared/types'
// locals
import { Mismatch } from '../MismatchParser'

export interface LayoutRecord {
feature: Feature
Expand Down
2 changes: 1 addition & 1 deletion plugins/alignments/src/PileupRenderer/renderMismatches.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { bpSpanPx, measureText } from '@jbrowse/core/util'
import { Mismatch } from '../MismatchParser'
import { fillRect, LayoutFeature } from './util'
import { RenderArgsWithColor } from './makeImageData'
import { colord } from '@jbrowse/core/util/colord'
import { Mismatch } from '../shared/types'

export function renderMismatches({
ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { bpSpanPx } from '@jbrowse/core/util'
import { Theme } from '@mui/material'

// locals
import { Mismatch } from '../MismatchParser'
import { RenderArgsDeserializedWithFeaturesAndLayout } from './PileupRenderer'
import { fillRect, getCharWidthHeight, LayoutFeature } from './util'
import { Mismatch } from '../shared/types'

export function renderSoftClipping({
ctx,
Expand Down
Loading

0 comments on commit 93e1086

Please sign in to comment.