Skip to content

Commit

Permalink
Implements issue #325
Browse files Browse the repository at this point in the history
  • Loading branch information
dariober committed Nov 20, 2023
1 parent 2243bbb commit cf300c3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/jbrowse-plugin-apollo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import {
} from '@jbrowse/core/util'
import { LinearGenomeViewStateModel } from '@jbrowse/plugin-linear-genome-view'
import AddIcon from '@mui/icons-material/Add'
import { changeRegistry } from 'apollo-common'
import { changeRegistry, checkRegistry } from 'apollo-common'
import {
CDSCheck,
CoreValidation,
ParentChildValidation,
changes,
Expand Down Expand Up @@ -91,6 +92,9 @@ for (const [changeName, change] of Object.entries(changes)) {
changeRegistry.registerChange(changeName, change)
}

const cdsCheck = new CDSCheck()
checkRegistry.registerCheck(cdsCheck.name, cdsCheck)

validationRegistry.registerValidation(new CoreValidation())
validationRegistry.registerValidation(new ParentChildValidation())

Expand Down
38 changes: 30 additions & 8 deletions packages/jbrowse-plugin-apollo/src/util/loadAssemblyIntoClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import gff, { GFF3Comment, GFF3Feature, GFF3Sequence } from '@gmod/gff'
import { ClientDataStore } from 'apollo-common'
import { AnnotationFeatureSnapshot, CheckResultSnapshot } from 'apollo-mst'
import { ClientDataStore, checkRegistry } from 'apollo-common'
import {
AnnotationFeatureSnapshot,
ApolloAssemblyI,
CheckResultSnapshot,
} from 'apollo-mst'
import { getSnapshot } from 'mobx-state-tree'
import { nanoid } from 'nanoid'

export async function loadAssemblyIntoClient(
Expand All @@ -25,16 +30,14 @@ export async function loadAssemblyIntoClient(
assembly = apolloDataStore.addAssembly(assemblyId)
}

const checkResults: CheckResultSnapshot[] = []
for (const seqLine of featuresAndSequences) {
if (Array.isArray(seqLine)) {
// regular feature
const feature = createFeature(seqLine)

let ref = assembly.refSeqs.get(feature.refSeq)
if (!ref) {
ref = assembly.addRefSeq(feature.refSeq, feature.refSeq)
}
const ref =
assembly.refSeqs.get(feature.refSeq) ??
assembly.addRefSeq(feature.refSeq, feature.refSeq)
if (!ref.features.has(feature._id)) {
ref.addFeature(feature)
}
Expand All @@ -57,15 +60,34 @@ export async function loadAssemblyIntoClient(
})
}
}
apolloDataStore.addCheckResults(checkResults)

if (sequenceFeatureCount === 0) {
throw new Error('No embedded FASTA section found in GFF3')
}

const checkResults: CheckResultSnapshot[] = await checkFeatures(assembly)
apolloDataStore.addCheckResults(checkResults)
return assembly
}

async function checkFeatures(
assembly: ApolloAssemblyI,
): Promise<CheckResultSnapshot[]> {
let checkResults: CheckResultSnapshot[] = []
for (const ref of assembly.refSeqs.values()) {
for (const feature of ref.features.values()) {
for (const check of checkRegistry.getChecks().values()) {
const result: CheckResultSnapshot[] = await check.checkFeature(
getSnapshot(feature),
async (start: number, stop: number) => ref.getSequence(start, stop),
);
checkResults = [...checkResults, ...result]
}
}
}
return checkResults
}

function createFeature(gff3Feature: GFF3Feature): AnnotationFeatureSnapshot {
const [firstFeature] = gff3Feature
const {
Expand Down

0 comments on commit cf300c3

Please sign in to comment.