-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from akmorrow13/generic-pileup
Generic pileup
- Loading branch information
Showing
14 changed files
with
514 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Generic object that can be displayed. This can be a gene, feature or variant, etc. | ||
* See ../viz/GenericFeatureCache.js | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
/*jshint unused:false */ | ||
import ContigInterval from '../ContigInterval'; | ||
|
||
|
||
class GenericFeature { | ||
id: string; | ||
position: ContigInterval<string>; | ||
gFeature: Object; | ||
|
||
constructor(id: string, position: ContigInterval<string>, genericFeature: Object) { | ||
this.id = genericFeature.id; | ||
this.position = genericFeature.position; | ||
this.gFeature = genericFeature; | ||
} | ||
} | ||
|
||
module.exports = GenericFeature; |
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,79 @@ | ||
/** | ||
* AbstractCache | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
import _ from 'underscore'; | ||
/*jshint unused:false */ | ||
import ContigInterval from '../ContigInterval'; | ||
import Interval from '../Interval'; | ||
|
||
import utils from '../utils'; | ||
|
||
import type {TwoBitSource} from '../sources/TwoBitDataSource'; | ||
|
||
import type {VisualAlignment} from './PileupCache'; | ||
import GenericFeature from '../data/genericFeature.js'; | ||
|
||
|
||
export type VisualGroup<T: (VisualAlignment | GenericFeature)> = { | ||
key: string; | ||
row: number; // pileup row. | ||
span: ContigInterval<string>; // tip-to-tip span for the read group | ||
insert: ?Interval; // interval for the connector, if applicable. | ||
items: T[]; | ||
}; | ||
|
||
class AbstractCache { | ||
// maps groupKey to VisualGroup | ||
groups: {[key: string]: VisualGroup}; | ||
refToPileup: {[key: string]: Array<Interval[]>}; | ||
referenceSource: TwoBitSource; | ||
|
||
constructor(referenceSource: TwoBitSource) { | ||
this.groups = {}; | ||
this.refToPileup = {}; | ||
this.referenceSource = referenceSource; | ||
} | ||
|
||
pileupForRef(ref: string): Array<Interval[]> { | ||
if (ref in this.refToPileup) { | ||
return this.refToPileup[ref]; | ||
} else { | ||
var alt = utils.altContigName(ref); | ||
if (alt in this.refToPileup) { | ||
return this.refToPileup[alt]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
} | ||
|
||
// How many rows tall is the pileup for a given ref? This is related to the | ||
// maximum read depth. This is 'chr'-agnostic. | ||
pileupHeightForRef(ref: string): number { | ||
var pileup = this.pileupForRef(ref); | ||
return pileup ? pileup.length : 0; | ||
} | ||
|
||
// Find groups overlapping the range. This is 'chr'-agnostic. | ||
getGroupsOverlapping(range: ContigInterval<string>): VisualGroup[] { | ||
// TODO: speed this up using an interval tree | ||
return _.filter(this.groups, group => group.span.intersects(range)); | ||
} | ||
|
||
// Determine the number of groups at a locus. | ||
// Like getGroupsOverlapping(range).length > 0, but more efficient. | ||
anyGroupsOverlapping(range: ContigInterval<string>): boolean { | ||
for (var k in this.groups) { | ||
var group = this.groups[k]; | ||
if (group.span.intersects(range)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = AbstractCache; |
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
Oops, something went wrong.