From: gmungoc Date: Tue, 23 May 2017 13:50:28 +0000 (+0100) Subject: JAL-2490 test coverage for printGffFormat before refactoring X-Git-Tag: Release_2_10_3b1~244 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c05b2da460c1e6ba38e2c0a0d3e8399e0b847d60;p=jalview.git JAL-2490 test coverage for printGffFormat before refactoring --- diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index 70a5f16..6429e16 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -39,6 +39,7 @@ import jalview.gui.JvOptionPane; import java.awt.Color; import java.io.File; import java.io.IOException; +import java.util.HashMap; import java.util.Map; import org.testng.annotations.BeforeClass; @@ -469,4 +470,85 @@ public class FeaturesFileTest + "ENDGROUP\tuniprot\n"; assertEquals(expected, exported); } + + @Test(groups = { "Functional" }) + public void testPrintGffFormat() throws Exception + { + File f = new File("examples/uniref50.fa"); + AlignmentI al = readAlignmentFile(f); + AlignFrame af = new AlignFrame(al, 500, 500); + + /* + * no features + */ + FeaturesFile featuresFile = new FeaturesFile(); + FeatureRenderer fr = af.alignPanel.getFeatureRenderer(); + Map visible = new HashMap(); + String exported = featuresFile.printGffFormat( + al.getSequencesArray(), visible, false); + String gffHeader = "##gff-version 2\n"; + assertEquals(gffHeader, exported); + exported = featuresFile.printGffFormat(al.getSequencesArray(), visible, + true); + assertEquals(gffHeader, exported); + + /* + * add some features + */ + al.getSequenceAt(0).addSequenceFeature( + new SequenceFeature("Domain", "Cath", 0, 0, 0f, "Uniprot")); + al.getSequenceAt(0).addSequenceFeature( + new SequenceFeature("METAL", "Cath", 39, 39, 1.2f, null)); + al.getSequenceAt(1) + .addSequenceFeature( + new SequenceFeature("GAMMA-TURN", "Turn", 36, 38, 2.1f, + "s3dm")); + SequenceFeature sf = new SequenceFeature("Pfam", "", 20, 20, 0f, "Uniprot"); + sf.setAttributes("x=y;black=white"); + sf.setStrand("+"); + sf.setPhase("2"); + al.getSequenceAt(1).addSequenceFeature(sf); + + /* + * with no features displayed, exclude non-positional features + */ + exported = featuresFile.printGffFormat(al.getSequencesArray(), visible, + false); + assertEquals(gffHeader, exported); + + /* + * include non-positional features + */ + exported = featuresFile.printGffFormat(al.getSequencesArray(), + visible, true); + String expected = gffHeader + + "FER_CAPAA\tUniprot\tDomain\t0\t0\t0.0\t.\t.\n"; + assertEquals(expected, exported); + + /* + * set METAL (in uniprot group) and GAMMA-TURN visible, but not Pfam + */ + fr.setVisible("METAL"); + fr.setVisible("GAMMA-TURN"); + visible = fr.getDisplayedFeatureCols(); + exported = featuresFile.printGffFormat(al.getSequencesArray(), + visible, 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"; + assertEquals(expected, exported); + + /* + * now set Pfam visible + */ + fr.setVisible("Pfam"); + visible = fr.getDisplayedFeatureCols(); + exported = featuresFile.printGffFormat(al.getSequencesArray(), + visible, 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"; + assertEquals(expected, exported); + } }