Эх сурвалжийг харах

Moved blast_ui_get_cvit_conf_text() and blast_ui_get_cvit_conf() from blast_ui.admin.inc to blast_ui.api.inc

E.Cannon 7 жил өмнө
parent
commit
579d49f305

+ 59 - 17
api/blast_ui.api.inc

@@ -47,9 +47,9 @@ function get_blast_database($identifiers) {
  */
 function get_blast_database_options($type) {
   global $user;
-  
+
   // Get all BlastDB nodes
-  $nodes = get_blast_database_nodes(); 
+  $nodes = get_blast_database_nodes();
 
   // Support obsolete database type n/p
   $obs_type = '';
@@ -75,6 +75,12 @@ function get_blast_database_options($type) {
   return $options;
 }
 
+/**
+ * Returns all blast database nodes.
+ *
+ * @return
+ *   An array of nodes.
+ */
 function get_blast_database_nodes() {
   // Use the Entity API to get a list of BLAST Nodes to load
   // We use this function in order respect node access control so that
@@ -106,11 +112,11 @@ function get_blast_database_nodes() {
 function get_BLAST_job($job_id) {
 
   $blastjob = db_query('SELECT * FROM blastjob WHERE job_id=:id', array(':id' => $job_id))->fetchObject();
-  
+
   if (!$blastjob) {
     return false;
   }
-  
+
   $tripal_job = tripal_get_job($job_id);
 
   $job = new stdClass();
@@ -339,8 +345,8 @@ function run_BLAST_tripal_job($program, $query, $database, $output_filestub, $op
  */
 function validate_fasta_sequence($type, $sequence) {
   //Includes IUPAC codes.
-  $fastaSeqRegEx = ($type == 'nucleotide') 
-                   ? '/^[ATCGNUKMBVSWDYRHatcgnukmbvswdyrh\[\/\]\s\n\r]*$/' 
+  $fastaSeqRegEx = ($type == 'nucleotide')
+                   ? '/^[ATCGNUKMBVSWDYRHatcgnukmbvswdyrh\[\/\]\s\n\r]*$/'
                    : '/^[ABCDEFGHIKLMNPQRSTUVWYZXabcdefghiklmnpqrstuvwyzx\*\-\s\n\r]*$/';
   $defRegEx      = '/^>.*(\\n|\\r)(.*)$/sm';
   if (preg_match($defRegEx, $sequence, $matches)) {
@@ -351,7 +357,7 @@ function validate_fasta_sequence($type, $sequence) {
   else if ($sequence != '' && preg_match($defRegEx, $sequence)) {
     return true;
   }
-  
+
   return false;
 }
 
@@ -753,7 +759,7 @@ function convert_tsv2gff3($blast_tsv,$blast_gff){
   $last_s = NULL;
   $hsp = NULL;
   $HitResult=array();
-  
+
   while(!feof($tsv)) {
     $line = fgets($tsv);
     $line = rtrim($line);
@@ -788,9 +794,9 @@ function convert_tsv2gff3($blast_tsv,$blast_gff){
     $qs = $parts[6];
     $qe = $parts[7];
     $e = $parts[10];
-     
 
-    // if this is a new hit print the last and 
+
+    // if this is a new hit print the last and
     // empty the $HitResult array and
     // reset hsp counter
     if ($last_s != NULL and $s != $last_s ) {
@@ -798,10 +804,10 @@ function convert_tsv2gff3($blast_tsv,$blast_gff){
       $HitResult = array();
       $hsp=0;
     }
-  
+
     // every line is a new hsp
     $hsp++;
-  
+
     // determine query strand to use in match_part line, no need to store, just print
     $q_strand = '+';
     if ($qs > $qe) {
@@ -816,12 +822,12 @@ function convert_tsv2gff3($blast_tsv,$blast_gff){
        list($start,$end) = array($se,$ss);
        $HitResult["$s,$q"]['strand']='-';
      }
-  
+
     // store smallest start
      if (!array_key_exists('SS',$HitResult["$s,$q"]) or $ss < $HitResult["$s,$q"]['SS']) {
        $HitResult["$s,$q"]['SS'] = $ss;
      }
-    
+
     // store largest end
      if (!array_key_exists('SE',$HitResult["$s,$q"]) or $se > $HitResult["$s,$q"]['SE']) {
        $HitResult["$s,$q"]['SE'] = $se;
@@ -830,8 +836,8 @@ function convert_tsv2gff3($blast_tsv,$blast_gff){
      // store best evalue
      if (!array_key_exists('E',$HitResult["$s,$q"]) or $e < $HitResult["$s,$q"]['E']) {
        $HitResult["$s,$q"]['E'] = $e;
-     }   
-    
+     }
+
      // generate the match_part line for each hsp
      $HitResult["$s,$q"]['HSPs'][] = join("\t", array($s, "BLASTRESULT" , "match_part" , $start , $end , $e , $HitResult["$s,$q"]['strand'] , '.' , "ID=$s.$q.$hsp;Parent=$s.$q;Target=$q $qs $qe $q_strand"));
      $last_s = $s;
@@ -855,7 +861,6 @@ function convert_tsv2gff3($blast_tsv,$blast_gff){
  *
  *
  */
-
 function printGFF_parent_children ($gff,$blast_feature_array){
   foreach ($blast_feature_array as $sq => $value ) {
     list ($s,$q) = preg_split('/,/' , $sq);
@@ -866,3 +871,40 @@ function printGFF_parent_children ($gff,$blast_feature_array){
     fwrite($gff,$child);
   }
 }
+
+/**
+ * Get text from cvitjs conf file, if possible.
+ *
+ * @return
+ *   A string containing the entire contents of the cvitjs configuration file. FALSE otherwise.
+ */
+function blast_ui_get_cvit_conf_text() {
+  if ($cvit_conf=blast_ui_get_cvit_conf(variable_get('blast_ui_cvitjs_location', false))) {
+    if ($contents=file_get_contents($cvit_conf)) {
+      return $contents;
+    }
+  }
+
+  return false;
+}
+
+
+/**
+ * Get path to cvitjs conf file.
+ *
+ * ASSUMPTION: Assumes the code is contained within the blast ui module.
+ *
+ * @return
+ *  The path to the CViTjs codebase.
+ */
+function blast_ui_get_cvit_conf($cvitjs_location) {
+  if (!$cvitjs_location) {
+    return false;
+  }
+
+  $cvit_conf_path = drupal_get_path('module','blast_ui')
+                  . DIRECTORY_SEPARATOR . $cvitjs_location
+                  . DIRECTORY_SEPARATOR . 'cvit.conf';
+
+  return $cvit_conf_path;
+}

+ 9 - 40
includes/blast_ui.admin.inc

@@ -194,7 +194,7 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
   else {
     $disabled = false;
   }
-  
+
   $description = 'This is the contents of the file that defines data directories and '
                . 'backbone GFF files for each genome assembly target. It is named '
                . 'cvit.conf and is in the root directory for the CViTjs javascript code. '
@@ -213,7 +213,7 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
 //eksc:
   // WARNING
   $description = 'This permits display of a temporary warning message at the top of the
-                  BLAST input form. Text can include HTML tags. Remember to remove the 
+                  BLAST input form. Text can include HTML tags. Remember to remove the
                   message when it is no longer relevant.';
   $form['warning'] = array(
     '#type' => 'fieldset',
@@ -230,7 +230,7 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
     '#rows' => 10,
   );
 
-  
+
   // SUBMIT
   $form['submit'] = array(
     '#type' => 'submit',
@@ -260,20 +260,20 @@ function blast_ui_admin_form_validate($form, &$form_state) {
   if ($form_state['values']['cvitjs_enabled']) {
     $cvit_path = blast_ui_get_cvit_conf($form_state['values']['cvitjs_location']);
     if (!$cvit_path || !file_exists($cvit_path)) {
-      $msg = "The CViTjs configuration file, cvit.conf, does not exist at the path given (" 
+      $msg = "The CViTjs configuration file, cvit.conf, does not exist at the path given ("
            . $form_state['values']['cvitjs_location']
            . "). Please check your path. "
            . "If you have not yet downloaded CViTjs, see the help tab for more information.";
       form_set_error('cvitjs_location', t($msg));
     }
-    
+
     if (!is_writable($cvit_path)) {
       $msg = "The file $cvit_path is not writable by this page. "
            . "Please enable write access for apache then try saving these settings again.";
       form_set_error('cvitjs_location', t($msg));
     }
   }
-  
+
   // Empty contents of cvitjs_config textarea if it is disabled
   if ($form['cvitjs']['cvitjs_config']['#disabled']) {
     $form_state['values']['cvitjs_config'] = '';
@@ -289,46 +289,15 @@ function blast_ui_admin_form_validate($form, &$form_state) {
     form_set_error('cvitjs_config', t($msg));
   }
   if ($form_state['values']['cvitjs_config']
-        && !preg_match('/\[.*\]\s*\nconf = .*\ndefaultData =.*/m', 
+        && !preg_match('/\[.*\]\s*\nconf = .*\ndefaultData =.*/m',
                        $form_state['values']['cvitjs_config'])) {
     $msg = "The CViTjs configuration text looks incorrect. "
          . "It should contain one section for each genome target. "
          . "See the help tab for more information.";
     form_set_error('cvitjs_config', t($msg));
-  }    
-}
-
-
-/**
- * Get text from cvitjs conf file, if possible.
- */
-function blast_ui_get_cvit_conf_text() {
-  if ($cvit_conf=blast_ui_get_cvit_conf(variable_get('blast_ui_cvitjs_location', false))) {
-    if ($contents=file_get_contents($cvit_conf)) {
-      return $contents;
-    }
   }
-  
-  return false;
 }
 
-
-/**
- * Get path to cvitjs conf file.
- */
-function blast_ui_get_cvit_conf($cvitjs_location) {
-  if (!$cvitjs_location) {
-    return false;
-  }
-  
-  $cvit_conf_path = drupal_get_path('module','blast_ui') 
-                  . DIRECTORY_SEPARATOR . $cvitjs_location
-                  . DIRECTORY_SEPARATOR . 'cvit.conf';
-             
-  return $cvit_conf_path;
-}
-
-
 /**
  * Submit the Admin/settings form.
  */
@@ -347,7 +316,7 @@ function blast_ui_admin_form_submit($form, $form_state) {
   // Example sequence
   variable_set('blast_ui_nucleotide_example_sequence', $form_state['values']['nucleotide_example']);
   variable_set('blast_ui_protein_example_sequence', $form_state['values']['protein_example']);
-  
+
   // Protect against large result sets
   variable_set('blast_ui_max_results_displayed', $form_state['values']['max_results_displayed']);
 
@@ -366,7 +335,7 @@ function blast_ui_admin_form_submit($form, $form_state) {
       drupal_set_message("Unable to open CViTjs conf file for writing: <pre>" . print_r(error_get_last(),true) . "</pre>");
     }
   }
-  
+
 //eksc:
   // Warning text
   variable_set('blast_ui_warning_text', $form_state['values']['warning_text']);