Browse Source

Merge pull request #22 from LegumeFederation/remove_all_webservice_code

Remove all web service code
ekcannon 7 years ago
parent
commit
d206e6d281
2 changed files with 268 additions and 909 deletions
  1. 268 251
      includes/blast_ui.form_advanced_options.inc
  2. 0 658
      includes/blast_ui.services.inc

+ 268 - 251
includes/blast_ui.form_advanced_options.inc

@@ -51,7 +51,7 @@ function blast_ui_blastn_advanced_options_form(&$form, $form_state) {
     '#description' => t('Select the maximum number of unique target sequences per query sequence to show results for.'),
   );
 
-/*eksc- remove until we learn how this is implemented by NCBI
+/*eksc: remove until we learn how this is implemented by NCBI
   $form['ALG']['GParam']['shortQueries'] = array(
     '#type' => 'checkbox',
     '#title' => t('Automatically adjust parameters for short input sequences'),
@@ -76,6 +76,8 @@ function blast_ui_blastn_advanced_options_form(&$form, $form_state) {
     '#description' => t('The length of the seed that initiates an alignment'),
   );
 
+/*eksc: remove this as it is either the same as max_target_seqs, or miss-implemented
+       as culling_limit, which is something else entirely
   $form['ALG']['GParam']['qRange'] = array(
     '#type' => 'textfield',
     '#title' => t('Max matches in a query range'),
@@ -84,7 +86,7 @@ function blast_ui_blastn_advanced_options_form(&$form, $form_state) {
     '#maxlength' => 20,
     '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
   );
-
+*/
   // Scoring parameters
   //.........................
 
@@ -127,12 +129,13 @@ function blast_ui_blastn_advanced_options_form_validate($form, $form_state) {
     form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
   }
 
+/*eksc: removed until/unless it can be properly implemented
   // Next textfield up, "Max matches in a query range" which is also expected
   // to be a positive number.
   if (!is_numeric($form_state['values']['qRange'])) {
     form_set_error('qRange', 'The "Max matches in a query range" should be a positive integer.');
   }
-
+*/
 }
 
 /**
@@ -260,6 +263,8 @@ function blast_ui_blastx_advanced_options_form(&$form, $form_state) {
     ),
   );
 
+/*eksc: removed as this is either equivalent to max_target_sequences or mis-implemented
+       as culling_limit
   $form['ALG']['GParam']['qRange'] = array(
     '#type' => 'textfield',
     '#title' => t('Max matches in a query range'),
@@ -268,8 +273,9 @@ function blast_ui_blastx_advanced_options_form(&$form, $form_state) {
     '#maxlength' => 20,
     '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
   );
+*/
 
-/*eksc- NOT match/mismatch but instead computational adjustments;
+/*eksc: NOT match/mismatch but instead computational adjustments;
         need to learn how there are implemented for blastx
   $form['ALG']['SParam']['M&MScores'] = array(
     '#type' => 'select',
@@ -302,12 +308,13 @@ function blast_ui_blastx_advanced_options_form_validate($form, $form_state) {
     form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
   }
 
+/*eksc: removed until/unless we know how to properly implement
   // Next textfield up, "Max matches in a query range" which is also expected
   // to be a positive number.
   if (!is_numeric($form_state['values']['qRange'])) {
     form_set_error('qRange', 'The "Max matches in a query range" should be a positive integer.');
   }
-
+*/
 }
 
 /**
@@ -367,7 +374,7 @@ function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
     '#description' => t('Select the maximum number of aligned sequences to display'),
   );
 
-/*eksc- remove until we learn how this is implemented
+/*eksc: remove until we learn how this is implemented
   $form['ALG']['GParam']['shortQueries'] = array(
    '#type' => 'checkbox',
    '#title' => t('Automatically adjust parameters for short input sequences'),
@@ -392,6 +399,8 @@ function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
     '#description' => t('The length of the seed that initiates an alignment'),
   );
 
+/*eksc: remove this as it is either the same as max_target_seqs, or miss-implemented
+       as culling_limit, which is something else entirely
   $form['ALG']['GParam']['qRange'] = array(
     '#type' => 'textfield',
     '#title' => t('Max matches in a query range'),
@@ -400,7 +409,7 @@ function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
     '#maxlength' => 20,
     '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
   );
-
+*/
   // Scoring parameters
 
   $form['ALG']['SParam'] = array(
@@ -422,7 +431,7 @@ function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
     ),
   );
 
-/*eksc- probably not used for blastp
+/*eksc: probably not used for blastp
   $form['ALG']['SParam']['gapCost'] = array(
     '#type' => 'select',
     '#title' => t('Gap Costs:'),
@@ -434,7 +443,7 @@ function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
   );
 */
 
