Browse Source

Fixed a mix up of validation for ID which should have been for seqid. Removed validation for ID. Altered tests to properly work. Added new test for invalid character in seqid/landmark id

Risharde Ramnath 4 years ago
parent
commit
bba096323a

+ 5 - 0
tests/tripal_chado/data/gff_seqid_invalid_character.gff

@@ -0,0 +1,5 @@
+##gff-version 3
+Contig'0	FRAEX38873_v2	gene	16315	44054	.	+	.	ID=FRAEX38873_v2_000000010;Name=FRAEX38873_v2_000000010;biotype=protein_coding
+Contig0	FRAEX38873_v2	mRNA	16315	44054	.	+	.	ID=FRAEX38873_v2_000000010.1;Parent=FRAEX38873_v2_000000010;Name=FRAEX38873_v2_000000010.1;biotype=protein_coding;AED=0.05
+Contig0	FRAEX38873_v2	polypeptide	16315	44054	.	+	.	ID=FRAEX38873_v2_000000010.1.3_test_protein;Parent=FRAEX38873_v2_000000010.1
+Contig0	FRAEX38873_v2	gene	16315	44054	.	+	.	ID=FRAEX38873_v2_000000011;Name=FRAEX38873_v2_000000010;biotype=protein_coding

+ 63 - 26
tests/tripal_chado/loaders/GFF3ImporterTest.php

@@ -52,14 +52,14 @@ class GFF3ImporterTest extends TripalTestCase {
   }
 
   /**
-   * Run the GFF loader on gff_unescaped_ids.gff for testing.
-   *
-   * This tests whether the GFF loader detects invalid ID that contains  
-   * unescaped whitespaces. The GFF loader should throw an exception which this
-   * unit test detects.
+   * Run the GFF loader on gff_seqid_invalid_character.gff for testing.
+   * Seqids seem to also be called landmarks within GFF loader.
+   * This tests whether the GFF loader has any issues with characters like  
+   * single quotes.
    */  
