Skip to content
Permalink
Browse files

Draft of FastaTrack

  • Loading branch information
csw11004 committed Sep 11, 2015
1 parent 18e2ff3 commit b175432eb81529a99260e68c31709d6e15fc9e65
Showing with 163 additions and 14 deletions.
  1. +160 −14 VQI_GenomeBrowser.js
  2. +3 −0 VQI_GenomeBrowserDemo.html
@@ -521,6 +521,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
};

var setBounds = function (min, max) {
panExtent[0] = 0;
var xMin = Number(min) > panExtent[0] ? Number(min) : panExtent[0];
var xMax = Number(max) < panExtent[1] ? Number(max) : panExtent[1];
var initialZoom = 10000 //defines what will be considered a zoom scale of 1
@@ -633,6 +634,8 @@ function VQI_GenomeBrowser(id, serviceURL) {
trackList.push(new CpgTrack(name, fileHandle, graphRegion.append("g")));
if(type == "bed")
trackList.push(new BedTrack(name, fileHandle, graphRegion.append("g")));
if(type == "fasta")
trackList.push(new FastaTrack(name, graphRegion.append("g")));

clipPath.attr("height", Number(svg.attr("height")));
zoomOnly = true;
@@ -1101,11 +1104,11 @@ function VQI_GenomeBrowser(id, serviceURL) {
position: {
my: 'top center',
at: 'top center',
target: 'mouse',
adjust: {
mouse: true, // Can be omitted (e.g. default behaviour)
y: 10
}
target: 'mouse',
adjust: {
mouse: true, // Can be omitted (e.g. default behaviour)
y: 10
}
}
})
});
@@ -1136,6 +1139,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
.then(function(content) {
// Set the tooltip content upon successful retrieval
selected.qtip('option', 'content.text', content);
selected.qtip('reposition', event);
}, function(xhr, status, error) {
// Upon failure... set the tooltip content to the status and error value
selected.qtip('option', 'content.text', status + ': ' + error);
@@ -1206,10 +1210,6 @@ function VQI_GenomeBrowser(id, serviceURL) {

var trackHeight = 10;

var trackScalableGroup = graphRegion.selectAll("g").data([name], function (d) {
return d;
}).select("g.scalable");

trackGroup.selectAll("rect")
.data(data, function (d) {
return d;
@@ -1340,6 +1340,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
.then(function(content) {
// Set the tooltip content upon successful retrieval
selected.qtip('option', 'content.text', content);
selected.qtip('reposition', event);
}, function(xhr, status, error) {
// Upon failure... set the tooltip content to the status and error value
selected.qtip('option', 'content.text', status + ': ' + error);
@@ -1370,12 +1371,15 @@ function VQI_GenomeBrowser(id, serviceURL) {
}

}).success(function (returnData) {
if(returnData[name][0][0].length === 4) //if no exons exist
drawTrack(returnData[name]);
else
drawTrack(returnData[name][0], returnData[name][1]);
if(returnData[name].length > 0)
{
if(returnData[name][0][0].length === 4) //if no exons exist
drawTrack(returnData[name]);
else
drawTrack(returnData[name][0], returnData[name][1]);

data = returnData;
data = returnData;
}
}
).error(function (req, status, error) {
$("body").append(status + ": " + error);
@@ -1397,6 +1401,148 @@ function VQI_GenomeBrowser(id, serviceURL) {
}
}

var faFile;
var faiData;

function FastaTrack(name, group) {
Track.call(this, name, group);
var trackGroup = this.trackGroup;

var data;

var reader = new FileReader();

var drawTrack = function(data)
{
trackGroup.selectAll("text")
.data(data, function (d) {
return d;
})
.exit()
.remove();

trackGroup.selectAll("text")
.data(data, function (d) {
return d;
})
.enter()
.append("text")

trackGroup.selectAll("text")
.data(data, function (d) {
return d;
})
.text(function (d) {return d[0]})
.attr("x", function (d) {
return xScale(d[1]) - 2; //-2 to center text
})

addTooltip(trackGroup.selectAll("text"))
}

var clearTrack = function()
{
trackGroup.selectAll("text").remove();
}

var addTooltip = function(selection)
{
var start = (Math.round(xScale.domain()[0])).toString();
var end = (Math.round(xScale.domain()[1])).toString();
var scale = (end - start)/1000;

selection.each(
function(d){
$(this).qtip({
content: {
text: d[1]
},
position: {
my: 'top center',
at: 'top center',
target: 'mouse',
adjust: {
mouse: true, // Can be omitted (e.g. default behaviour)
y: 10
}
}
})
});
}

this.zoomed = function(){
trackGroup.selectAll("text")
.attr("x", function (d) {
return xScale(d[1]) - 2;
})
};

this.updateTrack = function(){
if(faFile)
{
if( zoom.scale() >= (panExtent[1] - panExtent[0]) / 100 / 10000)
{
var offset;
for(var i = 0; i < faiData.length; i++)
{
if(faiData[i][0] == chrom_curr)
{
offset = Number(faiData[i][2]);
break;
}
}
xStart = Math.floor(xScale.domain()[0]);
var blob = faFile.slice(xStart+offset ,Math.ceil(xScale.domain()[1])+offset);
var data;
reader.onload = function (e) {
data = reader.result;
data = data.split("");
for(var i = 0; i < data.length; i++)
{
data[i] = [data[i], xStart + i]
}
drawTrack(data);
}
reader.readAsText(blob);
}
else
{
clearTrack();
}
}
};

}

this.makeTempForm = function() { //just for putting in .fa and .fai files for now

var fileInput = document.createElement('input');
fileInput.type = 'file';


fileInput.addEventListener('change', function (e) {
var file = fileInput.files[0];
if (file.name == "hg19.fa.txt") {
faFile = file;
}
if (file.name == "hg19.fa.fai.txt") {
var reader = new FileReader();
reader.onload = function (e) {
data = reader.result;
data = data.split("\n");
for(var i = 0; i < data.length; i++)
{
data[i] = data[i].split("\t");
}
faiData = data;
}
reader.readAsText(file);
}
});
$("#" + divId).append(fileInput);
}

this.makeTempForm();

}

@@ -31,6 +31,9 @@
<script type="text/javascript">
var obj = new VQI_GenomeBrowser("test",'dynamic_loading.php');
//just choose the .fa file then the .fai file in file select at bottom to load
obj.addTrack([[""],[""]], "fasta", "fasta");
obj.addOneTrackFromDatabase("upload1437097194,upload1437098473,upload1437098556", "cpg", "cpg");
obj.addOneTrackFromDatabase("upload1436481988", "HG19", "bed");
obj.addOneTrackFromDatabase("upload1436411775", "Tile2 Content Snp", "bed");

0 comments on commit b175432

Please sign in to comment.
You can’t perform that action at this time.