2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertNull;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.SequenceDummy;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.AlignFrame;
35 import java.io.IOException;
37 import org.testng.annotations.Test;
39 public class Gff3tests
42 private static String exonerateSeqs = "examples/testdata/exonerateseqs.fa",
43 exonerateOutput = "examples/testdata/exonerateoutput.gff",
44 simpleGff3file = "examples/testdata/simpleGff3.gff";
46 @Test(groups = { "Functional" })
47 public void testExonerateImport()
49 // exonerate does not tag sequences after features, so we have a more
50 // conventional annotation import test here
52 FileLoader loader = new FileLoader(false);
54 AlignFrame af = loader.LoadFileWaitTillLoaded(exonerateSeqs,
57 assertEquals("Unexpected number of DNA protein associations", 0, af
58 .getViewport().getAlignment().getCodonFrames().size());
60 af.loadJalviewDataFile(exonerateOutput, FormatAdapter.FILE, null, null);
62 assertNotEquals("Expected at least one DNA protein association",
63 0, af.getViewport().getAlignment().getDataset()
64 .getCodonFrames().size(),
69 @Test(groups = { "Functional" })
70 public void simpleGff3FileIdentify()
72 assertEquals("Didn't recognise file correctly.", IdentifyFile.GFF3File,
73 new IdentifyFile().Identify(simpleGff3file, FormatAdapter.FILE));
76 @Test(groups = { "Functional" })
77 public void simpleGff3FileClass() throws IOException
79 AlignmentI dataset = new Alignment(new SequenceI[] {});
80 FeaturesFile ffile = new FeaturesFile(simpleGff3file,
83 boolean parseResult = ffile.parse(dataset, null, null, false, false);
84 assertTrue("return result should be true", parseResult);
85 checkDatasetfromSimpleGff3(dataset);
88 @Test(groups = { "Functional" })
89 public void simpleGff3FileLoader() throws IOException
91 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
92 simpleGff3file, FormatAdapter.FILE);
94 "Didn't read the alignment into an alignframe from Gff3 File",
96 checkDatasetfromSimpleGff3(af.getViewport().getAlignment().getDataset());
99 @Test(groups = { "Functional" })
100 public void simpleGff3RelaxedIdMatching() throws IOException
102 AlignmentI dataset = new Alignment(new SequenceI[] {});
103 FeaturesFile ffile = new FeaturesFile(simpleGff3file,
106 boolean parseResult = ffile.parse(dataset, null, null, false, true);
107 assertTrue("return result (relaxedID matching) should be true",
109 checkDatasetfromSimpleGff3(dataset);
112 @Test(groups = { "Functional" })
113 public void readGff3File() throws IOException
115 Gff3File gff3reader = new Gff3File(simpleGff3file, FormatAdapter.FILE);
116 Alignment dataset = new Alignment(gff3reader.getSeqsAsArray());
117 gff3reader.addProperties(dataset);
118 checkDatasetfromSimpleGff3(dataset);
122 private void checkDatasetfromSimpleGff3(AlignmentI dataset)
124 assertEquals("no sequences extracted from GFF3 file", 2,
125 dataset.getHeight());
127 SequenceI seq1 = dataset.findName("seq1"), seq2 = dataset
132 "Failed to replace dummy seq1 with real sequence",
133 seq1 instanceof SequenceDummy
134 && ((SequenceDummy) seq1).isDummy());
136 "Failed to replace dummy seq2 with real sequence",
137 seq2 instanceof SequenceDummy
138 && ((SequenceDummy) seq2).isDummy(),
139 "Failed to replace dummy seq2 with real sequence");
140 String placeholderseq = new SequenceDummy("foo").getSequenceAsString();
141 assertFalse("dummy replacement buggy for seq1",
142 placeholderseq.equals(seq1.getSequenceAsString()));
143 assertFalse("dummy replacement buggy for seq2",
144 placeholderseq.equals(seq2.getSequenceAsString()));
145 assertNotNull("No features added to seq1", seq1.getSequenceFeatures());
146 assertEquals("Wrong number of features", 3,
147 seq1.getSequenceFeatures().length);
148 assertNull(seq2.getSequenceFeatures());
150 "Wrong number of features",
152 seq2.getSequenceFeatures() == null ? 0 : seq2
153 .getSequenceFeatures().length);
155 "Expected at least one CDNA/Protein mapping for seq1",
156 dataset.getCodonFrame(seq1) != null
157 && dataset.getCodonFrame(seq1).size() > 0,
158 "Expected at least one CDNA/Protein mapping for seq1");
161 // @Test(groups ={ "Functional" })
162 // public final void testPrintGFFFormatSequenceIArrayMapOfStringObject()
164 // fail("Not yet implemented");
167 // @Test(groups ={ "Functional" })
168 // public final void testAlignFileBooleanStringString()
170 // fail("Not yet implemented");