-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
820 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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<string, string> | ||
|
||
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<BasicRegion[]> { | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.