Skip to content

Commit

Permalink
VariantTrack VCF format
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 21, 2024
1 parent 7a9ce57 commit fc30ee7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ const SaveTrackDataDialog = observer(function ({
}
handleClose: () => void
}) {
const options = model.saveTrackFileFormatOptions()
const { classes } = useStyles()
const [error, setError] = useState<unknown>()
const [features, setFeatures] = useState<Feature[]>()
const [type, setType] = useState('gff3')
const [type, setType] = useState(Object.keys(options)[0])
const [str, setStr] = useState('')

useEffect(() => {
Expand All @@ -91,8 +92,6 @@ const SaveTrackDataDialog = observer(function ({
})()
}, [model])

const options = model.saveTrackFileFormatOptions()

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
Expand Down
16 changes: 15 additions & 1 deletion plugins/variants/src/VariantTrack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType'
import { createBaseTrackModel } from '@jbrowse/core/pluggableElementTypes/models'
import configSchemaF from './configSchema'

import { stringifyVCF } from './saveTrackFormats/vcf'

export default (pm: PluginManager) => {
pm.addTrackType(() => {
const configSchema = configSchemaF(pm)
return new TrackType({
name: 'VariantTrack',
displayName: 'Variant track',
configSchema,
stateModel: createBaseTrackModel(pm, 'VariantTrack', configSchema),
stateModel: createBaseTrackModel(pm, 'VariantTrack', configSchema).views(
() => ({
saveTrackFileFormatOptions() {
return {
vcf: {
name: 'VCF',
extension: 'vcf',
callback: stringifyVCF,
},
}
},
}),
),
})
})
}
9 changes: 9 additions & 0 deletions plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Feature } from '@jbrowse/core/util'

export function stringifyVCF({ features }: { features: Feature[] }) {
return features
.map(feature => {
return `hello ${feature.get('name')}`
})
.join('\n')
}

0 comments on commit fc30ee7

Please sign in to comment.