Skip to content

Commit 4e90d4f

Browse files
authored
Optimizations for SNPCoverageAdapter (#5380)
1 parent c09d7e8 commit 4e90d4f

File tree

21 files changed

+1269
-931
lines changed

21 files changed

+1269
-931
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default defineConfig(
2222
'config/jest/*',
2323
'benchmarks/*',
2424
'**/build/**/*',
25-
'**/dist/**/*',
25+
'**/dist*/**/*',
2626
'scripts/analyze_cpuprof.ts',
2727
'**/esm/**/*',
2828
'**/public/**/*',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
"storybook": "^10.1.11",
132132
"style-loader": "^4.0.0",
133133
"terser-webpack-plugin": "^5.2.5",
134-
"ts-node": "^10.4.0",
135134
"tslib": "^2.0.1",
136135
"typescript": "^5.8.0",
137136
"typescript-eslint": "^8.51.0",

packages/core/ui/EditableTypography.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { forwardRef, useState } from 'react'
22

33
import { makeStyles } from '@jbrowse/core/util/tss-react'
4-
import useMeasure from '../util/useMeasure'
4+
import useMeasure from '@jbrowse/core/util/useMeasure'
55
import { InputBase, Typography, useTheme } from '@mui/material'
66

77
import type { TypographyProps } from '@mui/material'

packages/core/util/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type React from 'react'
22
import { useEffect, useRef, useState } from 'react'
33

44
import { unzip } from '@gmod/bgzf-filehandle'
5-
import useMeasure from './useMeasure'
5+
import useMeasure from '@jbrowse/core/util/useMeasure'
66
import {
77
getEnv as getEnvMST,
88
getParent,

plugins/alignments/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist_branch*
21.2 MB
Binary file not shown.
65.8 KB
Binary file not shown.

plugins/alignments/build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CURRENT_BRANCH=$(git branch --show-current)
6+
BRANCH1="${1:-main}"
7+
BRANCH2="${2:-$CURRENT_BRANCH}"
8+
9+
if ! git diff --quiet || ! git diff --cached --quiet; then
10+
echo "Error: Uncommitted changes detected. Please commit or stash your changes first."
11+
exit 1
12+
fi
13+
14+
rm -rf dist_branch1 dist_branch2
15+
16+
echo "Building $BRANCH1 branch..."
17+
git checkout "$BRANCH1"
18+
yarn build
19+
mv dist dist_branch1
20+
echo "$BRANCH1" >dist_branch1/branchname.txt
21+
22+
echo "Building $BRANCH2 branch..."
23+
git checkout "$BRANCH2"
24+
yarn build
25+
mv dist dist_branch2
26+
echo "$BRANCH2" >dist_branch2/branchname.txt
27+
28+
echo "Build complete!"
29+
echo "$BRANCH1 build: dist_branch1/index.js"
30+
echo "$BRANCH2 build: dist_branch2/index.js"

plugins/alignments/src/BamAdapter/forEachMismatchNumeric.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,33 @@ export function forEachMismatchNumeric(
141141
soffset += len
142142
roffset += len
143143
} else if (op === CIGAR_I) {
144-
let insertedBases = ''
145-
for (let j = 0; j < len && soffset + j < seqLength; j++) {
146-
const seqIdx = soffset + j
147-
const sb = numericSeq[seqIdx >> 1]!
148-
const nibble = (sb >> ((1 - (seqIdx & 1)) << 2)) & 0xf
149-
insertedBases += SEQRET[nibble]!
144+
// Optimized insertion base extraction - avoid string concat for common cases
145+
const safeLen = Math.min(len, seqLength - soffset)
146+
let insertedBases: string
147+
if (safeLen === 1) {
148+
// Single base insertion - most common case
149+
const sb = numericSeq[soffset >> 1]!
150+
const nibble = (sb >> ((1 - (soffset & 1)) << 2)) & 0xf
151+
insertedBases = SEQRET[nibble]!
152+
} else if (safeLen === 2) {
153+
// Two base insertion - second most common
154+
const seqIdx0 = soffset
155+
const sb0 = numericSeq[seqIdx0 >> 1]!
156+
const nibble0 = (sb0 >> ((1 - (seqIdx0 & 1)) << 2)) & 0xf
157+
const seqIdx1 = soffset + 1
158+
const sb1 = numericSeq[seqIdx1 >> 1]!
159+
const nibble1 = (sb1 >> ((1 - (seqIdx1 & 1)) << 2)) & 0xf
160+
insertedBases = SEQRET[nibble0]! + SEQRET[nibble1]!
161+
} else {
162+
// Longer insertions - use array join (avoids intermediate string allocations)
163+
const bases = new Array<string>(safeLen)
164+
for (let j = 0; j < safeLen; j++) {
165+
const seqIdx = soffset + j
166+
const sb = numericSeq[seqIdx >> 1]!
167+
const nibble = (sb >> ((1 - (seqIdx & 1)) << 2)) & 0xf
168+
bases[j] = SEQRET[nibble]!
169+
}
170+
insertedBases = bases.join('')
150171
}
151172
callback(INSERTION_TYPE, roffset, 0, insertedBases, -1, 0, len)
152173
soffset += len
@@ -198,6 +219,9 @@ export function forEachMismatchNumeric(
198219
} else if (mdMatchRemaining > 0) {
199220
mdMatchRemaining--
200221
}
222+
} else if (ref) {
223+
// No MD tag - get reference base from ref string
224+
altbaseCode = ref.charCodeAt(roffset + j)
201225
}
202226

203227
callback(

plugins/alignments/src/CramAdapter/readFeaturesToCIGAR.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const NUMERIC_CIGAR_CODES = [
55
77, 73, 68, 78, 83, 72, 80, 61, 88, 63, 63, 63, 63, 63, 63, 63,
66
]
77

8-
function numericCigarToString(numeric: Uint32Array): string {
8+
function numericCigarToString(numeric: ArrayLike<number>): string {
99
let result = ''
1010
for (let i = 0, l = numeric.length; i < l; i++) {
1111
const packed = numeric[i]!

0 commit comments

Comments
 (0)