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

Render CSQ and ANN fields in VCF feature details as data grids #3152

Merged
merged 9 commits into from
Aug 25, 2022
Merged
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
21 changes: 19 additions & 2 deletions plugins/variants/src/LinearVariantDisplay/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
export { LinearVariantDisplayConfigFactory as configSchemaFactory } from './configSchema'
export { default as modelFactory } from './model'
import PluginManager from '@jbrowse/core/PluginManager'
import { LinearVariantDisplayConfigFactory } from './configSchema'
import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view'
import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'
import stateModelFactory from './model'

export default (pluginManager: PluginManager) => {
pluginManager.addDisplayType(() => {
const configSchema = LinearVariantDisplayConfigFactory(pluginManager)
return new DisplayType({
name: 'LinearVariantDisplay',
configSchema,
stateModel: stateModelFactory(configSchema),
trackType: 'VariantTrack',
viewType: 'LinearGenomeView',
ReactComponent: BaseLinearDisplayComponent,
})
})
}
28 changes: 28 additions & 0 deletions plugins/variants/src/VariantFeatureWidget/AnnotGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react'
import { DataGrid } from '@mui/x-data-grid'

export default function VariantAnnotPanel({
rows,
columns,
}: {
rows: any
columns: any[]
}) {
const rowHeight = 25
const hideFooter = rows.length < 100
const headerHeight = 80
return rows.length ? (
<div
style={{
height:
Math.min(rows.length, 100) * rowHeight +
headerHeight +
(hideFooter ? 0 : 50),
width: '100%',
}}
>
<DataGrid rowHeight={rowHeight} rows={rows} columns={columns} />
</div>
) : null
}
94 changes: 94 additions & 0 deletions plugins/variants/src/VariantFeatureWidget/BreakendPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useState } from 'react'
import { Link, Typography } from '@mui/material'
import SimpleFeature, {
SimpleFeatureSerialized,
} from '@jbrowse/core/util/simpleFeature'
import { getSession } from '@jbrowse/core/util'
import { getEnv } from 'mobx-state-tree'
import { BaseCard } from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail'
import BreakendOptionDialog from './BreakendOptionDialog'

export default function BreakendPanel(props: {
locStrings: string[]
model: any
feature: SimpleFeatureSerialized
}) {
const { model, locStrings, feature } = props
const session = getSession(model)
const { pluginManager } = getEnv(session)
const [breakpointDialog, setBreakpointDialog] = useState(false)
let viewType

try {
viewType = pluginManager.getViewType('BreakpointSplitView')
} catch (e) {
// ignore
}

const simpleFeature = new SimpleFeature(feature)
return (
<BaseCard {...props} title="Breakends">
<Typography>Link to linear view of breakend endpoints</Typography>
<ul>
{locStrings.map(locString => (
<li key={`${JSON.stringify(locString)}`}>
<Link
href="#"
onClick={event => {
event.preventDefault()
const { view } = model
try {
if (view) {
view.navToLocString?.(locString)
} else {
throw new Error(
'No view associated with this feature detail panel anymore',
)
}
} catch (e) {
console.error(e)
session.notify(`${e}`)
}
}}
>
{`LGV - ${locString}`}
</Link>
</li>
))}
</ul>
{viewType ? (
<div>
<Typography>
Launch split views with breakend source and target
</Typography>
<ul>
{locStrings.map(locString => (
<li key={`${JSON.stringify(locString)}`}>
<Link
href="#"
onClick={event => {
event.preventDefault()
setBreakpointDialog(true)
}}
>
{`${feature.refName}:${feature.start} // ${locString} (split view)`}
</Link>
</li>
))}
</ul>
{breakpointDialog ? (
<BreakendOptionDialog
model={model}
feature={simpleFeature}
viewType={viewType}
handleClose={() => {
setBreakpointDialog(false)
}}
/>
) : null}
</div>
) : null}
</BaseCard>
)
}
31 changes: 31 additions & 0 deletions plugins/variants/src/VariantFeatureWidget/VariantAnnPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react'
import { BaseCard } from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail'
import AnnotGrid from './AnnotGrid'

export default function VariantAnnPanel({
feature,
descriptions,
}: {
feature: any
descriptions: any
}) {
const annFields = (descriptions?.INFO?.ANN?.Description?.match(
/.*Functional annotations:'(.*)'$/,
)?.[1].split('|') || []) as string[]
const ann = (feature.INFO.ANN || []) as string[]

const rows =
ann.map((elt, id) => ({
id,
...Object.fromEntries(elt.split('|').map((e, i) => [annFields[i], e])),
})) || []
const columns = annFields.map(c => ({
field: c,
}))
return ann.length ? (
<BaseCard title="ANN table">
<AnnotGrid rows={rows} columns={columns} />
</BaseCard>
) : null
}
31 changes: 31 additions & 0 deletions plugins/variants/src/VariantFeatureWidget/VariantCsqPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react'
import { BaseCard } from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail'
import AnnotGrid from './AnnotGrid'

export default function VariantCsqPanel({
feature,
descriptions,
}: {
feature: any
descriptions: any
}) {
const csqFields = (descriptions?.INFO?.CSQ?.Description?.match(
/.*Format: (.*)/,
)?.[1].split('|') || []) as string[]

const csq = (feature.INFO.CSQ || []) as string[]
const rows =
csq.map((elt, id) => ({
id,
...Object.fromEntries(elt.split('|').map((e, i) => [csqFields[i], e])),
})) || []
const columns = csqFields.map(c => ({
field: c,
}))
return csq.length ? (
<BaseCard title="CSQ table">
<AnnotGrid rows={rows} columns={columns} />
</BaseCard>
) : null
}
Loading