From 8708cf4bf3cf0b0f4469fe37dc09fc20eb2e7dd0 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 +- 7 files changed, 35 insertions(+), 153 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,