From bf340734b42b52f53d8d6b9f9c3ea0c271262ae7 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 ------------------- 2 files changed, 135 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) -}