Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 13, 2024
1 parent c39d3c1 commit fd47c34
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getSession, Feature, Region } from '@jbrowse/core/util'
import {
getSession,
Feature,
Region,
AbstractSessionModel,
} from '@jbrowse/core/util'
import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType'
import { parseBreakend } from '@gmod/vcf'
import { IStateTreeNode } from 'mobx-state-tree'
Expand Down Expand Up @@ -103,15 +108,12 @@ export default class BreakpointSplitViewType extends ViewType {
featureData: undefined as unknown,
}
}

snapshotFromBreakendFeature(
async snapshotFromBreakendFeature(
feature: Feature,
view: { displayedRegions: Region[] } & IStateTreeNode,
assemblyName: string,
session: AbstractSessionModel,
) {
const session = getSession(view)
const bpPerPx = 10
const { assemblyName } = view.displayedRegions[0]!

const { assemblyManager } = session
const assembly = assemblyManager.get(assemblyName)
if (!assembly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ const PairedFeatures = observer(function ({
const [mouseoverElt, setMouseoverElt] = useState<string>()
const snap = getSnapshot(model)
useNextFrame(snap)
const assembly = assemblyManager.get(views[0]!.assemblyNames[0]!)

if (!assembly) {
return null
}
const assembly = views[0]
? assemblyManager.get(views[0].assemblyNames[0]!)
: undefined

let yoff = 0
if (ref.current) {
const rect = ref.current.getBoundingClientRect()
yoff = rect.top
}

return (
return assembly ? (
<g
stroke="green"
strokeWidth={5}
Expand Down Expand Up @@ -121,7 +119,7 @@ const PairedFeatures = observer(function ({
return ret
})}
</g>
)
) : null
})

export default PairedFeatures
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const Translocations = observer(function ({
const snap = getSnapshot(model)
useNextFrame(snap)

const assembly = assemblyManager.get(views[0]!.assemblyNames[0]!)
const assembly = views[0]
? assemblyManager.get(views[0].assemblyNames[0]!)
: undefined
let yOffset = 0
if (ref.current) {
const rect = ref.current.getBoundingClientRect()
Expand All @@ -60,7 +62,6 @@ const Translocations = observer(function ({
// just return null here note: would need to do processing of the INFO
// CHR2/END and see which view could contain those coordinates to really do
// it properly

return !assembly || views.length < 2 ? null : (
<g
fill="none"
Expand All @@ -80,20 +81,18 @@ const Translocations = observer(function ({
}

const info = f1.get('INFO')
const chr1 = f1.get('refName')
const chr2 = info.CHR2[0]
const f1ref = assembly.getCanonicalRefName(chr2) || chr2
const f2ref = assembly.getCanonicalRefName(chr1) || chr2
const end2 = info.END[0]
const res = info.STRANDS?.[0]?.split('') // not all files have STRANDS
const [myDirection, mateDirection] = res ?? ['.', '.']

const r = getPxFromCoordinate(views[level2]!, chr2, end2, assembly)
const r = getPxFromCoordinate(views[level2]!, f2ref, end2)
if (r) {
const c2: LayoutRecord = [r, 0, r + 1, 0]
const x1 = getPxFromCoordinate(
views[level1]!,
f1.get('refName'),
c1[LEFT],
assembly,
)
const x1 = getPxFromCoordinate(views[level1]!, f1ref, c1[LEFT])
const x2 = r
const reversed1 = views[level1]!.pxToBp(x1).reversed
const reversed2 = views[level2]!.pxToBp(x2).reversed
Expand Down
10 changes: 2 additions & 8 deletions plugins/breakpoint-split-view/src/BreakpointSplitView/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { clamp } from '@jbrowse/core/util'

// locals
import { LayoutRecord } from './model'
import { Assembly } from '@jbrowse/core/assemblyManager/assembly'

type LGV = LinearGenomeViewModel

Expand Down Expand Up @@ -35,15 +34,10 @@ export function heightFromSpecificLevel(
: views[level]!.trackRefs[trackId]?.getBoundingClientRect().top || 0
}

export function getPxFromCoordinate(
view: LGV,
refName: string,
coord: number,
asm: Assembly,
) {
export function getPxFromCoordinate(view: LGV, refName: string, coord: number) {
return (
(view.bpToPx({
refName: asm.getCanonicalRefName(refName) || refName,
refName,
coord,
})?.offsetPx || 0) - view.offsetPx
)
Expand Down
5 changes: 0 additions & 5 deletions plugins/spreadsheet-view/src/LaunchSpreadsheetView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ export default function LaunchSpreadsheetViewF(pluginManager: PluginManager) {
uri: string
}) => {
const view = session.addView('SpreadsheetView') as SpreadsheetViewModel

if (!view) {
throw new Error('Failed to initialize view')
}

view.importWizard.setSelectedAssemblyName(assembly)
view.importWizard.setSpreadsheetFilehandle({
uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ImportWizard = observer(({ model }: { model: ImportWizardModel }) => {
const { assemblyNames, assemblyManager } = session
const { fileTypes, error, loading } = model
const [selected, setSelected] = useState(assemblyNames[0])
const err = assemblyManager.get(selected)?.error || error
const err = assemblyManager.get(selected || '')?.error || error
const rootModel = getRoot<AbstractRootModel>(model)
const [tmp, setTmp] = useState<FileLocation>()
const [fileType, setFileType] = useState(getFileType(tmp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export async function parseBedBuffer(buffer: Buffer) {
for (
;
i < lines.length &&
(lines[i].startsWith('#') ||
lines[i].startsWith('browser') ||
lines[i].startsWith('track'));
(lines[i]!.startsWith('#') ||
lines[i]!.startsWith('browser') ||
lines[i]!.startsWith('track'));
i++
) {
headerLines.push(lines[i])
Expand Down Expand Up @@ -45,13 +45,13 @@ export async function parseBedBuffer(buffer: Buffer) {
])
const rows = []
for (let j = 0; i < lines.length; i++, j++) {
const line = lines[i]
const line = lines[i]!
const l = line.split('\t')
const refName = l[0]
const start = +l[1]
const end = +l[2]
const name = l[3]
const score = +l[4]
const refName = l[0]!
const start = +l[1]!
const end = +l[2]!
const name = l[3]!
const score = +l[4]!
const strand = parseStrand(l[5])

const extra = l.slice(MAX_BED_COL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export async function parseBedPEBuffer(buffer: Buffer) {
for (
;
i < lines.length &&
(lines[i].startsWith('#') ||
lines[i].startsWith('browser') ||
lines[i].startsWith('track'));
(lines[i]!.startsWith('#') ||
lines[i]!.startsWith('browser') ||
lines[i]!.startsWith('track'));
i++
) {
headerLines.push(lines[i])
Expand Down Expand Up @@ -43,22 +43,22 @@ export async function parseBedPEBuffer(buffer: Buffer) {
])
const rows = []
for (let j = 0; i < lines.length; i++, j++) {
const line = lines[i]
const line = lines[i]!
const l = line.split('\t')
const ref1 = l[0]
const start1 = +l[1]
const end1 = +l[2]
const ref2 = l[3]
const start2 = +l[4]
const end2 = +l[5]
const name = l[6]
const score = +l[7]
const ref1 = l[0]!
const start1 = +l[1]!
const end1 = +l[2]!
const ref2 = l[3]!
const start2 = +l[4]!
const end2 = +l[5]!
const name = l[6]!
const score = +l[7]!
const strand1 = parseStrand(l[8])
const strand2 = parseStrand(l[9])

let extra = l.slice(MAX_BEDPE_COL)
let ALT
if (['DUP', 'TRA', 'INV', 'CNV', 'DEL'].includes(extra[0])) {
let ALT: string | undefined
if (['DUP', 'TRA', 'INV', 'CNV', 'DEL'].includes(extra[0] || '')) {
ALT = `<${extra[0]}>`
if (j < MAX_SET_SCAN) {
columns.add('ALT')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function parseSTARFusionBuffer(buffer: Buffer) {
const str = new TextDecoder('utf8').decode(buffer)
const lines = str.split(/\n|\r\n/)
const header = lines[0].slice(1).split('\t')
const header = lines[0]?.slice(1).split('\t') || []
return {
rows: lines
.slice(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function getRows(lines: string[], vcfParser: VCF) {
.map(f => f.trim())
.map(e => {
const [key, val = 'true'] = e.split('=')
const k = `INFO.${key.trim()}`
const k = `INFO.${key!.trim()}`
keys.add(k)
return [k, val.trim()]
}) || [],
Expand Down Expand Up @@ -45,7 +45,7 @@ export function parseVcfBuffer(buffer: Buffer) {
.filter(f => !!f)
const headerLines = []
let i = 0
for (; i < lines.length && lines[i].startsWith('#'); i++) {
for (; i < lines.length && lines[i]!.startsWith('#'); i++) {
headerLines.push(lines[i])
}
const header = headerLines.join('\n')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import VCF, { parseBreakend } from '@gmod/vcf'
import { locationLinkClick } from '../components/util'
import { SpreadsheetModel } from '../models/Spreadsheet'

export function parseStrand(strand: string) {
export function parseStrand(strand?: string) {
if (strand === '+') {
return 1
} else if (strand === '-') {
Expand Down Expand Up @@ -83,8 +83,8 @@ function getBreakpoints(feature: Feature) {
const alt = feature.get('ALT')?.[0]

const bnd = alt ? parseBreakend(alt) : undefined
let endPos
let mateRefName: string | undefined
let endPos: number
let mateRefName: string

// a VCF breakend feature
if (alt === '<TRA>') {
Expand All @@ -93,12 +93,14 @@ function getBreakpoints(feature: Feature) {
mateRefName = INFO.CHR2[0]
} else if (bnd?.MatePosition) {
const matePosition = bnd.MatePosition.split(':')
endPos = +matePosition[1] - 1
mateRefName = matePosition[0]
endPos = +matePosition[1]! - 1
mateRefName = matePosition[0]!
} else if (feature.get('mate')) {
const mate = feature.get('mate')
mateRefName = mate.refName
endPos = mate.start
} else {
throw new Error('unknown mate')
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { GenericFilehandle } from 'generic-filehandle'

// locals
import { SpreadsheetViewStateModel } from './SpreadsheetView'
import { autorun } from 'mobx'
import { getFileType, getFilename } from '../components/util'

Expand Down Expand Up @@ -143,10 +142,6 @@ function stateModelFactory() {
self.fileType as keyof typeof fileTypeParsers
]()

if (!typeParser) {
throw new Error(`cannot open files of type '${self.fileType}'`)
}

const { unzip } = await import('@gmod/bgzf-filehandle')
const { pluginManager } = getEnv(self)
const f = openLocation(spreadsheetFilehandle, pluginManager)
Expand All @@ -162,7 +157,7 @@ function stateModelFactory() {
const buffer = await f.readFile()
const buf2 = self.requiresUnzip ? await unzip(buffer) : buffer
const spreadsheet = await typeParser(buf2)
getParent<SpreadsheetViewStateModel>(self).displaySpreadsheet(
getParent<any>(self).displaySpreadsheet(
spreadsheet,
self.selectedAssemblyName,
)
Expand Down
6 changes: 0 additions & 6 deletions plugins/sv-inspector/src/LaunchSvInspectorView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ export default function LaunchSvInspectorViewF(pluginManager: PluginManager) {
assembly: string
uri: string
}) => {
// add view, make typescript happy with return type
const view = session.addView('SvInspectorView') as SvInspectorViewModel

if (!view) {
throw new Error('Failed to initialize view')
}

view.spreadsheetView.importWizard.setSelectedAssemblyName(assembly)
view.spreadsheetView.importWizard.setSpreadsheetFilehandle({
uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SvInspectorView = observer(function ({
onDrag={(_, total) => {
circularView.setWidth(initialCircWidth + total)
spreadsheetView.setWidth(initialSpreadsheetWidth - total)
return undefined
}}
onMouseDown={() => {
setInitialSpreadsheetWidth(spreadsheetView.width)
Expand Down
3 changes: 3 additions & 0 deletions plugins/sv-inspector/src/SvInspectorView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ async function defaultOnChordClick(
'BreakpointSplitView',
) as BreakpointSplitViewType
const [assemblyName] = view.assemblyNames
if (!assemblyName) {
throw new Error('error trying to understand what assembly to use')
}
const viewSnapshot = await viewType.snapshotFromBreakendFeature(
feature,
assemblyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ function SvInspectorViewF(pluginManager: PluginManager) {
{
type: 'ChordVariantDisplay',
displayId: `sv-inspector-variant-track-chord-display-${self.id}`,
onChordClick: `jexl:defaultOnChordClick(feature, track, pluginManager)`,
onChordClick:
'jexl:defaultOnChordClick(feature, track, pluginManager)',
renderer: {
type: 'StructuralVariantChordRenderer',
},
Expand Down Expand Up @@ -308,7 +309,7 @@ function SvInspectorViewF(pluginManager: PluginManager) {
circularView.hideTrack(t.configuration.trackId),
)
// put our track in as the only track
if (assemblyName && featuresCircularTrackConfiguration) {
if (assemblyName) {
circularView.addTrackConf(featuresCircularTrackConfiguration)
}
}),
Expand Down

0 comments on commit fd47c34

Please sign in to comment.