0) {
return "aa";
} else {
return "na";
}
}
function get_seq($x) {
$fck = 0;
$seq = "";
$fl = explode("\n", $x);
$sh = trim(array_shift($fl));
if($sh == null) {
$fck++;
}
$fl = array_filter($fl);
foreach($fl as $str) {
$seq .= trim($str);
}
$seq = strtoupper($seq);
$seq = preg_replace("/[^ACDEFGHIKLMNPQRSTVWY]/i", "", $seq);
global $moltype;
$moltype = mol_type($seq);
if ((count($fl) < 1) || (strlen($seq) == 0)) {
$fck++;
return $fck;
} else {
return $fck;
}
}
function fcheck($x) {
$gt = substr($x, 0, 1);
$flck = 0;
if ($gt != ">") {
$flck++;
return $flck;
} else {
$gtr = substr($x, 1);
$sqs = explode(">", $gtr);
if (count($sqs) > 1) {
foreach ($sqs as $sq) {
$flck += get_seq($sq);
}
return $flck;
} else {
$flck += get_seq($gtr);
return $flck;
}
}
}
$error = 0;
ini_set('file_uploads', 1);
ini_set('max_execution_time', 0);
$program = $_POST['program'];
$datalib = $_POST['datalib'];
$sequence = $_POST['sequence'];
$outfmt = $_POST['outfmt'];
$seqfile = $_FILES['seqfile']['name'];
$path = realpath($_FILES['seqfile']['name']);
$tpath = realpath($_FILES['seqfile']['tmp_name']);
$extn = strtolower(pathinfo($_FILES['seqfile']['name'], PATHINFO_EXTENSION));
if (($sequence == "") && (empty($seqfile))) {
//print "Input Sequence or File Not Found!
";
require_once('header.php');
print "Input Sequence or File Not Found!";
require_once('footer.php');
$error++;
}
if (!empty($seqfile)) {
if(!in_array($extn, array('fa', 'fas', 'fsa', 'fasta', 'seq'))) {
require_once('header.php');
print "Invalid FASTA file Input!";
require_once('footer.php');
//print "Invalid FASTA file input!!
";
$error++;
}
}
if ($error == 0) {
if (($sequence != "") && (!empty($seqfile))) {
//print "Input Either Sequence or File!
";
require_once('header.php');
print "Input Either Sequence or File!";
require_once('footer.php');
} else if (!empty($seqfile)) {
$input = pathinfo($_FILES['seqfile']['tmp_name'], PATHINFO_FILENAME) . ".fas";
move_uploaded_file($_FILES['seqfile']['tmp_name'], $input);
if ($outfmt == 16) {
$tmpxm = pathinfo($_FILES['seqfile']['tmp_name'], PATHINFO_FILENAME) . ".xml";
$cmd = $osstrt . $program . $osextn . " -db " . $datalib . " -query " . $input . " -outfmt " . $outfmt . " -out " . $tmpxm . $advparam;
$topfs = $tmpxm;
} else {
$tmpof = pathinfo($_FILES['seqfile']['tmp_name'], PATHINFO_FILENAME) . ".htm";
$cmd = $osstrt . $program . $osextn . " -db " . $datalib . " -query " . $input . " -outfmt " . $outfmt . " -out " . $tmpof . " -html" . $advparam;
$topfs = $tmpof;
}
$fh = fopen($input, 'r');
$f = fread($fh, filesize($input));
fclose($fh);
$status = fcheck($f);
$param_error = 0;
if ($status == 0) {
if ((in_array($program, $blast_aa_program) && in_array($datalib, $aa_db)) && ($moltype == "aa")) {
$param_error = 0;
} elseif ((in_array($program, $blast_na_program) && in_array($datalib, $na_db)) && ($moltype == "na")) {
$param_error = 0;
} elseif ((in_array($program, $blast_tra_program) && in_array($datalib, $na_db)) && ($moltype == "aa")) {
$param_error = 0;
} elseif ((in_array($program, $blast_trn_program) && in_array($datalib, $aa_db)) && ($moltype == "na")) {
$param_error = 0;
} else {
//print "Invalid Input/Program/Database Selection!
";
require_once('header.php');
print "Invalid Input/Program/Database Selection1!";
require_once('footer.php');
$param_error++;
if (file_exists($input)) { unlink ($input); }
}
if ($param_error == 0) {
print "";
require_once('header.php');
print "
";
require_once('footer.php');
print "
";
exec($cmd, $exec_output, $exec_return);
if (!$exec_return) {
$foh = fopen($topfs, 'r');
if (filesize($topfs) == 0) {
require_once('header.php');
print "Program Execution Failed!";
require_once('footer.php');
//print "Program Execution Failed!
";
fclose($foh);
if (file_exists($input)) { unlink ($input); }
if ($outfmt == 16) {
if (file_exists($tmpxm)) { unlink ($tmpxm); }
} else {
if (file_exists($tmpof)) { unlink ($tmpof); }
}
} else {
$fo = fread($foh, filesize($topfs));
if ($outfmt == 16) {
print "";
print "locBLAST - local NCBI BLAST
";
print "
";
require_once('xml.php');
print "
";
} else {
print "";
print "locBLAST - local NCBI BLAST
";
}
fclose($foh);
if (file_exists($input)) { unlink ($input); }
if ($outfmt == 16) {
if (file_exists($tmpxm)) { unlink ($tmpxm); }
} else {
if (file_exists($tmpof)) { unlink ($tmpof); }
}
}
} else {
//print "Invalid Input/Program/Database Selection!
";
print "";
include('header.php');
print "Invalid Input/Program/Database Selection2!";
include('footer.php');
if (file_exists($input)) { unlink ($input); }
if ($outfmt == 16) {
if (file_exists($tmpxm)) { unlink ($tmpxm); }
} else {
if (file_exists($tmpof)) { unlink ($tmpof); }
}
}
}
} else {
require_once('header.php');
print "Invalid FASTA File Input!";
require_once('footer.php');
//print "Invalid FASTA File Input!
";
if (file_exists($input)) { unlink ($input); }
}
} else {
$tmpif = 'blast' . date("Y.m.d.h.i.s") . '.fas';
if ($outfmt == 16) {
$tmpxm = 'blast' . date("Y.m.d.h.i.s") . '.xml';
$cmds = $osstrt . $program . $osextn . " -db " . $datalib . " -query " . $tmpif . " -outfmt " . $outfmt . " -out " . $tmpxm . $advparam;
$topfs = $tmpxm;
} else {
$tmpof = 'blast' . date("Y.m.d.h.i.s") . '.htm';
$cmds = $osstrt . $program . $osextn . " -db " . $datalib . " -query " . $tmpif . " -outfmt " . $outfmt . " -out " . $tmpof . " -html" . $advparam;
$topfs = $tmpof;
}
$fhsq = fopen($tmpif, 'w') or die("File Creation Failed!
");
fwrite($fhsq, $sequence);
fclose($fhsq);
$sttus = fcheck($sequence);
$param_error = 0;
if ($sttus == 0) {
if ((in_array($program, $blast_aa_program) && in_array($datalib, $aa_db)) && ($moltype == "aa")) {
$param_error = 0;
} elseif ((in_array($program, $blast_na_program) && in_array($datalib, $na_db)) && ($moltype == "na")) {
$param_error = 0;
} elseif ((in_array($program, $blast_tra_program) && in_array($datalib, $na_db)) && ($moltype == "aa")) {
$param_error = 0;
} elseif ((in_array($program, $blast_trn_program) && in_array($datalib, $aa_db)) && ($moltype == "na")) {
$param_error = 0;
} else {
//print "Invalid Input/Program/Database Selection!
";
require_once('header.php');
print "Invalid Input/Program/Database Selection3!";
require_once('footer.php');
$param_error++;
if (file_exists($tmpif)) { unlink ($tmpif); }
}
if ($param_error == 0) {
print "";
require_once('header.php');
print "
";
require_once('footer.php');
print "
";
exec($cmds, $exec_output, $exec_return);
if (!$exec_return) {
$fsoh = fopen($topfs, 'r');
if (filesize($topfs) == 0) {
//print "Failed to Execute!
";
require_once('header.php');
print "Failed to Execute!";
require_once('footer.php');
fclose($fsoh);
if (file_exists($tmpif)) { unlink ($tmpif); }
if ($outfmt == 16) {
if (file_exists($tmpxm)) { unlink ($tmpxm); }
} else {
if (file_exists($tmpof)) { unlink ($tmpof); }
}
} else {
$fot = fread($fsoh, filesize($topfs));
if ($outfmt == 16) {
print "";
print "locBLAST - local NCBI BLAST
";
print "
";
require_once('xml.php');
print "
";
} else {
print "";
print "locBLAST - local NCBI BLAST
";
}
fclose($fsoh);
if (file_exists($tmpif)) { unlink ($tmpif); }
if ($outfmt == 16) {
if (file_exists($tmpxm)) { unlink ($tmpxm); }
} else {
if (file_exists($tmpof)) { unlink ($tmpof); }
}
}
} else {
print "";
include('header.php');
print "Invalid Input/Program/Database Selection4!";
echo "";
echo "";
echo "";
include('footer.php');
//print "Invalid Input/Program/Database Selection!
";
if (file_exists($tmpif)) { unlink ($tmpif); }
if ($outfmt == 16) {
if (file_exists($tmpxm)) { unlink ($tmpxm); }
} else {
if (file_exists($tmpof)) { unlink ($tmpof); }
}
}
}
} else {
//print "Invalid FASTA File Input!
";
require_once('header.php');
print "Invalid FASTA File Input!";
require_once('footer.php');
if (file_exists($tmpif)) { unlink ($tmpif); }
}
}
}
} else {
require_once('header.php');
print "Choose Program to Use and Database to Search";
require_once('footer.php');
}
?>