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 assertTrue("Expected at least one DNA protein association", af
63 .getViewport().getAlignment().getDataset().getCodonFrames()
68 @Test(groups = { "Functional" })
69 public void simpleGff3FileIdentify()
71 assertEquals("Didn't recognise file correctly.", IdentifyFile.GFF3File,
72 new IdentifyFile().Identify(simpleGff3file, FormatAdapter.FILE));
75 @Test(groups = { "Functional" })
76 public void simpleGff3FileClass() throws IOException
78 AlignmentI dataset = new Alignment(new SequenceI[] {});
79 FeaturesFile ffile = new FeaturesFile(simpleGff3file,
82 boolean parseResult = ffile.parse(dataset, null, null, false, false);
83 assertTrue("return result should be true", parseResult);
84 checkDatasetfromSimpleGff3(dataset);
87 @Test(groups = { "Functional" })
88 public void simpleGff3FileLoader() throws IOException
90 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
91 simpleGff3file, FormatAdapter.FILE);
93 "Didn't read the alignment into an alignframe from Gff3 File",
95 checkDatasetfromSimpleGff3(af.getViewport().getAlignment().getDataset());
98 @Test(groups = { "Functional" })
99 public void simpleGff3RelaxedIdMatching() throws IOException
101 AlignmentI dataset = new Alignment(new SequenceI[] {});
102 FeaturesFile ffile = new FeaturesFile(simpleGff3file,
105 boolean parseResult = ffile.parse(dataset, null, null, false, true);
106 assertTrue("return result (relaxedID matching) should be true",
108 checkDatasetfromSimpleGff3(dataset);
111 @Test(groups = { "Functional" })
112 public void readGff3File() throws IOException
114 Gff3File gff3reader = new Gff3File(simpleGff3file, FormatAdapter.FILE);
115 Alignment dataset = new Alignment(gff3reader.getSeqsAsArray());
116 gff3reader.addProperties(dataset);
117 checkDatasetfromSimpleGff3(dataset);
121 private void checkDatasetfromSimpleGff3(AlignmentI dataset)
123 assertEquals("no sequences extracted from GFF3 file", 2,
124 dataset.getHeight());
126 SequenceI seq1 = dataset.findName("seq1"), seq2 = dataset
131 "Failed to replace dummy seq1 with real sequence",
132 seq1 instanceof SequenceDummy
133 && ((SequenceDummy) seq1).isDummy());
135 "Failed to replace dummy seq2 with real sequence",
136 seq2 instanceof SequenceDummy
137 && ((SequenceDummy) seq2).isDummy());
138 String placeholderseq = new SequenceDummy("foo").getSequenceAsString();
139 assertFalse("dummy replacement buggy for seq1",
140 placeholderseq.equals(seq1.getSequenceAsString()));
141 assertFalse("dummy replacement buggy for seq2",
142 placeholderseq.equals(seq2.getSequenceAsString()));
143 assertNotNull("No features added to seq1", seq1.getSequenceFeatures());// !=
145 assertEquals("Wrong number of features", 3,
146 seq1.getSequenceFeatures().length);
147 assertNull(seq2.getSequenceFeatures());
149 "Wrong number of features",
151 seq2.getSequenceFeatures() == null ? 0 : seq2
152 .getSequenceFeatures().length);
154 "Expected at least one CDNA/Protein mapping for seq1",
155 dataset.getCodonFrame(seq1) != null
156 && dataset.getCodonFrame(seq1).size() > 0);
159 // @Test(groups ={ "Functional" })
160 // public final void testPrintGFFFormatSequenceIArrayMapOfStringObject()
162 // fail("Not yet implemented");
165 // @Test(groups ={ "Functional" })
166 // public final void testAlignFileBooleanStringString()
168 // fail("Not yet implemented");