Merge branch 'documentation/JAL-3407_2.11.1_release' into releases/Release_2_11_1_Branch
[jalview.git] / test / jalview / io / FeaturesFileTest.java
index 3632cc7..b753e94 100644 (file)
@@ -27,6 +27,18 @@ import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
 
+import java.awt.Color;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
 import jalview.api.FeatureColourI;
 import jalview.api.FeatureRenderer;
 import jalview.datamodel.Alignment;
@@ -47,18 +59,7 @@ import jalview.structure.StructureSelectionManager;
 import jalview.util.matcher.Condition;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
-
-import java.awt.Color;
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import junit.extensions.PA;
 
 public class FeaturesFileTest
 {
@@ -268,10 +269,12 @@ public class FeaturesFileTest
     AlignFrame af = new AlignFrame(al, 500, 500);
     Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
-    // GFF3 uses '=' separator for name/value pairs in colum 9
+    // GFF3 uses '=' separator for name/value pairs in column 9
+    // comma (%2C) equals (%3D) or semi-colon (%3B) should be url-escaped in values
     String gffData = "##gff-version 3\n"
             + "FER_CAPAA\tuniprot\tMETAL\t39\t39\t0.0\t.\t.\t"
-            + "Note=Iron-sulfur (2Fe-2S);Note=another note;evidence=ECO:0000255|PROSITE-ProRule:PRU00465\n"
+            + "Note=Iron-sulfur (2Fe-2S);Note=another note,and another;evidence=ECO%3B0000255%2CPROSITE%3DProRule:PRU00465;"
+            + "CSQ=AF=21,POLYPHEN=benign,possibly_damaging,clin_sig=Benign%3Dgood\n"
             + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t3.0\t.\t.\tID=$23";
     FeaturesFile featuresFile = new FeaturesFile(gffData,
             DataSourceType.PASTE);
@@ -284,14 +287,25 @@ public class FeaturesFileTest
     assertEquals(1, sfs.size());
     SequenceFeature sf = sfs.get(0);
     // description parsed from Note attribute
-    assertEquals("Iron-sulfur (2Fe-2S),another note", sf.description);
+    assertEquals("Iron-sulfur (2Fe-2S),another note,and another",
+            sf.description);
     assertEquals(39, sf.begin);
     assertEquals(39, sf.end);
     assertEquals("uniprot", sf.featureGroup);
     assertEquals("METAL", sf.type);
-    assertEquals(
-            "Note=Iron-sulfur (2Fe-2S);Note=another note;evidence=ECO:0000255|PROSITE-ProRule:PRU00465",
-            sf.getValue("ATTRIBUTES"));
+    assertEquals(5, sf.otherDetails.size());
+    assertEquals("ECO;0000255,PROSITE=ProRule:PRU00465", // url decoded
+            sf.getValue("evidence"));
+    assertEquals("Iron-sulfur (2Fe-2S),another note,and another",
+            sf.getValue("Note"));
+    assertEquals("21", sf.getValueAsString("CSQ", "AF"));
+    assertEquals("benign,possibly_damaging",
+            sf.getValueAsString("CSQ", "POLYPHEN"));
+    assertEquals("Benign=good", sf.getValueAsString("CSQ", "clin_sig")); // url decoded
+    // todo change STRAND and !Phase into fields of SequenceFeature instead
+    assertEquals(".", sf.otherDetails.get("STRAND"));
+    assertEquals(0, sf.getStrand());
+    assertEquals(".", sf.getPhase());
 
     // verify feature on FER1_SOLLC1
     sfs = al.getSequenceAt(2).getDatasetSequence().getSequenceFeatures();
@@ -476,7 +490,7 @@ public class FeaturesFileTest
      */
     FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
     String exported = featuresFile
-            .printJalviewFormat(al.getSequencesArray(), fr, false);
+            .printJalviewFormat(al.getSequencesArray(), fr, false, false);
     String expected = "No Features Visible";
     assertEquals(expected, exported);
 
@@ -485,7 +499,7 @@ public class FeaturesFileTest
      */
     fr.setGroupVisibility("uniprot", true);
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            true);
+            true, false);
     expected = "\nSTARTGROUP\tuniprot\n"
             + "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
             + "ENDGROUP\tuniprot\n\n"
