From 572510ba0fea6a8f4e4dd3e81bfee506d7febed6 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 24 Sep 2015 16:24:43 +0100 Subject: [PATCH] JAL-1904 parse feature file colours on to alignment sequences --- examples/exampleFeatures.txt | 82 +++++------ src/jalview/io/FeaturesFile.java | 2 +- .../seqfeatures/FeatureRendererModel.java | 2 +- src/jalview/ws/jws1/SeqSearchWSThread.java | 6 +- test/jalview/io/FeaturesFileTest.java | 153 ++++++++++++++++++++ 5 files changed, 200 insertions(+), 45 deletions(-) create mode 100644 test/jalview/io/FeaturesFileTest.java diff --git a/examples/exampleFeatures.txt b/examples/exampleFeatures.txt index adb1745..0bb8b7e 100755 --- a/examples/exampleFeatures.txt +++ b/examples/exampleFeatures.txt @@ -24,7 +24,7 @@ BETA-BULGE 1dc451 Pfam dc206a PHOSPHORYLATION (S) b974a5 PHOSPHORYLATION (Y) 7d3881 -Cath 93b1d2 +Cath 93b1d1 ASX-TURN-IR 4ccc6e BETA-BULGE-LOOP-5 4066da CATMAT-4 4dc465 @@ -44,70 +44,70 @@ BETA-TURN-IIL 8b5b50 ST-MOTIF ac25a1 STARTGROUP uniprot -Iron-sulfur (2Fe-2S) FER_CAPAA -1 39 39 METAL -Iron-sulfur (2Fe-2S) FER_CAPAA -1 44 44 METAL -Iron-sulfur (2Fe-2S) FER_CAPAA -1 47 47 METAL -Iron-sulfur (2Fe-2S) FER_CAPAA -1 77 77 METAL +Iron-sulfur (2Fe-2S) FER_CAPAA -1 39 39 METAL +Iron-sulfur (2Fe-2S) FER_CAPAA -1 44 44 METAL +Iron-sulfur (2Fe-2S) FER_CAPAA -1 47 47 METAL +Iron-sulfur (2Fe-2S) FER_CAPAA -1 77 77 METAL Fer2 Status: True Positive Pfam 8_8 FER_CAPAA -1 8 83 Pfam Ferredoxin_fold Status: True Positive FER_CAPAA -1 3 93 Cath -Iron-sulfur (2Fe-2S) FER_CAPAN -1 86 86 METAL -Iron-sulfur (2Fe-2S) FER_CAPAN -1 91 91 METAL -Iron-sulfur (2Fe-2S) FER_CAPAN -1 94 94 METAL -Iron-sulfur (2Fe-2S) FER_CAPAN -1 124 124 METAL +Iron-sulfur (2Fe-2S) FER_CAPAN -1 86 86 METAL +Iron-sulfur (2Fe-2S) FER_CAPAN -1 91 91 METAL +Iron-sulfur (2Fe-2S) FER_CAPAN -1 94 94 METAL +Iron-sulfur (2Fe-2S) FER_CAPAN -1 124 124 METAL Fer2 Status: True Positive Pfam 55_13 FER_CAPAN -1 55 130 Pfam Ferredoxin_fold Status: True Positive FER_CAPAN -1 45 140 Cath -Iron-sulfur (2Fe-2S) FER1_SOLLC -1 86 86 METAL -Iron-sulfur (2Fe-2S) FER1_SOLLC -1 91 91 METAL -Iron-sulfur (2Fe-2S) FER1_SOLLC -1 94 94 METAL -Iron-sulfur (2Fe-2S) FER1_SOLLC -1 124 124 METAL +Iron-sulfur (2Fe-2S) FER1_SOLLC -1 86 86 METAL +Iron-sulfur (2Fe-2S) FER1_SOLLC -1 91 91 METAL +Iron-sulfur (2Fe-2S) FER1_SOLLC -1 94 94 METAL +Iron-sulfur (2Fe-2S) FER1_SOLLC -1 124 124 METAL Fer2 Status: True Positive Pfam 55_13 FER1_SOLLC -1 55 130 Pfam Ferredoxin_fold Status: True Positive FER1_SOLLC -1 45 140 Cath Fer2 Status: True Positive Pfam 55_13 Q93XJ9_SOLTU -1 55 130 Pfam Ferredoxin_fold Status: True Positive Q93XJ9_SOLTU -1 45 140 Cath -Iron-sulfur (2Fe-2S) FER1_PEA -1 91 91 METAL -Iron-sulfur (2Fe-2S) FER1_PEA -1 96 96 METAL -Iron-sulfur (2Fe-2S) FER1_PEA -1 99 99 METAL -Iron-sulfur (2Fe-2S) FER1_PEA -1 129 129 METAL +Iron-sulfur (2Fe-2S) FER1_PEA -1 91 91 METAL +Iron-sulfur (2Fe-2S) FER1_PEA -1 96 96 METAL +Iron-sulfur (2Fe-2S) FER1_PEA -1 99 99 METAL +Iron-sulfur (2Fe-2S) FER1_PEA -1 129 129 METAL Fer2 Status: True Positive Pfam 60_13 FER1_PEA -1 60 135 Pfam Ferredoxin_fold Status: True Positive FER1_PEA -1 50 145 Cath Fer2 Status: True Positive Pfam 63_13 Q7XA98_TRIPR -1 63 138 Pfam Ferredoxin_fold Status: True Positive Q7XA98_TRIPR -1 53 148 Cath -Iron-sulfur (2Fe-2S) FER1_MESCR -1 90 90 METAL -Iron-sulfur (2Fe-2S) FER1_MESCR -1 95 95 METAL -Iron-sulfur (2Fe-2S) FER1_MESCR -1 98 98 METAL -Iron-sulfur (2Fe-2S) FER1_MESCR -1 128 128 METAL +Iron-sulfur (2Fe-2S) FER1_MESCR -1 90 90 METAL +Iron-sulfur (2Fe-2S) FER1_MESCR -1 95 95 METAL +Iron-sulfur (2Fe-2S) FER1_MESCR -1 98 98 METAL +Iron-sulfur (2Fe-2S) FER1_MESCR -1 128 128 METAL Fer2 Status: True Positive Pfam 59_13 FER1_MESCR -1 59 134 Pfam Ferredoxin_fold Status: True Positive FER1_MESCR -1 49 144 Cath -Iron-sulfur (2Fe-2S) FER1_SPIOL -1 89 89 METAL -Iron-sulfur (2Fe-2S) FER1_SPIOL -1 94 94 METAL -Iron-sulfur (2Fe-2S) FER1_SPIOL -1 97 97 METAL -Iron-sulfur (2Fe-2S) FER1_SPIOL -1 127 127 METAL +Iron-sulfur (2Fe-2S) FER1_SPIOL -1 89 89 METAL +Iron-sulfur (2Fe-2S) FER1_SPIOL -1 94 94 METAL +Iron-sulfur (2Fe-2S) FER1_SPIOL -1 97 97 METAL +Iron-sulfur (2Fe-2S) FER1_SPIOL -1 127 127 METAL Fer2 Status: True Positive Pfam 58_13 FER1_SPIOL -1 58 133 Pfam Ferredoxin_fold Status: True Positive FER1_SPIOL -1 48 143 Cath -Iron-sulfur (2Fe-2S) FER3_RAPSA -1 39 39 METAL -Iron-sulfur (2Fe-2S) FER3_RAPSA -1 44 44 METAL -Iron-sulfur (2Fe-2S) FER3_RAPSA -1 47 47 METAL -Iron-sulfur (2Fe-2S) FER3_RAPSA -1 77 77 METAL +Iron-sulfur (2Fe-2S) FER3_RAPSA -1 39 39 METAL +Iron-sulfur (2Fe-2S) FER3_RAPSA -1 44 44 METAL +Iron-sulfur (2Fe-2S) FER3_RAPSA -1 47 47 METAL +Iron-sulfur (2Fe-2S) FER3_RAPSA -1 77 77 METAL Fer2 Status: True Positive Pfam 8_8 FER3_RAPSA -1 8 83 Pfam Ferredoxin_fold Status: True Positive FER3_RAPSA -1 3 93 Cath -Iron-sulfur (2Fe-2S) FER_BRANA -1 39 39 METAL -Iron-sulfur (2Fe-2S) FER_BRANA -1 44 44 METAL -Iron-sulfur (2Fe-2S) FER_BRANA -1 47 47 METAL -Iron-sulfur (2Fe-2S) FER_BRANA -1 77 77 METAL +Iron-sulfur (2Fe-2S) FER_BRANA -1 39 39 METAL +Iron-sulfur (2Fe-2S) FER_BRANA -1 44 44 METAL +Iron-sulfur (2Fe-2S) FER_BRANA -1 47 47 METAL +Iron-sulfur (2Fe-2S) FER_BRANA -1 77 77 METAL Fer2 Status: True Positive Pfam 8_8 FER_BRANA -1 8 83 Pfam Ferredoxin_fold Status: True Positive FER_BRANA -1 2 96 Cath -Iron-sulfur (2Fe-2S) FER2_ARATH -1 91 91 METAL -Iron-sulfur (2Fe-2S) FER2_ARATH -1 96 96 METAL -Iron-sulfur (2Fe-2S) FER2_ARATH -1 99 99 METAL -Iron-sulfur (2Fe-2S) FER2_ARATH -1 129 129 METAL +Iron-sulfur (2Fe-2S) FER2_ARATH -1 91 91 METAL +Iron-sulfur (2Fe-2S) FER2_ARATH -1 96 96 METAL +Iron-sulfur (2Fe-2S) FER2_ARATH -1 99 99 METAL +Iron-sulfur (2Fe-2S) FER2_ARATH -1 129 129 METAL Fer2 Status: True Positive Pfam 60_13 FER2_ARATH -1 60 135 Pfam Ferredoxin_fold Status: True Positive FER2_ARATH -1 50 145 Cath Fer2 Status: True Positive Pfam 60_11 Q93Z60_ARATH -1 60 118 Pfam Ferredoxin_fold Status: True Positive Q93Z60_ARATH -1 52 118 Cath -Iron-sulfur (2Fe-2S) FER1_MAIZE -1 91 91 METAL -Iron-sulfur (2Fe-2S) FER1_MAIZE -1 96 96 METAL -Iron-sulfur (2Fe-2S) FER1_MAIZE -1 99 99 METAL -Iron-sulfur (2Fe-2S) FER1_MAIZE -1 129 129 METAL +Iron-sulfur (2Fe-2S) FER1_MAIZE -1 91 91 METAL +Iron-sulfur (2Fe-2S) FER1_MAIZE -1 96 96 METAL +Iron-sulfur (2Fe-2S) FER1_MAIZE -1 99 99 METAL +Iron-sulfur (2Fe-2S) FER1_MAIZE -1 129 129 METAL Fer2 Status: True Positive Pfam 60_13 FER1_MAIZE -1 60 135 Pfam Ferredoxin_fold Status: True Positive FER1_MAIZE -1 50 145 Cath Fer2 Status: True Positive Pfam 52_12 O80429_MAIZE -1 52 127 Pfam diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index 498226b..d0960e7 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -123,7 +123,7 @@ public class FeaturesFile extends AlignFile * - process html strings into plain text * @return true if features were added */ - public boolean parse(AlignmentI align, Hashtable colours, + public boolean parse(AlignmentI align, Map colours, boolean removeHTML) { return parse(align, colours, null, removeHTML, false); diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 87ebf1a..8db907c 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -683,7 +683,7 @@ public abstract class FeatureRendererModel implements @Override public Map getFeatureColours() { - return new ConcurrentHashMap(featureColours); + return featureColours; } /** diff --git a/src/jalview/ws/jws1/SeqSearchWSThread.java b/src/jalview/ws/jws1/SeqSearchWSThread.java index a6e3731..a28494c 100644 --- a/src/jalview/ws/jws1/SeqSearchWSThread.java +++ b/src/jalview/ws/jws1/SeqSearchWSThread.java @@ -34,7 +34,9 @@ import jalview.ws.AWsJob; import jalview.ws.JobStateSummary; import jalview.ws.WSClientI; +import java.util.HashMap; import java.util.Hashtable; +import java.util.Map; import java.util.Vector; import vamsas.objects.simple.MsaResult; @@ -168,7 +170,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI * * @return null or { Alignment(+features and annotation), NewickFile)} */ - public Object[] getAlignment(Alignment dataset, Hashtable featureColours) + public Object[] getAlignment(Alignment dataset, Map featureColours) { if (result != null && result.isFinished()) @@ -610,7 +612,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI // NewickFile nf[] = new NewickFile[jobs.length]; for (int j = 0; j < jobs.length; j++) { - Hashtable featureColours = new Hashtable(); + Map featureColours = new HashMap(); Alignment al = null; NewickFile nf = null; if (jobs[j].hasResults()) diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java new file mode 100644 index 0000000..f56cd51 --- /dev/null +++ b/test/jalview/io/FeaturesFileTest.java @@ -0,0 +1,153 @@ +/* + * 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.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"), new Color(0x93b1d1)); + assertEquals(colours.get("ASX-MOTIF"), 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); + } +} -- 1.7.10.2