123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- function get_blast_database($identifiers) {
- $node = FALSE;
- if (isset($identifiers['nid'])) {
- $node = node_load($identifiers['nid']);
- }
- elseif (isset($identifiers['name'])) {
- $nid = db_query('SELECT nid FROM {blastdb} WHERE name=:name', array(':name' => $identifiers['name']))->fetchField();
- $node = node_load($nid);
- } elseif (isset($identifiers['path'])) {
- $nid = db_query('SELECT nid FROM {blastdb} WHERE path LIKE :path', array(':path' => db_like($identifiers['path']) . '%'))->fetchField();
- $node = node_load($nid);
- }
- return $node;
- }
- function get_blast_database_options($type) {
- global $user;
-
-
-
-
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'node')
-
- ->entityCondition('bundle', 'blastdb')
-
- ->propertyCondition('status', 1)
-
- ->addTag('node_access');
- $entities = $query->execute();
-
- $nodes = node_load_multiple(array_keys($entities['node']));
-
- $obs_type = '';
- if ($type == 'protein') {
- $obs_type = 'p';
- }
- else {
- $obs_type = 'n';
- }
- $options = array();
- foreach ($nodes as $node) {
- if ( isset($node) && isset($node->db_dbtype) ) {
- if ( ($node->db_dbtype == $type) OR ($node->db_dbtype == $obs_type) ) {
- $options[$node->nid] = $node->db_name;
- }
- }
- }
- asort($options);
- $options[0] = 'Select a Dataset';
- return $options;
- }
- function run_BLAST_tripal_job($program, $query, $database, $output_filestub, $options, $job_id = NULL) {
- $output_file = file_directory_temp() . DIRECTORY_SEPARATOR . $output_filestub . '.blast.asn';
- $output_dir = variable_get('file_public_path', conf_path() . '/files')
- . DIRECTORY_SEPARATOR . 'tripal' . DIRECTORY_SEPARATOR . 'tripal_blast';
- $output_file_xml = $output_dir . DIRECTORY_SEPARATOR . $output_filestub . '.blast.xml';
- $output_file_tsv = $output_dir . DIRECTORY_SEPARATOR . $output_filestub . '.blast.tsv';
- $output_file_html = $output_dir . DIRECTORY_SEPARATOR . $output_filestub . '.blast.html';
- print "\nExecuting $program\n\n";
- print "Query: $query\n";
- print "Database: $database\n";
- print "Results File: $output_file\n";
- print "Options:\n";
-
-
- $blast_path = variable_get('blast_path', '');
- $blast_threads = variable_get('blast_threads', '');
-
-
- $database = preg_replace("/(.*)\.[pn]\w\w/", '$1', $database);
-
-
- $program = $blast_path . $program;
- $blast_formatter_command = $blast_path . 'blast_formatter';
- $blast_cmd = "$program -query '$query' -db '$database' -out '$output_file' -outfmt=11";
- if (!empty($options)) {
- foreach ($options as $opt => $val) {
- print "\t$opt: $val\n";
- $blast_cmd .= " -$opt $val";
- }
- }
- print "\nExecuting the following BLAST command:\n" . $blast_cmd . "\n";
- system($blast_cmd);
- if(!file_exists($output_file)) {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_ERROR,
- "BLAST did not complete successfully as is implied by the lack of output file (%file). The command run was @command",
- array('%file' => $output_file, '@command' => $blast_cmd),
- array('print' => TRUE)
- );
- return FALSE;
- }
- print "\nGenerating additional download formats...\n";
- print "\tXML\n";
- $format_cmd = "$blast_formatter_command -archive $output_file -outfmt 5 -out $output_file_xml";
- print "\nExecuting $format_cmd\n\n";
- system($format_cmd);
- if(!file_exists($output_file_xml)) {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_ERROR,
- "Unable to convert BLAST ASN.1 archive (%archive) to XML (%file).",
- array('%archive' => $output_file, '%file' => $output_file_xml),
- array('print' => TRUE)
- );
- }
- print "\tTab-delimited\n";
- system("$blast_formatter_command -archive $output_file -outfmt 7 -out $output_file_tsv");
- if(!file_exists($output_file_tsv)) {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_WARNING,
- "Unable to convert BLAST ASN.1 archive (%archive) to Tabular Output (%file).",
- array('%archive' => $output_file, '%file' => $output_file_tsv),
- array('print' => TRUE)
- );
- }
- print "\tHTML (includes alignments)\n";
- system("$blast_formatter_command -archive $output_file -outfmt 0 -out $output_file_html -html");
- if(!file_exists($output_file_tsv)) {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_WARNING,
- "Unable to convert BLAST ASN.1 archive (%archive) to HTML Output (%file).",
- array('%archive' => $output_file, '%file' => $output_file_html),
- array('print' => TRUE)
- );
- }
- print "\nDone!\n";
- }
- function validate_fasta_sequence($type, $sequence) {
- if ($type == 'nucleotide') {
- $fastaIdRegEx = '/^>.*(\\n|\\r)/';
- $fastaSeqRegEx = '/[^acgntuACGNTU\n\r]/';
- if ( preg_match($fastaSeqRegEx,$sequence) && !(preg_match($fastaIdRegEx,$sequence)) ) {
- return TRUE;
- } else {
- return FALSE;
- }
- } elseif ($type == 'protein') {
- $fastaIdRegEx = '/^>.*(\\n|\\r)/';
- $fastaSeqRegEx = '/[^acgturykmswbdhvnxACGTURYKMSWBDHVNX\*\-\n\r]/';
- if ( preg_match($fastaSeqRegEx,$sequence) && !(preg_match($fastaIdRegEx,$sequence)) ) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- return FALSE;
- }
- function get_blastdb_linkout_regex($node, $options = array()) {
- if (empty($node->linkout->regex)) {
- switch ($node->linkout->regex_type) {
- case 'default':
- $regex = '/^(\S+).*/';
- break;
- case 'genbank':
- $regex = '/^gb\|([^\|])*\|.*/';
- break;
- case 'embl':
- $regex = '/^embl\|([^\|])*\|.*/';
- break;
- case 'swissprot':
- $regex = '/^sp\|([^\|])*\|.*/';
- break;
- }
- }
- else {
- $regex = $node->linkout->regex;
- }
- return $regex;
- }
- function get_recent_jobs() {
- $html = "
- <h3><strong> Recent Jobs </h3>
- <dl>";
- $sid = session_id();
- $jobs = $_SESSION['all_jobs'][$sid];
-
- foreach ($jobs as $job_id => $job) {
- if ($diff = abs(time() - strtotime($job['date'])) > 172800) {
- unset($jobs[$job_id]);
- }
- }
- $_SESSION['all_jobs'][$sid] = $jobs;
- foreach (array_reverse($jobs) as $job) {
- $q_def = !isset($job['query_defs'][0]) ? "Query" : $job['query_defs'][0];
- $html .= "
- <dd>
- <a href='" . "../../" . $job['job_output_url'] ."'>
- $q_def X " . $job['target'] . ' (' . $job['program'] . ') - ' . $job['date'] . "
- </a>
- </dd>";
- }
- $html .= "
- </dl>";
-
- return $html;
- }
|