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

452 reactive sync ontology #477

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions packages/apollo-mst/src/AnnotationFeatureModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { intersection2 } from '@jbrowse/core/util'
import { getSession, intersection2 } from '@jbrowse/core/util'
import {
IAnyModelType,
IMSTMap,
Expand Down Expand Up @@ -109,7 +109,14 @@ export const AnnotationFeatureModel = types
return false
},
get cdsLocations(): { min: number; max: number; phase: 0 | 1 | 2 }[][] {
if (self.type !== 'mRNA') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
const session = getSession(self) as any
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { apolloDataStore } = session
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const { featureTypeOntology } = apolloDataStore.ontologyManager
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
if (!featureTypeOntology.isTypeOf(self.type, 'mRNA')) {
throw new Error(
'Only features of type "mRNA" or equivalent can calculate CDS locations',
)
Expand All @@ -119,7 +126,8 @@ export const AnnotationFeatureModel = types
throw new Error('no CDS or exons in mRNA')
}
const cdsChildren = [...children.values()].filter(
(child) => child.type === 'CDS',
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
(child) => featureTypeOntology.isTypeOf(child.type, 'CDS'),
)
if (cdsChildren.length === 0) {
throw new Error('no CDS in mRNA')
Expand All @@ -130,7 +138,8 @@ export const AnnotationFeatureModel = types
const { max: cdsMax, min: cdsMin } = cds
const locs: { min: number; max: number }[] = []
for (const [, child] of children) {
if (child.type !== 'exon') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
if (!featureTypeOntology.isTypeOf(child.type, 'exon')) {
continue
}
const [start, end] = intersection2(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@
const { notify } = session as unknown as AbstractSessionModel
const currentAssembly = session.apolloDataStore.assemblies.get(assembly)
const refData = currentAssembly?.getByRefName(refName)
const { changeManager } = session.apolloDataStore

const { changeManager, ontologyManager } = session.apolloDataStore
const { featureTypeOntology } = ontologyManager

Check warning on line 87 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx#L86-L87

Added lines #L86 - L87 were not covered by tests
if (!featureTypeOntology) {
throw new Error('featureTypeOntology is undefined')

Check warning on line 89 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx#L89

Added line #L89 was not covered by tests
}
function handleStartChange(
newStart: number,
featureId: string,
Expand All @@ -100,10 +103,14 @@
if (!subFeature?.children) {
return
}
if (!featureTypeOntology) {
throw new Error('featureTypeOntology is undefined')

Check warning on line 107 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx#L107

Added line #L107 was not covered by tests
}
// Let's check CDS start and end values. And possibly update those too
for (const child of subFeature.children) {
if (
(child[1].type === 'CDS' || child[1].type === 'exon') &&
(featureTypeOntology.isTypeOf(child[1].type, 'CDS') ||
featureTypeOntology.isTypeOf(child[1].type, 'exon')) &&

Check warning on line 113 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx#L113

Added line #L113 was not covered by tests
child[1].min === oldStart
) {
const change = new LocationStartChange({
Expand Down Expand Up @@ -135,10 +142,14 @@
if (!subFeature?.children) {
return
}
if (!featureTypeOntology) {
throw new Error('featureTypeOntology is undefined')

Check warning on line 146 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx#L146

Added line #L146 was not covered by tests
}
// Let's check CDS start and end values. And possibly update those too
for (const child of subFeature.children) {
if (
(child[1].type === 'CDS' || child[1].type === 'exon') &&
(featureTypeOntology.isTypeOf(child[1].type, 'CDS') ||
featureTypeOntology.isTypeOf(child[1].type, 'exon')) &&

Check warning on line 152 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx#L152

Added line #L152 was not covered by tests
child[1].max === oldEnd
) {
const change = new LocationEndChange({
Expand All @@ -160,7 +171,7 @@
const featureNew = feature
let exonsArray: ExonInfo[] = []
const traverse = (currentFeature: AnnotationFeature) => {
if (currentFeature.type === 'exon') {
if (featureTypeOntology.isTypeOf(currentFeature.type, 'exon')) {
exonsArray.push({
min: currentFeature.min + 1,
max: currentFeature.max,
Expand Down Expand Up @@ -384,10 +395,10 @@
{transcriptItems.map((item, index) => (
<div key={index} style={{ display: 'flex', alignItems: 'center' }}>
<span style={{ marginLeft: '20px', width: '50px' }}>
{item.type === 'three_prime_UTR'
{featureTypeOntology.isTypeOf(item.type, 'three_prime_UTR')
? '3 UTR'
: // eslint-disable-next-line unicorn/no-nested-ternary
item.type === 'five_prime_UTR'
featureTypeOntology.isTypeOf(item.type, 'five_prime_UTR')
? '5 UTR'
: 'CDS'}
</span>
Expand All @@ -397,7 +408,7 @@
<NumberTextField
margin="dense"
id={item.id}
disabled={item.type !== 'CDS'}
disabled={!featureTypeOntology.isTypeOf(item.type, 'CDS')}
style={{
width: '150px',
marginLeft: '8px',
Expand All @@ -419,7 +430,7 @@
<NumberTextField
margin="dense"
id={item.id}
disabled={item.type !== 'CDS'}
disabled={!featureTypeOntology.isTypeOf(item.type, 'CDS')}
style={{
width: '150px',
backgroundColor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import React, { useState } from 'react'

import { ApolloSessionModel } from '../session'
import { OntologyRecord } from '../OntologyManager'

export interface CDSInfo {
id: string
Expand All @@ -28,6 +29,7 @@
const getCDSInfo = (
feature: AnnotationFeature,
refData: ApolloRefSeqI,
featureTypeOntology: OntologyRecord,
): CDSInfo[] => {
const CDSresult: CDSInfo[] = []
const traverse = (
Expand All @@ -36,9 +38,9 @@
) => {
if (
isParentMRNA &&
(currentFeature.type === 'CDS' ||
currentFeature.type === 'three_prime_UTR' ||
currentFeature.type === 'five_prime_UTR')
(featureTypeOntology.isTypeOf(currentFeature.type, 'CDS') ||
featureTypeOntology.isTypeOf(currentFeature.type, 'three_prime_UTR') ||
featureTypeOntology.isTypeOf(currentFeature.type, 'five_prime_UTR'))

Check warning on line 43 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L41-L43

Added lines #L41 - L43 were not covered by tests
) {
let startSeq = refData.getSequence(
Number(currentFeature.min) - 2,
Expand Down Expand Up @@ -149,14 +151,22 @@
if (!refSeq) {
return null
}
const transcriptItems = getCDSInfo(feature, refData)
const { featureTypeOntology } = session.apolloDataStore.ontologyManager

Check warning on line 154 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L154

Added line #L154 was not covered by tests
if (!featureTypeOntology) {
throw new Error('featureTypeOntology is undefined')

Check warning on line 156 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L156

Added line #L156 was not covered by tests
}
const transcriptItems = getCDSInfo(feature, refData, featureTypeOntology)

Check warning on line 158 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L158

Added line #L158 was not covered by tests
const { max, min } = feature
let sequence = ''
if (showSequence) {
getSequenceAsString(min, max)
getSequenceAsString(min, max, featureTypeOntology)

Check warning on line 162 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L162

Added line #L162 was not covered by tests
}

function getSequenceAsString(start: number, end: number): string {
function getSequenceAsString(
start: number,
end: number,
featureTypeOntology: OntologyRecord,

Check warning on line 168 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L168

Added line #L168 was not covered by tests
): string {
sequence = refSeq?.getSequence(start, end) ?? ''
if (sequence === '') {
void session.apolloDataStore.loadRefSeq([
Expand All @@ -165,15 +175,18 @@
} else {
sequence = formatSequence(sequence, refName, start, end)
}
getSequenceAsTextSegment(selectedOption) // For color coded sequence
getSequenceAsTextSegment(selectedOption, featureTypeOntology) // For color coded sequence

Check warning on line 178 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L178

Added line #L178 was not covered by tests
return sequence
}

const handleSeqButtonClick = () => {
setShowSequence(!showSequence)
}

function getSequenceAsTextSegment(option: string) {
function getSequenceAsTextSegment(
option: string,
featureTypeOntology: OntologyRecord,

Check warning on line 188 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L188

Added line #L188 was not covered by tests
) {
let seqData = ''
textSegments = []
if (!refData) {
Expand All @@ -183,7 +196,7 @@
case 'CDS': {
textSegments.push({ text: `>${refName} : CDS\n`, color: 'black' })
for (const item of transcriptItems) {
if (item.type === 'CDS') {
if (featureTypeOntology.isTypeOf(item.type, 'CDS')) {
const refSeq: string = refData.getSequence(
Number(item.min + 1),
Number(item.max),
Expand All @@ -198,16 +211,16 @@
textSegments.push({ text: `>${refName} : cDNA\n`, color: 'black' })
for (const item of transcriptItems) {
if (
item.type === 'CDS' ||
item.type === 'three_prime_UTR' ||
item.type === 'five_prime_UTR'
featureTypeOntology.isTypeOf(item.type, 'CDS') ||
featureTypeOntology.isTypeOf(item.type, 'three_prime_UTR') ||
featureTypeOntology.isTypeOf(item.type, 'five_prime_UTR')

Check warning on line 216 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L215-L216

Added lines #L215 - L216 were not covered by tests
) {
const refSeq: string = refData.getSequence(
Number(item.min + 1),
Number(item.max),
)
seqData += item.strand === -1 && refSeq ? revcom(refSeq) : refSeq
if (item.type === 'CDS') {
if (featureTypeOntology.isTypeOf(item.type, 'CDS')) {
textSegments.push({ text: seqData, color: cdsColor })
} else {
textSegments.push({ text: seqData, color: utrColor })
Expand Down Expand Up @@ -239,9 +252,9 @@
textSegments.push({ text: seqData, color: 'black' })
}
if (
item.type === 'CDS' ||
item.type === 'three_prime_UTR' ||
item.type === 'five_prime_UTR'
featureTypeOntology.isTypeOf(item.type, 'CDS') ||
featureTypeOntology.isTypeOf(item.type, 'three_prime_UTR') ||
featureTypeOntology.isTypeOf(item.type, 'five_prime_UTR')

Check warning on line 257 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L256-L257

Added lines #L256 - L257 were not covered by tests
) {
const refSeq: string = refData.getSequence(
Number(item.min + 1),
Expand Down Expand Up @@ -274,10 +287,13 @@
}
}

function handleChangeSeqOption(e: SelectChangeEvent) {
function handleChangeSeqOption(
e: SelectChangeEvent,
featureTypeOntology: OntologyRecord,

Check warning on line 292 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L292

Added line #L292 was not covered by tests
) {
const option = e.target.value
setSelectedOption(option)
getSequenceAsTextSegment(option)
getSequenceAsTextSegment(option, featureTypeOntology)

Check warning on line 296 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L296

Added line #L296 was not covered by tests
}

// Function to copy text to clipboard
Expand Down Expand Up @@ -329,7 +345,9 @@
{showSequence && (
<Select
value={selectedOption}
onChange={handleChangeSeqOption}
onChange={(e: SelectChangeEvent) => {
handleChangeSeqOption(e, featureTypeOntology)

Check warning on line 349 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx#L348-L349

Added lines #L348 - L349 were not covered by tests
}}
style={{ width: '150px', marginLeft: '15px', height: '25px' }}
>
<MenuItem value={'Select'}>Select</MenuItem>
Expand Down
Loading