Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 30, 2023
1 parent 52f9fbe commit 2effe63
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 266 deletions.
75 changes: 1 addition & 74 deletions plugins/arc/src/LinearPairedArcDisplay/components/Arcs.tsx
Expand Up @@ -13,80 +13,7 @@ import { getConf } from '@jbrowse/core/configuration'
// local
import { LinearArcDisplayModel } from '../model'
import ArcTooltip from '../../ArcTooltip'

export function makeFeaturePair(feature: Feature, alt?: string) {
const bnd = alt ? parseBreakend(alt) : undefined
let start = feature.get('start')
let end = feature.get('end')
const strand = feature.get('strand')
const mate = feature.get('mate') as {
refName: string
start: number
end: number
mateDirection?: number
}
const refName = feature.get('refName')

let mateRefName: string | undefined
let mateEnd = 0
let mateStart = 0
let joinDirection = 0
let mateDirection = 0

// one sided bracket used, because there could be <INS:ME> and we just check
// startswith below
const symbolicAlleles = ['<TRA', '<DEL', '<INV', '<INS', '<DUP', '<CNV']
if (symbolicAlleles.some(a => alt?.startsWith(a))) {
// END is defined to be a single value, not an array. CHR2 not defined in
// VCF spec, but should be similar
const info = feature.get('INFO')
const e = info?.END?.[0] ?? end
mateRefName = info?.CHR2?.[0] ?? refName
mateEnd = e
mateStart = e - 1
// re-adjust the arc to be from start to end of feature by re-assigning end
// to the 'mate'
start = start
end = start + 1
} else if (bnd?.MatePosition) {
const matePosition = bnd.MatePosition.split(':')
mateDirection = bnd.MateDirection === 'left' ? 1 : -1
joinDirection = bnd.Join === 'left' ? -1 : 1
mateEnd = +matePosition[1]
mateStart = +matePosition[1] - 1
mateRefName = matePosition[0]
}

return {
k1: {
refName,
start,
end,
strand,
mateDirection,
},
k2: mate ?? {
refName: mateRefName,
end: mateEnd,
start: mateStart,
mateDirection: joinDirection,
},
}
}

export function makeSummary(feature: Feature, alt?: string) {
const { k1, k2 } = makeFeaturePair(feature, alt)
return [
feature.get('name'),
feature.get('id'),
assembleLocString(k1),
assembleLocString(k2),
feature.get('INFO')?.SVTYPE,
alt,
]
.filter(f => !!f)
.join(' - ')
}
import { makeFeaturePair, makeSummary } from './util'

type LGV = LinearGenomeViewModel

Expand Down
75 changes: 75 additions & 0 deletions plugins/arc/src/LinearPairedArcDisplay/components/util.ts
@@ -0,0 +1,75 @@
import { parseBreakend } from '@gmod/vcf'
import { Feature, assembleLocString } from '@jbrowse/core/util'
export function makeFeaturePair(feature: Feature, alt?: string) {
const bnd = alt ? parseBreakend(alt) : undefined
let start = feature.get('start')
let end = feature.get('end')
const strand = feature.get('strand')
const mate = feature.get('mate') as {
refName: string
start: number
end: number
mateDirection?: number
}
const refName = feature.get('refName')

let mateRefName: string | undefined
let mateEnd = 0
let mateStart = 0
let joinDirection = 0
let mateDirection = 0

// one sided bracket used, because there could be <INS:ME> and we just check
// startswith below
const symbolicAlleles = ['<TRA', '<DEL', '<INV', '<INS', '<DUP', '<CNV']
if (symbolicAlleles.some(a => alt?.startsWith(a))) {
// END is defined to be a single value, not an array. CHR2 not defined in
// VCF spec, but should be similar
const info = feature.get('INFO')
const e = info?.END?.[0] ?? end
mateRefName = info?.CHR2?.[0] ?? refName
mateEnd = e
mateStart = e - 1
// re-adjust the arc to be from start to end of feature by re-assigning end
// to the 'mate'
start = start
end = start + 1
} else if (bnd?.MatePosition) {
const matePosition = bnd.MatePosition.split(':')
mateDirection = bnd.MateDirection === 'left' ? 1 : -1
joinDirection = bnd.Join === 'left' ? -1 : 1
mateEnd = +matePosition[1]
mateStart = +matePosition[1] - 1
mateRefName = matePosition[0]
}

return {
k1: {
refName,
start,
end,
strand,
mateDirection,
},
k2: mate ?? {
refName: mateRefName,
end: mateEnd,
start: mateStart,
mateDirection: joinDirection,
},
}
}

export function makeSummary(feature: Feature, alt?: string) {
const { k1, k2 } = makeFeaturePair(feature, alt)
return [
feature.get('name'),
feature.get('id'),
assembleLocString(k1),
assembleLocString(k2),
feature.get('INFO')?.SVTYPE,
alt,
]
.filter(f => !!f)
.join(' - ')
}

0 comments on commit 2effe63

Please sign in to comment.