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.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.gui.AlignFrame;
31 import java.awt.Color;
33 import java.io.IOException;
36 import org.testng.annotations.Test;
38 public class FeaturesFileTest
41 static String TestFiles[][] = {
42 { "Test example features import/export",
43 "examples/uniref50.fa", "examples/exampleFeatures.txt" } };
45 @Test(groups = { "Functional" })
46 public void testParse() throws Exception
48 testFeaturesFileIO("Features file test");
51 public static AlignmentI readAlignmentFile(File f) throws IOException
53 System.out.println("Reading file: " + f);
54 String ff = f.getPath();
55 FormatAdapter rf = new FormatAdapter();
57 AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
58 new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
60 al.setDataset(null); // creates dataset sequences
61 assertNotNull("Couldn't read supplied alignment data.", al);
66 * Helper method for testing
72 * features file to load on to the alignment
75 public static void testFeaturesFileIO(String testname) throws IOException
77 File f = new File("examples/uniref50.fa");
78 AlignmentI al = readAlignmentFile(f);
79 AlignFrame af = new AlignFrame(al, 500, 500);
80 Map<String, Object> colours = af.getFeatureRenderer()
82 FeaturesFile featuresFile = new FeaturesFile(
83 "examples/exampleFeatures.txt", FormatAdapter.FILE);
84 assertTrue("Test " + testname + "\nFailed to parse features file.",
85 featuresFile.parse(al.getDataset(), colours, true));
88 * Refetch the colour map from the FeatureRenderer (to confirm it has been
89 * updated - JAL-1904), and verify (some) feature group colours
91 colours = af.getFeatureRenderer().getFeatureColours();
92 assertEquals("26 feature group colours not found", 26, colours.size());
93 assertEquals(colours.get("Cath"), new Color(0x93b1d1));
94 assertEquals(colours.get("ASX-MOTIF"), new Color(0x6addbb));
97 * verify (some) features on sequences
99 SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
100 .getSequenceFeatures(); // FER_CAPAA
101 assertEquals(7, sfs.length);
102 SequenceFeature sf = sfs[0];
103 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
104 assertEquals(39, sf.begin);
105 assertEquals(39, sf.end);
106 assertEquals("uniprot", sf.featureGroup);
107 assertEquals("METAL", sf.type);
109 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
110 assertEquals(44, sf.begin);
111 assertEquals(44, sf.end);
112 assertEquals("uniprot", sf.featureGroup);
113 assertEquals("METAL", sf.type);
115 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
116 assertEquals(47, sf.begin);
117 assertEquals(47, sf.end);
118 assertEquals("uniprot", sf.featureGroup);
119 assertEquals("METAL", sf.type);
121 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
122 assertEquals(77, sf.begin);
123 assertEquals(77, sf.end);
124 assertEquals("uniprot", sf.featureGroup);
125 assertEquals("METAL", sf.type);
127 assertEquals("Fer2 Status: True Positive Pfam 8_8%LINK%",
129 assertEquals("Pfam 8_8|http://pfam.sanger.ac.uk/family/PF00111",
130 sf.links.get(0).toString());
131 assertEquals(8, sf.begin);
132 assertEquals(83, sf.end);
133 assertEquals("uniprot", sf.featureGroup);
134 assertEquals("Pfam", sf.type);
136 assertEquals("Ferredoxin_fold Status: True Positive ", sf.description);
137 assertEquals(3, sf.begin);
138 assertEquals(93, sf.end);
139 assertEquals("uniprot", sf.featureGroup);
140 assertEquals("Cath", sf.type);
143 "High confidence server. Only hits with scores over 0.8 are reported. PHOSPHORYLATION (T) 89_8%LINK%",
146 "PHOSPHORYLATION (T) 89_8|http://www.cbs.dtu.dk/cgi-bin/proview/webface-link?seqid=P83527&service=NetPhos-2.0",
147 sf.links.get(0).toString());
148 assertEquals(89, sf.begin);
149 assertEquals(89, sf.end);
150 assertEquals("netphos", sf.featureGroup);
151 assertEquals("PHOSPHORYLATION (T)", sf.type);