JAL-653 test and testdata for importing GFF3 file with ##fasta pragma
authorJim Procter <jprocter@issues.jalview.org>
Sat, 6 Jun 2015 16:57:53 +0000 (17:57 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sat, 6 Jun 2015 16:57:53 +0000 (17:57 +0100)
examples/testdata/simplegff3.gff [new file with mode: 0644]
test/jalview/io/Gff3tests.java

diff --git a/examples/testdata/simplegff3.gff b/examples/testdata/simplegff3.gff
new file mode 100644 (file)
index 0000000..2ac5421
--- /dev/null
@@ -0,0 +1,19 @@
+##gff-version 2
+##source-version exonerate:protein2genome:local 2.2.0
+##date 2015-01-16
+##type DNA
+#
+#
+# seqname source feature start end score strand frame attributes
+#
+seq1   exonerate:protein2genome:local  gene    8       11      3652    -       .       gene_id 0 ; sequence seq2 ; gene_orientation .
+seq1   exonerate:protein2genome:local  cds     9       11      .       -       .       
+seq1   exonerate:protein2genome:local  exon    9       11      .       -       .       insertions 3 ; deletions 6
+seq1   exonerate:protein2genome:local  similarity      8       11      3652    -       .       alignment_id 0 ; Query seq2 ; Align 11 1 3
+##FASTA
+>seq1
+ACTACGACACGACGACGACGACG
+>seq2
+CDEQEATGTQDAQEQAQC
+
+
index cbb7f24..8c4a40d 100644 (file)
@@ -1,7 +1,13 @@
 package jalview.io;
 
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceDummy;
+import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 
+import java.io.IOException;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -9,7 +15,8 @@ public class Gff3tests
 {
 
   private static String exonerateSeqs = "examples/testdata/exonerateseqs.fa",
-          exonerateOutput = "examples/testdata/exonerateoutput.gff";
+          exonerateOutput = "examples/testdata/exonerateoutput.gff",
+          simpleGff3file = "examples/testdata/simpleGff3.gff";
 
   @Test
   public void testExonerateImport()
@@ -31,6 +38,65 @@ public class Gff3tests
             0, af.getViewport().getAlignment().getDataset()
                     .getCodonFrames().size());
 
+  }
+
+  @Test
+  public void simpleGff3() throws IOException
+  {
+    AlignmentI dataset = new Alignment(new SequenceI[]
+    {});
+    FeaturesFile ffile = new FeaturesFile(simpleGff3file,
+            FormatAdapter.FILE);
+
+    boolean parseResult = ffile.parse(dataset, null, null, false, false);
+    Assert.assertTrue("return result should be true", parseResult);
+    checkDatasetfromSimpleGff3(dataset);
+  }
+
+  @Test
+  public void simpleGff3RelaxedIdMatching() throws IOException
+  {
+    AlignmentI dataset = new Alignment(new SequenceI[]
+    {});
+    FeaturesFile ffile = new FeaturesFile(simpleGff3file,
+            FormatAdapter.FILE);
+
+    boolean parseResult = ffile.parse(dataset, null, null, false, true);
+    Assert.assertTrue("return result (relaxedID matching) should be true",
+            parseResult);
+    checkDatasetfromSimpleGff3(dataset);
+  }
+
+  private void checkDatasetfromSimpleGff3(AlignmentI dataset)
+  {
+    Assert.assertEquals("no sequences extracted from GFF3 file", 2,
+            dataset.getHeight());
+
+    SequenceI seq1 = dataset.findName("seq1"), seq2 = dataset
+            .findName("seq2");
+    Assert.assertNotNull(seq1);
+    Assert.assertNotNull(seq2);
+    Assert.assertFalse(
+            "Failed to replace dummy seq1 with real sequence",
+            seq1 instanceof SequenceDummy
+                    && ((SequenceDummy) seq1).isDummy());
+    Assert.assertFalse(
+            "Failed to replace dummy seq2 with real sequence",
+            seq2 instanceof SequenceDummy
+                    && ((SequenceDummy) seq2).isDummy());
+    String placeholderseq = new SequenceDummy("foo").getSequenceAsString();
+    Assert.assertFalse("dummy replacement buggy for seq1",
+            placeholderseq.equals(seq1.getSequenceAsString()));
+    Assert.assertNotEquals("dummy replacement buggy for seq2",
+            placeholderseq.equals(seq2.getSequenceAsString()));
+    Assert.assertNotNull("No features added to seq1",
+            seq1.getSequenceFeatures());// != null);
+    Assert.assertEquals("Wrong number of features", 3,
+            seq1.getSequenceFeatures().length);
+    Assert.assertNull(seq2.getSequenceFeatures());
+    Assert.assertEquals("Wrong number of features", 0, seq2
+            .getSequenceFeatures() == null ? 0
+            : seq2.getSequenceFeatures().length);
 
   }
   // @Test