Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sequence adapter config in afterAttach for baseTrackConfig #4037

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ async function loadRefNameMap(
signal?: AbortSignal,
) {
const { sessionId } = options
await when(() => !!(assembly.regions && assembly.refNameAliases), {
signal,
name: 'when assembly ready',
})

await when(
() =>
!!(
assembly.regions &&
assembly.refNameAliases &&
adapterConfig.sequenceAdapter
),
{
signal,
name: 'when assembly ready',
},
)

const refNames = (await assembly.rpcManager.call(
sessionId || 'assemblyRpc',
Expand All @@ -82,10 +91,9 @@ async function loadRefNameMap(
}

const refNameMap = Object.fromEntries(
refNames.map(name => {
checkRefName(name)
return [assembly.getCanonicalRefName(name), name]
}),
refNames
.map(name => checkRefName(name))
.map(name => [assembly.getCanonicalRefName(name), name]),
)

// make the reversed map too
Expand All @@ -107,6 +115,7 @@ function checkRefName(refName: string) {
if (!refNameRegex.test(refName)) {
throw new Error(`Encountered invalid refName: "${refName}"`)
}
return refName
}

type RefNameAliases = Record<string, string | undefined>
Expand Down
71 changes: 59 additions & 12 deletions packages/core/pluggableElementTypes/models/baseTrackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { types, Instance } from 'mobx-state-tree'
import { ConfigurationSchema } from '../../configuration'
import {
types,
Instance,
getSnapshot,
getRoot,
addDisposer,
} from 'mobx-state-tree'
import { ConfigurationSchema, readConfObject } from '../../configuration'
import PluginManager from '../../PluginManager'
import { AssemblyManager, notEmpty } from '../../util'
import { autorun } from 'mobx'

/**
* #config BaseTrack
Expand Down Expand Up @@ -81,6 +89,14 @@ export function createBaseTrackConfig(pluginManager: PluginManager) {
),
}),

/**
* #slot
*/
sequenceAdapters: {
type: 'frozen',
defaultValue: {},
},

/**
* #slot
*/
Expand Down Expand Up @@ -180,20 +196,51 @@ export function createBaseTrackConfig(pluginManager: PluginManager) {
explicitlyTyped: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actions: (self: any) => ({
addDisplayConf(conf: { type: string; displayId: string }) {
const { type } = conf
forceAddDisplay(c: { type: string; displayId: string }) {
self.displays.push(c)
return self.displays.at(-1)
},
addDisplayConf(c: { type: string; displayId: string }) {
const { type } = c
if (!type) {
throw new Error(`unknown display type ${type}`)
}
const display = self.displays.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(d: any) => d?.displayId === conf.displayId,
return (
self.displays.find(
(d: { displayId: string }) => d?.displayId === c.displayId,
) ?? self.forceAddDisplay(c)
)
},
setSequenceAdapters(a: Record<string, unknown>) {
self.sequenceAdapters = a
},
afterAttach() {
addDisposer(
self,
autorun(() => {
const { assemblyManager } = getRoot<{
assemblyManager: AssemblyManager
}>(self)
const assemblyNames = readConfObject(
self,
'assemblyNames',
) as string[]
self.setSequenceAdapters(
assemblyNames
.map(a => {
const conf = assemblyManager.get(a)?.configuration
return conf ? ([a, getSnapshot(conf)] as const) : undefined
})
.filter(notEmpty),
)
const c = assemblyManager.get(assemblyNames[0])?.configuration
if (c) {
self.adapter.setSequenceAdapter?.(
readConfObject(c.sequence.adapter),
)
}
}),
)
if (display) {
return display
}
const length = self.displays.push(conf)
return self.displays[length - 1]
},
}),
},
Expand Down
8 changes: 7 additions & 1 deletion packages/product-core/src/ui/AboutDialogContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ export default function AboutContents({
) : null}
<Attributes
attributes={confPostExt}
omit={['displays', 'baseUri', 'refNames', 'formatAbout']}
omit={[
'displays',
'baseUri',
'refNames',
'formatAbout',
'sequenceAdapters',
]}
hideUris={hideUris}
/>
</BaseCard>
Expand Down
98 changes: 48 additions & 50 deletions plugins/alignments/src/BamAdapter/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,59 @@ import { types } from 'mobx-state-tree'
* #config BamAdapter
* used to configure BAM adapter
*/
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars

const configSchema = ConfigurationSchema(
'BamAdapter',
{
/**
* #slot
*/
bamLocation: {
type: 'fileLocation',
defaultValue: { uri: '/path/to/my.bam', locationType: 'UriLocation' },
},
export default function configSchemaF() {
return ConfigurationSchema(
'BamAdapter',
{
/**
* #slot
*/
bamLocation: {
type: 'fileLocation',
defaultValue: { uri: '/path/to/my.bam', locationType: 'UriLocation' },
},

index: ConfigurationSchema('BamIndex', {
index: ConfigurationSchema('BamIndex', {
/**
* #slot index.indexType
*/
indexType: {
model: types.enumeration('IndexType', ['BAI', 'CSI']),
type: 'stringEnum',
defaultValue: 'BAI',
},
/**
* #slot index.location
*/
location: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/my.bam.bai',
locationType: 'UriLocation',
},
},
}),
/**
* #slot index.indexType
* #slot
*/
indexType: {
model: types.enumeration('IndexType', ['BAI', 'CSI']),
type: 'stringEnum',
defaultValue: 'BAI',
fetchSizeLimit: {
type: 'number',
description:
'size to fetch in bytes over which to display a warning to the user that too much data will be fetched',
defaultValue: 5_000_000,
},
/**
* #slot index.location
* #slot
* generally refers to the reference genome assembly's sequence adapter
* currently needs to be manually added
*/
location: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/my.bam.bai',
locationType: 'UriLocation',
},
sequenceAdapter: {
type: 'frozen',
description:
'sequence data adapter, used to calculate SNPs when BAM reads lacking MD tags',
defaultValue: null,
},
}),
/**
* #slot
*/
fetchSizeLimit: {
type: 'number',
description:
'size to fetch in bytes over which to display a warning to the user that too much data will be fetched',
defaultValue: 5_000_000,
},
/**
* #slot
* generally refers to the reference genome assembly's sequence adapter
* currently needs to be manually added
*/
sequenceAdapter: {
type: 'frozen',
description:
'sequence data adapter, used to calculate SNPs when BAM reads lacking MD tags',
defaultValue: null,
},
},
{ explicitlyTyped: true },
)

export default configSchema
{ explicitlyTyped: true },
)
}
4 changes: 2 additions & 2 deletions plugins/alignments/src/BamAdapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import PluginManager from '@jbrowse/core/PluginManager'
import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType'
import configSchema from './configSchema'
import configSchemaF from './configSchema'

export default function BamAdapterF(pluginManager: PluginManager) {
pluginManager.addAdapterType(() => {
return new AdapterType({
name: 'BamAdapter',
displayName: 'BAM adapter',
configSchema,
configSchema: configSchemaF(),
getAdapterClass: () => import('./BamAdapter').then(r => r.default),
})
})
Expand Down
96 changes: 53 additions & 43 deletions plugins/alignments/src/CramAdapter/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,62 @@ import { ConfigurationSchema } from '@jbrowse/core/configuration'
*/
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars

const configSchema = ConfigurationSchema(
'CramAdapter',
{
/**
* #slot fetchSizeLimit
*/
fetchSizeLimit: {
type: 'number',
description:
'size in bytes over which to display a warning to the user that too much data will be fetched',
defaultValue: 3_000_000,
},
export default function configSchemaF() {
return ConfigurationSchema(
'CramAdapter',
{
/**
* #slot fetchSizeLimit
*/
fetchSizeLimit: {
type: 'number',
description:
'size in bytes over which to display a warning to the user that too much data will be fetched',
defaultValue: 3_000_000,
},

/**
* #slot cramLocation
*/
cramLocation: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/my.cram',
locationType: 'UriLocation',
/**
* #slot cramLocation
*/
cramLocation: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/my.cram',
locationType: 'UriLocation',
},
},
},

/**
* #slot craiLocation
*/
craiLocation: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/my.cram.crai',
locationType: 'UriLocation',
/**
* #slot craiLocation
*/
craiLocation: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/my.cram.crai',
locationType: 'UriLocation',
},
},
},

/**
* #slot sequenceAdapter
* generally refers to the reference genome assembly's sequence adapter
* currently needs to be manually added
*/
sequenceAdapter: {
type: 'frozen',
description: 'sequence data adapter',
defaultValue: null,
/**
* #slot sequenceAdapter
* generally refers to the reference genome assembly's sequence adapter
* this can be manually added via the baseTrackConfig autorun, or manually
* specified
*/
sequenceAdapter: {
type: 'frozen',
description: 'sequence data adapter',
defaultValue: null,
},
},
{
explicitlyTyped: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actions: (self: any) => ({
setSequenceAdapter(s: Record<string, unknown>) {
self.sequenceAdapter = s
},
}),
},
},
{ explicitlyTyped: true },
)
export default configSchema
)
}
Loading
Loading