@@ -499,12 +513,12 @@ public class FeaturesFileTest
     fr.setVisible("METAL");
     fr.setVisible("GAMMA-TURN");
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     expected = "METAL\tcc9900\n"
             + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
             + "\nSTARTGROUP\tuniprot\n"
-            + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n"
+            + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "ENDGROUP\tuniprot\n";
     assertEquals(expected, exported);
 
@@ -513,7 +527,7 @@ public class FeaturesFileTest
      */
     fr.setVisible("Pfam");
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     /*
      * features are output within group, ordered by sequence and type
      */
@@ -521,9 +535,9 @@ public class FeaturesFileTest
             + "Pfam\tff0000\n"
             + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
             + "\nSTARTGROUP\tuniprot\n"
-            + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n"
             + "<html>Pfam domain<a href=\"http://pfam.xfam.org/family/PF00111\">Pfam_3_4</a></html>\tFER_CAPAA\t-1\t20\t20\tPfam\t0.0\n"
+            + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "ENDGROUP\tuniprot\n"
             // null / empty group features are output after named groups
             + "\ndesc2\tFER_CAPAN\t-1\t4\t9\tPfam\n"
@@ -539,14 +553,14 @@ public class FeaturesFileTest
             + "\ndesc2\tFER_CAPAN\t-1\t4\t9\tPfam\n"
             + "\ndesc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n";
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     assertEquals(expected, exported);
 
     /*
      * include non-positional (overrides group not shown)
      */
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            true);
+            true, false);
     expected = "METAL\tcc9900\n" + "Pfam\tff0000\n"
             + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
             + "\nSTARTGROUP\tuniprot\n"
@@ -573,11 +587,11 @@ public class FeaturesFileTest
     FeatureRendererModel fr = (FeatureRendererModel) af.alignPanel
             .getFeatureRenderer();
     String exported = featuresFile.printGffFormat(al.getSequencesArray(),
-            fr, false);
+            fr, false, false);
     String gffHeader = "##gff-version 2\n";
     assertEquals(gffHeader, exported);
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            true);
+            true, false);
     assertEquals(gffHeader, exported);
 
     /*
@@ -593,9 +607,14 @@ public class FeaturesFileTest
                             "s3dm"));
     SequenceFeature sf = new SequenceFeature("Pfam", "", 20, 20, 0f,
             "Uniprot");
-    sf.setAttributes("x=y;black=white");
     sf.setStrand("+");
     sf.setPhase("2");
+    sf.setValue("x", "y");
+    sf.setValue("black", "white");
+    Map<String, String> csq = new HashMap<>();
+    csq.put("SIFT", "benign,mostly benign,cloudy, with meatballs");
+    csq.put("consequence", "missense_variant");
+    sf.setValue("CSQ", csq);
     al.getSequenceAt(1).addSequenceFeature(sf);
 
     /*
@@ -614,7 +633,7 @@ public class FeaturesFileTest
      * with no features displayed, exclude non-positional features
      */
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     assertEquals(gffHeader, exported);
 
     /*
@@ -623,7 +642,7 @@ public class FeaturesFileTest
     fr.setGroupVisibility("Uniprot", true);
     fr.setGroupVisibility("s3dm", false);
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            true);
+            true, false);
     String expected = gffHeader
             + "FER_CAPAA\tUniprot\tDomain\t0\t0\t0.0\t.\t.\n";
     assertEquals(expected, exported);
@@ -635,7 +654,7 @@ public class FeaturesFileTest
     fr.setVisible("METAL");
     fr.setVisible("GAMMA-TURN");
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     // METAL feature has null group: description used for column 2
     expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n";
     assertEquals(expected, exported);
@@ -645,7 +664,7 @@ public class FeaturesFileTest
      */
     fr.setGroupVisibility("s3dm", true);
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     // METAL feature has null group: description used for column 2
     expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
             + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n";
@@ -656,12 +675,16 @@ public class FeaturesFileTest
      */
     fr.setVisible("Pfam");
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     // Pfam feature columns include strand(+), phase(2), attributes
     expected = gffHeader
             + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
-            + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n"
-            + "FER_CAPAN\tUniprot\tPfam\t20\t20\t0.0\t+\t2\tx=y;black=white\n";
+            // CSQ output as CSQ=att1=value1,att2=value2
+            // note all commas are encoded here which is wrong - it should be
+            // SIFT=benign,mostly benign,cloudy%2C with meatballs
+            + "FER_CAPAN\tUniprot\tPfam\t20\t20\t0.0\t+\t2\tx=y;black=white;"
+            + "CSQ=SIFT=benign%2Cmostly benign%2Ccloudy%2C with meatballs,consequence=missense_variant\n"
+            + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n";
     assertEquals(expected, exported);
   }
 
