Browse Source

Merge pull request #976 from tripal/7.x-3.x_75

add regexp validation for FASTA importer and fix bugs
Bradford Condon 5 years ago
parent
commit
742a3c2951

+ 0 - 7
tripal/includes/TripalImporter.inc

@@ -69,13 +69,6 @@ class TripalImporter {
    */
   public static $button_text = 'Import File';
 
-  /**
-   * If the loader should provide a submit button using $button_text above.
-   * Set this to FALSE to exclude the default button. This is useful for
-   * multi-page forms which need to change the button text.
-   */
-  public static $use_button = TRUE;
-
   /**
    * Indicates the methods that the file uploader will support.
    */

+ 5 - 7
tripal/includes/tripal.importer.inc

@@ -111,13 +111,11 @@ function tripal_get_importer_form($form, &$form_state, $class) {
   // to change the order of their elements in reference to the default ones.
   $form = array_merge($form, $element_form);
 
-  if ($class::$use_button == TRUE) {
-    $form['button'] = [
-      '#type' => 'submit',
-      '#value' => t($class::$button_text),
-      '#weight' => 10,
-    ];
-  }
+  $form['button'] = [
+    '#type' => 'submit',
+    '#value' => t($class::$button_text),
+    '#weight' => 10,
+  ];
   return $form;
 }
 

+ 24 - 7
tripal_chado/includes/TripalImporter/FASTAImporter.inc

@@ -243,7 +243,7 @@ class FASTAImporter extends TripalImporter {
       '#description' => t('Enter the regular expression that will extract the unique
                          name needed to identify the existing sequence for which the
                          relationship type selected above will apply.  If no regular
-                         expression is provided, the parent unique name must be the 
+                         expression is provided, the parent unique name must be the
                          same as the loaded feature name.'),
       '#weight' => 6,
     ];
@@ -319,6 +319,20 @@ class FASTAImporter extends TripalImporter {
       form_set_error('db_id', t("Please select a database"));
     }
 
+    // Check to make sure the regexps are valid.
+    if ($re_name && @preg_match("/$re_name/", null) === false) {
+      form_set_error('re_name', t("please provide a valid regular expression for the feature name."));
+    }
+    if ($re_uname && @preg_match("/$re_uname/", null) === false) {
+      form_set_error('re_uname', t("please provide a valid regular expression for the feature unique name."));
+    }
+    if ($re_accession && @preg_match("/$re_accession/", null) === false) {
+      form_set_error('re_accession', t("please provide a valid regular expression for the external database accession."));
+    }
+    if ($re_subject && @preg_match("/$re_subject/", null) === false) {
+      form_set_error('re_subject', t("please provide a valid regular expression for the relationship parent."));
+    }
+
     // check to make sure the types exists
     $cvtermsql = "
       SELECT CVT.cvterm_id
@@ -498,7 +512,10 @@ class FASTAImporter extends TripalImporter {
     $num_seqs = 0;
     $prev_pos = 0;
     $set_start = FALSE;
+    $i = 0;
+
     while ($line = fgets($fh)) {
+      $i++;
       $num_read += strlen($line);
 
       // If we encounter a definition line then get the name, uniquename,
@@ -651,7 +668,7 @@ class FASTAImporter extends TripalImporter {
       ], $values);
       if (count($results) > 1) {
         $this->logMessage("Multiple features exist with the name '!name' of type '!type' for the organism.  skipping",
-          ['!name' => $name, '!type' => $type], TRIPAL_ERROR);
+          ['!name' => $name, '!type' => $cvterm->name], TRIPAL_ERROR);
         return 0;
       }
       if (count($results) == 1) {
@@ -670,7 +687,7 @@ class FASTAImporter extends TripalImporter {
       $results = chado_select_record('feature', ['feature_id'], $values);
       if (count($results) > 1) {
         $this->logMessage("Multiple features exist with the name '!name' of type '!type' for the organism.  skipping",
-          ['!name' => $name, '!type' => $type], TRIPAL_WARNING);
+          ['!name' => $name, '!type' => $cvterm->name], TRIPAL_WARNING);
         return 0;
       }
       if (count($results) == 1) {
@@ -711,7 +728,7 @@ class FASTAImporter extends TripalImporter {
       if (!$success) {
         $this->logMessage("Failed to insert feature '!name (!uname)'", [
           '!name' => $name,
-          '!uname' => $numane,
+          '!uname' => $uname,
         ], TRIPAL_ERROR);
         return 0;
       }
@@ -730,7 +747,7 @@ class FASTAImporter extends TripalImporter {
       else {
         $this->logMessage("Failed to retreive newly inserted feature '!name (!uname)'", [
           '!name' => $name,
-          '!uname' => $numane,
+          '!uname' => $uname,
         ], TRIPAL_ERRORR);
         return 0;
       }
@@ -772,7 +789,7 @@ class FASTAImporter extends TripalImporter {
               [
                 '!name' => $name,
                 '!uname' => $uname,
-                '!type' => $type,
+                '!type' => $cvterm->name,
               ], TRIPAL_ERROR);
             return 0;
           }
@@ -861,7 +878,7 @@ class FASTAImporter extends TripalImporter {
         }
         else {
           $this->logMessage("Failed to retreive newly inserted dbxref '!name (!uname)'",
-            ['!name' => $name, '!uname' => $numane], TRIPAL_ERROR);
+            ['!name' => $name, '!uname' => $uname], TRIPAL_ERROR);
           return 0;
         }
       }