Skip to content
Permalink
Browse files

ajax calls for fasta files

  • Loading branch information
csw11004 committed Sep 17, 2015
1 parent 0f81a93 commit cbe57b837e9175ec3857170138948305e7883cf0
Showing with 69 additions and 83 deletions.
  1. +61 −81 VQI_GenomeBrowser.js
  2. +4 −2 VQI_GenomeBrowserDemo.html
  3. +4 −0 dynamic_loading.php
@@ -696,7 +696,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
}
}

var addOneTrack = function (data, name, type, fileHandle) {
var addOneTrack = function (data, name, type, args) {

var trackIndex = trackList.length;

@@ -721,11 +721,11 @@ function VQI_GenomeBrowser(id, serviceURL) {
name = name || "track-" + (trackIndex + 1);

if(type == "cpg")
trackList.push(new CpgTrack(name, fileHandle, graphRegion.append("g")));
trackList.push(new CpgTrack(name, graphRegion.append("g"), args));
if(type == "bed")
trackList.push(new BedTrack(name, fileHandle, graphRegion.append("g")));
trackList.push(new BedTrack(name, graphRegion.append("g"), args));
if(type == "fasta")
trackList.push(new FastaTrack(name, graphRegion.append("g")));
trackList.push(new FastaTrack(name, graphRegion.append("g"), args));

clipPath.attr("height", Number(svg.attr("height")));
zoomOnly = true;
@@ -788,21 +788,21 @@ function VQI_GenomeBrowser(id, serviceURL) {
}

}).success(function (returnData) {
thisObj.addTrack(returnData[0], name, type, fileHandle);
thisObj.addTrack(returnData[0], name, type, {"fileHandle" : fileHandle});
isready = true;
updateTrack();
}).error(function (req, status, error) {
$("body").append(status + ": " + error);
});
}

this.addTrack = function (data, name, type, fileHandle) {
this.addTrack = function (data, name, type, args) {

if(data[0][0] != "chrom")
{
data.unshift(["chrom", "chrom_start", "chrom_end", "name", "score", "strand"])
}
data = addOneTrack(data, name, type, fileHandle);
data = addOneTrack(data, name, type, args);

reorderTracks();
updateAllTracksSelectBoxes();
@@ -1120,11 +1120,11 @@ function VQI_GenomeBrowser(id, serviceURL) {
this.getData = function(){};
}

function CpgTrack(name, fileHandle, group) {
function CpgTrack(name, group, args) {
Track.call(this, name, group);
var trackGroup = this.trackGroup;

this.fileHandle = fileHandle;
var fileHandle = args.fileHandle;
var tempHandles = fileHandle.split(",");
var cpgFileHandle = tempHandles[0];
var shelveFileHandle = tempHandles[1];
@@ -1341,12 +1341,11 @@ function VQI_GenomeBrowser(id, serviceURL) {
}
}

function BedTrack(name, fileHandle, group) {
function BedTrack(name, group, args) {
Track.call(this, name, group)
var trackGroup = this.trackGroup;

this.fileHandle = fileHandle;
var tempHandles = fileHandle.split(",");
var fileHandle = args.fileHandle;
var data;
var redrawCutoff = 1000; //Scale at which rectangles will be drawn individually

@@ -1594,16 +1593,12 @@ function VQI_GenomeBrowser(id, serviceURL) {
}
}

var faFile;
var faiData;

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

var data;

var reader = new FileReader();
var file = args.file;
var indexFile = args.indexFile

var drawTrack = function(data)
{
@@ -1668,74 +1663,59 @@ function VQI_GenomeBrowser(id, serviceURL) {
.attr("x", function (d) {
return xScale(d[1]) - 2;
})
};
}

this.updateTrack = function(){
if(faFile)
if( zoom.scale() >= (panExtent[1] - panExtent[0]) / 100/ initialZoom)
{
if( zoom.scale() >= (panExtent[1] - panExtent[0]) / 100/ initialZoom)
{
var offset;
for(var i = 0; i < faiData.length; i++)
var LoadingText = group.append("g")
LoadingText.append("rect")
.attr("x", 450)
.attr("width", 100)
.attr("y", -10)
.attr("height", 20)
.attr("rx", 6)
.attr("ry", 6)
.style("fill-opacity", .6)
.style("fill", "white")

LoadingText.append("text")
.text("Loading...")
.attr("x", 475)
.attr("y", 5);

var xStart = Math.floor(xScale.domain()[0]);
var length = Math.ceil(xScale.domain()[1]) - xStart;
$.ajax({
url: serviceURL,
type: 'POST',
dataType: "json",
data: {
"loadFastaData": "",
"chrom" : chrom_curr,
"start": xStart,
"length": length,
"file": file,
"indexFile": indexFile
}
}).success(function (returnData) {
var data = returnData.split("");
for(var i = 0; i < returnData.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);
data[i] = [data[i], xStart + i]
}
reader.readAsText(blob);
}
else
{
clearTrack();
}
drawTrack(data);
data = returnData;
LoadingText.remove();
}).error(function (req, status, error) {
$("body").append(status + ": " + error);
});
}
};

}

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 == "mm9.fa.txt") {
faFile = file;
}
if (file.name == "mm9.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);
else
{
clearTrack();
}
}
}

this.makeTempForm();

}

@@ -27,8 +27,10 @@
<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");
//insert path to file and indexfile
obj.addTrack([[""],[""]], "fasta", "fasta",
{ "file" : "",
"indexFile" : ""});
obj.addOneTrackFromDatabase("upload1437097194,upload1437098473,upload1437098556", "cpg", "cpg");
obj.addOneTrackFromDatabase("upload1436481988", "HG19", "bed");
@@ -54,6 +54,10 @@
$result = loadTooltip($_POST["chrom"],$_POST["trackName"], $_POST["type"], $_POST["min"],$_POST["max"],$_POST["fileHandle"]);
ajaxReturn($result);
}
else if (isset($_POST["loadFastaData"])){
$result = loadFastaData($_POST["chrom"],$_POST["start"], $_POST["length"], $_POST["file"],$_POST["indexFile"]);
ajaxReturn($result);
}
else {
loadTable();
}

0 comments on commit cbe57b8

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