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

Make ontology for feature types configurable #458

Closed
garrettjstevens opened this issue Oct 2, 2024 · 2 comments · Fixed by #472
Closed

Make ontology for feature types configurable #458

garrettjstevens opened this issue Oct 2, 2024 · 2 comments · Fixed by #472
Assignees

Comments

@garrettjstevens
Copy link
Contributor

This should be configurable in the JBrowse config.json in the ApolloPlugin section:

{
  "configuration": {
    "ApolloPlugin": {
      "featureTypeOntology": "Some Ontology Name",
      "ontologies": [
        {
          "name": "Some Ontology Name",
          "version": "full",
          "source": {
            "uri": "path/to/some_ontology.json",
            "locationType": "UriLocation"
          }
        },
      ]
    }
  }
}

You can add a slot to the ApolloPlugin schema like this:

--- 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

And then read it with something like this:

--- 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 {
+  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 { ApolloRootModel } from '../types'
+import ApolloPluginConfigurationSchema from '../config'
 
 export { isDeprecated } from './OntologyStore/indexeddb-schema'
 
@@ -61,9 +72,15 @@ export const OntologyManagerType = types
      * 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')
+      const pluginConfiguration = getRoot<ApolloRootModel>(self).jbrowse
+        .configuration.ApolloPlugin as Instance<
+        typeof ApolloPluginConfigurationSchema
+      >
+      const featureTypeOntologyName = readConfObject(
+        pluginConfiguration,
+        'featureTypeOntologyName',
+      )
+      return this.findOntology(featureTypeOntologyName)
     },
 
     findOntology(name: string, version?: string) {
@garrettjstevens
Copy link
Contributor Author

It turns out getRoot doesn't work the way I thought it would here, so instead let's try passing the configuration into the ontologyManager like this:

--- a/packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts
+++ b/packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts
@@ -1,4 +1,4 @@
-import { ConfigurationSchema } from '@jbrowse/core/configuration'
+import { ConfigurationSchema, readConfObject } from '@jbrowse/core/configuration'
 import {
   BlobLocation,
   LocalPathLocation,
@@ -7,6 +7,8 @@ import {
 import { autorun } from 'mobx'
 import { Instance, addDisposer, getSnapshot, types } from 'mobx-state-tree'
 
+import ApolloPluginConfigurationSchema from '../config'
+
 import OntologyStore, { OntologyStoreOptions } from './OntologyStore'
 import { OntologyDBNode } from './OntologyStore/indexeddb-schema'
 import { applyPrefixes, expandPrefixes } from './OntologyStore/prefixes'
@@ -54,16 +56,23 @@ export const OntologyManagerType = types
       'GO:': 'http://purl.obolibrary.org/obo/GO_',
       'SO:': 'http://purl.obolibrary.org/obo/SO_',
     }),
+    pluginConfiguration: ApolloPluginConfigurationSchema,
   })
+  .views((self) => ({
+    get featureTypeOntologyName(): string {
+      return readConfObject(
+        self.pluginConfiguration,
+        'featureTypeOntologyName',
+      ) as string
+    },
+  }))
   .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) {
--- 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
--- a/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts
+++ b/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts
@@ -136,7 +136,9 @@ export function clientDataStoreFactory(
       desktopFileDriver: isElectron
         ? new DesktopFileDriver(self as unknown as ClientDataStoreType)
         : undefined,
-      ontologyManager: OntologyManagerType.create(),
+      ontologyManager: OntologyManagerType.create({
+        pluginConfiguration: self.pluginConfiguration,
+      }),
     }))
     .actions((self) => ({
       afterCreate() {

@garrettjstevens
Copy link
Contributor Author

@dariober, after the issues we saw earlier today with the most recent approach, I tried a different approach. See my branch here: configurable-ontology-issue458-gs.

Could you try this branch out and see if it works on your end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants