Skip to content

Commit

Permalink
Small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 7, 2024
1 parent a9508ea commit 67e1c6b
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 166 deletions.
2 changes: 1 addition & 1 deletion plugins/alignments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"clean": "rimraf dist esm *.tsbuildinfo"
},
"dependencies": {
"@gmod/bam": "^2.0.0",
"@gmod/bam": "^3.0.0",
"@gmod/cram": "^3.0.3",
"@jbrowse/sv-core": "^2.16.1",
"@mui/icons-material": "^6.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import Formatter from './Formatter'
const SupplementaryAlignments = lazy(() => import('./SupplementaryAlignments'))
const LinkedPairedAlignments = lazy(() => import('./LinkedPairedAlignments'))

const omit = ['clipPos', 'flags']

const AlignmentsFeatureDetails = observer(function (props: {
model: AlignmentFeatureWidgetModel
}) {
Expand All @@ -32,7 +30,6 @@ const AlignmentsFeatureDetails = observer(function (props: {
<Paper data-testid="alignment-side-drawer">
<FeatureDetails
{...props}
omit={omit}
// @ts-expect-error
descriptions={{ ...tags, tags: tags }}
feature={feat}
Expand Down
21 changes: 13 additions & 8 deletions plugins/alignments/src/BamAdapter/BamSlightlyLazyFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { BamRecord } from '@gmod/bam'

// locals
import { getClip, getMismatches } from '../MismatchParser'
import { getMismatches, parseCigar } from '../MismatchParser'
import BamAdapter from './BamAdapter'

export default class BamSlightlyLazyFeature implements Feature {
Expand Down Expand Up @@ -41,10 +41,14 @@ export default class BamSlightlyLazyFeature implements Feature {
return undefined
}

get fields() {
get parsedCigar() {
return parseCigar(this.record.CIGAR)
}

get fields(): SimpleFeatureSerialized {
const r = this.record
const a = this.adapter

const p = r.isPaired()
return {
id: this.id(),
start: r.start,
Expand All @@ -61,16 +65,16 @@ export default class BamSlightlyLazyFeature implements Feature {
seq: r.seq,
type: 'match',
pair_orientation: r.pair_orientation,
next_ref: r.isPaired() ? a.refIdToName(r.next_refid) : undefined,
next_pos: r.isPaired() ? r.next_pos : undefined,
next_segment_position: r.isPaired()
next_ref: p ? a.refIdToName(r.next_refid) : undefined,
next_pos: p ? r.next_pos : undefined,
next_segment_position: p
? `${a.refIdToName(r.next_refid)}:${r.next_pos + 1}`
: undefined,
uniqueId: this.id(),
}
}

toJSON() {
toJSON(): SimpleFeatureSerialized {
return this.fields
}
}
Expand All @@ -80,7 +84,7 @@ function cacheGetter<T>(ctor: { prototype: T }, prop: keyof T): void {
if (!desc) {
throw new Error('t1')
}
// eslint-disable-next-line @typescript-eslint/unbound-method

const getter = desc.get
if (!getter) {
throw new Error('t2')
Expand All @@ -95,3 +99,4 @@ function cacheGetter<T>(ctor: { prototype: T }, prop: keyof T): void {
}

cacheGetter(BamSlightlyLazyFeature, 'fields')
cacheGetter(BamSlightlyLazyFeature, 'parsedCigar')
Loading

0 comments on commit 67e1c6b

Please sign in to comment.