From 1c309fc327fff8e63a08db5a522225b98739cef9 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 25 Sep 2023 12:40:57 -0400 Subject: [PATCH] VariantTrack VCF format --- .../models/components/SaveTrackData.tsx | 5 ++--- plugins/variants/src/VariantTrack/index.ts | 16 +++++++++++++++- .../src/VariantTrack/saveTrackFormats/vcf.ts | 9 +++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts diff --git a/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx index 112fc8a6bb2..4ad64eb1bf8 100644 --- a/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx +++ b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx @@ -71,10 +71,11 @@ const SaveTrackDataDialog = observer(function ({ } handleClose: () => void }) { + const options = model.saveTrackFileFormatOptions() const { classes } = useStyles() const [error, setError] = useState() const [features, setFeatures] = useState() - const [type, setType] = useState('gff3') + const [type, setType] = useState(Object.keys(options)[0]) const [str, setStr] = useState('') useEffect(() => { @@ -91,8 +92,6 @@ const SaveTrackDataDialog = observer(function ({ })() }, [model]) - const options = model.saveTrackFileFormatOptions() - useEffect(() => { // eslint-disable-next-line @typescript-eslint/no-floating-promises ;(async () => { diff --git a/plugins/variants/src/VariantTrack/index.ts b/plugins/variants/src/VariantTrack/index.ts index 62e40227ffe..49999a794cc 100644 --- a/plugins/variants/src/VariantTrack/index.ts +++ b/plugins/variants/src/VariantTrack/index.ts @@ -3,6 +3,8 @@ 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) @@ -10,7 +12,19 @@ export default (pm: PluginManager) => { 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, + }, + } + }, + }), + ), }) }) } diff --git a/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts b/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts new file mode 100644 index 00000000000..3bcf751ab83 --- /dev/null +++ b/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts @@ -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') +}