JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / test / jalview / io / FeaturesFileTest.java
index 73d8826..602ce9f 100644 (file)
@@ -26,6 +26,7 @@ import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.api.FeatureColourI;
 import jalview.api.FeatureRenderer;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
@@ -33,8 +34,6 @@ import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
 
 import java.awt.Color;
 import java.io.File;
@@ -54,7 +53,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     FeaturesFile featuresFile = new FeaturesFile(
             "examples/exampleFeatures.txt", FormatAdapter.FILE);
@@ -68,61 +67,71 @@ public class FeaturesFileTest
      */
     colours = af.getFeatureRenderer().getFeatureColours();
     assertEquals("26 feature group colours not found", 26, colours.size());
-    assertEquals(colours.get("Cath"), new Color(0x93b1d1));
-    assertEquals(colours.get("ASX-MOTIF"), new Color(0x6addbb));
+    assertEquals(colours.get("Cath").getColour(), new Color(0x93b1d1));
+    assertEquals(colours.get("ASX-MOTIF").getColour(), new Color(0x6addbb));
 
     /*
      * verify (some) features on sequences
      */
     SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
             .getSequenceFeatures(); // FER_CAPAA
-    assertEquals(7, sfs.length);
+    assertEquals(8, sfs.length);
     SequenceFeature sf = sfs[0];
