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

Copy feature from evidence track #473

Open
wants to merge 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable @typescript-eslint/no-misused-promises */
import React, { useEffect, useMemo, useState } from 'react'

Check warning on line 3 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L3

Added line #L3 was not covered by tests

import {

Check warning on line 5 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L5

Added line #L5 was not covered by tests
Box,
Button,
Checkbox,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
FormControlLabel,
MenuItem,
Select,
SelectChangeEvent,
Typography,
} from '@mui/material'

import { Dialog } from './Dialog'

Check warning on line 20 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L20

Added line #L20 was not covered by tests
import { ApolloSessionModel } from '../session'
import { AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
import { getSnapshot } from 'mobx-state-tree'
import { AddFeatureChange } from '@apollo-annotation/shared'

Check warning on line 24 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L23-L24

Added lines #L23 - L24 were not covered by tests
import { Assembly } from '@jbrowse/core/assemblyManager/assembly'
import { AbstractSessionModel } from '@jbrowse/core/util'

interface CreateApolloAnnotationProps {
session: AbstractSessionModel
handleClose(): void
annotationFeature: AnnotationFeatureSnapshot
assembly: Assembly
refSeqId: string
}

// TODO: Integrate SO
const isGeneOrTranscript = (annotationFeature: AnnotationFeatureSnapshot) => {
return (

Check warning on line 38 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L37-L38

Added lines #L37 - L38 were not covered by tests
annotationFeature.type === 'gene' ||
annotationFeature.type === 'mRNA' ||
annotationFeature.type === 'transcript'

Check warning on line 41 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L40-L41

Added lines #L40 - L41 were not covered by tests
)
}

// TODO: Integrate SO
const isTranscript = (annotationFeature: AnnotationFeatureSnapshot) => {
return (

Check warning on line 47 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L46-L47

Added lines #L46 - L47 were not covered by tests
annotationFeature.type === 'mRNA' || annotationFeature.type === 'transcript'
)
}

export function CreateApolloAnnotation({

Check warning on line 52 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L52

Added line #L52 was not covered by tests
annotationFeature,
assembly,
handleClose,
refSeqId,
session,
}: CreateApolloAnnotationProps) {
const apolloSessionModel = session as unknown as ApolloSessionModel
const childIds = useMemo(

Check warning on line 60 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L58-L60

Added lines #L58 - L60 were not covered by tests
() => Object.keys(annotationFeature.children ?? {}),
[annotationFeature],
)

const features = useMemo(() => {
for (const [, asm] of apolloSessionModel.apolloDataStore.assemblies) {

Check warning on line 66 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L65-L66

Added lines #L65 - L66 were not covered by tests
if (asm._id === assembly.name) {
for (const [, refSeq] of asm.refSeqs) {

Check warning on line 68 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L68

Added line #L68 was not covered by tests
if (refSeq._id === refSeqId) {
return refSeq.features

Check warning on line 70 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L70

Added line #L70 was not covered by tests
}
}
}
}
return []

Check warning on line 75 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L75

Added line #L75 was not covered by tests
}, [])

const [parentFeatureChecked, setParentFeatureChecked] = useState(true)
const [checkedChildrens, setCheckedChildrens] = useState<string[]>(childIds)
const [errorMessage, setErrorMessage] = useState('')
const [destinationFeatures, setDestinationFeatures] = useState<

Check warning on line 81 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L78-L81

Added lines #L78 - L81 were not covered by tests
AnnotationFeatureSnapshot[]
>([])
const [selectedDestinationFeature, setSelectedDestinationFeature] =
useState<AnnotationFeatureSnapshot>()

Check warning on line 85 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L85

Added line #L85 was not covered by tests

const getFeatures = (min: number, max: number) => {
const filteredFeatures: AnnotationFeatureSnapshot[] = []

Check warning on line 88 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L87-L88

Added lines #L87 - L88 were not covered by tests

for (const [, f] of features) {
const featureSnapshot = getSnapshot(f)

Check warning on line 91 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L90-L91

Added lines #L90 - L91 were not covered by tests
if (min >= featureSnapshot.min && max <= featureSnapshot.max) {
filteredFeatures.push(featureSnapshot)

Check warning on line 93 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L93

Added line #L93 was not covered by tests
}
}

return filteredFeatures

Check warning on line 97 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L97

Added line #L97 was not covered by tests
}

useEffect(() => {
setErrorMessage('')

Check warning on line 101 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L100-L101

Added lines #L100 - L101 were not covered by tests
if (checkedChildrens.length === 0) {
setParentFeatureChecked(false)
return

Check warning on line 104 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L103-L104

Added lines #L103 - L104 were not covered by tests
}

if (annotationFeature.children) {
const checkedAnnotationFeatureChildren = Object.values(

Check warning on line 108 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L108

Added line #L108 was not covered by tests
annotationFeature.children,
)
.filter((child) => isTranscript(child))
.filter((child) => checkedChildrens.includes(child._id))
const mins = checkedAnnotationFeatureChildren.map((f) => f.min)
const maxes = checkedAnnotationFeatureChildren.map((f) => f.max)
const min = Math.min(...mins)
const max = Math.max(...maxes)
const filteredFeatures = getFeatures(min, max)
setDestinationFeatures(filteredFeatures)

Check warning on line 118 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L111-L118

Added lines #L111 - L118 were not covered by tests

if (
filteredFeatures.length === 0 &&
checkedChildrens.length > 0 &&
!parentFeatureChecked

Check warning on line 123 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L122-L123

Added lines #L122 - L123 were not covered by tests
) {
setErrorMessage('No destination features found')

Check warning on line 125 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L125

Added line #L125 was not covered by tests
}
}
}, [checkedChildrens])

const handleParentFeatureCheck = (

Check warning on line 130 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L130

Added line #L130 was not covered by tests
event: React.ChangeEvent<HTMLInputElement>,
) => {
const isChecked = event.target.checked
setParentFeatureChecked(isChecked)

Check warning on line 134 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L132-L134

Added lines #L132 - L134 were not covered by tests
setCheckedChildrens(isChecked ? childIds : [])
}

const handleChildFeatureCheck = (

Check warning on line 138 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L138

Added line #L138 was not covered by tests
event: React.ChangeEvent<HTMLInputElement>,
child: AnnotationFeatureSnapshot,
) => {
setCheckedChildrens((prevChecked) =>

Check warning on line 142 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L141-L142

Added lines #L141 - L142 were not covered by tests
event.target.checked
? [...prevChecked, child._id]
: prevChecked.filter((childId) => childId !== child._id),

Check warning on line 145 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L144-L145

Added lines #L144 - L145 were not covered by tests
)
}

const handleDestinationFeatureChange = (e: SelectChangeEvent) => {
const selectedFeature = destinationFeatures.find(
(f) => f._id === e.target.value,

Check warning on line 151 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L149-L151

Added lines #L149 - L151 were not covered by tests
)
setSelectedDestinationFeature(selectedFeature)

Check warning on line 153 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L153

Added line #L153 was not covered by tests
}

const handleCreateApolloAnnotation = async () => {

Check warning on line 156 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L156

Added line #L156 was not covered by tests
if (parentFeatureChecked) {
const change = new AddFeatureChange({

Check warning on line 158 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L158

Added line #L158 was not covered by tests
changedIds: [annotationFeature._id],
typeName: 'AddFeatureChange',
assembly: assembly.name,
addedFeature: annotationFeature,
})
await apolloSessionModel.apolloDataStore.changeManager.submit(change)
session.notify('Annotation added successfully', 'success')
handleClose()
} else {

Check warning on line 167 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L164-L167

Added lines #L164 - L167 were not covered by tests
if (!annotationFeature.children) {
return

Check warning on line 169 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L169

Added line #L169 was not covered by tests
}
if (!selectedDestinationFeature) {
return

Check warning on line 172 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L172

Added line #L172 was not covered by tests
}

for (const childId of checkedChildrens) {
const child = annotationFeature.children[childId]
const change = new AddFeatureChange({

Check warning on line 177 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L175-L177

Added lines #L175 - L177 were not covered by tests
parentFeatureId: selectedDestinationFeature._id,
changedIds: [selectedDestinationFeature._id],
typeName: 'AddFeatureChange',
assembly: assembly.name,
addedFeature: child,
})
await apolloSessionModel.apolloDataStore.changeManager.submit(change)
session.notify('Annotation added successfully', 'success')
handleClose()

Check warning on line 186 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L184-L186

Added lines #L184 - L186 were not covered by tests
}
}
}

return (

Check warning on line 191 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L191

Added line #L191 was not covered by tests
<Dialog
open
title="Create Apollo Annotation"
handleClose={handleClose}
fullWidth={true}
maxWidth="sm"
>
<DialogTitle fontSize={15}>
Select the feature to be copied to apollo track
</DialogTitle>
<DialogContent>
<Box sx={{ ml: 3 }}>
{isGeneOrTranscript(annotationFeature) && (
<FormControlLabel

Check warning on line 205 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L205

Added line #L205 was not covered by tests
control={
<Checkbox
size="small"
checked={parentFeatureChecked}
onChange={handleParentFeatureCheck}
/>
}
label={`${annotationFeature.type}:${annotationFeature.min}..${annotationFeature.max}`}
/>
)}
{annotationFeature.children && (
<Box sx={{ display: 'flex', flexDirection: 'column', ml: 3 }}>

Check warning on line 217 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L217

Added line #L217 was not covered by tests
{Object.values(annotationFeature.children)
.filter((child) => isTranscript(child))

Check warning on line 219 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L219

Added line #L219 was not covered by tests
.map((child) => (
<FormControlLabel

Check warning on line 221 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L221

Added line #L221 was not covered by tests
key={child._id}
control={
<Checkbox
size="small"
checked={checkedChildrens.includes(child._id)}
onChange={(e) => {
handleChildFeatureCheck(e, child)

Check warning on line 228 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L227-L228

Added lines #L227 - L228 were not covered by tests
}}
/>
}
label={`${child.type}:${child.min}..${child.max}`}
/>
))}
</Box>
)}
</Box>
{!parentFeatureChecked &&
checkedChildrens.length > 0 &&
destinationFeatures.length > 0 && (
<Box sx={{ ml: 3 }}>

Check warning on line 241 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L239-L241

Added lines #L239 - L241 were not covered by tests
<Typography variant="caption" fontSize={12}>
Select the destination feature to copy the selected features
</Typography>

<Box sx={{ mt: 1 }}>
<Select
labelId="label"
style={{ width: '100%' }}
value={selectedDestinationFeature?._id ?? ''}
onChange={handleDestinationFeatureChange}
>
{destinationFeatures.map((f) => (
<MenuItem key={f._id} value={f._id}>

Check warning on line 254 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L254

Added line #L254 was not covered by tests
{`${f.type}:${f.min}..${f.max}`}
</MenuItem>
))}
</Select>
</Box>
</Box>
)}
</DialogContent>
<DialogActions>
<Button
variant="contained"
type="submit"
disabled={
checkedChildrens.length === 0 ||
(!parentFeatureChecked &&
checkedChildrens.length > 0 &&
!selectedDestinationFeature)

Check warning on line 271 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L269-L271

Added lines #L269 - L271 were not covered by tests
}
onClick={handleCreateApolloAnnotation}
>
Create
</Button>
<Button variant="outlined" type="submit" onClick={handleClose}>
Cancel
</Button>
</DialogActions>
{errorMessage ? (
<DialogContent>

Check warning on line 282 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L282

Added line #L282 was not covered by tests
<DialogContentText color="error">{errorMessage}</DialogContentText>
</DialogContent>
) : null}

Check warning on line 285 in packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/components/CreateApolloAnnotation.tsx#L285

Added line #L285 was not covered by tests
</Dialog>
)
}
Loading