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[][] = { { "Test example features import/export",
42 "examples/uniref50.fa", "examples/exampleFeatures.txt" } };
44 @Test(groups = { "Functional" })
45 public void testParse() throws Exception
47 testFeaturesFileIO("Features file test");
50 public static AlignmentI readAlignmentFile(File f) throws IOException
52 System.out.println("Reading file: " + f);
53 String ff = f.getPath();
54 FormatAdapter rf = new FormatAdapter();
56 AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
57 new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
59 al.setDataset(null); // creates dataset sequences
60 assertNotNull("Couldn't read supplied alignment data.", al);
65 * Helper method for testing
71 * features file to load on to the alignment
74 public static void testFeaturesFileIO(String testname) throws IOException
76 File f = new File("examples/uniref50.fa");
77 AlignmentI al = readAlignmentFile(f);
78 AlignFrame af = new AlignFrame(al, 500, 500);
79 Map<String, Object> colours = af.getFeatureRenderer()
81 FeaturesFile featuresFile = new FeaturesFile(
82 "examples/exampleFeatures.txt", FormatAdapter.FILE);
83 assertTrue("Test " + testname + "\nFailed to parse features file.",
84 featuresFile.parse(al.getDataset(), colours, true));
87 * Refetch the colour map from the FeatureRenderer (to confirm it has been
88 * updated - JAL-1904), and verify (some) feature group colours
90 colours = af.getFeatureRenderer().getFeatureColours();
91 assertEquals("26 feature group colours not found", 26, colours.size());
92 assertEquals(colours.get("Cath"), new Color(0x93b1d1));
93 assertEquals(colours.get("ASX-MOTIF"), new Color(0x6addbb));
96 * verify (some) features on sequences
98 SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
99 .getSequenceFeatures(); // FER_CAPAA
100 assertEquals(7, sfs.length);
101 SequenceFeature sf = sfs[0];
102 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
103 assertEquals(39, sf.begin);
104 assertEquals(39, sf.end);
105 assertEquals("uniprot", sf.featureGroup);
106 assertEquals("METAL", sf.type);
108 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
109 assertEquals(44, sf.begin);
110 assertEquals(44, sf.end);
111 assertEquals("uniprot", sf.featureGroup);
112 assertEquals("METAL", sf.type);
114 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
115 assertEquals(47, sf.begin);
116 assertEquals(47, sf.end);
117 assertEquals("uniprot", sf.featureGroup);
118 assertEquals("METAL", sf.type);
120 assertEquals("Iron-sulfur (2Fe-2S)", sf.description);
121 assertEquals(77, sf.begin);
122 assertEquals(77, sf.end);
123 assertEquals("uniprot", sf.featureGroup);
124 assertEquals("METAL", sf.type);
126 assertEquals("Fer2 Status: True Positive Pfam 8_8%LINK%",
128 assertEquals("Pfam 8_8|http://pfam.sanger.ac.uk/family/PF00111",
129 sf.links.get(0).toString());
130 assertEquals(8, sf.begin);
131 assertEquals(83, sf.end);
132 assertEquals("uniprot", sf.featureGroup);
133 assertEquals("Pfam", sf.type);
135 assertEquals("Ferredoxin_fold Status: True Positive ", sf.description);
136 assertEquals(3, sf.begin);
137 assertEquals(93, sf.end);
138 assertEquals("uniprot", sf.featureGroup);
139 assertEquals("Cath", sf.type);
142 "High confidence server. Only hits with scores over 0.8 are reported. PHOSPHORYLATION (T) 89_8%LINK%",
145 "PHOSPHORYLATION (T) 89_8|http://www.cbs.dtu.dk/cgi-bin/proview/webface-link?seqid=P83527&service=NetPhos-2.0",
146 sf.links.get(0).toString());
147 assertEquals(89, sf.begin);
148 assertEquals(89, sf.end);
149 assertEquals("netphos", sf.featureGroup);
150 assertEquals("PHOSPHORYLATION (T)", sf.type);