Skip to content

Commit

Permalink
No specialized multi-step bezier
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 11, 2024
1 parent c381714 commit 4f4cabb
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 104 deletions.
6 changes: 3 additions & 3 deletions packages/sv-core/src/BreakendMultiLevelOptionDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react'
import { observer } from 'mobx-react'
import { Button, DialogActions, DialogContent, TextField } from '@mui/material'
import { Button, DialogActions, DialogContent } from '@mui/material'
import { getSnapshot } from 'mobx-state-tree'
import { Dialog } from '@jbrowse/core/ui'
import { when } from 'mobx'
import { getSession, Feature, useLocalStorage } from '@jbrowse/core/util'
import { getSession, Feature } from '@jbrowse/core/util'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
import type { Assembly } from '@jbrowse/core/assemblyManager/assembly'

Expand Down Expand Up @@ -85,6 +85,7 @@ const BreakendMultiLevelOptionDialog = observer(function ({
<DialogActions>
<Button
onClick={() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
const session = getSession(model)
try {
Expand All @@ -100,7 +101,6 @@ const BreakendMultiLevelOptionDialog = observer(function ({
assembly: asm,
})


const viewTracks = getSnapshot(view.tracks) as Track[]
const breakpointSplitView = session.addView(
'BreakpointSplitView',
Expand Down
98 changes: 50 additions & 48 deletions packages/sv-core/src/BreakendSingleLevelOptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,56 +90,58 @@ const BreakendSingleLevelOptionDialog = observer(function ({
<Button
onClick={() => {
const session = getSession(model)
try {
console.log({ assemblyName })
const assembly = session.assemblyManager.get(assemblyName)
const w = +windowSize
if (Number.isNaN(w)) {
throw new Error('windowSize not a number')
}
const { refName, pos, mateRefName, matePos } =
// @ts-expect-error
viewType.getBreakendCoveringRegions({ feature, assembly })
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
const assembly = session.assemblyManager.get(assemblyName)
const w = +windowSize
if (Number.isNaN(w)) {
throw new Error('windowSize not a number')
}
const { refName, pos, mateRefName, matePos } =
// @ts-expect-error
viewType.getBreakendCoveringRegions({ feature, assembly })

const breakpointSplitView = session.addView(
'BreakpointSplitView',
{
type: 'BreakpointSplitView',
displayName: `${
feature.get('name') || feature.get('id') || 'breakend'
} split detail`,
views: [
{
type: 'LinearGenomeView',
tracks: stripIds(getSnapshot(view.tracks)),
},
],
},
) as unknown as { views: LinearGenomeViewModel[] }
const breakpointSplitView = session.addView(
'BreakpointSplitView',
{
type: 'BreakpointSplitView',
displayName: `${
feature.get('name') || feature.get('id') || 'breakend'
} split detail`,
views: [
{
type: 'LinearGenomeView',
tracks: stripIds(getSnapshot(view.tracks)),
},
],
},
) as unknown as { views: LinearGenomeViewModel[] }

breakpointSplitView.views[0]!.navToLocations(
gatherOverlaps(
[
{
refName,
start: Math.max(0, pos - w),
end: pos + w,
assemblyName,
},
{
refName: mateRefName,
start: Math.max(0, matePos - w),
end: matePos + w,
assemblyName,
},
],
w,
),
)
} catch (e) {
console.error(e)
session.notify(`${e}`)
}
await breakpointSplitView.views[0]!.navToLocations(
gatherOverlaps(
[
{
refName,
start: Math.max(0, pos - w),
end: pos + w,
assemblyName,
},
{
refName: mateRefName,
start: Math.max(0, matePos - w),
end: matePos + w,
assemblyName,
},
],
w,
),
)
} catch (e) {
console.error(e)
session.notify(`${e}`)
}
})()
handleClose()
}}
variant="contained"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
getMatchedAlignmentFeatures,
hasPairedReads,
} from './util'
import { yPos, useNextFrame, getPxFromCoordinate } from '../util'
import {
yPos,
useNextFrame,
getPxFromCoordinate,
heightFromSpecificLevel,
} from '../util'
import { BreakpointViewModel } from '../model'
import {
getLongReadOrientationAbnormal,
Expand All @@ -37,7 +42,8 @@ const AlignmentConnections = observer(function ({
const session = getSession(model)
const snap = getSnapshot(model)
const { assemblyManager } = session
const assembly = assemblyManager.get(views[0]!.assemblyNames[0]!)
const v0 = views[0]
const assembly = v0 ? assemblyManager.get(v0.assemblyNames[0]!) : undefined
useNextFrame(snap)
const allFeatures = model.getTrackFeatures(trackId)
const hasPaired = useMemo(() => hasPairedReads(allFeatures), [allFeatures])
Expand Down Expand Up @@ -128,60 +134,42 @@ const AlignmentConnections = observer(function ({
yPos(trackId, level2, views, tracks, c2, getTrackYPosOverride) -
yOffset
const sameLevel = level1 === level2
const trackHeight =
sameLevel && isAbnormal ? tracks[level1].displays[0].height / 2 : 0
const abnormalSpecialRenderFlag = sameLevel && isAbnormal
const trackHeight = abnormalSpecialRenderFlag
? tracks[level1].displays[0].height
: 0
const pf1 = hasPaired ? -1 : 1
const y0 = heightFromSpecificLevel(
views,
trackId,
level1,
getTrackYPosOverride,
)

// possible todo: use totalCurveHeight to possibly make alternative
// squiggle if the S is too small
const path = isAbnormal
? [
'M',
x1,
y1,
'C',

// first bezier x,y
x1 + 100 * f1.get('strand') * rf1,
y1,

// second bezier x,y
x1 + 100 * f1.get('strand') * rf1,
y1 + 100,

// third bezier x,y
x2 - 100 * f2.get('strand') * rf2 * pf1,
y2 + 100,

// bezier continuation
'S',

// first bezier x,y
x2 - 100 * f2.get('strand') * rf2 * pf1,
y2 + 100,

// second bezier x,y
x2,
y2,
].join(' ')
: [
'M',
x1,
y1,
'C',

// first bezier x,y
x1 + 200 * f1.get('strand') * rf1,
y1,

// second bezier x,y
x2 - 200 * f2.get('strand') * rf2 * pf1,
y2,

// third bezier x,y
x2,
y2,
].join(' ')
const path = [
'M',
x1,
y1,
'C',

// first bezier x,y
x1 + 200 * f1.get('strand') * rf1,
abnormalSpecialRenderFlag
? Math.min(y0 - yOffset + trackHeight, y1 + trackHeight)
: y1,

// second bezier x,y
x2 - 200 * f2.get('strand') * rf2 * pf1,
abnormalSpecialRenderFlag
? Math.min(y0 - yOffset + trackHeight, y2 + trackHeight)
: y2,

// third bezier x,y
x2,
y2,
].join(' ')
const id = `${f1.id()}-${f2.id()}`
ret.push(
<path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function cheight(chunk: LayoutRecord) {
return chunk[BOTTOM] - chunk[TOP]
}

function heightFromSpecificLevel(
export function heightFromSpecificLevel(
views: LGV[],
trackId: string,
level: number,
Expand Down

0 comments on commit 4f4cabb

Please sign in to comment.