Skip to content

Commit 46345d3

Browse files
committed
Bugfixes
1 parent ff35d4d commit 46345d3

12 files changed

Lines changed: 42 additions & 65 deletions

File tree

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default tseslint.config(
1313
'example/*',
1414
'eslint.config.mjs',
1515
'esbuild.mjs',
16+
'vitest.config.ts',
1617
'benchmarks/*',
18+
'test/*',
1719
],
1820
},
1921
{

src/BigMafAdapter/BigMafAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ export default class BigMafAdapter extends BaseFeatureDataAdapter {
3636
}
3737

3838
async getRefNames() {
39-
const { adapter } = await this.setup()
39+
const { adapter } = await this.setupPre()
4040
return adapter.getRefNames()
4141
}
4242

4343
async getHeader() {
44-
const { adapter } = await this.setup()
44+
const { adapter } = await this.setupPre()
4545
return adapter.getHeader()
4646
}
4747

src/LinearMafDisplay/components/useDragSelection.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ export function useDragSelection(
107107
const dragDistanceX = Math.abs(dragEndX - dragStartX)
108108

109109
if (dragDistanceX > MIN_DRAG_DISTANCE) {
110+
const rect = ref.current?.getBoundingClientRect()
111+
const left = rect?.left || 0
112+
const top = rect?.top || 0
110113
setContextCoord({
111114
coord: [event.clientX, event.clientY],
112-
dragEndX: event.clientX,
115+
dragEndX: event.clientX - left,
113116
dragStartX: dragStartX,
114117
dragStartY: dragStartY,
115-
dragEndY: dragEndY,
118+
dragEndY: event.clientY - top,
116119
})
117120
setShowSelectionBox(true)
118121
} else {
@@ -121,7 +124,7 @@ export function useDragSelection(
121124
}
122125
setIsDragging(false)
123126
},
124-
[isDragging, dragStartX, dragEndX, dragStartY, dragEndY, clearSelectionBox],
127+
[ref, isDragging, dragStartX, dragEndX, dragStartY, dragEndY, clearSelectionBox],
125128
)
126129

127130
const handleMouseLeave = useCallback(() => {

src/MafAddTrackWorkflow/AddTrackWorkflow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default function MultiMAFWidget({ model }: { model: AddTrackModel }) {
9696
<FormControl>
9797
<FormLabel>Index type</FormLabel>
9898
<RadioGroup
99-
value={fileTypeChoice}
99+
value={indexTypeChoice}
100100
onChange={event => {
101101
setIndexTypeChoice(event.target.value as IndexTypeOptions)
102102
}}

src/MafSequenceWidget/MafSequenceWidget.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ const MafSequenceWidget = observer(function MafSequenceWidget({
104104

105105
let formatted: string
106106
if (singleLineFormat) {
107-
const maxLabelLength = Math.max(
108-
...samples.map(s => (s.label ?? s.id).length),
109-
)
107+
let maxLabelLength = 0
108+
for (const s of samples) {
109+
const len = (s.label ?? s.id).length
110+
if (len > maxLabelLength) {
111+
maxLabelLength = len
112+
}
113+
}
110114
formatted = fastaSequence
111115
.map((r, idx) => {
112116
const sample = samples[idx]!

src/parseNewick.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default function parseNewick(s: string) {
8181
case ':': // optional length next
8282
break
8383
default: {
84-
const x = tokens[i - 1]!
84+
const x = i > 0 ? tokens[i - 1] : undefined
8585
if (x === ')' || x === '(' || x === ',') {
8686
tree.name = token
8787
} else if (x === ':') {

src/util/__snapshots__/fastaUtils.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`includeInsertions - insertions at multiple positions 1`] = `
1616

1717
exports[`includeInsertions - insertions in multiple samples with different lengths 1`] = `
1818
[
19-
"ac-t-gtac",
19+
"act--gtac",
2020
"actttgtac",
2121
]
2222
`;

src/util/extractSubsequence.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ test('handles a sequence with mixed characters and gaps', () => {
5050

5151
// Positions 2-5 would be G,T,A after skipping gaps
5252
expect(extractedSequence).toBe('GT--A')
53-
expect(actualStart).toBe(5)
53+
expect(actualStart).toBe(4)
5454
})

src/util/extractSubsequence.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
/**
2-
* Helper function to extract a subsequence from an alignment string
3-
* accounting for gaps in the reference sequence
4-
* @param sequence - The alignment sequence
5-
* @param relativeStart - The start position in the reference sequence (without gaps)
6-
* @param relativeEnd - The end position in the reference sequence (without gaps)
7-
* @returns The extracted sequence and the actual start position in the alignment
8-
*/
91
export function extractSubsequence(
102
sequence: string,
113
relativeStart: number,
124
relativeEnd: number,
135
): { extractedSequence: string; actualStart: number } {
14-
// Handle sequence with only gaps
156
if (sequence.split('').every(char => char === '-')) {
167
return {
178
extractedSequence: sequence,
189
actualStart: 0,
1910
}
2011
}
2112

22-
// Create a mapping from non-gap positions to actual positions in the sequence
2313
const nonGapToActualMap: number[] = []
2414

2515
let nonGapCount = 0
@@ -30,41 +20,21 @@ export function extractSubsequence(
3020
}
3121
}
3222

33-
// Handle case where there aren't enough non-gap characters
3423
if (nonGapCount <= relativeStart) {
3524
return {
3625
extractedSequence: sequence,
3726
actualStart: 0,
3827
}
3928
}
4029

41-
// Special cases for test compatibility
42-
if (sequence === 'A--CGT--ACGT' && relativeStart === 2 && relativeEnd === 5) {
43-
return {
44-
extractedSequence: 'GT--A',
45-
actualStart: 5,
46-
}
47-
}
48-
49-
if (sequence === 'A-CGT-ACGT' && relativeStart === 2 && relativeEnd === 6) {
50-
return {
51-
extractedSequence: 'GT-AC',
52-
actualStart: 3,
53-
}
54-
}
55-
56-
// Find start and end indices in the original sequence
57-
const startIndex =
58-
nonGapToActualMap[relativeStart] !== undefined
59-
? nonGapToActualMap[relativeStart]
60-
: 0
30+
const startIndex = nonGapToActualMap[relativeStart] ?? 0
6131
let endIndex = sequence.length
6232

6333
if (
6434
relativeEnd < nonGapCount &&
6535
nonGapToActualMap[relativeEnd] !== undefined
6636
) {
67-
endIndex = nonGapToActualMap[relativeEnd]
37+
endIndex = nonGapToActualMap[relativeEnd]!
6838
}
6939

7040
return {

src/util/fastaUtils.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,14 @@ export function processFeaturesToFasta({
7777
let insertionSequence = ''
7878
while (i < alignment.length && seq[i] === '-') {
7979
const alignChar = alignment[i]!
80-
insertionSequence +=
81-
alignChar !== '-' && alignChar !== ' '
82-
? alignChar.toLowerCase()
83-
: '-'
80+
if (alignChar !== '-' && alignChar !== ' ') {
81+
insertionSequence += alignChar.toLowerCase()
82+
}
8483
i++
8584
}
8685
i--
8786

88-
// Only add insertion if it contains at least one actual base (not
89-
// just gaps). This filters out insertions that only exist in samples
90-
// that aren't currently visible.
91-
if (insertionSequence.length > 0 && /[^-]/.test(insertionSequence)) {
87+
if (insertionSequence.length > 0) {
9288
const insertPos = leftCoord + o - region.start
9389
if (insertPos >= 0 && insertPos <= rlen) {
9490
const existing = insertionsAtPosition.get(insertPos) || []
@@ -150,14 +146,15 @@ function expandWithInsertions(
150146
const insertionSeq = sampleInsertions.get(sampleIdx)
151147

152148
if (insertionSeq) {
153-
// This sample has an insertion - add it, padded with gaps if needed
154149
const paddedInsertion = insertionSeq.padEnd(maxLen, '-')
155-
// Insert after position `pos`
156-
rowArray.splice(pos, 0, ...paddedInsertion.split(''))
150+
const chars = paddedInsertion.split('')
151+
for (let k = chars.length - 1; k >= 0; k--) {
152+
rowArray.splice(pos, 0, chars[k]!)
153+
}
157154
} else {
158-
// No insertion for this sample - fill with gaps
159-
const gaps = new Array(maxLen).fill('-')
160-
rowArray.splice(pos, 0, ...gaps)
155+
for (let k = 0; k < maxLen; k++) {
156+
rowArray.splice(pos, 0, '-')
157+
}
161158
}
162159
}
163160
}

0 commit comments

Comments
 (0)