-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathutil.ts
63 lines (58 loc) · 1.59 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { parseBreakend } from '@gmod/vcf'
import type { Track } from './types'
import type { Assembly } from '@jbrowse/core/assemblyManager/assembly'
import type { Feature } from '@jbrowse/core/util'
export function getBreakendCoveringRegions({
feature,
assembly,
}: {
feature: Feature
assembly: Assembly
}) {
const alt = feature.get('ALT')?.[0]
const bnd = alt ? parseBreakend(alt) : undefined
const startPos = feature.get('start')
const refName = feature.get('refName')
const f = (ref: string) => assembly.getCanonicalRefName(ref) || ref
if (alt === '<TRA>') {
const INFO = feature.get('INFO')
return {
pos: startPos,
refName: f(refName),
mateRefName: f(INFO.CHR2[0]),
matePos: INFO.END[0] - 1,
}
} else if (bnd?.MatePosition) {
const matePosition = bnd.MatePosition.split(':')
return {
pos: startPos,
refName: f(refName),
mateRefName: f(matePosition[0]!),
matePos: +matePosition[1]! - 1,
}
} else if (feature.get('mate')) {
const mate = feature.get('mate')
return {
pos: startPos,
refName: f(refName),
mateRefName: f(mate.refName),
matePos: mate.start,
}
} else {
return {
pos: startPos,
refName: f(refName),
mateRefName: f(refName),
matePos: feature.get('end'),
}
}
}
export function stripIds(arr: Track[]) {
return arr.map(({ id, displays, ...rest }) => ({
...rest,
displays: displays.map(({ id, ...rest }) => rest),
}))
}
export function makeTitle(f: Feature) {
return `${f.get('name') || f.get('id') || 'breakend'} split detail`
}