+    assertEquals("Pfam family%LINK%", sf.description);
+    assertEquals(0, sf.begin);
+    assertEquals(0, sf.end);
+    assertEquals("uniprot", sf.featureGroup);
+    assertEquals("Pfam", sf.type);
+    assertEquals(1, sf.links.size());
+    assertEquals("Pfam family|http://pfam.xfam.org/family/PF00111",
+            sf.links.get(0));
+
+    sf = sfs[1];
     assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
     assertEquals(39, sf.begin);
     assertEquals(39, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("METAL", sf.type);
-    sf = sfs[1];
+    sf = sfs[2];
     assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
     assertEquals(44, sf.begin);
     assertEquals(44, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("METAL", sf.type);
-    sf = sfs[2];
+    sf = sfs[3];
     assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
     assertEquals(47, sf.begin);
     assertEquals(47, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("METAL", sf.type);
-    sf = sfs[3];
+    sf = sfs[4];
     assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
     assertEquals(77, sf.begin);
     assertEquals(77, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("METAL", sf.type);
-    sf = sfs[4];
+    sf = sfs[5];
     assertEquals("Fer2 Status: True Positive Pfam 8_8%LINK%",
             sf.description);
     assertEquals("Pfam 8_8|http://pfam.xfam.org/family/PF00111",
-            sf.links.get(0).toString());
+            sf.links.get(0));
     assertEquals(8, sf.begin);
     assertEquals(83, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("Pfam", sf.type);
-    sf = sfs[5];
+    sf = sfs[6];
     assertEquals("Ferredoxin_fold Status: True Positive ", sf.description);
     assertEquals(3, sf.begin);
     assertEquals(93, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("Cath", sf.type);
-    sf = sfs[6];
+    sf = sfs[7];
     assertEquals(
             "High confidence server. Only hits with scores over 0.8 are reported. PHOSPHORYLATION (T) 89_8%LINK%",
             sf.description);
     assertEquals(
             "PHOSPHORYLATION (T) 89_8|http://www.cbs.dtu.dk/cgi-bin/proview/webface-link?seqid=P83527&amp;service=NetPhos-2.0",
-            sf.links.get(0).toString());
+            sf.links.get(0));
     assertEquals(89, sf.begin);
     assertEquals(89, sf.end);
     assertEquals("netphos", sf.featureGroup);
@@ -141,10 +150,11 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     // GFF2 uses space as name/value separator in column 9
-    String gffData = "METAL\tcc9900\n" + "GFF\n"
+    String gffData = "METAL\tcc9900\n"
+            + "GFF\n"
             + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\tNote Iron-sulfur; Note 2Fe-2S\n"
             + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t2.0\t.\t.";
     FeaturesFile featuresFile = new FeaturesFile(gffData,
@@ -155,7 +165,7 @@ public class FeaturesFileTest
     // verify colours read or synthesized
     colours = af.getFeatureRenderer().getFeatureColours();
     assertEquals("1 feature group colours not found", 1, colours.size());
-    assertEquals(colours.get("METAL"), new Color(0xcc9900));
+    assertEquals(colours.get("METAL").getColour(), new Color(0xcc9900));
 
     // verify feature on FER_CAPAA
     SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
@@ -196,45 +206,6 @@ public class FeaturesFileTest
   }
 
   /**
-   * Test various ways of describing a feature colour scheme
-   * 
-   * @throws Exception
-   */
-  @Test(groups = { "Functional" })
-  public void testParseGraduatedColourScheme() throws Exception
-  {
-    FeaturesFile ff = new FeaturesFile();
-
-    // colour by label:
-    GraduatedColor gc = ff.parseGraduatedColourScheme(
-            "BETA-TURN-IR\t9a6a94", "label");
-    assertTrue(gc.isColourByLabel());
-    assertEquals(Color.white, gc.getMinColor());
-    assertEquals(Color.black, gc.getMaxColor());
-    assertTrue(gc.isAutoScale());
-
-    // using colour name, rgb, etc:
-    String spec = "blue|255,0,255|absolute|20.0|95.0|below|66.0";
-    gc = ff.parseGraduatedColourScheme("BETA-TURN-IR\t" + spec, spec);
-    assertFalse(gc.isColourByLabel());
-    assertEquals(Color.blue, gc.getMinColor());
-    assertEquals(new Color(255, 0, 255), gc.getMaxColor());
-    assertFalse(gc.isAutoScale());
-    assertFalse(gc.getTolow());
-    assertEquals(20.0f, gc.getMin(), 0.001f);
-    assertEquals(95.0f, gc.getMax(), 0.001f);
-    assertEquals(AnnotationColourGradient.BELOW_THRESHOLD,
-            gc.getThreshType());
-    assertEquals(66.0f, gc.getThresh(), 0.001f);
-
-    // inverse gradient high to low:
-    spec = "blue|255,0,255|95.0|20.0|below|66.0";
-    gc = ff.parseGraduatedColourScheme("BETA-TURN-IR\t" + spec, spec);
-    assertTrue(gc.isAutoScale());
-    assertTrue(gc.getTolow());
-  }
-
-  /**
    * Test parsing a features file with GFF formatted content only
    * 
    * @throws Exception
@@ -245,7 +216,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     // GFF3 uses '=' separator for name/value pairs in colum 9
     String gffData = "##gff-version 3\n"
@@ -297,7 +268,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
 
     /*
@@ -334,7 +305,7 @@ public class FeaturesFileTest
   {
     assertEquals("no sequences extracted from GFF3 file", 2,
             dataset.getHeight());
-  
+
     SequenceI seq1 = dataset.findName("seq1");
     SequenceI seq2 = dataset.findName("seq2");
     assertNotNull(seq1);
@@ -365,7 +336,7 @@ public class FeaturesFileTest
             "Expected at least one CDNA/Protein mapping for seq1",
             dataset.getCodonFrame(seq1) != null
                     && dataset.getCodonFrame(seq1).size() > 0);
-  
+
   }
 
   @Test(groups = { "Functional" })
@@ -382,9 +353,8 @@ public class FeaturesFileTest
   public void simpleGff3FileClass() throws IOException
   {
     AlignmentI dataset = new Alignment(new SequenceI[] {});
-    FeaturesFile ffile = new FeaturesFile(simpleGffFile,
-            FormatAdapter.FILE);
-  
+    FeaturesFile ffile = new FeaturesFile(simpleGffFile, FormatAdapter.FILE);
+
     boolean parseResult = ffile.parse(dataset, null, false, false);
     assertTrue("return result should be true", parseResult);
     checkDatasetfromSimpleGff3(dataset);
@@ -405,9 +375,8 @@ public class FeaturesFileTest
   public void simpleGff3RelaxedIdMatching() throws IOException
   {
     AlignmentI dataset = new Alignment(new SequenceI[] {});
-    FeaturesFile ffile = new FeaturesFile(simpleGffFile,
-            FormatAdapter.FILE);
-  
+    FeaturesFile ffile = new FeaturesFile(simpleGffFile, FormatAdapter.FILE);
+
     boolean parseResult = ffile.parse(dataset, null, false, true);
     assertTrue("return result (relaxedID matching) should be true",
             parseResult);
@@ -420,7 +389,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     String features = "METAL\tcc9900\n"
             + "GAMMA-TURN\tred|0,255,255|20.0|95.0|below|66.0\n"
@@ -438,8 +407,7 @@ public class FeaturesFileTest
      * first with no features displayed
      */
     FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
-    Map<String, Object> visible = fr
-            .getDisplayedFeatureCols();
+    Map<String, FeatureColourI> visible = fr.getDisplayedFeatureCols();
     String exported = featuresFile.printJalviewFormat(
             al.getSequencesArray(), visible);
     String expected = "No Features Visible";