Skip to content

Commit

Permalink
Rename some files
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 25, 2025
1 parent 766f2f1 commit f974810
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 167 deletions.
63 changes: 4 additions & 59 deletions plugins/bed/src/BedpeAdapter/BedpeAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,14 @@
import IntervalTree from '@flatten-js/interval-tree'
import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'
import { SimpleFeature, fetchAndMaybeUnzipText } from '@jbrowse/core/util'
import { fetchAndMaybeUnzipText } from '@jbrowse/core/util'
import { openLocation } from '@jbrowse/core/util/io'
import { ObservableCreate } from '@jbrowse/core/util/rxjs'

import { featureData } from './util'

import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'
import type { Feature, Region } from '@jbrowse/core/util'

const svTypes = new Set(['DUP', 'TRA', 'INV', 'CNV', 'DEL'])

export function featureData(
line: string,
uniqueId: string,
flip: boolean,
names?: string[],
) {
const l = line.split('\t')
const ref1 = l[flip ? 3 : 0]!
const start1 = +l[flip ? 4 : 1]!
const end1 = +l[flip ? 5 : 2]!
const ref2 = l[!flip ? 3 : 0]!
const start2 = +l[!flip ? 4 : 1]!
const end2 = +l[!flip ? 5 : 2]!
const name = l[6]!
const score = +l[7]!
const strand1 = parseStrand(l[8]!)
const strand2 = parseStrand(l[9]!)
const extra = l.slice(10)
const rest = names
? Object.fromEntries(names.slice(10).map((n, idx) => [n, extra[idx]]))
: {}
const ALT = svTypes.has(extra[0]!) ? `<${extra[0]}>` : undefined

return new SimpleFeature({
...rest,
start: start1,
end: end1,
type: 'paired_feature',
refName: ref1,
strand: strand1,
name,
score,
uniqueId,
mate: {
refName: ref2,
start: start2,
end: end2,
strand: strand2,
},
...(ALT ? { ALT: [ALT] } : {}), // ALT is an array in VCF
})
}

function parseStrand(strand: string) {
if (strand === '+') {
return 1
} else if (strand === '-') {
return -1
} else if (strand === '.') {
return 0
} else {
return undefined
}
}