-/*eksc- NOT match/mismatch but instead computational adjustments;
+/*eksc: NOT match/mismatch but instead computational adjustments;
         need to learn how there are implemented for blastp
   $form['ALG']['SParam']['M&MScores'] = array(
     '#type' => 'select',
@@ -467,11 +476,13 @@ function blast_ui_blastp_advanced_options_form_validate($form, $form_state) {
     form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
   }
 
+/*eksc: remove until/unless we know how to correctly implement it
   // Next textfield up, "Max matches in a query range" which is also expected
   // to be a positive number.
   if (!is_numeric($form_state['values']['qRange'])) {
     form_set_error('qRange', 'The "Max matches in a query range" should be a positive integer.');
   }
+*/
 }
 
 /**
@@ -495,7 +506,7 @@ function blast_ui_blastp_advanced_options_form_submit($form, $form_state) {
   // Expand Gap Cost key into open and extend penalties
   $matrix = $form_state['values']['Matrix'];
   $gapKey = $form_state['values']['gapCost'];
-  $gap    = getGap($matrix, $gapKey);
+  $gap    = _set_protein_gap($matrix, $gapKey);
 
 //eksc- need to implement query range limit
 //  q_range
@@ -701,7 +712,7 @@ function blast_ui_tblastn_advanced_options_form(&$form, $form_state) {
     '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml#expect" target="_blank">More Information</a> | <a href="https://www.youtube.com/watch?v=nO0wJgZRZJs" target="_blank">Expect value vedio tutorial</a>'),
   );
 
-/*eksc- need to learn how this is implemented for tblastn
+/*eksc: need to learn how this is implemented for tblastn
   $form['ALG']['GParam']['shortQueries'] = array(
     '#type' => 'checkbox',
     '#title' => t('Automatically adjust parameters for short input sequences'),
@@ -749,6 +760,8 @@ function blast_ui_tblastn_advanced_options_form(&$form, $form_state) {
     '#description' => t('Cost to create and extend a gap in an alignment.'),
   );
 
+/*eksc: remove this as it is either the same as max_target_seqs, or miss-implemented
+       as culling_limit, which is something else entirely
   $form['ALG']['GParam']['qRange'] = array(
     '#type' => 'textfield',
     '#title' => t('Max matches in a query range'),
@@ -757,6 +770,7 @@ function blast_ui_tblastn_advanced_options_form(&$form, $form_state) {
     '#maxlength' => 20,
     '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
   );
+*/
 }
 
 /**
@@ -775,11 +789,13 @@ function blast_ui_tblastn_advanced_options_form_validate($form, $form_state) {
     form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
   }
 
+/*eksc: remove until/unless we know how to correctly implement it
   // Next textfield up, "Max matches in a query range" which is also expected
   // to be a positive number.
   if (!is_numeric($form_state['values']['qRange'])) {
     form_set_error('qRange', 'The "Max matches in a query range" should be a positive integer.');
   }
+*/
 }
 
 /**
@@ -800,7 +816,7 @@ function blast_ui_tblastn_advanced_options_form_submit($form, $form_state) {
 function _get_default_values($options) {
   // restore previous values or set to default
   $max_target = (isset($options['max_target_seqs']))
-            ? $options['max_target_seqs'] : 0;
+            ? $options['max_target_seqs'] : 500;
   $short_queries = (isset($options['shortQueries']))
             ? $options['shortQueries'] : true;
   $evalue = (isset($options['evalue']))
@@ -808,7 +824,7 @@ function _get_default_values($options) {
   $word_size = (isset($options['word_size']))
             ? $options['word_size'] : 11;
   $qRange = (isset($options['culling_limit']))
-            ? $options['culling_limit'] : variable_get('qRange',0);
+            ? $options['culling_limit'] : variable_get('qRange', 0);
 
   $matchmiss = 0;
   $reward = (isset($options['reward']))
@@ -946,356 +962,446 @@ function _get_match_mismatch($which) {
   }//switch
 }
 
+/**
+ * Get a list of options for gaps.
+ */
+function _get_gap_options($which) {
+  switch ($which) {
+    case 'blastn':
+      return array(
+        0 => t('Existence: 5 Extension: 2'),
+        1 => t('Existence: 2 Extension: 2'),
+        2 => t('Existence: 1 Extension: 2'),
+        3 => t('Existence: 0 Extension: 2'),
+        4 => t('Existence: 3 Extension: 1'),
+        5 => t('Existence: 2 Extension: 1'),
+        6 => t('Existence: 1 Extension: 1'),
+      );
+   }//switch
+}
+
+/**
+ * Translate above gap options into blast gap open and extend costs.
+ */
+function _set_gap($gap_key) {
+ switch ($gap_key) {
+   case 0:
+      $gapOpen = 5;
+      $gapExtend = 2;
+      break;
+   case 1:
+      $gapOpen = 2;
+      $gapExtend = 2;
+      break;
+   case 2:
+      $gapOpen = 1;
+      $gapExtend = 2;
+      break;
+   case 3:
+      $gapOpen = 0;
+      $gapExtend = 2;
+      break;
+   case 4:
+      $gapOpen = 3;
+      $gapExtend = 1;
+      break;
+   case 5:
+      $gapOpen = 2;
+      $gapExtend = 1;
+      break;
+   case 6:
+      $gapOpen = 1;
+      $gapExtend = 1;
+      break;
+  }//switch
+
+  return array('gapOpen' => $gapOpen, 'gapExtend' => $gapExtend);
+}
+
+/**
+ * Translate mismatch/match ratio option into blast penalty/reward options.
+ */
+function _set_match_mismatch($m_m) {
+  switch ($m_m) {
+   case 0:
+      $penalty = -2;
+      $reward = 1;
+      break;
+   case 1:
+      $penalty = -3;
+      $reward = 1;
+      break;
+   case 2:
+      $penalty = -4;
+      $reward = 1;
+      break;
+   case 3:
+      $penalty = -3;
+      $reward = 2;
+      break;
+   case 4:
+      $penalty = -5;
+      $reward = 4;
+      break;
+   case 5:
+      $penalty = -1;
+      $reward = 1;
+      break;
+  }//switch
+
+  return array('penalty' => $penalty, 'reward' => $reward);
+}
+
+
 /** 
  * Get gap values based on matrix and selected gap "key"
  */
