/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.io; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; import jalview.api.FeatureColourI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceFeature; import jalview.gui.AlignFrame; import java.awt.Color; import java.io.File; import java.io.IOException; import java.util.Map; import org.testng.annotations.Test; public class FeaturesFileTest { static String TestFiles[][] = { { "Test example features import/export", "examples/uniref50.fa", "examples/exampleFeatures.txt" } }; @Test(groups = { "Functional" }) public void testParse() throws Exception { testFeaturesFileIO("Features file test"); } public static AlignmentI readAlignmentFile(File f) throws IOException { System.out.println("Reading file: " + f); String ff = f.getPath(); FormatAdapter rf = new FormatAdapter(); AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE, new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE)); al.setDataset(null); // creates dataset sequences assertNotNull("Couldn't read supplied alignment data.", al); return al; } /** * Helper method for testing * * @param testname * @param f * alignment file * @param featFile * features file to load on to the alignment * @throws IOException */ public static void testFeaturesFileIO(String testname) throws IOException { File f = new File("examples/uniref50.fa"); AlignmentI al = readAlignmentFile(f); AlignFrame af = new AlignFrame(al, 500, 500); Map colours = af.getFeatureRenderer() .getFeatureColours(); FeaturesFile featuresFile = new FeaturesFile( "examples/exampleFeatures.txt", FormatAdapter.FILE); assertTrue("Test " + testname + "\nFailed to parse features file.", featuresFile.parse(al.getDataset(), colours, true)); /* * Refetch the colour map from the FeatureRenderer (to confirm it has been * updated - JAL-1904), and verify (some) feature group colours */ colours = af.getFeatureRenderer().getFeatureColours(); assertEquals("26 feature group colours not found", 26, colours.size()); assertEquals(colours.get("Cath").getColour(), new Color(0x93b1d1)); assertEquals(colours.get("ASX-MOTIF").getColour(), new Color(0x6addbb)); /* * verify (some) features on sequences */ SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence() .getSequenceFeatures(); // FER_CAPAA assertEquals(7, sfs.length); SequenceFeature sf = sfs[0]; assertEquals("Iron-sulfur (2Fe-2S)", sf.description); assertEquals(39, sf.begin); assertEquals(39, sf.end); assertEquals("uniprot", sf.featureGroup); assertEquals("METAL", sf.type); sf = sfs[1]; assertEquals("Iron-sulfur (2Fe-2S)", sf.description); assertEquals(44, sf.begin); assertEquals(44, sf.end); assertEquals("uniprot", sf.featureGroup); assertEquals("METAL", sf.type); sf = sfs[2]; assertEquals("Iron-sulfur (2Fe-2S)", sf.description); assertEquals(47, sf.begin); assertEquals(47, sf.end); assertEquals("uniprot", sf.featureGroup); assertEquals("METAL", sf.type); sf = sfs[3]; assertEquals("Iron-sulfur (2Fe-2S)", sf.description); assertEquals(77, sf.begin); assertEquals(77, sf.end); assertEquals("uniprot", sf.featureGroup); assertEquals("METAL", sf.type); sf = sfs[4]; assertEquals("Fer2 Status: True Positive Pfam 8_8%LINK%", sf.description); assertEquals("Pfam 8_8|http://pfam.sanger.ac.uk/family/PF00111", sf.links.get(0).toString()); assertEquals(8, sf.begin); assertEquals(83, sf.end); assertEquals("uniprot", sf.featureGroup); assertEquals("Pfam", sf.type); sf = sfs[5]; assertEquals("Ferredoxin_fold Status: True Positive ", sf.description); assertEquals(3, sf.begin); assertEquals(93, sf.end); assertEquals("uniprot", sf.featureGroup); assertEquals("Cath", sf.type); sf = sfs[6]; assertEquals( "High confidence server. Only hits with scores over 0.8 are reported. PHOSPHORYLATION (T) 89_8%LINK%", sf.description); assertEquals( "PHOSPHORYLATION (T) 89_8|http://www.cbs.dtu.dk/cgi-bin/proview/webface-link?seqid=P83527&service=NetPhos-2.0", sf.links.get(0).toString()); assertEquals(89, sf.begin); assertEquals(89, sf.end); assertEquals("netphos", sf.featureGroup); assertEquals("PHOSPHORYLATION (T)", sf.type); } }