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 GffFileTest
42 private static String exonerateSeqs = "examples/testdata/exonerateseqs.fa",
43 exonerateOutput = "examples/testdata/exonerateoutput.gff",
44 simpleGffFile = "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", 0 != af
63 .getViewport().getAlignment().getDataset().getCodonFrames()
67 @Test(groups = { "Functional" })
68 public void simpleGff3FileIdentify()
70 assertEquals("Didn't recognise file correctly.",
71 IdentifyFile.FeaturesFile,
72 new IdentifyFile().identify(simpleGffFile, FormatAdapter.FILE));
75 @Test(groups = { "Functional" })
76 public void simpleGff3FileClass() throws IOException
78 AlignmentI dataset = new Alignment(new SequenceI[] {});
79 FeaturesFile ffile = new FeaturesFile(simpleGffFile,
82 boolean parseResult = ffile.parse(dataset, 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 simpleGffFile, FormatAdapter.FILE);
93 "Didn't read the alignment into an alignframe from Gff3 File",
95 // FIXME codon mappings are on the alignment but not on the dataset
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(simpleGffFile,
106 boolean parseResult = ffile.parse(dataset, 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 FeaturesFile gffreader = new FeaturesFile(true, simpleGffFile,
117 Alignment dataset = new Alignment(gffreader.getSeqsAsArray());
118 gffreader.addProperties(dataset);
119 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 String placeholderseq = new SequenceDummy("foo").getSequenceAsString();
140 assertFalse("dummy replacement buggy for seq1",
141 placeholderseq.equals(seq1.getSequenceAsString()));
142 assertFalse("dummy replacement buggy for seq2",
143 placeholderseq.equals(seq2.getSequenceAsString()));
144 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);