Skip to content

Commit

Permalink
removed 'killChr' requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
akmorrow13 committed Sep 12, 2017
1 parent 980dc6f commit 1472bdb
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 59 deletions.
7 changes: 2 additions & 5 deletions examples/data-ga4gh.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ var sources = [
data: pileup.formats.GAVariant({
endpoint: ga4ghReferenceServer,
variantSetId: "WyIxa2dlbm9tZXMiLCJ2cyIsInBoYXNlMy1yZWxlYXNlIl0",
callSetIds: ["WyIxa2dlbm9tZXMiLCJ2cyIsInBoYXNlMy1yZWxlYXNlIiwiSEcwMDA5NiJd"],
killChr: true
callSetIds: ["WyIxa2dlbm9tZXMiLCJ2cyIsInBoYXNlMy1yZWxlYXNlIiwiSEcwMDA5NiJd"]
}),
options: {
onVariantClicked: function(data) {
Expand All @@ -63,7 +62,7 @@ var sources = [
viz: pileup.viz.features(),
data: pileup.formats.GAFeature({
endpoint: ga4ghReferenceServer,
featureSetId: "WyIxa2dlbm9tZXMiLCJnZW5jb2RlX3YyNGxpZnQzNyJd",
featureSetId: "WyIxa2dlbm9tZXMiLCJnZW5jb2RlX3YyNGxpZnQzNyJd"
}),
name: 'gencode_v24lift37'
},
Expand All @@ -72,7 +71,6 @@ var sources = [
data: pileup.formats.GAReadAlignment({
endpoint: ga4ghReferenceServer,
readGroupId: "WyIxa2dlbm9tZXMiLCJyZ3MiLCJOQTEyODc4IiwiU1JSNjIyNDYxIl0",
killChr: true,
forcedReferenceId: "WyJOQ0JJMzciLCIxIl0"
}),
cssClass: 'normal',
Expand All @@ -83,7 +81,6 @@ var sources = [
data: pileup.formats.GAReadAlignment({
endpoint: ga4ghReferenceServer,
readGroupId: "WyIxa2dlbm9tZXMiLCJyZ3MiLCJOQTEyODc4IiwiU1JSNjIyNDYxIl0",
killChr: true,
forcedReferenceId: "WyJOQ0JJMzciLCIxIl0"
}),
cssClass: 'normal',
Expand Down
24 changes: 9 additions & 15 deletions src/main/ContigInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,35 @@ class ContigInterval<T: (number|string)> {
return this.interval.length();
}

intersects(other: ContigInterval<T>): boolean {
return (this.contig === other.contig &&
this.interval.intersects(other.interval));
}
// intersects(other: ContigInterval<T>): boolean {
// return (this.contig === other.contig &&
// this.interval.intersects(other.interval));
// }

// Like intersects(), but allows 'chr17' vs. '17'-style mismatches.
chrIntersects(other: ContigInterval<T>): boolean {
intersects(other: ContigInterval<T>): boolean {
return (this.chrOnContig(other.contig) &&
this.interval.intersects(other.interval));
}

containsInterval(other: ContigInterval<T>): boolean {
return (this.contig === other.contig &&
return (this.chrOnContig(other.contig) &&
this.interval.containsInterval(other.interval));
}

isAdjacentTo(other: ContigInterval<T>): boolean {
return (this.contig === other.contig &&
return (this.chrOnContig(other.contig) &&
(this.start() == 1 + other.stop() ||
this.stop() + 1 == other.start()));
}

isCoveredBy(intervals: ContigInterval<T>[]): boolean {
var ivs = intervals.filter(iv => iv.contig === this.contig)
var ivs = intervals.filter(iv => this.chrOnContig(iv.contig))
.map(iv => iv.interval);
return this.interval.isCoveredBy(ivs);
}

containsLocus(contig: T, position: number): boolean {
return this.contig === contig &&
this.interval.contains(position);
}

// Like containsLocus, but allows 'chr17' vs '17'-style mismatches
chrContainsLocus(contig: T, position: number): boolean {
return this.chrOnContig(contig) &&
this.interval.contains(position);
}
Expand All @@ -86,7 +80,7 @@ class ContigInterval<T: (number|string)> {
*/
complementIntervals(intervals: ContigInterval<T>[]): ContigInterval<T>[] {
return this.interval.complementIntervals(
flatMap(intervals, ci => ci.contig === this.contig ? [ci.interval] : []))
flatMap(intervals, ci => this.chrOnContig(ci.contig) ? [ci.interval] : []))
.map(iv => new ContigInterval(this.contig, iv.start, iv.stop));
}

Expand Down
17 changes: 2 additions & 15 deletions src/main/sources/GA4GHAlignmentSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ var BASE_PAIRS_PER_FETCH = 100;
type GA4GHSpec = {
endpoint: string;
readGroupId: string;
// HACK if set, strips "chr" from reference names.
// See https://github.com/ga4gh/schemas/issues/362
killChr: boolean;
// HACK for demo. If set, will always use this reference id.
// This is for fetching referenceIds specified in GA4GH reference
// server
Expand Down Expand Up @@ -63,12 +60,7 @@ function create(spec: GA4GHSpec): AlignmentDataSource {
}

function rangeChanged(newRange: GenomeRange) {
// HACK FOR DEMO
var contig = newRange.contig.replace(/^chr/, '');
if (!spec.killChr) {
contig = `chr${contig}`;
}
var interval = new ContigInterval(contig, newRange.start, newRange.stop);
var interval = new ContigInterval(newRange.contig, newRange.start, newRange.stop);
if (interval.isCoveredBy(coveredRanges)) return;

interval = interval.round(BASE_PAIRS_PER_FETCH, ZERO_BASED);
Expand Down Expand Up @@ -142,12 +134,7 @@ function create(spec: GA4GHSpec): AlignmentDataSource {
function getAlignmentsInRange(range: ContigInterval<string>): Alignment[] {
if (!range) return [];

// HACK FOR DEMO
var contig = range.contig.replace(/^chr/, '');
if (!spec.killChr) {
contig = `chr${contig}`;
}
range = new ContigInterval(contig, range.start(), range.stop());
range = new ContigInterval(range.contig, range.start(), range.stop());

return _.filter(reads, read => read.intersects(range));
}
Expand Down
14 changes: 2 additions & 12 deletions src/main/sources/GA4GHVariantSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type GA4GHVariantSpec = {
endpoint: string;
variantSetId: string;
callSetIds: string[];
// HACK for demo. If true, strips "chr" from reference names. If false, adds chr.
killChr: boolean;
};

function create(spec: GA4GHVariantSpec): VcfDataSource {
Expand All @@ -47,11 +45,7 @@ function create(spec: GA4GHVariantSpec): VcfDataSource {
}

function rangeChanged(newRange: GenomeRange) {
var contig = newRange.contig.replace(/^chr/, '');
if (!spec.killChr) {
contig = `chr${contig}`;
}
var interval = new ContigInterval(contig, newRange.start, newRange.stop);
var interval = new ContigInterval(newRange.contig, newRange.start, newRange.stop);

if (interval.isCoveredBy(coveredRanges)) return;

Expand Down Expand Up @@ -121,11 +115,7 @@ function create(spec: GA4GHVariantSpec): VcfDataSource {
function getFeaturesInRange(range: ContigInterval<string>): Variant[] {
if (!range) return [];

var contig = range.contig.replace(/^chr/, '');
if (!spec.killChr) {
contig = `chr${contig}`;
}
range = new ContigInterval(contig, range.start(), range.stop());
range = new ContigInterval(range.contig, range.start(), range.stop());

return _.filter(variants, variant => intersects(variant, range));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/sources/VcfDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function createFromVcfFile(remoteSource: VcfFile): VcfDataSource {

function getFeaturesInRange(range: ContigInterval<string>): Variant[] {
if (!range) return []; // XXX why would this happen?
return _.filter(variants, v => range.chrContainsLocus(v.contig, v.position));
return _.filter(variants, v => range.containsLocus(v.contig, v.position));
}

var o = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/viz/FeatureTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function renderFeatures(ctx: DataCanvasRenderingContext2D,

features.forEach(feature => {
var position = new ContigInterval(feature.contig, feature.start, feature.stop);
if (!position.chrIntersects(range)) return;
if (!position.intersects(range)) return;
ctx.pushObject(feature);
ctx.lineWidth = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/main/viz/GeneTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class GeneTrack extends React.Component {
ctx.font = `${style.GENE_FONT_SIZE}px ${style.GENE_FONT}`;
ctx.textAlign = 'center';
this.state.genes.forEach(gene => {
if (!gene.position.chrIntersects(range)) return;
if (!gene.position.intersects(range)) return;
ctx.pushObject(gene);
ctx.lineWidth = 1;
ctx.strokeStyle = style.GENE_COLOR;
Expand Down
8 changes: 4 additions & 4 deletions src/main/viz/PileupCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class PileupCache {
var reads = this.groups[k].alignments;
for (var vRead of reads) {
var read = vRead.read;
if (read.getInterval().chrIntersects(range)) {
if (read.getInterval().intersects(range)) {
var opInfo = getOpInfo(read, this.referenceSource);
vRead.mismatches = opInfo.mismatches;
}
Expand Down Expand Up @@ -178,15 +178,15 @@ class PileupCache {
// 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.chrIntersects(range));
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.chrIntersects(range)) {
if (group.span.intersects(range)) {
return true;
}
}
Expand All @@ -205,7 +205,7 @@ class PileupCache {
// Find the groups for which an alignment overlaps the locus.
var groups = _.filter(this.groups,
group => _.any(group.alignments,
a => a.read.getInterval().chrContainsLocus(contig, position)));
a => a.read.getInterval().containsLocus(contig, position)));

// For each row, find the left-most point (for sorting).
var rowsOverlapping =
Expand Down
4 changes: 2 additions & 2 deletions src/main/viz/TiledCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TiledCanvas {
tilesAtRes = tilesAtRes.concat(this.makeNewTiles(existingIntervals, pixelsPerBase, range));
}

var tiles = tilesAtRes.filter(tile => range.chrIntersects(tile.range));
var tiles = tilesAtRes.filter(tile => range.intersects(tile.range));

tiles.forEach(tile => {
var left = Math.round(scale(tile.range.start())),
Expand Down Expand Up @@ -114,7 +114,7 @@ class TiledCanvas {
}

invalidateRange(range: ContigInterval) {
this.tileCache = this.tileCache.filter(tile => !tile.range.chrIntersects(range));
this.tileCache = this.tileCache.filter(tile => !tile.range.intersects(range));
}

heightForRef(ref: string): number {
Expand Down
1 change: 0 additions & 1 deletion src/test/sources/GA4GHAlignmentSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('GA4GHAlignmentSource', function() {
var source = GA4GHAlignmentSource.create({
endpoint: '/v0.5.1',
readGroupId: 'some-group-set:some-read-group',
killChr: false,
forcedReferenceId: null
});

Expand Down
3 changes: 1 addition & 2 deletions src/test/sources/GA4GHVariantSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ describe('GA4GHVariantSource', function() {
source = GA4GHVariantSource.create({
endpoint: '/v0.6.0',
variantSetId: "WyIxa2dlbm9tZXMiLCJ2cyIsInBoYXNlMy1yZWxlYXNlIl0",
callSetIds: ["WyIxa2dlbm9tZXMiLCJ2cyIsInBoYXNlMy1yZWxlYXNlIiwiSEcwMDA5NiJd"],
killChr: true
callSetIds: ["WyIxa2dlbm9tZXMiLCJ2cyIsInBoYXNlMy1yZWxlYXNlIiwiSEcwMDA5NiJd"]
});

return new RemoteFile('/test-data/variants.ga4gh.chr1.10000-11000.json').getAllString().then(data => {
Expand Down

0 comments on commit 1472bdb

Please sign in to comment.