Skip to content

Commit

Permalink
Refname renaming fix for breakpoint split view
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 3, 2023
1 parent 1c08a12 commit f7dd8e3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const AlignmentConnections = observer(function ({
const session = getSession(model)
const snap = getSnapshot(model)
const { assemblyManager } = session
const assembly = assemblyManager.get(views[0].assemblyNames[0])
const asm = assemblyManager.get(views[0].assemblyNames[0])
useNextFrame(snap)
const allFeatures = model.getTrackFeatures(trackId)
const hasPaired = useMemo(() => hasPairedReads(allFeatures), [allFeatures])
Expand Down Expand Up @@ -59,7 +59,7 @@ const AlignmentConnections = observer(function ({
yOffset = rect.top
}

if (!assembly) {
if (!asm) {
return null
}

Expand All @@ -86,20 +86,15 @@ const AlignmentConnections = observer(function ({
if (!showIntraviewLinks && level1 === level2) {
return null
}
const f1ref = assembly.getCanonicalRefName(f1.get('refName'))
const f2ref = assembly.getCanonicalRefName(f2.get('refName'))

if (!f1ref || !f2ref) {
throw new Error(`unable to find ref for ${f1ref || f2ref}`)
}

const f1ref = f1.get('refName')
const f2ref = f2.get('refName')
const s1 = f1.get('strand')
const s2 = f2.get('strand')
const p1 = c1[s1 === -1 ? LEFT : RIGHT]
const sn1 = s2 === -1
const p2 = hasPaired ? c2[sn1 ? LEFT : RIGHT] : c2[sn1 ? RIGHT : LEFT]
const x1 = getPxFromCoordinate(views[level1], f1ref, p1)
const x2 = getPxFromCoordinate(views[level2], f2ref, p2)
const x1 = getPxFromCoordinate(views[level1], f1ref, p1, asm)
const x2 = getPxFromCoordinate(views[level2], f2ref, p2, asm)
const reversed1 = views[level1].pxToBp(x1).reversed
const reversed2 = views[level2].pxToBp(x2).reversed
const tracks = views.map(v => v.getTrack(trackId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const Breakends = observer(function ({
const [mouseoverElt, setMouseoverElt] = useState<string>()
const snap = getSnapshot(model)
useNextFrame(snap)
const assembly = assemblyManager.get(views[0].assemblyNames[0])
const asm = assemblyManager.get(views[0].assemblyNames[0])

if (!assembly) {
if (!asm) {
return null
}

Expand Down Expand Up @@ -69,15 +69,10 @@ const Breakends = observer(function ({
if (!c1 || !c2) {
return null
}
const f1origref = f1.get('refName')
const f2origref = f2.get('refName')
const f1ref = assembly.getCanonicalRefName(f1origref)
const f2ref = assembly.getCanonicalRefName(f2origref)
if (!f1ref || !f2ref) {
throw new Error(`unable to find ref for ${f1ref || f2ref}`)
}
const x1 = getPxFromCoordinate(views[level1], f1ref, c1[LEFT])
const x2 = getPxFromCoordinate(views[level2], f2ref, c2[LEFT])
const f1ref = f1.get('refName')
const f2ref = f2.get('refName')
const x1 = getPxFromCoordinate(views[level1], f1ref, c1[LEFT], asm)
const x2 = getPxFromCoordinate(views[level2], f2ref, c2[LEFT], asm)
const reversed1 = views[level1].pxToBp(x1).reversed
const reversed2 = views[level2].pxToBp(x2).reversed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ const Translocations = observer(function ({
const end2 = info.END[0]
const [myDirection, mateDirection] = info.STRANDS[0].split('')

const r = getPxFromCoordinate(views[level2], chr2, end2)
const r = getPxFromCoordinate(views[level2], chr2, end2, assembly)
if (r) {
const c2: LayoutRecord = [r, 0, r + 1, 0]
const x1 = getPxFromCoordinate(
views[level1],
f1.get('refName'),
c1[LEFT],
assembly,
)
const x2 = r
const reversed1 = views[level1].pxToBp(x1).reversed
Expand All @@ -99,21 +100,11 @@ const Translocations = observer(function ({
const y2 =
yPos(trackId, level2, views, tracks, c2, getTrackYPosOverride) -
yOffset

const path = [
'M', // move to
x1 - 20 * (myDirection === '+' ? 1 : -1) * (reversed1 ? -1 : 1),
y1,
'L', // line to
x1,
y1,
'L', // line to
x2,
y2,
'L', // line to
x2 - 20 * (mateDirection === '+' ? 1 : -1) * (reversed2 ? -1 : 1),
y2,
].join(' ')
const foot1 =
x1 - 20 * (myDirection === '+' ? 1 : -1) * (reversed1 ? -1 : 1)
const foot2 =
x2 - 20 * (mateDirection === '+' ? 1 : -1) * (reversed2 ? -1 : 1)
const path = `M ${foot1} ${y1} L ${x1} ${y1} L ${x2} ${y2} L ${foot2} ${y2}`
ret.push(
<path
d={path}
Expand Down
15 changes: 13 additions & 2 deletions plugins/breakpoint-split-view/src/BreakpointSplitView/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 @@ -34,8 +35,18 @@ function heightFromSpecificLevel(
: views[level].trackRefs[trackId]?.getBoundingClientRect().top || 0
}

export function getPxFromCoordinate(view: LGV, refName: string, coord: number) {
return (view.bpToPx({ refName, coord })?.offsetPx || 0) - view.offsetPx
export function getPxFromCoordinate(
view: LGV,
refName: string,
coord: number,
asm: Assembly,
) {
return (
(view.bpToPx({
refName: asm.getCanonicalRefName(refName) || refName,
coord,
})?.offsetPx || 0) - view.offsetPx
)
}

// get's the yposition of a layout record in a track
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { assembleLocString } from '@jbrowse/core/util'

// locals
import LocString from './components/LocString'
import { launchBreakpointSplitView, launchLGV } from './util'
import {
launchBreakpointSplitView,
launchLinearGenomeView,
launchLinearGenomeViewWithEndFocus,
} from './util'
import { SpreadsheetModel } from '../models/Spreadsheet'

type Row = Record<string, unknown>
Expand Down Expand Up @@ -84,13 +88,19 @@ export function parseVcfBuffer(buffer: Buffer) {
}) => [
{
label: 'Launch linear genome view',
onClick: () => launchLGV({ model, value: row.loc as string }),
onClick: () =>
launchLinearGenomeView({ model, value: row.loc as string }),
},
{
label: 'Launch breakpoint split view',
onClick: () =>
launchBreakpointSplitView({ model, row, vcfParser }),
},
{
label: 'Launch linear genome view focused on ends of SV',
onClick: () =>
launchLinearGenomeViewWithEndFocus({ model, row, vcfParser }),
},
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function parseStrand(strand: string) {
}
}

export async function launchLGV({
export async function launchLinearGenomeView({
model,
value,
}: {
Expand Down Expand Up @@ -62,10 +62,28 @@ export async function launchBreakpointSplitView({
assemblyName,
session,
)
const v = getParent<{ width: number }>(model)
snap.views[0].offsetPx -= v.width / 2 + 100
snap.views[1].offsetPx -= v.width / 2 + 100

session.addView('BreakpointSplitView', snap)
} catch (e) {
console.error(e)
getSession(model).notify(`${e}`, 'error')
}
}

export async function launchLinearGenomeViewWithEndFocus({
model,
value,
}: {
model: SpreadsheetModel
value: string
}) {
try {
await locationLinkClick(model, value)
} catch (e) {
console.error(e)
getSession(model).notify(`${e}`, 'error')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ function stateModelFactory() {
const { data, widths } = self
return data?.columns.map(m => {
const res = data.CustomComponents?.[m]
console.log({ self })
return {
field: m,
width: widths[m],
Expand Down
6 changes: 2 additions & 4 deletions plugins/variants/src/VariantFeatureWidget/BreakendPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ export default function BreakendPanel(props: {
const session = getSession(model)
const { pluginManager } = getEnv(session)
const [breakpointDialog, setBreakpointDialog] = useState(false)
let viewType: BreakpointSplitViewType | undefined
let viewType

try {
viewType = pluginManager.getViewType(
'BreakpointSplitView',
) as BreakpointSplitViewType
viewType = pluginManager.getViewType('BreakpointSplitView')
} catch (e) {
// ignore
}
Expand Down

0 comments on commit f7dd8e3

Please sign in to comment.