package jalview.io;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceFeature;
import jalview.gui.AlignFrame;
+import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.GraduatedColor;
import java.awt.Color;
import java.io.File;
public class FeaturesFileTest
{
- static String TestFiles[][] = { { "Test example features import/export",
- "examples/uniref50.fa", "examples/exampleFeatures.txt" } };
-
@Test(groups = { "Functional" })
public void testParse() throws Exception
{
- testFeaturesFileIO("Features file test");
- }
-
- public static AlignmentI readAlignmentFile(File f) throws IOException
- {
- System.out.println("Reading file: " + f);
- String ff = f.getPath();
- FormatAdapter rf = new FormatAdapter();
-
- AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
- new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
-
- al.setDataset(null); // creates dataset sequences
- assertNotNull("Couldn't read supplied alignment data.", al);
- return al;
- }
-
- /**
- * Helper method for testing
- *
- * @param testname
- * @param f
- * alignment file
- * @param featFile
- * features file to load on to the alignment
- * @throws IOException
- */
- public static void testFeaturesFileIO(String testname) throws IOException
- {
File f = new File("examples/uniref50.fa");
AlignmentI al = readAlignmentFile(f);
AlignFrame af = new AlignFrame(al, 500, 500);
.getFeatureColours();
FeaturesFile featuresFile = new FeaturesFile(
"examples/exampleFeatures.txt", FormatAdapter.FILE);
- assertTrue("Test " + testname + "\nFailed to parse features file.",
+ assertTrue("Test " + "Features file test"
+ + "\nFailed to parse features file.",
featuresFile.parse(al.getDataset(), colours, true));
/*
assertEquals("netphos", sf.featureGroup);
assertEquals("PHOSPHORYLATION (T)", sf.type);
}
+
+ /**
+ * Test parsing a features file with a mix of Jalview and GFF formatted
+ * content
+ *
+ * @throws Exception
+ */
+ @Test(groups = { "Functional" })
+ public void testParse_mixedJalviewGff() throws Exception
+ {
+ File f = new File("examples/uniref50.fa");
+ AlignmentI al = readAlignmentFile(f);
+ AlignFrame af = new AlignFrame(al, 500, 500);
+ Map<String, Object> colours = af.getFeatureRenderer()
+ .getFeatureColours();
+ String gffData = "METAL\tcc9900\n" + "GFF\n"
+ + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n"
+ + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t2.0\t.\t.";
+ FeaturesFile featuresFile = new FeaturesFile(gffData,
+ FormatAdapter.PASTE);
+ assertTrue("Failed to parse features file",
+ featuresFile.parse(al.getDataset(), colours, true));
+
+ // 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));
+
+ // verify feature on FER_CAPAA
+ SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
+ .getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ SequenceFeature sf = sfs[0];
+ assertEquals("uniprot", sf.description);
+ assertEquals(44, sf.begin);
+ assertEquals(45, sf.end);
+ assertEquals("uniprot", sf.featureGroup);
+ assertEquals("METAL", sf.type);
+ assertEquals(4f, sf.getScore(), 0.001f);
+
+ // verify feature on FER1_SOLLC
+ sfs = al.getSequenceAt(2).getDatasetSequence().getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ sf = sfs[0];
+ assertEquals("uniprot", sf.description);
+ assertEquals(55, sf.begin);
+ assertEquals(130, sf.end);
+ assertEquals("uniprot", sf.featureGroup);
+ assertEquals("Pfam", sf.type);
+ assertEquals(2f, sf.getScore(), 0.001f);
+ }
+
+ public static AlignmentI readAlignmentFile(File f) throws IOException
+ {
+ System.out.println("Reading file: " + f);
+ String ff = f.getPath();
+ FormatAdapter rf = new FormatAdapter();
+
+ AlignmentI al = rf.readFile(ff, FormatAdapter.FILE,
+ new IdentifyFile().identify(ff, FormatAdapter.FILE));
+
+ al.setDataset(null); // creates dataset sequences
+ assertNotNull("Couldn't read supplied alignment data.", al);
+ return al;
+ }
+
+ /**
+ * 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
+ */
+ @Test(groups = { "Functional" })
+ public void testParse_pureGff() throws Exception
+ {
+ File f = new File("examples/uniref50.fa");
+ AlignmentI al = readAlignmentFile(f);
+ AlignFrame af = new AlignFrame(al, 500, 500);
+ Map<String, Object> colours = af.getFeatureRenderer()
+ .getFeatureColours();
+ String gffData = "##gff-version 2\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"
+ + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t3.0\t.\t.";
+ FeaturesFile featuresFile = new FeaturesFile(gffData,
+ FormatAdapter.PASTE);
+ assertTrue("Failed to parse features file",
+ featuresFile.parse(al.getDataset(), colours, true));
+
+ // verify feature on FER_CAPAA
+ SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
+ .getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ SequenceFeature sf = sfs[0];
+ // description parsed from Note attribute
+ assertEquals("Iron-sulfur (2Fe-2S); another note", 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"));
+
+ // verify feature on FER1_SOLLC1
+ sfs = al.getSequenceAt(2).getDatasetSequence().getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ sf = sfs[0];
+ assertEquals("uniprot", sf.description);
+ assertEquals(55, sf.begin);
+ assertEquals(130, sf.end);
+ assertEquals("uniprot", sf.featureGroup);
+ assertEquals("Pfam", sf.type);
+ assertEquals(3f, sf.getScore(), 0.001f);
+ }
+
+ /**
+ * Test parsing a features file with Jalview format features (but no colour
+ * descriptors or startgroup to give the hint not to parse as GFF)
+ *
+ * @throws Exception
+ */
+ @Test(groups = { "Functional" })
+ public void testParse_jalviewFeaturesOnly() throws Exception
+ {
+ File f = new File("examples/uniref50.fa");
+ AlignmentI al = readAlignmentFile(f);
+ AlignFrame af = new AlignFrame(al, 500, 500);
+ Map<String, Object> colours = af.getFeatureRenderer()
+ .getFeatureColours();
+
+ /*
+ * one feature on FER_CAPAA and one on sequence 3 (index 2) FER1_SOLLC
+ */
+ String featureData = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
+ + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n";
+ FeaturesFile featuresFile = new FeaturesFile(featureData,
+ FormatAdapter.PASTE);
+ assertTrue("Failed to parse features file",
+ featuresFile.parse(al.getDataset(), colours, true));
+
+ // verify FER_CAPAA feature
+ SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
+ .getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ SequenceFeature sf = sfs[0];
+ assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
+ assertEquals(39, sf.begin);
+ assertEquals(39, sf.end);
+ assertEquals("METAL", sf.type);
+
+ // verify FER1_SOLLC feature
+ sfs = al.getSequenceAt(2).getDatasetSequence().getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ sf = sfs[0];
+ assertEquals("Iron-phosphorus (2Fe-P)", sf.description);
+ assertEquals(86, sf.begin);
+ assertEquals(87, sf.end);
+ assertEquals("METALLIC", sf.type);
+ }
}