From 0f81a939b995a8e1e7ac1b0d9fc4f2de55ee4afe Mon Sep 17 00:00:00 2001 From: Yuchen Jiang Date: Thu, 17 Sep 2015 16:07:09 -0400 Subject: [PATCH] fasta server side --- VQI_GenomeBrowser.js | 4 ++-- dynamic_loading.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/VQI_GenomeBrowser.js b/VQI_GenomeBrowser.js index 4d21d79..f861793 100755 --- a/VQI_GenomeBrowser.js +++ b/VQI_GenomeBrowser.js @@ -1715,10 +1715,10 @@ function VQI_GenomeBrowser(id, serviceURL) { fileInput.addEventListener('change', function (e) { var file = fileInput.files[0]; - if (file.name == "hg19.fa.txt") { + if (file.name == "mm9.fa.txt") { faFile = file; } - if (file.name == "hg19.fa.fai.txt") { + if (file.name == "mm9.fa.fai.txt") { var reader = new FileReader(); reader.onload = function (e) { data = reader.result; diff --git a/dynamic_loading.php b/dynamic_loading.php index 6d7c771..faee70e 100644 --- a/dynamic_loading.php +++ b/dynamic_loading.php @@ -58,6 +58,49 @@ loadTable(); } + function loadFastaData($chrom, $start, $length, $file, $indexFile){ + + $indexFile = fopen($indexFile, "r"); + $indexArray = []; + while (($line = fgets($indexFile))) { + if($line !== ""){ + + $lineArray = explode("\t", $line); + array_push($indexArray,$lineArray); + + } + } + fclose($indexFile); + + + + foreach ($indexArray as $key => $value) { + if ($value[0] == $chrom){ + $chromStart = $value[2]; + $chromLength = $value[1]; + $lineLength = $value[3]; + } + } + + + $lineNum = floor($start/$lineLength); //the line number of the starting bit + $startBit = $chromStart + $lineNum + $start; //starting bit position + + + $file = new SplFileObject($file); + + $file->fseek($startBit); + + $resultLine1 = $file->current(); + $file->next(); + $nextLine2 = $file->current(); + $file->next(); + $nextLine3 = $file->current(); + + $composeLine = $resultLine1 . $nextLine2 . $nextLine3; + $returnString = str_replace("\n", "", $composeLine); + return substr($returnString,0,$length); + } function processData($serviceUrl,$processFileHandle){