Skip to content

Commit 1e6c167

Browse files
cmdcolinclaude
andcommitted
Further code quality improvements
- Revert selectReferenceSequenceString to loop approach for proper undefined handling - Extract SampleConfig type alias for clarity in getSamples.ts - Clean up rowInstructions.ts to use proper type assertion - Fix import/export spacing in BigMafAdapter - Remove unnecessary non-null assertion in selectReferenceSequenceString Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent a43b558 commit 1e6c167

4 files changed

Lines changed: 14 additions & 17 deletions

File tree

src/BgzipTaffyAdapter/rowInstructions.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,14 @@ export function parseRowInstructions(meta: string) {
6767
for (let i = 0; i < ret.length; ) {
6868
const type = ret[i++]
6969
if (type === 'i' || type === 's') {
70-
const row = +ret[i++]!
71-
const sequenceName = ret[i++]!
72-
const narrowedType = type
7370
rows.push({
74-
type: narrowedType,
75-
row,
76-
sequenceName,
71+
type,
72+
row: +ret[i++]!,
73+
sequenceName: ret[i++]!,
7774
start: +ret[i++]!,
7875
strand: ret[i++] === '-' ? -1 : 1,
7976
sequenceLength: +ret[i++]!,
80-
})
77+
} as RowInsert | RowSubstitute)
8178
} else if (type === 'd') {
8279
rows.push({
8380
type,

src/BigMafAdapter/BigMafAdapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getSamplesFromConfig } from '../util/getSamples'
99

1010
import type { AlignmentRecord, MafAdapterOptions } from '../types'
1111
import type { Feature, Region } from '@jbrowse/core/util'
12+
1213
export default class BigMafAdapter extends BaseFeatureDataAdapter {
1314
public setupP?: Promise<{ adapter: BaseFeatureDataAdapter }>
1415

src/util/getSamples.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { openLocation } from '@jbrowse/core/util/io'
22
import parseNewick from '../parseNewick'
33
import { normalize } from '../util'
44

5+
type SampleConfig = string[] | { id: string; label?: string; color?: string }[]
6+
57
export async function getSamplesFromConfig(
68
getConf: (key: string) => unknown,
79
) {
@@ -19,11 +21,7 @@ export async function getSamplesFromConfig(
1921
)
2022

2123
return {
22-
samples: normalize(
23-
getConf('samples') as
24-
| string[]
25-
| { id: string; label?: string; color?: string }[],
26-
),
24+
samples: normalize(getConf('samples') as SampleConfig),
2725
tree: nh ? parseNewick(nh) : undefined,
2826
}
2927
}

src/util/parseAssemblyName.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ export function selectReferenceSequenceString(
8383
queryAssemblyName: string | undefined,
8484
firstAssemblyNameFound: string | undefined,
8585
): string | undefined {
86-
return (
87-
alignments[refAssemblyName ?? '']?.seq ??
88-
alignments[queryAssemblyName ?? '']?.seq ??
89-
alignments[firstAssemblyNameFound ?? '']?.seq
90-
)
86+
for (const name of [refAssemblyName, queryAssemblyName, firstAssemblyNameFound]) {
87+
if (name && alignments[name]) {
88+
return alignments[name].seq
89+
}
90+
}
91+
return undefined
9192
}

0 commit comments

Comments
 (0)