From 143354232ff73b042aa0f55996b6b94068eeb748 Mon Sep 17 00:00:00 2001 From: Garrett Stevens Date: Wed, 13 Nov 2024 16:29:57 -0700 Subject: [PATCH] Make feature type ontology configurable (#472) --- .../src/OntologyManager/index.ts | 35 +++++++++++++++---- packages/jbrowse-plugin-apollo/src/config.ts | 5 +++ .../src/session/ClientDataStore.ts | 2 +- .../src/session/session.ts | 1 + 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts b/packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts index 3225c522f..d10f0edf6 100644 --- a/packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts +++ b/packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts @@ -1,15 +1,26 @@ -import { ConfigurationSchema } from '@jbrowse/core/configuration' +import { + AnyConfigurationModel, + ConfigurationSchema, + readConfObject, +} from '@jbrowse/core/configuration' import { BlobLocation, LocalPathLocation, UriLocation, } from '@jbrowse/core/util/types/mst' import { autorun } from 'mobx' -import { Instance, addDisposer, getSnapshot, types } from 'mobx-state-tree' - +import { + Instance, + addDisposer, + getRoot, + getSnapshot, + types, +} from 'mobx-state-tree' import OntologyStore, { OntologyStoreOptions } from './OntologyStore' import { OntologyDBNode } from './OntologyStore/indexeddb-schema' import { applyPrefixes, expandPrefixes } from './OntologyStore/prefixes' +import ApolloPluginConfigurationSchema from '../config' +import { ApolloRootModel } from '../types' export { isDeprecated } from './OntologyStore/indexeddb-schema' @@ -55,15 +66,27 @@ export const OntologyManagerType = types 'SO:': 'http://purl.obolibrary.org/obo/SO_', }), }) + .views((self) => ({ + get featureTypeOntologyName(): string { + const jbConfig = getRoot(self).jbrowse + .configuration as AnyConfigurationModel + const pluginConfiguration = jbConfig.ApolloPlugin as Instance< + typeof ApolloPluginConfigurationSchema + > + const featureTypeOntologyName = readConfObject( + pluginConfiguration, + 'featureTypeOntologyName', + ) as string + return featureTypeOntologyName + }, + })) .views((self) => ({ /** * gets the OntologyRecord for the ontology we should be * using for feature types (e.g. SO or maybe biotypes) **/ get featureTypeOntology() { - // TODO: change this to read some configuration for which feature type ontology - // we should be using. currently hardcoded to use SO. - return this.findOntology('Sequence Ontology') + return this.findOntology(self.featureTypeOntologyName) }, findOntology(name: string, version?: string) { diff --git a/packages/jbrowse-plugin-apollo/src/config.ts b/packages/jbrowse-plugin-apollo/src/config.ts index de8fae010..66f92669e 100644 --- a/packages/jbrowse-plugin-apollo/src/config.ts +++ b/packages/jbrowse-plugin-apollo/src/config.ts @@ -5,6 +5,11 @@ import { OntologyRecordConfiguration } from './OntologyManager' const ApolloPluginConfigurationSchema = ConfigurationSchema('ApolloPlugin', { ontologies: types.array(OntologyRecordConfiguration), + featureTypeOntologyName: { + description: 'Name of the feature type ontology', + type: 'string', + defaultValue: 'Sequence Ontology', + }, }) export default ApolloPluginConfigurationSchema diff --git a/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts b/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts index a6a91faa4..20cea3a5d 100644 --- a/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts +++ b/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts @@ -51,6 +51,7 @@ export function clientDataStoreFactory( typeName: types.optional(types.literal('Client'), 'Client'), assemblies: types.map(ApolloAssembly), checkResults: types.map(CheckResult), + ontologyManager: types.optional(OntologyManagerType, {}), }) .views((self) => ({ get internetAccounts() { @@ -136,7 +137,6 @@ export function clientDataStoreFactory( desktopFileDriver: isElectron ? new DesktopFileDriver(self as unknown as ClientDataStoreType) : undefined, - ontologyManager: OntologyManagerType.create(), })) .actions((self) => ({ afterCreate() { diff --git a/packages/jbrowse-plugin-apollo/src/session/session.ts b/packages/jbrowse-plugin-apollo/src/session/session.ts index 4e56759af..615ff0e47 100644 --- a/packages/jbrowse-plugin-apollo/src/session/session.ts +++ b/packages/jbrowse-plugin-apollo/src/session/session.ts @@ -419,6 +419,7 @@ export function extendSession( ([, assembly]) => assembly.backendDriverType === 'InMemoryFileDriver', ), ) + // @ts-expect-error ontologyManager isn't actually required snap.apolloDataStore = { typeName: 'Client', assemblies,