JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / io / gff / Gff3HelperTest.java
index 3b6930f..5660666 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.io.gff;
 
 import static org.testng.AssertJUnit.assertEquals;
@@ -13,16 +33,27 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.gui.JvOptionPane;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 public class Gff3HelperTest
 {
 
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   /**
    * Test processing one PASA GFF line giving a match from forward strand to
    * forward strand
@@ -63,11 +94,11 @@ public class Gff3HelperTest
     assertSame(newseqs.get(0), mapping.getAaSeqs()[0]);
     assertEquals(1, mapping.getdnaToProt().length);
     assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
-    assertArrayEquals(new int[] { 12923, 13060 }, mapping.getdnaToProt()[0]
-            .getFromRanges().get(0));
+    assertArrayEquals(new int[] { 12923, 13060 },
+            mapping.getdnaToProt()[0].getFromRanges().get(0));
     assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
-    assertArrayEquals(new int[] { 1, 138 }, mapping.getdnaToProt()[0]
-            .getToRanges().get(0));
+    assertArrayEquals(new int[] { 1, 138 },
+            mapping.getdnaToProt()[0].getToRanges().get(0));
   }
 
   /**
@@ -110,11 +141,11 @@ public class Gff3HelperTest
     assertSame(newseqs.get(0), mapping.getAaSeqs()[0]);
     assertEquals(1, mapping.getdnaToProt().length);
     assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
-    assertArrayEquals(new int[] { 12923, 13060 }, mapping.getdnaToProt()[0]
-            .getFromRanges().get(0));
+    assertArrayEquals(new int[] { 12923, 13060 },
+            mapping.getdnaToProt()[0].getFromRanges().get(0));
     assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
-    assertArrayEquals(new int[] { 138, 1 }, mapping.getdnaToProt()[0]
-            .getToRanges().get(0));
+    assertArrayEquals(new int[] { 138, 1 },
+            mapping.getdnaToProt()[0].getToRanges().get(0));
   }
 
   /**
@@ -192,14 +223,59 @@ public class Gff3HelperTest
     assertEquals(1, mapping.getdnaToProt().length);
     assertEquals(2, mapping.getdnaToProt()[0].getFromRanges().size());
     // the two spliced dna ranges are combined in one MapList
-    assertArrayEquals(new int[] { 12923, 13060 }, mapping.getdnaToProt()[0]
-            .getFromRanges().get(0));
-    assertArrayEquals(new int[] { 13411, 13550 }, mapping.getdnaToProt()[0]
-            .getFromRanges().get(1));
+    assertArrayEquals(new int[] { 12923, 13060 },
+            mapping.getdnaToProt()[0].getFromRanges().get(0));
+    assertArrayEquals(new int[] { 13411, 13550 },
+            mapping.getdnaToProt()[0].getFromRanges().get(1));
     assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
     // the two cdna ranges are merged into one contiguous region
-    assertArrayEquals(new int[] { 1, 278 }, mapping.getdnaToProt()[0]
-            .getToRanges().get(0));
+    assertArrayEquals(new int[] { 1, 278 },
+            mapping.getdnaToProt()[0].getToRanges().get(0));
   }
 
+  @Test(groups = "Functional")
+  public void testGetDescription()
+  {
+    Gff3Helper testee = new Gff3Helper();
+    SequenceFeature sf = new SequenceFeature("type", "desc", 10, 20, 3f,
+            "group");
+    Map<String, List<String>> attributes = new HashMap<String, List<String>>();
+    assertNull(testee.getDescription(sf, attributes));
+
+    // ID if any is a fall-back for description
+    sf.setValue("ID", "Patrick");
+    assertEquals("Patrick", testee.getDescription(sf, attributes));
+
+    // Target is set by Exonerate
+    sf.setValue("Target", "Destination Moon");
+    assertEquals("Destination", testee.getDescription(sf, attributes));
+
+    // Ensembl variant feature - extract "alleles" value
+    // may be sequence_variant or a sub-type in the sequence ontology
+    sf = new SequenceFeature("feature_variant", "desc", 10, 20, 3f,
+            "group");
+    List<String> atts = new ArrayList<String>();
+    atts.add("A");
+    atts.add("C");
+    atts.add("T");
+    attributes.put("alleles", atts);
+    assertEquals("A,C,T", testee.getDescription(sf, attributes));
+
+    // Ensembl transcript or exon feature - extract Name
+    List<String> atts2 = new ArrayList<String>();
+    atts2.add("ENSE00001871077");
+    attributes.put("Name", atts2);
+    sf = new SequenceFeature("transcript", "desc", 10, 20, 3f, "group");
+    assertEquals("ENSE00001871077", testee.getDescription(sf, attributes));
+    // transcript sub-type in SO
+    sf = new SequenceFeature("mRNA", "desc", 10, 20, 3f, "group");
+    assertEquals("ENSE00001871077", testee.getDescription(sf, attributes));
+    // special usage of feature by Ensembl
+    sf = new SequenceFeature("NMD_transcript_variant", "desc", 10, 20, 3f,
+            "group");
+    assertEquals("ENSE00001871077", testee.getDescription(sf, attributes));
+    // exon feature
+    sf = new SequenceFeature("exon", "desc", 10, 20, 3f, "group");
+    assertEquals("ENSE00001871077", testee.getDescription(sf, attributes));
+  }
 }