Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Check table exists method added
  • Loading branch information
csw11004 committed Oct 9, 2015
1 parent fc7e395 commit 9d92804
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 43 deletions.
50 changes: 46 additions & 4 deletions VQI_GenomeBrowser.js
Expand Up @@ -711,9 +711,25 @@ function VQI_GenomeBrowser(id, serviceURL) {
selectBox.options.length = 0;
var optionIndex = 0;
for (var key in genomes) {
console.log(key)
var text = key;
var value = key;
selectBox.options[optionIndex++] = new Option(text, value);
for(var key2 in genomes[key])
{
if(key2 === 'custom' || key2 ==='genes')
{
checkTableUpload(genomes[key][key2].table_name)
}
if(key2 === 'cpg')
{
var tempHandles = genomes[key][key2].table_name.split(",");
for(var i in tempHandles)
{
checkTableUpload(tempHandles[i].trim())
}
}
}
}
}

Expand All @@ -729,6 +745,25 @@ function VQI_GenomeBrowser(id, serviceURL) {
}
}

var checkTableUpload = function(tableName) {

$.ajax({
url: serviceURL,
type: 'POST',
dataType: "json",
data: {
"checkTable": "",
"tableName": tableName
}

}).success(function (returnData) {
console.log(returnData);
}
).error(function (req, status, error) {
$("body").append(status + ": " + error);
});
}

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

