Browse Source

This latest commit detects a bug using the testGFFImporterEscapedTagValueWithComma unit test

Risharde Ramnath 4 years ago
parent
commit
5260a06a06

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

@@ -0,0 +1,5 @@
+##gff-version 3
+Contig0	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_000000010%2C20;Name=FRAEX38873_v2_000000010%2C20;biotype=protein_coding

+ 43 - 0
tests/tripal_chado/loaders/GFF3ImporterTest.php

@@ -94,6 +94,49 @@ class GFF3ImporterTest extends TripalTestCase {
     $this->assertEquals($hasException, true);
   }
 
+  /**
+   * Run the GFF loader on gff_tagvalue_unescaped_character.gff for testing.
+   *
+   * This tests whether the GFF loader adds IDs that contain a comma. 
+   * The GFF loader should allow it
+   */  
+  public function testGFFImporterEscapedTagValueWithComma() {
+    $gff_file = ['file_local' => __DIR__ . '/../data/gff_tagvalue_encoded_character.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->runGFFLoader($run_args, $gff_file);
+
+    $results = db_query("SELECT * FROM chado.feature",array());
+
+    foreach ($results as $row) {
+      print_r($row);
+    }
+
+    //$this->assertEquals($hasException, true);
+  }
+
+
   /**
    * Run the GFF loader on gff_tagvalue_unescaped_character.gff for testing.
    *

+ 6 - 1
tripal_chado/includes/TripalImporter/GFF3Importer.inc

@@ -1035,6 +1035,12 @@ class GFF3Importer extends TripalImporter {
         );
       }
 
+      // Let us convert escaped characters back to original 
+      // Is this too general?\
+      $tag[0] = urldecode($tag[0]);
+      $tag[1] = urldecode($tag[1]);
+
+
       // Multiple values of an attribute are separated by commas
       $tag_name = $tag[0];
       if (!array_key_exists($tag_name, $tags)) {
@@ -2799,7 +2805,6 @@ class GFF3Importer extends TripalImporter {
     elseif (!array_key_exists('Name', $attrs)) {
       $uniquename = $attrs['ID'][0];
       $name = $attrs['ID'][0];
-
     }
     elseif (!array_key_exists('ID', $attrs)) {
       $uniquename = $attrs['Name'][0];