Skip to content

Commit

Permalink
Save track data
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 11, 2023
1 parent 29e641f commit 2f01c56
Show file tree
Hide file tree
Showing 27 changed files with 7,629 additions and 6,888 deletions.
99 changes: 88 additions & 11 deletions packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export interface Loading {
lowerCaseRefNameAliases: RefNameAliases
cytobands: Feature[]
}

/**
* #stateModel Assembly
*/
export default function assemblyFactory(
assemblyConfigType: IAnyType,
pm: PluginManager,
Expand All @@ -161,6 +165,9 @@ export default function assemblyFactory(
})
return types
.model({
/**
* #slot
*/
configuration: types.safeReference(assemblyConfigType),
})
.volatile(() => ({
Expand All @@ -173,72 +180,107 @@ export default function assemblyFactory(
cytobands: undefined as Feature[] | undefined,
}))
.views(self => ({
/**
* #getter
*/
get initialized() {
// @ts-expect-error
self.load()
return !!self.refNameAliases
},
/**
* #getter
*/
get name(): string {
return getConf(self, 'name')
},

/**
* #getter
*/
get regions() {
// @ts-expect-error
self.load()
return self.volatileRegions
},

/**
* #getter
*/
get aliases(): string[] {
return getConf(self, 'aliases')
},

/**
* #getter
*/
get displayName(): string | undefined {
return getConf(self, 'displayName')
},

/**
* #getter
*/
hasName(name: string) {
return this.allAliases.includes(name)
},

/**
* #getter
*/
get allAliases() {
return [this.name, ...this.aliases]
},

// note: lowerCaseRefNameAliases not included here: this allows the list
// of refnames to be just the "normal casing", but things like
// getCanonicalRefName can resolve a lower-case name if needed
/**
* #getter
* note: lowerCaseRefNameAliases not included here: this allows the list
* of refnames to be just the "normal casing", but things like
* getCanonicalRefName can resolve a lower-case name if needed
*/
get allRefNames() {
return !self.refNameAliases
? undefined
: Object.keys(self.refNameAliases)
},

/**
* #getter
*/
get lowerCaseRefNames() {
return !self.lowerCaseRefNameAliases
? undefined
: Object.keys(self.lowerCaseRefNameAliases || {})
},

/**
* #getter
*/
get allRefNamesWithLowerCase() {
return this.allRefNames && this.lowerCaseRefNames
? [...new Set([...this.allRefNames, ...this.lowerCaseRefNames])]
: undefined
},
get rpcManager() {
/**
* #getter
*/
get rpcManager(): RpcManager {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return getParent<any>(self, 2).rpcManager
},
/**
* #getter
*/
get refNameColors() {
const colors: string[] = getConf(self, 'refNameColors')
return colors.length === 0 ? refNameColors : colors
},
}))
.views(self => ({
/**
* #getter
*/
get refNames() {
return self.regions?.map(region => region.refName)
},
}))
.views(self => ({
/**
* #method
*/
getCanonicalRefName(refName: string) {
if (!self.refNameAliases || !self.lowerCaseRefNameAliases) {
throw new Error(
Expand All @@ -249,6 +291,9 @@ export default function assemblyFactory(
self.refNameAliases[refName] || self.lowerCaseRefNameAliases[refName]
)
},
/**
* #method
*/
getRefNameColor(refName: string) {
if (!self.refNames) {
return undefined
Expand All @@ -259,6 +304,9 @@ export default function assemblyFactory(
}
return self.refNameColors[idx % self.refNameColors.length]
},
/**
* #method
*/
isValidRefName(refName: string) {
if (!self.refNameAliases) {
throw new Error(
Expand All @@ -269,6 +317,9 @@ export default function assemblyFactory(
},
}))
.actions(self => ({
/**
* #action
*/
setLoaded({
adapterRegionsWithAssembly,
refNameAliases,
Expand All @@ -280,23 +331,41 @@ export default function assemblyFactory(
this.setRefNameAliases(refNameAliases, lowerCaseRefNameAliases)
this.setCytobands(cytobands)
},
/**
* #action
*/
setError(e: unknown) {
console.error(e)
self.error = e
},
/**
* #action
*/
setRegions(regions: Region[]) {
self.volatileRegions = regions
},
/**
* #action
*/
setRefNameAliases(aliases: RefNameAliases, lcAliases: RefNameAliases) {
self.refNameAliases = aliases
self.lowerCaseRefNameAliases = lcAliases
},
/**
* #action
*/
setCytobands(cytobands: Feature[]) {
self.cytobands = cytobands
},
/**
* #action
*/
setLoadingP(p?: Promise<void>) {
self.loadingP = p
},
/**
* #action
*/
load() {
if (!self.loadingP) {
self.loadingP = this.loadPre().catch(e => {
Expand All @@ -306,6 +375,9 @@ export default function assemblyFactory(
}
return self.loadingP
},
/**
* #action
*/
async loadPre() {
const conf = self.configuration
const refNameAliasesAdapterConf = conf.refNameAliases?.adapter
Expand Down Expand Up @@ -349,6 +421,9 @@ export default function assemblyFactory(
},
}))
.views(self => ({
/**
* #method
*/
getAdapterMapEntry(adapterConf: unknown, options: BaseOptions) {
const { signal, statusCallback, ...rest } = options
if (!options.sessionId) {
Expand All @@ -371,6 +446,7 @@ export default function assemblyFactory(
},

/**
* #method
* get Map of `canonical-name -> adapter-specific-name`
*/
async getRefNameMapForAdapter(adapterConf: unknown, opts: BaseOptions) {
Expand All @@ -382,6 +458,7 @@ export default function assemblyFactory(
},

/**
* #method
* get Map of `adapter-specific-name -> canonical-name`
*/
async getReverseRefNameMapForAdapter(
Expand Down
29 changes: 14 additions & 15 deletions packages/core/assemblyManager/assemblyConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { ConfigurationSchema } from '../configuration'
import PluginManager from '../PluginManager'

/**
* #config BaseAssembly
* This corresponds to the assemblies section of the config
* #config Assembly
* This corresponds to the assemblies section of the config, generally accessed
* through the assemblyManager
*/
function assemblyConfigSchema(pluginManager: PluginManager) {
export default function assemblyConfigSchema(pluginManager: PluginManager) {
return ConfigurationSchema(
'BaseAssembly',
{
Expand All @@ -21,8 +22,8 @@ function assemblyConfigSchema(pluginManager: PluginManager) {

/**
* #slot
* sequence refers to a reference sequence track that has an adapter containing,
* importantly, a sequence adapter such as IndexedFastaAdapter
* sequence refers to a reference sequence track that has an adapter
* containing, importantly, a sequence adapter such as IndexedFastaAdapter
*/
sequence: pluginManager.getTrackType('ReferenceSequenceTrack')
.configSchema,
Expand All @@ -42,9 +43,9 @@ function assemblyConfigSchema(pluginManager: PluginManager) {
{
/**
* #slot refNameAliases.adapter
* refNameAliases help resolve e.g. chr1 and 1 as the same entity
* the data for refNameAliases are fetched from an adapter, that is
* commonly a tsv like chromAliases.txt from UCSC or similar
* refNameAliases help resolve e.g. chr1 and 1 as the same entity the
* data for refNameAliases are fetched from an adapter, that is commonly a tsv
* like chromAliases.txt from UCSC or similar
*/
adapter: pluginManager.pluggableConfigSchemaType('adapter'),
},
Expand All @@ -64,8 +65,8 @@ function assemblyConfigSchema(pluginManager: PluginManager) {
{
/**
* #slot cytobands.adapter
* cytoband data is fetched from an adapter, and can be displayed by a
* view type as ideograms
* cytoband data is fetched from an adapter, and can be displayed by
* a view type as ideograms
*/
adapter: pluginManager.pluggableConfigSchemaType('adapter'),
},
Expand Down Expand Up @@ -94,13 +95,11 @@ function assemblyConfigSchema(pluginManager: PluginManager) {
{
/**
* #identifier name
* the name acts as a unique identifier in the config, so it cannot be duplicated.
* it usually a short human readable "id" like hg38, but you can also optionally
* customize the assembly "displayName" config slot
* the name acts as a unique identifier in the config, so it cannot be
* duplicated. it usually a short human readable "id" like hg38, but you can
* also optionally customize the assembly "displayName" config slot
*/
explicitIdentifier: 'name',
},
)
}

export default assemblyConfigSchema
27 changes: 14 additions & 13 deletions packages/core/assemblyManager/assemblyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import {
Instance,
IAnyType,
} from 'mobx-state-tree'
import { when } from '../util'
import { reaction } from 'mobx'
// locals
import { when } from '../util'
import { readConfObject, AnyConfigurationModel } from '../configuration'
import assemblyFactory, { Assembly } from './assembly'
import PluginManager from '../PluginManager'

function assemblyManagerFactory(conf: IAnyType, pm: PluginManager) {
export default function assemblyManagerFactory(
conf: IAnyType,
pm: PluginManager,
) {
type Conf = Instance<typeof conf> | string
return types
.model({
Expand Down Expand Up @@ -116,21 +120,20 @@ function assemblyManagerFactory(conf: IAnyType, pm: PluginManager) {
addDisposer(
self,
reaction(
// have to slice it to be properly reacted to
() => self.assemblyList,
assemblyConfigs => {
confs => {
self.assemblies.forEach(asm => {
if (!asm.configuration) {
this.removeAssembly(asm)
}
})
assemblyConfigs.forEach(assemblyConfig => {
const existingAssemblyIdx = self.assemblies.findIndex(
assembly =>
assembly.name === readConfObject(assemblyConfig, 'name'),
)
if (existingAssemblyIdx === -1) {
this.addAssembly(assemblyConfig)
confs.forEach(conf => {
if (
!self.assemblies.some(
a => a.name === readConfObject(conf, 'name'),
)
) {
this.addAssembly(conf)
}
})
},
Expand All @@ -154,5 +157,3 @@ function assemblyManagerFactory(conf: IAnyType, pm: PluginManager) {
},
}))
}

export default assemblyManagerFactory
Loading

0 comments on commit 2f01c56

Please sign in to comment.