Skip to content

Commit

Permalink
Start genbank
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 7, 2023
1 parent 5096330 commit 979e476
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import {
Button,
DialogActions,
DialogContent,
FormControl,
FormControlLabel,
FormLabel,
Radio,
RadioGroup,
TextField,
Typography,
} from '@mui/material'
Expand All @@ -19,7 +24,7 @@ import { getConf } from '@jbrowse/core/configuration'
import { BaseTrackModel } from '@jbrowse/core/pluggableElementTypes'

// locals
import { stringifyGFF3 } from './util'
import { stringifyGenbank, stringifyGFF3 } from './util'

const useStyles = makeStyles()({
root: {
Expand Down Expand Up @@ -56,6 +61,8 @@ export default observer(function SaveTrackDataDlg({
const { classes } = useStyles()
const [error, setError] = useState<unknown>()
const [features, setFeatures] = useState<Feature[]>()
const [type, setType] = useState('gff3')
const options = { gff3: 'GFF3', genbank: 'GenBank' }

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Expand All @@ -73,7 +80,11 @@ export default observer(function SaveTrackDataDlg({
})()
}, [model])

const str = features ? stringifyGFF3(features) : ''
const str = features
? type === 'gff3'
? stringifyGFF3(features)
: stringifyGenbank(features, {})
: ''

return (
<Dialog maxWidth="xl" open onClose={handleClose} title="Save track data">
Expand All @@ -84,6 +95,18 @@ export default observer(function SaveTrackDataDlg({
) : !features.length ? (
<Typography>No features found</Typography>
) : null}

<FormControl>
<FormLabel>File type</FormLabel>
<RadioGroup
value={type}
onChange={event => setType(event.target.value)}
>
{Object.entries(options).map(([key, val]) => (
<FormControlLabel value={key} control={<Radio />} label={val} />
))}
</RadioGroup>
</FormControl>
<TextField
variant="outlined"
multiline
Expand Down
22 changes: 22 additions & 0 deletions packages/core/pluggableElementTypes/models/components/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,25 @@ export function stringifyGFF3(feats: Feature[]) {
'\n',
)
}
// LOCUS Exported 1699 bp DNA linear UNA 04-FEB-2023
// FEATURES Location/Qualifiers
// source 1..1699
// CDS join(428..659,794..1099)
// CDS complement(join(1278..1411,1515..1650))
// ORIGIN
// 1 ttaatttgaaatagtttccattttttgataataatgaaaagctgctgaaaaaatggtttggcagttagcaattccaggaattttttcgagataagccataaattttaaaattatggaaattgatttacgtgtgtttttttctaattctaaattttttggtgacgttttccacgttgatttatttatttttcgaacccccctttccctcaaccaaaatagtatttattcttcagtttcaatattgtcaaaaagctcgatgcccgagtattttgaatcttctgcgatttcaattagaagaaatgctgcaggaaacgacgttcaaaaggtaattgaaagcatttagaacatctcataaagatgatgtttcagaacaaagttcaaaattggcttcacagtgtgatcgagcgtctcaagtggtggagtcccggacgatgtcagcagctcttcgtcgagaatgagctcatcgagctatgctacagagctcgtgagcagttctggaaaaacaaagtgaagctagatgtacgtttagcgtatgagggattagcaattcattttctaataatttcagatcgaagctcctgtcaaaatctgtggagacattcacggacagttcgaggacttgatggctctgttcgagttgaatgggtggcctgaagagcataagtaagccgccaatttgaatttggattagtatatgttttcatttcagatatctctttcttggtgattatgttgaccgtggtccattctccattgaagtcatcacactcctcttcacctttcaaatattgatgcctgacaaagtcttccttcttcgaggaaaccacgaaagccgccccgtcaatatgcaatatggattttatctggaatgcaagaagcgctactcagtcgccttgtatgatgcatttcaacttgcattcaattgtatgccactgtgcgctgtcgtgagcaagaagatcatatgtatgcatggaggaatatctgaagatctgattgacttgacgtaagatctttttccaatttccttatgtacttcaacaaccaatttccagacaactcgaaaagattgatcgtccatttgatattccggacattggcgtcatctccgacttgacctgggctgatcccgacgagaaggtcttcggatatgccgattctccacgtggcgcgggacgttctttcggtccgaatgcggtcaagaagttccttcaaatgcacaacctggatctagtcgttcgtgcccatcaggtcgtcatggatggttatgaattctttgcggaccgccaacttgtcacagtcttctcggcaccatcatactgcggacaattcgacaatgctgctgccgtgatgaatgttgacgacaaattgctctgtactttcacaatcttccgcccggatttgaaagttggcgacttcaagaagaaggacaagtgatattttgatttatcgaaataaagcattttttgtaccgtcttgattttcaggttaggctcgaatcacgcgcgcctgcttctcgaccttaaaaatgcctccaggtacaccaggaggcgagcccgctaagcaagaattccagcgccttctcccttctctcccgcttcctgagaatattgatgacataatcggtattctttttgtgtgtgcctgtatccattattcacgcacacaagaacaccaacaagcatgctggttttcttatata
/// /
export function stringifyGenbank(
feats: Feature[],
{ name = 'Exported', length = 100 }: { name?: string; length?: number },
) {
const today = new Date()
const month = today.toLocaleString('en-US', { month: 'short' }).toUpperCase()
const day = today.toLocaleString('en-US', { day: 'numeric' })
const year = today.toLocaleString('en-US', { year: 'numeric' })
const date = `${day}-${month}-${year}`
const l1 = `LOCUS ${name} ${length} bp DNA linear UNA ${date}`
const l2 = 'FEATURES Location/Qualifiers'
const l3 = ` source 1..${length}`
return [l1, l2, l3].join('\n')
}
5 changes: 4 additions & 1 deletion packages/core/rpc/methods/CoreSaveFeatureData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { toArray } from 'rxjs/operators'
import { firstValueFrom } from 'rxjs'

// locals
import { getAdapter } from '../../data_adapters/dataAdapterCache'
import RpcMethodType from '../../pluggableElementTypes/RpcMethodType'
import { RenderArgs } from './util'
Expand Down Expand Up @@ -58,7 +61,7 @@ export default class CoreGetFeatures extends RpcMethodType {
...opts,
signal,
})
const r = await ret.pipe(toArray()).toPromise()
const r = await firstValueFrom(ret.pipe(toArray()))
return r.map(f => f.toJSON())
}
}

0 comments on commit 979e476

Please sign in to comment.