@@ -703,7 +726,7 @@ public class FeaturesFileTest
     assertTrue(matcher.isByScore());
     assertSame(matcher.getMatcher().getCondition(), Condition.LT);
     assertEquals(matcher.getMatcher().getPattern(), "1.3");
-    assertEquals(matcher.getMatcher().getFloatValue(), 1.3f);
+    assertEquals(PA.getValue(matcher.getMatcher(), "floatValue"), 1.3f);
 
     assertFalse(matchers.hasNext());
   }
@@ -770,23 +793,24 @@ public class FeaturesFileTest
     fr.setVisible("METAL");
     fr.setColour("METAL", new FeatureColour(Color.PINK));
     String exported = featuresFile.printGffFormat(al.getSequencesArray(),
-            fr, false);
+            fr, false, false);
     String expected = gffHeader
-            + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
-            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+            + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\tclin_sig=Likely Pathogenic;AF=24\n"
+            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\tclin_sig=Benign;AF=46\n";
     assertEquals(expected, exported);
 
     /*
      * now threshold to Score > 1.1 - should exclude sf2
      */
-    FeatureColourI fc = new FeatureColour(Color.white, Color.BLACK,
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.BLACK,
             Color.white, 0f, 2f);
     fc.setAboveThreshold(true);
     fc.setThreshold(1.1f);
     fr.setColour("METAL", fc);
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
-    expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n";
+            false, false);
+    expected = gffHeader
+            + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\tclin_sig=Likely Pathogenic;AF=24\n";
     assertEquals(expected, exported);
 
     /*
@@ -794,9 +818,10 @@ public class FeaturesFileTest
      */
     fc.setAboveThreshold(false);
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
-    expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
-            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+            false, false);
+    expected = gffHeader
+            + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\tclin_sig=Likely Pathogenic;AF=24\n"
+            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\tclin_sig=Benign;AF=46\n";
     assertEquals(expected, exported);
 
     /*
@@ -807,8 +832,9 @@ public class FeaturesFileTest
             "clin_sig"));
     fr.setFeatureFilter("METAL", filter);
     exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
-            false);
-    expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+            false, false);
+    expected = gffHeader
+            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\tclin_sig=Benign;AF=46\n";
     assertEquals(expected, exported);
   }
 
@@ -843,7 +869,7 @@ public class FeaturesFileTest
     fr.setColour("METAL", new FeatureColour(Color.PINK));
     String exported = featuresFile.printJalviewFormat(
             al.getSequencesArray(),
-            fr, false);
+            fr, false, false);
     String expected = "METAL\tffafaf\n\nSTARTGROUP\tgrp1\n"
             + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n"
             + "ENDGROUP\tgrp1\n\nSTARTGROUP\tgrp2\n"
@@ -855,13 +881,13 @@ public class FeaturesFileTest
      * now threshold to Score > 1.1 - should exclude sf2
      * (and there should be no empty STARTGROUP/ENDGROUP output)
      */
-    FeatureColourI fc = new FeatureColour(Color.white, Color.BLACK,
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.BLACK,
             Color.white, 0f, 2f);
     fc.setAboveThreshold(true);
     fc.setThreshold(1.1f);
     fr.setColour("METAL", fc);
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     expected = "METAL\tscore|ffffff|000000|noValueMin|abso|0.0|2.0|above|1.1\n\n"
             + "STARTGROUP\tgrp1\n"
             + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n"
@@ -873,7 +899,7 @@ public class FeaturesFileTest
      */
     fc.setAboveThreshold(false);
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     expected = "METAL\tscore|ffffff|000000|noValueMin|abso|0.0|2.0|none\n\n"
             + "STARTGROUP\tgrp1\n"
             + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n"
@@ -890,7 +916,7 @@ public class FeaturesFileTest
             "clin_sig"));
     fr.setFeatureFilter("METAL", filter);
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
-            false);
+            false, false);
     expected = "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
     expected = "METAL\tscore|ffffff|000000|noValueMin|abso|0.0|2.0|none\n\n"
             + "STARTFILTERS\nMETAL\tclin_sig Contains benign\nENDFILTERS\n\n"