-function getGap($matrix, $gapkey) {
-   switch ($matrix) {
-      case 'PAM30':
-         switch ($gapKey) {
-            case 0:
-               $gapOpen   = 7;
-               $gapExtend = 2;
-               break;
-            case 1:
-               $gapOpen   = 6;
-               $gapExtend = 2;
-               break;
-            case 2:
-               $gapOpen   = 5;
-               $gapExtend = 2;
-               break;
-            case 3:
-               $gapOpen   = 10;
-               $gapExtend = 1;
-               break;
-            case 4:
-               $gapOpen   = 9;
-               $gapExtend = 1;
-               break;
-            case 5:
-               $gapOpen   = 8;
-               $gapExtend = 1;
-               break;
-         }
-         break;
-      case 'PAM70':
-         switch ($gapKey) {
-            case 0:
-               $gapOpen   = 8;
-               $gapExtend = 2;
-               break;
-            case 1:
-               $gapOpen   = 7;
-               $gapExtend = 2;
-               break;
-            case 2:
-               $gapOpen   = 6;
-               $gapExtend = 2;
-               break;
-            case 3:
-               $gapOpen   = 11;
-               $gapExtend = 1;
-               break;
-            case 4:
-               $gapOpen   = 10;
-               $gapExtend = 1;
-               break;
-            case 5:
-               $gapOpen   = 9;
-               $gapExtend = 1;
-               break;
-         }
-         break;
-      case 'PAM250':
-         switch ($gapKey) {
-            case 0:
+function _set_protein_gap($matrix, $gapkey) {
+  switch ($matrix) {
+    case 'PAM30':
+      switch ($gapKey) {
+        case 0:
+             $gapOpen   = 7;
+             $gapExtend = 2;
+             break;
+        case 1:
+             $gapOpen   = 6;
+             $gapExtend = 2;
+             break;
+        case 2:
+             $gapOpen   = 5;
+             $gapExtend = 2;
+             break;
+        case 3:
+             $gapOpen   = 10;
+             $gapExtend = 1;
+             break;
+        case 4:
+             $gapOpen   = 9;
+             $gapExtend = 1;
+             break;
+        case 5:
+             $gapOpen   = 8;
+             $gapExtend = 1;
+             break;
+      }
+      break;
+    case 'PAM70':
+      switch ($gapKey) {
+        case 0:
+             $gapOpen   = 8;
+             $gapExtend = 2;
+             break;
+        case 1:
+             $gapOpen   = 7;
+             $gapExtend = 2;
+             break;
+        case 2:
+             $gapOpen   = 6;
+             $gapExtend = 2;
+             break;
+        case 3:
+             $gapOpen   = 11;
+             $gapExtend = 1;
+             break;
+        case 4:
+             $gapOpen   = 10;
+             $gapExtend = 1;
+             break;
+        case 5:
+             $gapOpen   = 9;
+             $gapExtend = 1;
+             break;
+      }
+      break;
+    case 'PAM250':
+       switch ($gapKey) {
+          case 0:
                $gapOpen   = 15;
                $gapExtend = 3;
                break;
-            case 1:
+          case 1:
                $gapOpen   = 14;
                $gapExtend = 3;
                break;
-            case 2:
+          case 2:
                $gapOpen   = 13;
                $gapExtend = 3;
                break;
-            case 3:
+          case 3:
                $gapOpen   = 12;
                $gapExtend = 3;
                break;
-            case 4:
+          case 4:
                $gapOpen   = 11;
                $gapExtend = 3;
                break;
-            case 5:
+          case 5:
                $gapOpen   = 17;
                $gapExtend = 2;
                break;
-            case 6:
+          case 6:
                $gapOpen   = 16;
                $gapExtend = 2;
                break;
-            case 7:
+          case 7:
                $gapOpen   = 15;
                $gapExtend = 2;
                break;
-            case 8:
+          case 8:
                $gapOpen   = 14;
                $gapExtend = 2;
                break;
-            case 9:
+          case 9:
                $gapOpen   = 13;
                $gapExtend = 2;
                break;
-            case 10:
+          case 10:
                $gapOpen   = 21;
                $gapExtend = 1;
                break;
-            case 11:
+          case 11:
                $gapOpen   = 20;
                $gapExtend = 1;
                break;
-            case 12:
+          case 12:
                $gapOpen   = 19;
                $gapExtend = 1;
                break;
-            case 13:
+          case 13:
                $gapOpen   = 18;
                $gapExtend = 1;
                break;
-            case 14:
+          case 14:
                $gapOpen   = 17;
                $gapExtend = 1;
                break;
-         }
-         break;
-      case 'BLOSUM80':
-         switch ($gapKey) {
-            case 0:
+      }
+      break;
+    case 'BLOSUM80':
+       switch ($gapKey) {
+          case 0:
                $gapOpen   = 8;
                $gapExtend = 2;
                break;
-            case 1:
+          case 1:
                $gapOpen   = 7;
                $gapExtend = 2;
                break;
-            case 2:
+          case 2:
                $gapOpen   = 6;
                $gapExtend = 2;
                break;
-            case 3:
+          case 3:
                $gapOpen   = 11;
                $gapExtend = 1;
                break;
-            case 4:
+          case 4:
                $gapOpen   = 10;
                $gapExtend = 1;
                break;
-            case 5:
+          case 5:
                $gapOpen   = 9;
                $gapExtend = 1;
                break;
-         }
-         break;
-      case 'BLOSUM62':
-         switch ($gapKey) {
-            case 0:
+      }
+      break;
+    case 'BLOSUM62':
+       switch ($gapKey) {
+          case 0:
                $gapOpen   = 11;
                $gapExtend = 2;
                break;
-            case 1:
+          case 1:
                $gapOpen   = 10;
                $gapExtend = 2;
                break;
-            case 2:
+          case 2:
                $gapOpen   = 9;
                $gapExtend = 2;
                break;
-            case 3:
+          case 3:
                $gapOpen   = 8;
                $gapExtend = 2;
                break;
-            case 4:
+          case 4:
                $gapOpen   = 7;
                $gapExtend = 2;
                break;
-            case 5:
+          case 5:
                $gapOpen   = 6;
                $gapExtend = 2;
                break;
-            case 6:
+          case 6:
                $gapOpen   = 13;
                $gapExtend = 1;
                break;
-            case 7:
+          case 7:
                $gapOpen   = 12;
                $gapExtend = 1;
                break;
-            case 8:
+          case 8:
                $gapOpen   = 11;
                $gapExtend = 1;
                break;
-            case 9:
+          case 9:
                $gapOpen   = 10;
                $gapExtend = 1;
                break;
-            case 10:
+          case 10:
                $gapOpen   = 9;
                $gapExtend = 1;
                break;
-         }
-         break;
-      case 'BLOSUM45':
-         switch ($gapKey) {
-            case 0:
+      }
+      break;
+    case 'BLOSUM45':
+       switch ($gapKey) {
+          case 0:
                $gapOpen   = 13;
                $gapExtend = 3;
                break;
-            case 1:
+          case 1:
                $gapOpen   = 12;
                $gapExtend = 3;
                break;
-            case 2:
+          case 2:
                $gapOpen   = 11;
                $gapExtend = 3;
                break;
-            case 3:
+          case 3:
                $gapOpen   = 10;
                $gapExtend = 3;
                break;
-            case 4:
+          case 4:
                $gapOpen   = 15;
                $gapExtend = 2;
                break;
-            case 5:
+          case 5:
                $gapOpen   = 14;
                $gapExtend = 2;
                break;
-            case 6:
+          case 6:
                $gapOpen   = 13;
                $gapExtend = 2;
                break;
-            case 7:
+          case 7:
                $gapOpen   = 12;
                $gapExtend = 2;
                break;
-            case 8:
+          case 8:
                $gapOpen   = 19;
                $gapExtend = 1;
                break;
-            case 9:
+          case 9:
                $gapOpen   = 18;
                $gapExtend = 1;
                break;
-            case 10:
+          case 10:
                $gapOpen   = 17;
                $gapExtend = 1;
                break;
-            case 11:
+          case 11:
                $gapOpen   = 16;
                $gapExtend = 1;
                break;
-         }
-         break;
-      case 'BLOSUM50':
-         switch ($gapKey) {
-            case 0:
+      }
+      break;
+    case 'BLOSUM50':
+       switch ($gapKey) {
+          case 0:
                $gapOpen   = 13;
                $gapExtend = 3;
                break;
-            case 1:
+          case 1:
                $gapOpen   = 12;
                $gapExtend = 3;
                break;
-            case 2:
+          case 2:
                $gapOpen   = 11;
                $gapExtend = 3;
                break;
-            case 3:
+          case 3:
                $gapOpen   = 10;
                $gapExtend = 3;
                break;
-            case 4:
+          case 4:
                $gapOpen   = 9;
                $gapExtend = 3;
                break;
-            case 5:
+          case 5:
                $gapOpen   = 16;
                $gapExtend = 2;
                break;
-            case 6:
+          case 6:
                $gapOpen   = 15;
                $gapExtend = 2;
                break;
-            case 7:
+          case 7:
                $gapOpen   = 14;
                $gapExtend = 2;
                break;
-            case 8:
+          case 8:
                $gapOpen   = 13;
                $gapExtend = 2;
                break;
-            case 9:
+          case 9:
                $gapOpen   = 12;
                $gapExtend = 2;
                break;
-            case 10:
+          case 10:
                $gapOpen   = 19;
                $gapExtend = 1;
                break;
-            case 11:
+          case 11:
                $gapOpen   = 18;
                $gapExtend = 1;
                break;
-            case 12:
+          case 12:
                $gapOpen   = 17;
                $gapExtend = 1;
                break;
-            case 13:
+          case 13:
                $gapOpen   = 16;
                $gapExtend = 1;
                break;
-            case 14:
+          case 14:
                $gapOpen   = 15;
                $gapExtend = 1;
                break;
-         }
-         break;
-      case 'BLOSUM90':
-         switch ($gapKey) {
-            case 0:
+      }
+      break;
+    case 'BLOSUM90':
+       switch ($gapKey) {
+          case 0:
                $gapOpen   = 9;
                $gapExtend = 2;
                break;
-            case 1:
+          case 1:
                $gapOpen   = 8;
                $gapExtend = 2;
                break;
-            case 2:
+          case 2:
                $gapOpen   = 7;
                $gapExtend = 2;
                break;
-            case 3:
+          case 3:
                $gapOpen   = 6;
                $gapExtend = 2;
                break;
-            case 4:
+          case 4:
                $gapOpen   = 11;
                $gapExtend = 1;
                break;
-            case 5:
+          case 5:
                $gapOpen   = 10;
                $gapExtend = 1;
                break;
-            case 6:
+          case 6:
                $gapOpen   = 9;
                $gapExtend = 1;
                break;
-         }
-         break;
-         
+      }
+      break;
    }
    
    return array(
@@ -1305,92 +1411,3 @@ function getGap($matrix, $gapkey) {
  }
 
 
-/**
- * Get a list of options for gaps.
- */
-function _get_gap_options($which) {
-  switch ($which) {
-    case 'blastn':
-      return array(
-        0 => t('Existence: 5 Extension: 2'),
-        1 => t('Existence: 2 Extension: 2'),
-        2 => t('Existence: 1 Extension: 2'),
-        3 => t('Existence: 0 Extension: 2'),
-        4 => t('Existence: 3 Extension: 1'),
-        5 => t('Existence: 2 Extension: 1'),
-        6 => t('Existence: 1 Extension: 1'),
-      );
-   }//switch
-}
-
-/**
- * Translate above gap options into blast gap open and extend costs.
- */
-function _set_gap($gap_key) {
- switch ($gap_key) {
-   case 0:
-      $gapOpen = 5;
-      $gapExtend = 2;
-      break;
-   case 1:
-      $gapOpen = 2;
-      $gapExtend = 2;
-      break;
-   case 2:
-      $gapOpen = 1;
-      $gapExtend = 2;
-      break;
-   case 3:
-      $gapOpen = 0;
-      $gapExtend = 2;
-      break;
-   case 4:
-      $gapOpen = 3;
-      $gapExtend = 1;
-      break;
-   case 5:
-      $gapOpen = 2;
-      $gapExtend = 1;
-      break;
-   case 6:
-      $gapOpen = 1;
-      $gapExtend = 1;
-      break;
-  }//switch
-
-  return array('gapOpen' => $gapOpen, 'gapExtend' => $gapExtend);
-}
-
-/**
- * Translate mismatch/match ratio option into blast penalty/reward options.
- */
-function _set_match_mismatch($m_m) {
-  switch ($m_m) {
-   case 0:
-      $penalty = -2;
-      $reward = 1;
-      break;
-   case 1:
-      $penalty = -3;
-      $reward = 1;
-      break;
-   case 2:
-      $penalty = -4;
-      $reward = 1;
-      break;
-   case 3:
-      $penalty = -3;
-      $reward = 2;
-      break;
-   case 4:
-      $penalty = -5;
-      $reward = 4;
-      break;
-   case 5:
-      $penalty = -1;
-      $reward = 1;
-      break;
-  }//switch
-
-  return array('penalty' => $penalty, 'reward' => $reward);
-}

+ 0 - 658
includes/blast_ui.services.inc

@@ -1,658 +0,0 @@
-<?php
-/**
- * Implements hook_services_resources().
- * Hooks provided by Services for the definition of new services,
- */
-
-function blast_ui_services_resources()
- {
-   return array(
-       'blast' => array(
-          'retrieve' => array(
-             'help' => 'Retrieves a blastResult',
-            'callback' => 'getBlastData',
-            'access callback' => 'user_access',
-            'access arguments' => array(
-                'access content'
-            ),
-            'access arguments append' => FALSE,
-            'args' => array(
-                array(
-                   'name' => 'job_id',
-                  'type' => 'int',
-                  'description' => 'The information needed',
-                  'source' => array(
-                      'path' => '0'
-                  ),
-                  'optional' => FALSE
-               )
-            )
-         ),
-         'index' => array(
-             'help' => 'Retrieves a listing of blast_ui',
-            'callback' => '_blast_ui_index',
-            'access callback' => 'user_access',
-            'access arguments' => array(
-                'access content'
-            ),
-            'access arguments append' => FALSE,
-            'args' => array ()
-         ),
-
-         'actions' => array(
-             'getJobId' => array(
-                'help' => 'Retrieves a listing of database',
-               'callback' => '_blast_ui_getJobId',
-               'access callback' => 'user_access',
-               'access arguments' => array(
-                   'access content'
-               ),
-               'args' => array(
-                   array(
-                      'name' => 'data',
-                     'type' => 'array',
-                     'description' => 'Retrieve blast job id',
-                     'source' => 'data',
-                     'optional' => FALSE
-                  )
-               ),
-               'access arguments append' => FALSE
-            ),
-
-            'getDatabaseOptions' => array(
-                'help' => 'Retrieves a listing of database',
-               'callback' => '_blast_ui_getDatabaseOption',
-               'access callback' => 'user_access',
-               'access arguments' => array(
-                   'access content'
-               ),
-               'args' => array(
-                   array(
-                      'name' => 'data',
-                     'type' => 'array',
-                     'description' => 'The set database_type information',
-                     'source' => 'data',
-                     'optional' => FALSE
-                  )
-               ),
-               'access arguments append' => false
-            )
-         )
-      )
-   );
- }
-
-
-
-/**
- * Callback for retrieving blast services.
- *
- * @param int $id
- * @return object
- */
-function _blast_ui_retrieve( $id )
- {
-   return getBlastData( $id );
- }
-
-/**
- * Callback for Index blast services.
- * @return object
- */
-
-function _blast_ui_index()
- {
-   return array(
-
-       'query_type' => array(
-          '1' => 'nucleotide',
-         '2' => 'protein'
-      ),
-      'db_type' => array(
-          '1' => 'nucleotide',
-         '2' => 'protein'
-      ),
-      'blast_program' => array(
-          '1' => 'blastn',
-         '2' => 'blastx',
-         '3' => 'tblastn',
-         '4' => 'blastp'
-      )
-   );
- }
-
-/*
- **  Method returns Advanced options and Database Type
- **  @param Object $data
- **  web service url :  http://localhost:8080/restapi/blast/getDatabaseOptions.json
- */
-
-function _blast_ui_getDatabaseOption( $data )
- {
-
-   if ( !isset( $data[ query_type ] ) )
-    {
-      return services_error( 'Missing blast attribute $query_type [ set necleotide or protein in post request of query_type ]', 406 );
-    }
-   if ( !isset( $data[ db_type ] ) )
-    {
-      return services_error( 'Missing blast attribute $db_type [ set necleotide or protein in post request of db_type ]', 406 );
-    }
-   if ( !isset( $data[ blast_program ] ) )
-    {
-      return services_error( 'Missing blast attribute $blast_program [ set blastn, blastx, tblastn, blastp in post request of blast_program ]', 406 );
-    }
-
-   $query_type       = $data[ db_type ];
-   $db_type          = $data[ db_type ];
-   $blast_program    = $data[ blast_program ];
-   $options_database = get_blast_database_options( $db_type );
-
-   // Data Set send to user for selection of Blastn
-   if ( $blast_program == 'blastn' )
-    {
-      return array(
-          'Select_Database' => $options_database,
-         'Max_target_sequences' => _get_max_target( $blast_program ),
-         'Word_size' => _get_word_size( $blast_program ),
-         'Match_Mismatch_Scores' => _get_match_mismatch( $blast_program ),
-         'Gap_Costs' => _get_gap( $blast_program )
-      );
-    }
-   // Data Set send to user for selection of Blastx
-   elseif ( $blast_program == 'blastx' )
-    {
-      return array(
-          'Select_Database' => $options_database,
-         'Max_target_sequences' => _get_max_target( $blast_program ),
-         'Word_size' => _get_word_size( $blast_program ),
-         'Matrix_options' => _get_matrix_options()
-
-      );
-    }
-   //Data Set send to user for selection of tblastn
-   elseif ( $blast_program == 'tblastn' )
-    {
-      return array(
-          'Select_Database' => $options_database,
-         'Max_target_sequences' => _get_max_target( $blast_program ),
-         'Word_size' => _get_word_size( $blast_program ),
-         'Matrix_options' => _get_matrix_options(),
-         'Gap_Costs' => getGap_cost()
-      );
-    }
-   //Data Set send to user for selection of blastp
-   elseif ( $blast_program == 'blastp' )
-    {
-      return array(
-          'Select_Database' => $options_database,
-         'Max_target_sequences' => _get_max_target( $blast_program ),
-         'Word_size' => _get_word_size( $blast_program ),
-         'Matrix_options' => _get_matrix_options(),
-         'Gap_Costs' => getGap_cost()
-      );
-    }
- }
-
-/*
- ** validate the data
- */
-
-function blast_validation( $query_type, $db_type, $data )
- {
-   if ( $query_type == 'nucleotide' )
-    {
-      if ( $db_type == 'nucleotide' )
-       {
-
-         if ( !isset( $data[ Select_Database ] ) )
-          {
-            return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database you need to use]', 406 );
-          }
-         if ( !isset( $data[ Max_target_sequences ] ) )
-          {
-            return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Word_size ] ) )
-          {
-            return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Match_Mismatch_Scores ] ) )
-          {
-            return services_error( 'Missing blast attribute $Match_Mismatch_Scores [ query blast/getDatabaseOptions for options]', 406 );
-          }
-         if ( !isset( $data[ Gap_costs ] ) )
-          {
-            return services_error( 'Missing blast attribute $Gap_Costs [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( isset( $data[ seqQuery ] ) )
-          {
-            if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
-             {
-               return services_error( 'Please enter validate_fasta_sequence', 406 );
-             }
-          }
-         else
-          {
-            return services_error( 'Missing blast attribute data[seqQuery]', 406 );
-          }
-       }
-      else
-       {
-
-         if ( !isset( $data[ Select_Database ] ) )
-          {
-            return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database used by you]', 406 );
-          }
-         if ( !isset( $data[ Max_target_sequences ] ) )
-          {
-            return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Word_size ] ) )
-          {
-            return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Matrix_options ] ) )
-          {
-            return services_error( 'Missing blast attribute $Matrix_options [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( isset( $data[ seqQuery ] ) )
-          {
-            if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
-             {
-               return services_error( 'Please enter validate_fasta_sequence', 406 );
-             }
-          }
-         else
-          {
-            return services_error( 'Missing blast attribute data[seqQuery]', 406 );
-          }
-
-       }
-    }
-   else
-    {
-      if ( $db_type == 'nucleotide' )
-       {
-         if ( !isset( $data[ Select_Database ] ) )
-          {
-            return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database you need to use]', 406 );
-          }
-         if ( !isset( $data[ Max_target_sequences ] ) )
-          {
-            return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Word_size ] ) )
-          {
-            return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Matrix_options ] ) )
-          {
-            return services_error( 'Missing blast attribute $Matrix_options [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Gap_costs ] ) )
-          {
-            return services_error( 'Missing blast attribute [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-
-         if ( isset( $data[ seqQuery ] ) )
-          {
-            if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
-             {
-               return services_error( 'Please enter validate_fasta_sequence', 406 );
-             }
-          }
-         else
-          {
-            return services_error( 'Missing blast attribute data[seqQuery]', 406 );
-          }
-       }
-      else
-       {
-
-         //return $data;
-
-         if ( !isset( $data[ Select_Database ] ) )
-          {
-            return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database used by you]', 406 );
-          }
-         if ( !isset( $data[ Max_target_sequences ] ) )
-          {
-            return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Word_size ] ) )
-          {
-            return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( !isset( $data[ Matrix_options ] ) )
-          {
-            return services_error( 'Missing blast attribute $Matrix_options [ query blast/getDatabaseOptions for options ]', 406 );
-          }
-         if ( isset( $data[ seqQuery ] ) )
-          {
-            if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
-             {
-               return services_error( 'Please enter validate_fasta_sequence', 406 );
-             }
-          }
-         else
-          {
-            return services_error( 'Missing blast attribute data[seqQuery]', 406 );
-          }
-       }
-    }
- }
-
-/*
- ** Method call the blast_ui_getblastJobId by setting all the needed
- ** parameters
- ** web service url :  http://localhost:8080/restapi/blast/getJobId.json
- */
-
-
-function _blast_ui_getJobId( $data )
- {
-
-   $query_type;
-   $db_type;
-   // Setting the default value of qRange and eValue from blast_ui.admin
-   $eVal   = variable_get( 'eVal', '' );
-   $qRange = variable_get( 'qRange', '' );
-
-   /* check values in post query */
-
-   if ( !isset( $data[ query_type ] ) )
-    {
-      return services_error( 'Missing blast attribute $query_type [ set necleotide or protein in post request of query_type ]', 406 );
-    }
-   if ( !isset( $data[ db_type ] ) )
-    {
-      return services_error( 'Missing blast attribute $db_type [ set necleotide or protein in post request of db_type ]', 406 );
-    }
-
-   $query_type = $data[ query_type ];
-   $db_type    = $data[ db_type ];
-
-   // check the user input in $data
-   blast_validation( $query_type, $db_type, $data );
-
-
-   if ( isset( $data[ $eVal ] ) )
-    {
-      $eVal = $data[ $eVal ];
-    }
-   if ( isset( $data[ $culling_limit ] ) )
-    {
-      $qRange = $data[ $culling_limit ];
-    }
-
-   if ( $query_type == 'nucleotide' )
-    {
-      if ( $db_type == 'nucleotide' )
-       {
-         $blast_program    = 'blastn';
-         // code not working for wordvalue = 7 ?
-         $options_database = get_blast_database_options( $data[ db_type ] );
-         $Databasekey      = array_search( $data[ Select_Database ], $options_database );
-         $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
-
-       }
-      elseif ( $db_type == 'protein' )
-       {
-         $blast_program    = 'blastx';
-         // how to get gap cost - question
-         $options_database = get_blast_database_options( $data[ db_type ] );
-         $Databasekey      = array_search( $data[ Select_Database ], $options_database );
-         $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
-       }
-    }
-   elseif ( $query_type == 'protein' )
-    {
-      if ( $db_type == 'nucleotide' )
-       {
-         $blast_program    = 'tblastn';
-         $options_database = get_blast_database_options( $data[ db_type ] );
-         $Databasekey      = array_search( $data[ Select_Database ], $options_database );
-         $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
-
-       }
-      elseif ( $db_type == 'protein' )
-       {
-         $blast_program    = 'blastp';
-         $options_database = get_blast_database_options( $data[ db_type ] );
-         $Databasekey      = array_search( $data[ Select_Database ], $options_database );
-         $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
-       }
-    }
-
-
-   return blast_ui_getblastJobId( $data[ query_type ], $data[ db_type ], $data[ seqQuery ], $Databasekey, $advanced_options );
-
-
- }
-/*
- ** Define the advanced Options for Blast
- ** @return : advanced_options according to blast_program
- */
-function advanced_options( $blast_program, $eVal, $qRange, $data )
- {
-
-   if ( $blast_program == 'blastn' )
-    {
-      $wordvalue = intval( $data[ Word_size ] );
-      $numAlign  = intval( $data[ Max_target_sequences ] );
-
-      $Data_GapCost = _get_gap( $blast_program );
-      $gapkey       = array_search( $data[ Gap_Costs ], $Data_GapCost );
-
-      $gap                  = _set_gap( $gapkey );
-      $Data_Mismatch_Scores = _get_match_mismatch( $blast_program );
-
-      $Mismatch_Scores_key = array_search( $data[ Match_Mismatch_Scores ], $Data_Mismatch_Scores );
-      $m_m                 = _set_match_mismatch( $Mismatch_Scores_key );
-
-      return array(
-          'max_target_seqs' => $numAlign,
-         'evalue' => $eVal,
-         'word_size' => $wordvalue,
-         'gapopen' => $gap[ 'gapOpen' ],
-         'gapextend' => $gap[ 'gapExtend' ],
-         'penalty' => $m_m[ 'penalty' ],
-         'reward' => $m_m[ 'reward' ],
-         'culling_limit' => $qRange
-      );
-
-    }
-   elseif ( $blast_program == 'blastx' )
-    {
-      $wordSize = intval( $data[ Word_size ] );
-      $numAlign = intval( $data[ Max_target_sequences ] );
-      $matrix   = $data[ Matrix_options ];
-      $gap      = getGap( $matrix, 1 );
-
-      return array(
-          'max_target_seqs' => $numAlign,
-         'evalue' => $eVal,
-         'word_size' => $wordSize,
-         'gapopen' => $gap[ 'gapOpen' ],
-         'gapextend' => $gap[ 'gapExtend' ],
-         'culling_limit' => $qRange,
-         'matrix' => $matrix
-      );
-    }
-   elseif ( $blast_program == 'tblastn' )
-    {
-      $wordSize = intval( $data[ Word_size ] );
-      $numAlign = intval( $data[ Max_target_sequences ] );
-      $matrix   = $data[ Matrix_options ];
-      $gap      = getGap( $matrix, 1 );
-
-      return array(
-          'max_target_seqs' => $numAlign,
-         'evalue' => $eVal,
-         'word_size' => $wordSize,
-         'gapopen' => $gap[ 'gapOpen' ],
-         'gapextend' => $gap[ 'gapExtend' ],
-         'culling_limit' => $qRange,
-         'matrix' => $matrix
-      );
-    }
-   elseif ( $blast_program == 'blastp' )
-    {
-      $wordSize = intval( $data[ Word_size ] );
-      $numAlign = intval( $data[ Max_target_sequences ] );
-      $matrix   = $data[ Matrix_options ];
-      $gap      = getGap( $matrix, 1 );
-
-      return array(
-          'max_target_seqs' => $numAlign,
-         'evalue' => $eVal,
-         'word_size' => $wordSize,
-         'gapopen' => $gap[ 'gapOpen' ],
-         'gapextend' => $gap[ 'gapExtend' ],
-         'culling_limit' => $qRange,
-         'matrix' => $matrix
-      );
-    }
- }
-
-
-/*
- ** Call the core API of Triple
- ** @return :  Job_ID
- */
-
-function blast_ui_getblastJobId( $query_type, $db_type, $seqQuery, $Databasekey, $adv_options )
- {
-   if ( $query_type == 'nucleotide' )
-    {
-      if ( $db_type == 'nucleotide' )
-       {
-         $blast_program = 'blastn';
-       }
-      elseif ( $db_type == 'protein' )
-       {
-         $blast_program = 'blastx';
-       }
-    }
-   elseif ( $query_type == 'protein' )
-    {
-      if ( $db_type == 'nucleotide' )
-       {
-         $blast_program = 'tblastn';
-       }
-      elseif ( $db_type == 'protein' )
-       {
-         $blast_program = 'blastp';
-       }
-    }
-
-   $query = variable_get('file_temporary_path', file_directory_temp()) . '/' . date( 'YMd_His' ) . '_query.fasta';
-   file_put_contents( $query, $seqQuery );
-   $blastdb_node      = node_load( $Databasekey );
-   $blastdb_name      = $blastdb_node->db_name;
-   $blastdb_with_path = $blastdb_node->db_path;
-
-   // Now let each program process its own advanced options.
-
-
-   $advanced_options = $adv_options;
-   global $user;
-
-   $output_filestub = date( 'YMd_His' );
-   $job_args        = array(
-       'program' => $blast_program,
-      'query' => $query,
-      'database' => $blastdb_with_path,
-      'output_filename' => $output_filestub,
-      'options' => $advanced_options
-   );
-
-   $job_id = tripal_add_job( t( 'BLAST (@program): @query', array(
-       '@program' => $blast_program,
-      '@query' => $query
-   ) ), 'blast_job', 'run_BLAST_tripal_job', $job_args, $user->uid );
-
-   ob_start();
-   tripal_launch_job( 1, $job_id );
-   ob_end_clean();
-   return $job_id;
-   // return getBlastData($job_id);
- }
-
-
-
-
-
-
-
-function getBlaststatus( $job_id )
- {
-   /* $sql =  "SELECT status FROM tripal_jobs WHERE job_id = :job_id ";
-   $job_res = db_query($sql, array(':job_id' => $job_id))->fetchField();
-   return $job_res;  */
- }
-
-
-/*
- **Method returns file output data
- **  @param int $job_id
- **  web service url :  http://localhost:8080/restapi/blast/job_id
- */
-
-function getBlastData( $job_id )
- {
-   $result;
-   $sql     = "SELECT job_name FROM tripal_jobs WHERE job_id = :job_id ";
-   $job_res = db_query( $sql, array(
-       ':job_id' => $job_id
-   ) )->fetchField();
-
-   $file_path = str_replace( '_query.fasta', '.blast.asn', $job_res );
-
-
-   if ( stristr( $file_path, "tblastn" ) )
-    {
-      $file_path = str_replace( 'BLAST (tblastn): /', '/', $file_path );
-    }
-   elseif ( stristr( $file_path, "blastx" ) )
-    {
-      $file_path = str_replace( 'BLAST (blastx): /', '/', $file_path );
-    }
-   elseif ( stristr( $file_path, "blastn" ) )
-    {
-      $file_path = str_replace( 'BLAST (blastn): /', '/', $file_path );
-    }
-   elseif ( stristr( $file_path, "blastp" ) )
-    {
-      $file_path = str_replace( 'BLAST (blastp): /', '/', $file_path );
-    }
-
-
-   if ( file_exists( $file_path ) )
-    {
-      $result = file_get_contents( $file_path );
-    }
-   else
-    {
-      $result = "The file  $file_path does not exist";
-    }
-   return $result;
- }
-
-/*
- ** Used for tblastn
- */
-function getGap_cost()
- {
-   return array(
-       'PAM30' => _get_gap_for_matrix( 'PAM30' ),
-      'PAM70' => _get_gap_for_matrix( 'PAM70' ),
-      'PAM250' => _get_gap_for_matrix( 'PAM250' ),
-      'BLOSUM80' => _get_gap_for_matrix( 'BLOSUM80' ),
-      'BLOSUM62' => _get_gap_for_matrix( 'BLOSUM62' ),
-      'BLOSUM45' => _get_gap_for_matrix( 'BLOSUM45' ),
-      'BLOSUM50' => _get_gap_for_matrix( 'BLOSUM50' ),
-      'BLOSUM90' => _get_gap_for_matrix( 'BLOSUM90' )
-   );
- }