-  public function testGFFImporterUnescapedWhitespaceID() {
-    $gff_file = ['file_local' => __DIR__ . '/../data/gff_unescaped_ids.gff'];
+  public function testGFFImporterSeqidWithInvalidCharacter() {
+    $gff_file = ['file_local' => 
+      __DIR__ . '/../data/gff_seqid_invalid_character.gff'];
     $analysis = factory('chado.analysis')->create();
     $organism = factory('chado.organism')->create();
     $run_args = [
@@ -81,26 +81,65 @@ class GFF3ImporterTest extends TripalTestCase {
       'alt_id_attr' => NULL,
     ];
 
+  
+    $this->loadLandmarks($analysis, $organism);
+    // This will produce an exception due to quote character in Seqid
     $hasException = false;
-    try {    
-      $this->loadLandmarks($analysis, $organism);
-      // This will produce an exception due to unescaped whitespace in ID
+    try {
       $this->runGFFLoader($run_args, $gff_file);
     }
-    catch(\Exception $ex) {
+    catch (\Exception $ex) {
       $hasException = true;
     }
 
-    // We expect an exception to happen so we are looking for a return of true
     $this->assertEquals($hasException, true);
+
+  }
+
+  /**
+   * Run the GFF loader on gff_unescaped_ids.gff for testing.
+   *
+   * This tests whether the GFF loader adds IDs that contain whitespaces. 
+   * The GFF loader should allow it
+   */  
+  public function testGFFImporterUnescapedWhitespaceID() {
+    $gff_file = ['file_local' => __DIR__ . '/../data/gff_unescaped_ids.gff'];
+    $analysis = factory('chado.analysis')->create();
+    $organism = factory('chado.organism')->create();
+    $run_args = [
+      'analysis_id' => $analysis->analysis_id,
+      'organism_id' => $organism->organism_id,
+      'use_transaction' => 1,
+      'add_only' => 0,
+      'update' => 1,
+      'create_organism' => 0,
+      'create_target' => 0,
+      // regexps for mRNA and protein.
+      're_mrna' => NULL,
+      're_protein' => NULL,
+      // optional
+      'target_organism_id' => NULL,
+      'target_type' => NULL,
+      'start_line' => NULL,
+      'landmark_type' => NULL,
+      'alt_id_attr' => NULL,
+    ];
+
+  
+    $this->loadLandmarks($analysis, $organism);
+    // This should go through just fine
+    $this->runGFFLoader($run_args, $gff_file);
+
+    $results = db_query("SELECT * FROM chado.feature WHERE uniquename = 
+      'FRAEX38873_v2_000000010 SPACED';");
+    $this->assertEquals($results->rowCount(), 1);
   }
 
   /**
    * Run the GFF loader on gff_rightarrow_ids.gff for testing.
    *
-   * This tests whether the GFF loader detects invalid ID that contains  
-   * beginning arrow >. The GFF loader should throw an exception which this
-   * unit detects.
+   * This tests whether the GFF loader fails if ID contains  
+   * arrow >. It should not fail.
    */  
   public function testGFFImporterRightArrowID() {
     $gff_file = ['file_local' => __DIR__ . '/../data/gff_rightarrow_id.gff'];
@@ -125,18 +164,16 @@ class GFF3ImporterTest extends TripalTestCase {
       'alt_id_attr' => NULL,
     ];
 
-    $hasException = false;
-    try {    
-      $this->loadLandmarks($analysis, $organism);
-      // This will produce an exception due to right arrow in ID
-      $this->runGFFLoader($run_args, $gff_file);
-    }
-    catch(\Exception $ex) {
-      $hasException = true;
-    }
+ 
+    $this->loadLandmarks($analysis, $organism);
+    // This will produce an exception due to right arrow in ID
+    $this->runGFFLoader($run_args, $gff_file);
 
-    // We expect an exception to happen so we are looking for a return of true
-    $this->assertEquals($hasException, true);
+    $results = db_query("SELECT * FROM chado.feature 
+      WHERE uniquename = '>FRAEX38873_v2_000000010';");
+
+    // We expect this record to get inserted.
+    $this->assertEquals($results->rowCount(), 1);
   }
 
 

+ 9 - 8
tripal_chado/includes/TripalImporter/GFF3Importer.inc

@@ -948,6 +948,15 @@ class GFF3Importer extends TripalImporter {
     $ret['start'] = $fmin;
     $ret['stop'] = $fmax;
 
+    // Landmark (seqid) validation checks based on GFF3 specifications 
+    preg_match('/[a-zA-Z0-9\.:\^\*\$@!\+_\?-\|]*/', $ret['landmark'], $matches);
+    if($matches[0] != $ret['landmark']) {
+      throw new Exception(t("Landmark/seqid !landmark contains invalid 
+        characters. Only characters included in this regular expression is 
+        allowed [a-zA-Z0-9.:^*$@!+_?-|]", 
+        ['!landmark' => $ret['landmark']]));
+    }
+
     // Check to make sure strand has a valid character
     if (preg_match('/[\+-\?\.]/',$ret['strand']) == false) {
       throw new Exception(t('Invalid strand detected on line !line, 
@@ -2783,14 +2792,6 @@ class GFF3Importer extends TripalImporter {
     else {
       $uniquename = $attrs['ID'][0];
 
-      // Run ID validation checks based on GFF3 specifications 
-      preg_match('/[a-zA-Z0-9\.:\^\*\$@!\+_\?-\|]*/', $uniquename, $matches);
-      if($matches[0] != $uniquename) {
-        throw new Exception(t("ID !uniquename contains invalid characters. Only 
-          characters included in this regular expression is allowed 
-          [a-zA-Z0-9.:^*$@!+_?-|]", ['!uniquename' => $uniquename]));
-      }
-
       $name = $attrs['Name'][0];
     }