-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Feature } from '@jbrowse/core/util' | ||
|
||
// see similar function in protein3d plugin | ||
export function generateMap(f: Feature) { | ||
let iter = 0 | ||
|
||
const strand = f.get('strand') | ||
const subs = f.children() ?? [] | ||
return strand === -1 | ||
? subs | ||
.filter(f => f.get('type') === 'CDS') | ||
.sort((a, b) => b.get('start') - a.get('start')) | ||
.map(f => { | ||
const refName = f.get('refName').replace('chr', '') | ||
const featureStart = f.get('start') | ||
const featureEnd = f.get('end') | ||
const phase = f.get('phase') | ||
const len = featureEnd - featureStart | ||
const op = len / 3 | ||
const proteinStart = iter | ||
const proteinEnd = iter + op | ||
iter += op | ||
return { | ||
refName, | ||
featureStart, | ||
featureEnd, | ||
proteinStart, | ||
proteinEnd, | ||
phase, | ||
strand, | ||
} as const | ||
}) | ||
: subs | ||
.filter(f => f.get('type') === 'CDS') | ||
.sort((a, b) => a.get('start') - b.get('start')) | ||
.map(f => { | ||
const refName = f.get('refName').replace('chr', '') | ||
const featureStart = f.get('start') | ||
const featureEnd = f.get('end') | ||
const phase = f.get('phase') | ||
const len = featureEnd - featureStart | ||
const op = len / 3 | ||
const proteinStart = iter | ||
const proteinEnd = iter + op | ||
iter += op | ||
return { | ||
refName, | ||
featureStart, | ||
featureEnd, | ||
proteinStart, | ||
proteinEnd, | ||
phase, | ||
strand, | ||
} as const | ||
}) | ||
} | ||
|
||
export function checkHovered(hovered: unknown): hovered is { | ||
hoverFeature: Feature | ||
hoverPosition: { coord: number; refName: string } | ||
} { | ||
return ( | ||
!!hovered && | ||
typeof hovered == 'object' && | ||
'hoverFeature' in hovered && | ||
'hoverPosition' in hovered | ||
) | ||
} |