var trackIndex = trackList.length;
Expand All @@ -738,12 +773,19 @@ function VQI_GenomeBrowser(id, serviceURL) {
name = name || "track-" + (trackIndex + 1);

if(type == "cpg")
{
trackList.push(new CpgTrack(name, graphRegion.append("g"), args));
}
else if(type == "genes")
{
trackList.push(new BedTrack(name, graphRegion.append("g"), args));
}
else if(type == "fasta")
{
trackList.push(new FastaTrack(name, graphRegion.append("g"), args));
else{
}
else
{
args.exportable = true;
trackList.push(new CustomTrack(name, graphRegion.append("g"), args));
}
Expand Down Expand Up @@ -1236,7 +1278,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
data: {
"getRange": "",
"fileHandles": [fileHandle],
"name": [name],
"type": "cpg",
"chrom": chrom_curr
}
}).success(function (returnData) {
Expand Down Expand Up @@ -1526,7 +1568,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
data: {
"getRange": "",
"fileHandles": [fileHandle],
"name": [name],
"type": "gene",
"chrom": chrom_curr
}
}).success(function (returnData) {
Expand Down Expand Up @@ -1778,7 +1820,7 @@ function VQI_GenomeBrowser(id, serviceURL) {
data: {
"getRange": "",
"fileHandles": [fileHandle],
"name": [name],
"type": "custom",
"chrom": chrom_curr
}
}).success(function (returnData) {
Expand Down
2 changes: 1 addition & 1 deletion VQI_GenomeBrowserDemo.html
Expand Up @@ -47,7 +47,7 @@
cpg: {file: "../../genome/hg19_genes.txt", table_name:'hg19_cpg'},*/
fasta: {fasta: "/Users/corywang/Downloads/hg19.fa.txt", index : "/Users/corywang/Downloads/hg19.fa.fai.txt"},
genes: {file: "", table_name: "upload1436481988"},
cpg: {files: "", table_name: "upload1437097194,upload1437098473,upload1437098556"},
cpg: {file: "", table_name: "upload1437097194,upload1437098473,upload1437098556"},
custom: {file: "", table_name:'upload1436411775'}
},
"MM9":{
Expand Down
91 changes: 53 additions & 38 deletions dynamic_loading.php
Expand Up @@ -54,7 +54,7 @@
ajaxReturn($result);
}
else if (isset($_POST["getRange"])){
$result = getRange($_POST["fileHandles"], $_POST["name"], $_POST["chrom"]);
$result = getRange($_POST["fileHandles"], $_POST["type"], $_POST["chrom"]);
ajaxReturn($result);
}
else if (isset($_POST["loadTooltip"])){
Expand All @@ -73,10 +73,30 @@
$result = getFullTrackData($_POST["fileHandle"]);
ajaxReturn($result);
}
else if (isset($_POST["checkTable"])){
$result = checkTable($_POST["tableName"]);
ajaxReturn($result);
}
else {
loadTable();
}

function checkTable($tableName){
$db_name = $GLOBALS['db_name'];
$link = $GLOBALS['DBlink'];

$sql = "SELECT * FROM {$db_name}.{$tableName} LIMIT 1";

$res = mysqli_query ($link,$sql);

$firstRow = mysqli_fetch_row($res);

if($firstRow)
return "true";
else
return "false";
}

function loadFastaData($chrom, $start, $length, $file, $indexFile){

$indexFile = fopen($indexFile, "r");
Expand Down Expand Up @@ -299,7 +319,7 @@
}
}

function getHG19TrackData($fileHandle,$chrom,$start,$end){
function getGeneTrackData($fileHandle,$chrom,$start,$end){

$db_name = $GLOBALS['db_name'];
$link = $GLOBALS['DBlink'];
Expand Down Expand Up @@ -541,7 +561,7 @@
return $returnArray;
}

function getRange($fileHandles,$name,$chrom){
function getRange($fileHandles,$type,$chrom){
$db_name = $GLOBALS['db_name'];
$link = $GLOBALS['DBlink'];

Expand All @@ -551,47 +571,42 @@
$sql .= " WHERE `CHROM` = '".$chrom."'";
$sql .= " ORDER BY `CHROM_START` * 1 ASC";

foreach ($fileHandles as $key => $value) {
# code...
$fileHandle = $value;
$fileHandle = $value;

$minsql = "SELECT `CHROM`, `CHROM_START`, `CHROM_END`, `GENESYMBOL`, `SCORE` FROM {$db_name}.{$fileHandle} ORDER BY `CHROM_START` * 1 ASC LIMIT 1";
if ($name[$key] == "HG19"){
$minsql = "SELECT `chrom`, `txStart`, `txEnd`, `name2`, `score` FROM {$db_name}.{$fileHandle} ORDER BY `txStart` * 1 ASC LIMIT 1";
}
if ($name[$key] == "cpg"){
$temp = explode(",", $fileHandle);
$shelveFile = $temp[1];
$minsql = "SELECT `CHROM`, `START`, `END` FROM {$db_name}.{$shelveFile} ORDER BY `START` * 1 ASC LIMIT 1";
}
$minres = mysqli_query ($link,$minsql);
$minsql = "SELECT `CHROM`, `CHROM_START`, `CHROM_END`, `GENESYMBOL`, `SCORE` FROM {$db_name}.{$fileHandle} ORDER BY `CHROM_START` * 1 ASC LIMIT 1";
if ($type == "gene"){
$minsql = "SELECT `chrom`, `txStart`, `txEnd`, `name2`, `score` FROM {$db_name}.{$fileHandle} ORDER BY `txStart` * 1 ASC LIMIT 1";
}
if ($type == "cpg"){
$temp = explode(",", $fileHandle);
$shelveFile = $temp[1];
$minsql = "SELECT `CHROM`, `START`, `END` FROM {$db_name}.{$shelveFile} ORDER BY `START` * 1 ASC LIMIT 1";
}
$minres = mysqli_query ($link,$minsql);

while($row = mysqli_fetch_row($minres))
{
$min = $row[1];
array_push($returnArray, $min);
}
$row = mysqli_fetch_row($minres);
$min = $row[1];
array_push($returnArray, $min);


$maxsql = "SELECT `CHROM`, `CHROM_START`, `CHROM_END`, `GENESYMBOL`, `SCORE` FROM {$db_name}.{$fileHandle} ORDER BY `CHROM_END` * 1 DESC LIMIT 1";
if ($name[$key] == "HG19"){
$maxsql = "SELECT `chrom`, `txStart`, `txEnd`, `name2`, `score` FROM {$db_name}.{$fileHandle} ORDER BY `txEnd` * 1 DESC LIMIT 1";
}
if ($name[$key] == "cpg"){
$temp = explode(",", $fileHandle);
$shelveFile = $temp[1];
$maxsql = "SELECT `CHROM`, `START`, `END` FROM {$db_name}.{$shelveFile} ORDER BY `END` * 1 DESC LIMIT 1";
}
$maxres = mysqli_query ($link,$maxsql);
$maxsql = "SELECT `CHROM`, `CHROM_START`, `CHROM_END`, `GENESYMBOL`, `SCORE` FROM {$db_name}.{$fileHandle} ORDER BY `CHROM_END` * 1 DESC LIMIT 1";
if ($type == "gene"){
$maxsql = "SELECT `chrom`, `txStart`, `txEnd`, `name2`, `score` FROM {$db_name}.{$fileHandle} ORDER BY `txEnd` * 1 DESC LIMIT 1";
}
if ($type == "cpg"){
$temp = explode(",", $fileHandle);
$shelveFile = $temp[1];
$maxsql = "SELECT `CHROM`, `START`, `END` FROM {$db_name}.{$shelveFile} ORDER BY `END` * 1 DESC LIMIT 1";
}
$maxres = mysqli_query ($link,$maxsql);

while($row = mysqli_fetch_row($maxres))
{
$max = $row[2];
array_push($returnArray, $max);
}
$row = mysqli_fetch_row($maxres);
$max = $row[2];
array_push($returnArray, $max);

}
return $returnArray;
}
}

function loadTooltip($chrom, $type, $min, $max, $fileHandle){
//return $chrom.$trackName.$type.$xCoordinate.$scale.$fileHandle;
Expand Down Expand Up @@ -642,7 +657,7 @@

}

function loadHG19Tooltip($chrom,$type, $min,$max,$fileHandle){
function loadGeneTooltip($chrom,$type, $min,$max,$fileHandle){
$db_name = $GLOBALS['db_name'];
$link = $GLOBALS['DBlink'];

Expand Down

0 comments on commit 9d92804

Please sign in to comment.