export default class BedpeAdapter extends BaseFeatureDataAdapter {
protected bedpeFeatures?: Promise<{
header: string
Expand All @@ -81,7 +26,7 @@ export default class BedpeAdapter extends BaseFeatureDataAdapter {

private async loadDataP(opts?: BaseOptions) {
const data = await fetchAndMaybeUnzipText(
openLocation(this.getConf('bedLoc'), this.pluginManager),
openLocation(this.getConf('bedpeLocation'), this.pluginManager),
opts,
)

Expand Down
58 changes: 58 additions & 0 deletions plugins/bed/src/BedpeAdapter/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { SimpleFeature } from '@jbrowse/core/util'

const svTypes = new Set(['DUP', 'TRA', 'INV', 'CNV', 'DEL'])

export function featureData(
line: string,
uniqueId: string,
flip: boolean,
names?: string[],
) {
const l = line.split('\t')
const ref1 = l[flip ? 3 : 0]!
const start1 = +l[flip ? 4 : 1]!
const end1 = +l[flip ? 5 : 2]!
const ref2 = l[!flip ? 3 : 0]!
const start2 = +l[!flip ? 4 : 1]!
const end2 = +l[!flip ? 5 : 2]!
const name = l[6]!
const score = +l[7]!
const strand1 = parseStrand(l[8]!)
const strand2 = parseStrand(l[9]!)
const extra = l.slice(10)
const rest = names
? Object.fromEntries(names.slice(10).map((n, idx) => [n, extra[idx]]))
: {}
const ALT = svTypes.has(extra[0]!) ? `<${extra[0]}>` : undefined

return new SimpleFeature({
...rest,
start: start1,
end: end1,
type: 'paired_feature',
refName: ref1,
strand: strand1,
name,
score,
uniqueId,
mate: {
refName: ref2,
start: start2,
end: end2,
strand: strand2,
},
...(ALT ? { ALT: [ALT] } : {}), // ALT is an array in VCF
})
}

function parseStrand(strand: string) {
if (strand === '+') {
return 1
} else if (strand === '-') {
return -1
} else if (strand === '.') {
return 0
} else {
return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function LaunchBreakpointSplitViewPanel({
)
}

export default function BreakendPanel(props: {
export default function LaunchBreakendPanel(props: {
locStrings: string[]
model: VariantFeatureWidgetModel
feature: SimpleFeatureSerialized
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { lazy, Suspense } from 'react'

Check failure on line 1 in plugins/variants/src/VariantFeatureWidget/LaunchBreakendWidgetArea.tsx

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

`Suspense` import should occur before import of `lazy`

import { parseBreakend } from '@gmod/vcf'

import type { VariantFeatureWidgetModel } from './stateModelFactory'

// lazies
const LaunchBreakendPanel = lazy(() => import('./LaunchBreakendPanelEntry'))

export default function LaunchBreakendWidgetArea({
model,
}: {
model: VariantFeatureWidgetModel
}) {
const { featureData } = model
const feat = JSON.parse(JSON.stringify(featureData))
const { type = '' } = feat

return (
<Suspense fallback={null}>
{type === 'breakend' ? (
<LaunchBreakendPanel
feature={feat}
locStrings={feat.ALT.map(
(alt: string) => parseBreakend(alt)?.MatePosition || '',
)}
model={model}
/>
) : type === 'translocation' ? (
<LaunchBreakendPanel
feature={feat}
model={model}
locStrings={[`${feat.INFO.CHR2[0]}:${feat.INFO.END}`]}
/>
) : type === 'paired_feature' ? (
<LaunchBreakendPanel
feature={feat}
model={model}
locStrings={[`${feat.mate.refName}:${feat.mate.start}`]}
/>
) : type.includes('inversion') ||
type.includes('deletion') ||
type.includes('duplication') ||
type.includes('cnv') ||
type.includes('sv') ? (
<LaunchBreakendPanel
feature={{
uniqueId: 'random',
refName: feat.refName,
start: feat.start,
end: feat.start + 1,
mate: {
refName: feat.refName,
start: feat.end,
end: feat.end + 1,
},
}}
model={model}
locStrings={[`${feat.refName}:${feat.end}`]}
/>
) : null}
</Suspense>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import BaseCard from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail/BaseCard'

import VariantConsequenceDataGridWrapper from './VariantConsequenceDataGridWrapper'

export default function VariantConsequenceDataGrid({
data,
fields,
title,
}: {
data: string[]
fields: string[]
title: string
}) {
return data.length ? (
<BaseCard title={title}>
<VariantConsequenceDataGridWrapper
rows={data.map((elt, id) => ({
id,
...Object.fromEntries(elt.split('|').map((e, i) => [fields[i], e])),
}))}
columns={fields.map(c => ({ field: c }))}
/>
</BaseCard>
) : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DataGrid, GridToolbar } from '@mui/x-data-grid'

import type { GridColDef, GridValidRowModel } from '@mui/x-data-grid'

export default function VariantAnnotPanel({
export default function VariantConsequenceDataGridWrapper({
rows,
columns,
}: {
Expand All @@ -33,8 +33,13 @@ export default function VariantAnnotPanel({
<DataGrid
rowHeight={25}
rows={rows}
columns={columns.map((c, i) => ({ ...c, width: widths[i] }))}
slots={{ toolbar: checked ? GridToolbar : null }}
columns={columns.map((c, i) => ({
...c,
width: widths[i],
}))}
slots={{
toolbar: checked ? GridToolbar : null,
}}
/>
</div>
) : null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BaseCard from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail/BaseCard'

import AnnotGrid from './AnnotGrid'
import VariantConsequenceDataGridWrapper from './VariantConsequenceDataGridWrapper'

export default function VariantAnnotationTable({
export default function VariantConsequencePanel({
data,
fields,
title,
Expand All @@ -13,7 +13,7 @@ export default function VariantAnnotationTable({
}) {
return data.length ? (
<BaseCard title={title}>
<AnnotGrid
<VariantConsequenceDataGridWrapper
rows={data.map((elt, id) => ({
id,
...Object.fromEntries(elt.split('|').map((e, i) => [fields[i], e])),
Expand Down
Loading

0 comments on commit f974810

Please sign in to comment.