Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added chromosome name label and remove track option
  • Loading branch information
csw11004 committed Mar 18, 2015
1 parent c44f9a9 commit 512b5f5
Showing 1 changed file with 84 additions and 17 deletions.
101 changes: 84 additions & 17 deletions VQI_GenomeBrowser.js
Expand Up @@ -10,7 +10,6 @@ function VQI_GenomeBrowser(id) {
var panExtent = [0,width];

var trackList = [];
var trackSelections = [];

var genomeData = [];

Expand Down Expand Up @@ -177,9 +176,40 @@ function VQI_GenomeBrowser(id) {
};
this.makeFormForColocalization();

var self = this;
var removeTrack = function () {
var removedTrackName = $("#" + divId + " #removeTrack").val();

for (var i in trackList) {
var thisTrack = trackList[i];
if (thisTrack['name'] === removedTrackName) {
trackList[i]["selections"].remove();
trackList.splice(i,1);
break;
}
}

updateAllTracksSelectBoxes();
graph(chrom_curr, xScale.domain()[0], xScale.domain()[1]);
};

this.makeFormForRemoveTrack = function () {
var removeTrackSelect = "Remove: <select name='removeTrack' id='removeTrack'>";
for (var i in trackList) {
var thisTrack = trackList[i];
var text = thisTrack['name'];
var value = thisTrack['name'];
removeTrackSelect += "<option value='" + value + "'>" + text + "</option>";
}
removeTrackSelect += "</select>";

var removeButton = "<input type='button' id='removetrackbutton' value='Remove Track'>";
var form = "<form id='removeTrack_form'>" + removeTrackSelect + removeButton + "</form>";
$("#" + divId).append(form);
$("#" + divId + " #removetrackbutton").on("click", removeTrack.bind(this));
};
this.makeFormForRemoveTrack();

var self = this;

this.svg = d3.select("#" + id)
.append("svg")
Expand Down Expand Up @@ -257,9 +287,14 @@ function VQI_GenomeBrowser(id) {
return xScale(d[indexArray.start])
})

for (var i in trackSelections) {
trackSelections[i]
.attr("x1", function (d) {
for (var i in trackList) {

//Tried to select only the lines in the selection
var trackLines = trackList[i]["selections"].filter(function(d){
return d[indexArray.name].indexOf("/") == -1;
});

trackLines.attr("x1", function (d) {
return xScale(d[indexArray.start]);
})
.attr("x2", function (d) {
Expand Down Expand Up @@ -341,6 +376,9 @@ function VQI_GenomeBrowser(id) {
}

var graph = function (chromosome, min, max) {

svg.attr("height", height + 2 * margin);

var indexList = indexArray;
//Graphs the current chromosome. If min and max are specified, graph only in that range.
//Otherwise, graphs the whole chromosome
Expand All @@ -360,7 +398,7 @@ function VQI_GenomeBrowser(id) {
// return d;
// });

d3.select("#chrom").selectAll("option")
/*d3.select("#chrom").selectAll("option")
.data(chromosomes)
.enter()
.append("option")
Expand All @@ -369,7 +407,7 @@ function VQI_GenomeBrowser(id) {
})
.text(function (d) {
return d;
});
});*/
chrom_curr = chromosome;

currentData = genomeData.filter(function (d) {
Expand Down Expand Up @@ -398,6 +436,19 @@ function VQI_GenomeBrowser(id) {
setBounds(Number(min),Number(max));
}

svg.selectAll("text")
.data(["cpg"], function (d) {return d;})
.enter()
.append("text")
.attr("x", 0)
.attr("y", height / 2 + margin)
.attr("font-family", "sans-serif")
.attr("font-size", "12px")
.attr("fill", "red")
svg.selectAll("text")
.data(["cpg"], function (d) {return d;})
.text(chromosome);

svg.selectAll("rect")
.data(currentData)
.exit()
Expand Down Expand Up @@ -466,6 +517,9 @@ function VQI_GenomeBrowser(id) {
svg.attr("height", height + 2 * margin + ySpace);
var thisY = height / 2 + margin + 20 + ySpace;

//empty selection
var trackSelections = d3.selectAll(".empty");

if (!i) {
/*svg.append("line")
.attr("x1", margin)
Expand All @@ -477,13 +531,19 @@ function VQI_GenomeBrowser(id) {
svg.selectAll("text")
.data([name], function (d) {return d;})
.enter()
.append("text")
.attr("x", 0)
.attr("y", thisY - 10)
.attr("font-family", "sans-serif")
.attr("font-size", "12px")
.attr("fill", "red")
.text(name);
.append("text");

var text = svg.selectAll("text")
.data([name], function (d) {return d;});

trackSelections[0].push(text.node());

text.attr("x", 0)
.attr("y", thisY - 10)
.attr("font-family", "sans-serif")
.attr("font-size", "12px")
.attr("fill", "red")
.text(name);
}
// test.addTrack({start:20000000, end:20000100})
svg.selectAll("line")
Expand All @@ -510,7 +570,7 @@ function VQI_GenomeBrowser(id) {
.style("stroke", "black")
.style("stroke-width", "2px")

trackSelections.push(tracks);
trackSelections[0] = trackSelections[0].concat(tracks[0]);

var exons = [];
$.each(thisData, function (index, value) {
Expand All @@ -528,10 +588,12 @@ function VQI_GenomeBrowser(id) {
}
});

var exonRect = svg.selectAll("tracks")
svg.selectAll("rect")
.data(exons, function (d) {return d;})
.enter()
.append("rect");
var exonRect = svg.selectAll("rect")
.data(exons, function (d) {return d;});
var exonRectAttributes = exonRect
.attr("x", function (d) {
return xScale(d[index.start]);
Expand All @@ -555,6 +617,8 @@ function VQI_GenomeBrowser(id) {
//.on('mouseover', tip.show)
//.on('mouseout', tip.hide);

trackSelections[0] = trackSelections[0].concat(exonRect[0]);

$('svg rect').tipsy({
gravity: 'n',
html: true,
Expand All @@ -575,6 +639,7 @@ function VQI_GenomeBrowser(id) {
});

data['name'] = name;
data['selections'] = trackSelections;

return data;

Expand Down Expand Up @@ -746,7 +811,7 @@ function VQI_GenomeBrowser(id) {
// shelveData.push({"chromosome": value[0], "start": value[3], "end": value[4], "type": "shelve"});
});
genomeData = genomeData.concat(shelveData);
graph(chromosomes[0]);
graph("chr1");
});
}

Expand Down Expand Up @@ -849,6 +914,8 @@ function VQI_GenomeBrowser(id) {
updateSelectBoxWithTracks(track1Select.get(0));
var track2Select = $("#" + divId + " #track2");
updateSelectBoxWithTracks(track2Select.get(0));
var removeTrackSelect = $("#" + divId + " #removeTrack");
updateSelectBoxWithTracks(removeTrackSelect.get(0));
}
var updateSelectBoxWithTracks = function (selectBox) {
selectBox = selectBox;
Expand Down

0 comments on commit 512b5f5

Please sign in to comment.