-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): subscription for genomic axis changes #935
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
466e4e3
feat: subscription to genomic location data
etowahadams e9e5768
fix(api): make the location output be bounded
etowahadams 5ab56fa
test: add getRelativeGenomicPosition tests
etowahadams 0eca7ec
Merge branch 'master' into etowahadams/unify-brush
etowahadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -18,19 +18,48 @@ export interface ChromSize { | |
|
||
/** | ||
* Get relative chromosome position (e.g., `100` => `{ chromosome: 'chr1', position: 100 }`) | ||
* @param absPos number which is the absolute chromosome position | ||
* @param assembly the assembly used to calculate which chromosome position | ||
* @param returnWithinAssembly If true, then if the absolute position is before the first chromosome, it returns the | ||
* first position of the first chromosome. If the absolute position is after the last chromosome, it returns the last | ||
* position of the last chromosome | ||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the extra option I added to this function so that it doesn't return "unknown" chromosome if the axis is out of the assembly bounds. |
||
* @returns the genomic position of the absPos | ||
*/ | ||
export function getRelativeGenomicPosition(absPos: number, assembly?: Assembly): GenomicPosition { | ||
const [chromosome, absInterval] = Object.entries(computeChromSizes(assembly).interval).find(d => { | ||
const [start, end] = d[1]; | ||
return start <= absPos && absPos < end; | ||
}) ?? [null, null]; | ||
|
||
if (!chromosome || !absInterval) { | ||
// The number is out of range | ||
export function getRelativeGenomicPosition( | ||
absPos: number, | ||
assembly?: Assembly, | ||
returnWithinAssembly = false | ||
etowahadams marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): GenomicPosition { | ||
const chrSizes = Object.entries(computeChromSizes(assembly).interval); | ||
const minPosChr = { chromosome: 'unknown', position: Infinity } as GenomicPosition; | ||
const maxPosChr = { chromosome: 'unknown', position: 0 } as GenomicPosition; | ||
for (const chrSize of chrSizes) { | ||
const [chromosome, absInterval] = chrSize; | ||
const [start, end] = absInterval; | ||
// absPos was found within this chromosome | ||
if (start <= absPos && absPos < end) { | ||
return { chromosome, position: absPos - start } as GenomicPosition; | ||
} | ||
// Update the min and max chromosomes found | ||
if (start < minPosChr.position) { | ||
minPosChr.chromosome = chromosome; | ||
minPosChr.position = start; | ||
} | ||
if (end > maxPosChr.position) { | ||
maxPosChr.chromosome = chromosome; | ||
maxPosChr.position = end; | ||
} | ||
} | ||
if (returnWithinAssembly) { | ||
// Return either the min or max chromosome position | ||
if (absPos < minPosChr.position) { | ||
return minPosChr; | ||
} else { | ||
return maxPosChr; | ||
} | ||
} else { | ||
return { chromosome: 'unknown', position: absPos }; | ||
} | ||
|
||
return { chromosome, position: absPos - absInterval[0] }; | ||
} | ||
|
||
/** | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I've been testing the new location API. I noticed that there was commented out code for the other subscriptions so I did the same.