JAL-1805 test envirionment separation
[jalview.git] / test / jalview / io / Gff3tests.java
1 package jalview.io;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertNotNull;
6 import static org.testng.AssertJUnit.assertNull;
7 import static org.testng.AssertJUnit.assertTrue;
8
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.SequenceDummy;
12 import jalview.datamodel.SequenceI;
13 import jalview.gui.AlignFrame;
14
15 import java.io.IOException;
16
17 import org.testng.annotations.Test;
18
19 public class Gff3tests
20 {
21
22   private static String exonerateSeqs = "examples/testdata/exonerateseqs.fa",
23           exonerateOutput = "examples/testdata/exonerateoutput.gff",
24           simpleGff3file = "examples/testdata/simpleGff3.gff";
25
26   @Test(groups ={ "Functional" })
27   public void testExonerateImport()
28   {
29     // exonerate does not tag sequences after features, so we have a more
30     // conventional annotation import test here
31
32     FileLoader loader = new FileLoader(false);
33
34     AlignFrame af = loader.LoadFileWaitTillLoaded(exonerateSeqs,
35             FormatAdapter.FILE);
36
37     assertEquals("Unexpected number of DNA protein associations", 0,
38             af.getViewport().getAlignment().getCodonFrames().size());
39
40     af.loadJalviewDataFile(exonerateOutput, FormatAdapter.FILE, null, null);
41
42     assertTrue("Expected at least one DNA protein association", af
43             .getViewport().getAlignment().getDataset().getCodonFrames()
44             .size() > 0);
45
46   }
47
48   @Test(groups ={ "Functional" })
49   public void simpleGff3FileIdentify()
50   {
51     assertEquals("Didn't recognise file correctly.",
52             IdentifyFile.GFF3File,
53             new IdentifyFile().Identify(simpleGff3file, FormatAdapter.FILE));
54   }
55
56   @Test(groups ={ "Functional" })
57   public void simpleGff3FileClass() throws IOException
58   {
59     AlignmentI dataset = new Alignment(new SequenceI[]
60     {});
61     FeaturesFile ffile = new FeaturesFile(simpleGff3file,
62             FormatAdapter.FILE);
63
64     boolean parseResult = ffile.parse(dataset, null, null, false, false);
65     assertTrue("return result should be true", parseResult);
66     checkDatasetfromSimpleGff3(dataset);
67   }
68
69   @Test(groups ={ "Functional" })
70   public void simpleGff3FileLoader() throws IOException
71   {
72     AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
73             simpleGff3file, FormatAdapter.FILE);
74     assertTrue(
75             "Didn't read the alignment into an alignframe from Gff3 File",
76             af != null);
77     checkDatasetfromSimpleGff3(af.getViewport().getAlignment().getDataset());
78   }
79
80   @Test(groups ={ "Functional" })
81   public void simpleGff3RelaxedIdMatching() throws IOException
82   {
83     AlignmentI dataset = new Alignment(new SequenceI[]
84     {});
85     FeaturesFile ffile = new FeaturesFile(simpleGff3file,
86             FormatAdapter.FILE);
87
88     boolean parseResult = ffile.parse(dataset, null, null, false, true);
89     assertTrue("return result (relaxedID matching) should be true",
90             parseResult);
91     checkDatasetfromSimpleGff3(dataset);
92   }
93
94   @Test(groups ={ "Functional" })
95   public void readGff3File() throws IOException
96   {
97     Gff3File gff3reader = new Gff3File(simpleGff3file, FormatAdapter.FILE);
98     Alignment dataset = new Alignment(gff3reader.getSeqsAsArray());
99     gff3reader.addProperties(dataset);
100     checkDatasetfromSimpleGff3(dataset);
101
102   }
103
104   private void checkDatasetfromSimpleGff3(AlignmentI dataset)
105   {
106     assertEquals("no sequences extracted from GFF3 file", 2,
107             dataset.getHeight());
108
109     SequenceI seq1 = dataset.findName("seq1"), seq2 = dataset
110             .findName("seq2");
111     assertNotNull(seq1);
112     assertNotNull(seq2);
113     assertFalse(
114             "Failed to replace dummy seq1 with real sequence",
115             seq1 instanceof SequenceDummy
116                     && ((SequenceDummy) seq1).isDummy());
117     assertFalse(
118             "Failed to replace dummy seq2 with real sequence",
119             seq2 instanceof SequenceDummy
120                     && ((SequenceDummy) seq2).isDummy());
121     String placeholderseq = new SequenceDummy("foo").getSequenceAsString();
122     assertFalse("dummy replacement buggy for seq1",
123             placeholderseq.equals(seq1.getSequenceAsString()));
124     assertFalse("dummy replacement buggy for seq2",
125             placeholderseq.equals(seq2.getSequenceAsString()));
126     assertNotNull("No features added to seq1",
127             seq1.getSequenceFeatures());// != null);
128     assertEquals("Wrong number of features", 3,
129             seq1.getSequenceFeatures().length);
130     assertNull(seq2.getSequenceFeatures());
131     assertEquals(
132             "Wrong number of features",
133             0,
134             seq2
135             .getSequenceFeatures() == null ? 0
136             : seq2.getSequenceFeatures().length);
137     assertTrue(
138             "Expected at least one CDNA/Protein mapping for seq1",
139             dataset.getCodonFrame(seq1) != null
140                     && dataset.getCodonFrame(seq1).size() > 0);
141
142   }
143   // @Test(groups ={ "Functional" })
144   // public final void testPrintGFFFormatSequenceIArrayMapOfStringObject()
145   // {
146   // fail("Not yet implemented");
147   // }
148   //
149   // @Test(groups ={ "Functional" })
150   // public final void testAlignFileBooleanStringString()
151   // {
152   // fail("Not yet implemented");
153   // }
154
155 }