Skip to content

Commit

Permalink
Display message if sequence ontology is unavailable (#453) (#459)
Browse files Browse the repository at this point in the history
* Display message if sequence ontology is unavailable (#453)

* Use Alert component

* Better ontology loading error handling

---------

Co-authored-by: Garrett Stevens <[email protected]>
  • Loading branch information
dariober and garrettjstevens authored Nov 6, 2024
1 parent c78dafd commit eb301ba
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
UriLocation,
isUriLocation,
} from '@jbrowse/core/util'
import { IDBPTransaction, IndexNames, StoreNames } from 'idb/with-async-ittr'
import {
deleteDB,
IDBPTransaction,
IndexNames,
StoreNames,
} from 'idb/with-async-ittr'

import { textSearch } from './fulltext'
import { OntologyDB, OntologyDBEdge, isDeprecated } from './indexeddb-schema'
Expand Down Expand Up @@ -176,18 +181,24 @@ export default class OntologyStore {
return db
}

const { sourceLocation, sourceType } = this
if (sourceType === 'obo-graph-json') {
await this.loadOboGraphJson(db)
} else {
throw new Error(
`ontology source file ${JSON.stringify(
sourceLocation,
)} has type ${sourceType}, which is not yet supported`,
)
}
try {
const { sourceLocation, sourceType } = this
if (sourceType === 'obo-graph-json') {
await this.loadOboGraphJson(db)
} else {
throw new Error(
`ontology source file ${JSON.stringify(
sourceLocation,
)} has type ${sourceType}, which is not yet supported`,
)
}

return db
return db
} catch (error) {
db.close()
await deleteDB(this.dbName)
throw error
}
}

async termCount(tx?: Transaction<['nodes']>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ export async function loadOboGraphJson(this: OntologyStore, db: Database) {
// TODO: using file streaming along with an event-based json parser
// instead of JSON.parse and .readFile could probably make this faster
// and less memory intensive
const oboGraph = JSON.parse(
await openLocation(this.sourceLocation).readFile('utf8'),
) as GraphDocument
let oboGraph: GraphDocument
try {
oboGraph = JSON.parse(
await openLocation(this.sourceLocation).readFile('utf8'),
) as GraphDocument
} catch {
throw new Error('Error in loading ontology')
}

const parseTime = Date.now()

Expand Down
23 changes: 22 additions & 1 deletion packages/jbrowse-plugin-apollo/src/makeDisplayComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PluginManager from '@jbrowse/core/PluginManager'
import type LinearGenomeViewPlugin from '@jbrowse/plugin-linear-genome-view'
import ExpandLessIcon from '@mui/icons-material/ExpandLess'
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import { Typography, alpha } from '@mui/material'
import { Alert, Typography, alpha } from '@mui/material'
import { observer } from 'mobx-react'
import React, { useCallback, useEffect, useRef } from 'react'
import { makeStyles } from 'tss-react/mui'
Expand All @@ -14,6 +14,9 @@ import { TrackLines } from './SixFrameFeatureDisplay/components'
import { SixFrameFeatureDisplay } from './SixFrameFeatureDisplay/stateModel'
import { TabularEditorPane } from './TabularEditor'

import { getSession } from '@jbrowse/core/util'
import { ApolloSessionModel } from './session'

const accordionControlHeight = 12

const useStyles = makeStyles()((theme) => ({
Expand Down Expand Up @@ -52,6 +55,11 @@ const useStyles = makeStyles()((theme) => ({
// position: 'relative',
userSelect: 'none',
},
alertContainer: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
}))

function scrollSelectedFeatureIntoView(
Expand Down Expand Up @@ -155,6 +163,11 @@ export const DisplayComponent = observer(function DisplayComponent({
}: {
model: LinearApolloDisplayI
}) {
const session = getSession(model) as unknown as ApolloSessionModel
const { ontologyManager } = session.apolloDataStore
const { featureTypeOntology } = ontologyManager
const ontologyStore = featureTypeOntology?.dataStore

const { classes } = useStyles()

const {
Expand All @@ -177,6 +190,14 @@ export const DisplayComponent = observer(function DisplayComponent({
model.setDetailsHeight(detailsHeight - delta)
}

if (!ontologyStore) {
return (
<div className={classes.alertContainer}>
<Alert severity="error">Could not load feature type ontology.</Alert>
</div>
)
}

if (graphical && table) {
const tabularHeight = tabularEditor.isShown ? detailsHeight : 0
const featureAreaHeight = isShown
Expand Down

0 comments on commit eb301ba

Please sign in to comment.