From 10a6cca0de13e1c2f4f36c1ccdd157d88daa6381 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 25 Sep 2023 12:47:11 -0400 Subject: [PATCH] Updates --- .../models/components/SaveTrackData.tsx | 10 ++++++---- .../variants/src/VariantTrack/saveTrackFormats/vcf.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx index 4ad64eb1bf8..7105a4882de 100644 --- a/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx +++ b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx @@ -15,7 +15,7 @@ import { IAnyStateTreeNode } from 'mobx-state-tree' import { makeStyles } from 'tss-react/mui' import { saveAs } from 'file-saver' import { observer } from 'mobx-react' -import { Dialog, ErrorMessage, LoadingEllipses } from '@jbrowse/core/ui' +import { Dialog, ErrorMessage } from '@jbrowse/core/ui' import { getSession, getContainingView, @@ -96,9 +96,11 @@ const SaveTrackDataDialog = observer(function ({ // eslint-disable-next-line @typescript-eslint/no-floating-promises ;(async () => { try { - const view = getContainingView(model) + const { visibleRegions } = getContainingView(model) as { + visibleRegions?: Region[] + } const session = getSession(model) - if (!features) { + if (!features || !visibleRegions) { return } const generator = options[type] || { @@ -108,7 +110,7 @@ const SaveTrackDataDialog = observer(function ({ await generator.callback({ features, session, - assemblyName: view.visibleRegions[0].assemblyName, + assemblyName: visibleRegions[0].assemblyName, }), ) } catch (e) { diff --git a/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts b/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts index 3bcf751ab83..59a927efbb7 100644 --- a/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts +++ b/plugins/variants/src/VariantTrack/saveTrackFormats/vcf.ts @@ -1,9 +1,17 @@ import { Feature } from '@jbrowse/core/util' +function generateINFO(feature: Feature) { + return Object.entries(feature.get('INFO')) + .map(([key, value]) => `${key}=${value}`) + .join(';') +} export function stringifyVCF({ features }: { features: Feature[] }) { + const fields = ['refName', 'start', 'name', 'REF', 'ALT', 'QUAL', 'FILTER'] return features .map(feature => { - return `hello ${feature.get('name')}` + return `${fields + .map(field => feature.get(field) || '.') + .join('\t')}\t${generateINFO(feature)}` }) .join('\n') }