From 880efb886e2daa6b39647b307c94f80cddd6af9f Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 25 Jul 2024 11:47:31 -0400 Subject: [PATCH] Rm --- .../core/assemblyManager/loadRefNameMap.ts | 65 ----- packages/core/assemblyManager/util.ts | 70 ----- .../models/components/SaveTrackData.tsx | 24 +- .../models/saveTrackFileTypes/genbank.ts | 21 +- .../models/saveTrackFileTypes/gff3.ts | 2 +- packages/core/rpc/methods/CoreGetRegions.ts | 2 +- .../core/rpc/methods/CoreSaveFeatureData.ts | 4 +- .../LinearGenomeView.test.tsx.snap | 258 +++++++----------- .../JBrowseLinearGenomeView.test.tsx.snap | 139 ++++------ 9 files changed, 195 insertions(+), 390 deletions(-) delete mode 100644 packages/core/assemblyManager/loadRefNameMap.ts delete mode 100644 packages/core/assemblyManager/util.ts diff --git a/packages/core/assemblyManager/loadRefNameMap.ts b/packages/core/assemblyManager/loadRefNameMap.ts deleted file mode 100644 index 67928d2b7c..0000000000 --- a/packages/core/assemblyManager/loadRefNameMap.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { BaseOptions, checkRefName, RefNameAliases } from './util' -import RpcManager from '../rpc/RpcManager' -import { when } from '../util' - -export interface BasicRegion { - start: number - end: number - refName: string - assemblyName: string -} - -export async function loadRefNameMap( - assembly: { - name: string - regions: BasicRegion[] | undefined - refNameAliases: RefNameAliases | undefined - getCanonicalRefName: (arg: string) => string - rpcManager: RpcManager - }, - adapterConfig: unknown, - options: BaseOptions, - signal?: AbortSignal, -) { - const { sessionId } = options - await when(() => !!(assembly.regions && assembly.refNameAliases), { - signal, - name: 'when assembly ready', - }) - - const refNames = (await assembly.rpcManager.call( - sessionId, - 'CoreGetRefNames', - { - adapterConfig, - signal, - ...options, - }, - { timeout: 1000000 }, - )) as string[] - - const { refNameAliases } = assembly - if (!refNameAliases) { - throw new Error(`error loading assembly ${assembly.name}'s refNameAliases`) - } - - const refNameMap = Object.fromEntries( - refNames.map(name => { - checkRefName(name) - return [assembly.getCanonicalRefName(name), name] - }), - ) - - // make the reversed map too - const reversed = Object.fromEntries( - Object.entries(refNameMap).map(([canonicalName, adapterName]) => [ - adapterName, - canonicalName, - ]), - ) - - return { - forwardMap: refNameMap, - reverseMap: reversed, - } -} diff --git a/packages/core/assemblyManager/util.ts b/packages/core/assemblyManager/util.ts deleted file mode 100644 index e779fec009..0000000000 --- a/packages/core/assemblyManager/util.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { AnyConfigurationModel } from '../configuration' -import jsonStableStringify from 'json-stable-stringify' -import { BaseRefNameAliasAdapter } from '../data_adapters/BaseAdapter' -import PluginManager from '../PluginManager' -import { BasicRegion } from './loadRefNameMap' - -export type RefNameAliases = Record - -export interface BaseOptions { - signal?: AbortSignal - sessionId: string - statusCallback?: Function -} - -export async function getRefNameAliases( - config: AnyConfigurationModel, - pm: PluginManager, - signal?: AbortSignal, -) { - const type = pm.getAdapterType(config.type) - const CLASS = await type.getAdapterClass() - const adapter = new CLASS(config, undefined, pm) as BaseRefNameAliasAdapter - return adapter.getRefNameAliases({ signal }) -} - -export async function getCytobands( - config: AnyConfigurationModel, - pm: PluginManager, -) { - const type = pm.getAdapterType(config.type) - const CLASS = await type.getAdapterClass() - const adapter = new CLASS(config, undefined, pm) - - // @ts-expect-error - return adapter.getData() -} - -export async function getAssemblyRegions( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - assembly: any, - adapterConfig: AnyConfigurationModel, - signal?: AbortSignal, -): Promise { - const sessionId = 'loadRefNames' - return assembly.rpcManager.call( - sessionId, - 'CoreGetRegions', - { - adapterConfig, - sessionId, - signal, - }, - { timeout: 1000000 }, - ) -} - -const refNameRegex = new RegExp( - '[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*', -) - -// Valid refName pattern from https://samtools.github.io/hts-specs/SAMv1.pdf -export function checkRefName(refName: string) { - if (!refNameRegex.test(refName)) { - throw new Error(`Encountered invalid refName: "${refName}"`) - } -} - -export function getAdapterId(adapterConf: unknown) { - return jsonStableStringify(adapterConf) -} diff --git a/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx index 078afa6f30..88159898ec 100644 --- a/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx +++ b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx @@ -100,7 +100,7 @@ const SaveTrackDataDialog = observer(function ({ visibleRegions?: Region[] } const session = getSession(model) - if (!features || !visibleRegions) { + if (!features || !visibleRegions?.length || !type) { return } const generator = options[type] || { @@ -110,7 +110,7 @@ const SaveTrackDataDialog = observer(function ({ await generator.callback({ features, session, - assemblyName: visibleRegions[0].assemblyName, + assemblyName: visibleRegions[0]!.assemblyName, }), ) } catch (e) { @@ -130,7 +130,12 @@ const SaveTrackDataDialog = observer(function ({ File type - setType(e.target.value)}> + { + setType(e.target.value) + }} + > {Object.entries(options).map(([key, val]) => ( - diff --git a/packages/core/pluggableElementTypes/models/saveTrackFileTypes/genbank.ts b/packages/core/pluggableElementTypes/models/saveTrackFileTypes/genbank.ts index 1b78eb0e3f..90db178eca 100644 --- a/packages/core/pluggableElementTypes/models/saveTrackFileTypes/genbank.ts +++ b/packages/core/pluggableElementTypes/models/saveTrackFileTypes/genbank.ts @@ -45,20 +45,20 @@ function formatTags(f: Feature, parentId?: string, parentType?: string) { ...f .tags() .filter(tag => !coreFields.has(tag)) - .map(tag => [tag, fmt(f.get(tag))]) + .map(tag => [tag, fmt(f.get(tag))] as const) .filter(tag => !!tag[1] && tag[0] !== parentType) .map(tag => `${blank}/${retitle[tag[0]] || tag[0]}="${tag[1]}"`), ].filter(f => !!f) } -function rs(f: Feature, min: number) { +function relativeStart(f: Feature, min: number) { return f.get('start') - min + 1 } -function re(f: Feature, min: number) { +function relativeEnd(f: Feature, min: number) { return f.get('end') - min } function loc(f: Feature, min: number) { - return `${rs(f, min)}..${re(f, min)}` + return `${relativeStart(f, min)}..${relativeEnd(f, min)}` } function formatFeat( f: Feature, @@ -123,6 +123,9 @@ export async function stringifyGBK({ session: AbstractSessionModel features: Feature[] }) { + if (!features.length) { + return '' + } const today = new Date() const month = today.toLocaleString('en-US', { month: 'short' }).toUpperCase() const day = today.toLocaleString('en-US', { day: 'numeric' }) @@ -132,15 +135,15 @@ export async function stringifyGBK({ const start = min(features.map(f => f.get('start'))) const end = max(features.map(f => f.get('end'))) const length = end - start - const refName = features[0].get('refName') + const refName = features[0]!.get('refName') || '' const l1 = [ - `${'LOCUS'.padEnd(12)}`, + 'LOCUS'.padEnd(12), `${refName}:${start + 1}..${end}`.padEnd(20), - ` ${`${length} bp`}`.padEnd(15), + ` ${length} bp`.padEnd(15), ` ${'DNA'.padEnd(10)}`, - `${'linear'.padEnd(10)}`, - `${'UNK ' + date}`, + 'linear'.padEnd(10), + `UNK ${date}`, ].join('') const l2 = 'FEATURES Location/Qualifiers' const seq = await fetchSequence({ diff --git a/packages/core/pluggableElementTypes/models/saveTrackFileTypes/gff3.ts b/packages/core/pluggableElementTypes/models/saveTrackFileTypes/gff3.ts index 44605d6dae..3780ee02ad 100644 --- a/packages/core/pluggableElementTypes/models/saveTrackFileTypes/gff3.ts +++ b/packages/core/pluggableElementTypes/models/saveTrackFileTypes/gff3.ts @@ -54,7 +54,7 @@ function formatFeat(f: Feature, parentId?: string, parentRef?: string) { f .tags() .filter(tag => !coreFields.has(tag)) - .map(tag => [tag, fmt(f.get(tag))]) + .map(tag => [tag, fmt(f.get(tag))] as const) .filter(tag => !!tag[1]) .map(tag => `${retitle[tag[0]] || tag[0]}=${tag[1]}`) .join(';'), diff --git a/packages/core/rpc/methods/CoreGetRegions.ts b/packages/core/rpc/methods/CoreGetRegions.ts index 0761c2c62f..4d8b96353a 100644 --- a/packages/core/rpc/methods/CoreGetRegions.ts +++ b/packages/core/rpc/methods/CoreGetRegions.ts @@ -11,7 +11,7 @@ export default class CoreGetRegions extends RpcMethodType { args: { sessionId: string signal: RemoteAbortSignal - adapterConfig: {} + adapterConfig: Record }, rpcDriver: string, ) { diff --git a/packages/core/rpc/methods/CoreSaveFeatureData.ts b/packages/core/rpc/methods/CoreSaveFeatureData.ts index 21b4067a1d..4f93167aab 100644 --- a/packages/core/rpc/methods/CoreSaveFeatureData.ts +++ b/packages/core/rpc/methods/CoreSaveFeatureData.ts @@ -42,9 +42,9 @@ export default class CoreGetFeatures extends RpcMethodType { args: { sessionId: string regions: Region[] - adapterConfig: {} + adapterConfig: Record signal?: RemoteAbortSignal - // eslint-disable-next-line @typescript-eslint/no-explicit-any + opts?: any }, rpcDriver: string, diff --git a/plugins/linear-genome-view/src/LinearGenomeView/components/__snapshots__/LinearGenomeView.test.tsx.snap b/plugins/linear-genome-view/src/LinearGenomeView/components/__snapshots__/LinearGenomeView.test.tsx.snap index 176ee2e942..d723fd5296 100644 --- a/plugins/linear-genome-view/src/LinearGenomeView/components/__snapshots__/LinearGenomeView.test.tsx.snap +++ b/plugins/linear-genome-view/src/LinearGenomeView/components/__snapshots__/LinearGenomeView.test.tsx.snap @@ -17,7 +17,7 @@ exports[`renders one track, one region 1`] = ` >

ctgA @@ -35,31 +35,31 @@ exports[`renders one track, one region 1`] = ` style="left: 0px; width: 800px; border-color: rgb(153, 102, 0);" >

20

40

60

80

100 @@ -81,10 +81,10 @@ exports[`renders one track, one region 1`] = ` height="48" > @@ -92,7 +92,7 @@ exports[`renders one track, one region 1`] = ` class="css-cwpsam-headerBar" >

100bp

@@ -248,7 +236,7 @@ exports[`renders one track, one region 1`] = ` class="css-z84q6m-container" > @@ -297,14 +285,14 @@ exports[`renders one track, one region 1`] = `

@@ -434,10 +419,11 @@ exports[`renders one track, one region 1`] = `

Foo Track

ctgA @@ -596,7 +576,7 @@ exports[`renders two tracks, two regions 1`] = ` />

ctgB @@ -606,31 +586,31 @@ exports[`renders two tracks, two regions 1`] = ` style="left: 72.72727272727273px; width: 727.2727272727273px;" >

1,200

1,400

1,600

1,800

2,000 @@ -652,10 +632,10 @@ exports[`renders two tracks, two regions 1`] = ` height="48" > @@ -663,7 +643,7 @@ exports[`renders two tracks, two regions 1`] = ` class="css-cwpsam-headerBar" >

798bp

@@ -819,14 +787,14 @@ exports[`renders two tracks, two regions 1`] = ` class="css-z84q6m-container" > @@ -870,14 +835,14 @@ exports[`renders two tracks, two regions 1`] = `

1,000

@@ -1195,7 +1157,7 @@ exports[`renders two tracks, two regions 1`] = ` style="left: 199px;" >

1,200

@@ -1205,7 +1167,7 @@ exports[`renders two tracks, two regions 1`] = ` style="left: 399px;" >

1,400

@@ -1215,7 +1177,7 @@ exports[`renders two tracks, two regions 1`] = ` style="left: 599px;" >

1,600

@@ -1225,7 +1187,7 @@ exports[`renders two tracks, two regions 1`] = ` style="left: 799px;" >

1,800

@@ -1234,14 +1196,14 @@ exports[`renders two tracks, two regions 1`] = `

ctgA

@@ -1250,10 +1212,11 @@ exports[`renders two tracks, two regions 1`] = `

Foo Track
Bar Track
renders successfully 1`] = ` class="MuiScopedCssBaseline-root css-1pa2gw3-MuiScopedCssBaseline-root" >
renders successfully 1`] = ` class="css-122lw0e-grow" />
-
renders successfully 1`] = ` />

ctgA @@ -118,37 +112,37 @@ exports[` renders successfully 1`] = ` style="left: 0px; width: 800px; border-color: rgb(153, 102, 0);" >

20

40

60

80

100

120 @@ -181,7 +175,7 @@ exports[` renders successfully 1`] = ` class="css-cwpsam-headerBar" >

renders successfully 1`] = ` style="width: 175px;" >
renders successfully 1`] = ` aria-invalid="false" autocapitalize="none" autocomplete="off" - class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedEnd MuiAutocomplete-input MuiAutocomplete-inputFocused css-19qh8xo-MuiInputBase-input-MuiOutlinedInput-input" + class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedEnd MuiAutocomplete-input MuiAutocomplete-inputFocused css-1df20ln-MuiInputBase-input-MuiOutlinedInput-input" id=":r0:" placeholder="Search for location" role="combobox" @@ -275,12 +260,12 @@ exports[` renders successfully 1`] = ` value="ctgA:1..40" />
renders successfully 1`] = ` />
renders successfully 1`] = ` class="MuiOutlinedInput-notchedOutline css-1d3z3hw-MuiOutlinedInput-notchedOutline" > renders successfully 1`] = `

40bp

@@ -337,14 +319,14 @@ exports[` renders successfully 1`] = ` class="css-z84q6m-container" > renders successfully 1`] = `
renders successfully 1`] = ` data-testid="rubberband_controls" >
renders successfully 1`] = ` style="left: 180px;" >

10

@@ -832,7 +808,7 @@ exports[` renders successfully 1`] = ` style="left: 380px;" >

20

@@ -842,7 +818,7 @@ exports[` renders successfully 1`] = ` style="left: 580px;" >

30

@@ -852,7 +828,7 @@ exports[` renders successfully 1`] = ` style="left: 780px;" >

40

@@ -867,7 +843,7 @@ exports[` renders successfully 1`] = ` style="left: -20px;" >

40

@@ -877,7 +853,7 @@ exports[` renders successfully 1`] = ` style="left: 180px;" >

50

@@ -887,7 +863,7 @@ exports[` renders successfully 1`] = ` style="left: 380px;" >

60

@@ -897,7 +873,7 @@ exports[` renders successfully 1`] = ` style="left: 580px;" >

70

@@ -907,7 +883,7 @@ exports[` renders successfully 1`] = ` style="left: 780px;" >

80

@@ -916,7 +892,7 @@ exports[` renders successfully 1`] = `

@@ -925,10 +901,11 @@ exports[` renders successfully 1`] = `

renders successfully 1`] = ` > renders successfully 1`] = ` Reference sequence (volvox)