2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.
21 package jalview.ws.jws2;
23 import jalview.api.AlignCalcWorkerI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.Annotation;
26 import jalview.gui.AlignFrame;
27 import jalview.ws.jws2.jabaws2.Jws2Instance;
28 import jalview.ws.params.ArgumentI;
29 import jalview.ws.params.OptionI;
30 import jalview.ws.params.WsParamSetI;
31 import jalview.ws.uimodel.AlignAnalysisUIText;
33 import java.awt.Color;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.HashSet;
37 import java.util.List;
39 import compbio.data.sequence.FastaSequence;
40 import compbio.data.sequence.JpredAlignment;
41 import compbio.metadata.Argument;
43 public class JPred301Client extends JabawsMsaInterfaceAlignCalcWorker
44 implements AlignCalcWorkerI
49 * @return default args for this service when run as dynamic web service
51 public List<Argument> selectDefaultArgs()
53 List<ArgumentI> rgs = new ArrayList<ArgumentI>();
54 for (ArgumentI argi : service.getParamStore().getServiceParameters())
56 if (argi instanceof OptionI)
58 List<String> o = ((OptionI) argi).getPossibleValues();
59 if (o.contains("-pred-nohits"))
61 OptionI cpy = ((OptionI) argi).copy();
62 cpy.setValue("-pred-nohits");
67 return JabaParamStore.getJabafromJwsArgs(rgs);
70 public JPred301Client(Jws2Instance service, AlignFrame alignFrame,
71 WsParamSetI preset, List<Argument> paramset)
73 super(service, alignFrame, preset, paramset);
76 nucleotidesAllowed = false;
77 proteinAllowed = true;
78 gapMap = new boolean[0];
79 updateParameters(null, selectDefaultArgs());
83 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
85 return (seqs.size() > 1);
88 public String getServiceActionText()
90 return "calculating consensus secondary structure prediction using JPred service";
93 private static HashMap<String, String[]> jpredRowLabels = new HashMap<String, String[]>();
95 private static HashSet<String> jpredRes_graph, jpredRes_ssonly;
97 jpredRes_ssonly = new HashSet();
98 jpredRes_ssonly.add("jnetpred".toLowerCase());
99 jpredRes_ssonly.add("jnetpssm".toLowerCase());
100 jpredRes_ssonly.add("jnethmm".toLowerCase());
101 jpredRes_graph = new HashSet();
102 jpredRes_graph.add("jnetconf".toLowerCase());
103 jpredRes_graph.add("jnet burial".toLowerCase());
107 * update the consensus annotation from the sequence profile data using
108 * current visualization settings.
110 public void updateResultAnnotation(boolean immediate)
112 if (immediate || !calcMan.isWorking(this) && msascoreset != null)
114 if (msascoreset instanceof compbio.data.sequence.JpredAlignment)
116 JpredAlignment jpres = (JpredAlignment) msascoreset;
117 int alWidth = alignViewport.getAlignment().getWidth();
118 ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
119 char[] sol = new char[jpres.getJpredSequences().get(0).getLength()];
120 boolean firstsol = true;
121 for (FastaSequence fsq : jpres.getJpredSequences())
123 String[] k = jpredRowLabels.get(fsq.getId());
127 { fsq.getId(), "JNet Output" };
129 if (fsq.getId().startsWith("JNETSOL"))
131 char amnt = (fsq.getId().endsWith("25") ? "3" : fsq.getId()
132 .endsWith("5") ? "6" : "9").charAt(0);
133 char[] vseq = fsq.getSequence().toCharArray();
134 for (int spos = 0, sposL = fsq.getLength(); spos < sposL; spos++)
140 if (vseq[spos] == 'B' && (sol[spos]=='0' || sol[spos] < amnt))
149 createAnnotationRowFromString(
155 jpredRes_graph.contains(fsq.getId()) ? AlignmentAnnotation.BAR_GRAPH
156 : AlignmentAnnotation.NO_GRAPH, 0f, 9f,
161 createAnnotationRowFromString(
166 "<html>Prediction of Solvent Accessibility<br/>levels are<ul><li>0 - Exposed</li><li>3 - 25% or more S.A. accessible</li><li>6 - 5% or more S.A. accessible</li><li>9 - Buried (<5% exposed)</li></ul>",
167 AlignmentAnnotation.BAR_GRAPH, 0f, 9f, new String(sol));
168 for (FastaSequence fsq : jpres.getSequences())
170 if (fsq.getId().equalsIgnoreCase("QUERY"))
172 createAnnotationRowFromString(ourAnnot, getCalcId(), alWidth,
173 "Query", "JPred Reference Sequence",
174 AlignmentAnnotation.NO_GRAPH, 0f, 0f, fsq.getSequence());
177 if (ourAnnot.size() > 0)
179 updateOurAnnots(ourAnnot);
185 private void createAnnotationRowFromString(
186 ArrayList<AlignmentAnnotation> ourAnnot, String calcId,
187 int alWidth, String label, String descr, int rowType, float min,
188 float max, String jpredPrediction)
190 // simple annotation row
191 AlignmentAnnotation annotation = alignViewport.getAlignment()
192 .findOrCreateAnnotation(label, calcId, true, null, null);
193 if (alWidth == gapMap.length) // scr.getScores().size())
195 annotation.label = new String(label);
196 annotation.description = new String(descr);
197 annotation.graph = rowType;
198 annotation.graphMin = min;
199 annotation.graphMax = max;
200 if (constructAnnotationFromString(annotation, jpredPrediction,
203 // created a valid annotation from the data
204 ourAnnot.add(annotation);
205 // annotation.validateRangeAndDisplay();
210 private boolean constructAnnotationFromString(
211 AlignmentAnnotation annotation, String sourceData, int alWidth,
214 if (sourceData.length() == 0 && alWidth > 0)
218 Annotation[] elm = new Annotation[alWidth];
219 boolean ssOnly = jpredRes_ssonly.contains(annotation.label
221 boolean graphOnly = rowType != AlignmentAnnotation.NO_GRAPH;
222 if (!ssOnly && !graphOnly)
225 annotation.showAllColLabels = true;
228 for (int i = 0, iSize = sourceData.length(); i < iSize; i++)
230 char annot = sourceData.charAt(i);
231 // if we're at a gapped column then skip to next ungapped position
232 if (gapMap != null && gapMap.length > 0)
236 elm[i++] = new Annotation("", "", ' ', Float.NaN);
241 case AlignmentAnnotation.NO_GRAPH:
242 elm[i] = ssOnly ? new Annotation("", "", annot, Float.NaN,
243 colourSS(annot)) : new Annotation("" + annot, "" + annot,
249 elm[i] = new Annotation("" + annot, "" + annot, annot,
250 Integer.valueOf(""+annot));
251 } catch (Exception x)
253 System.err.println("Expected numeric value in character '"
259 annotation.annotations = elm;
260 annotation.belowAlignment = true;
261 annotation.validateRangeAndDisplay();
265 private Color colourSS(char annot)
270 return jalview.renderer.AnnotationRenderer.HELIX_COLOUR;
272 return jalview.renderer.AnnotationRenderer.SHEET_COLOUR;
274 return jalview.renderer.AnnotationRenderer.GLYPHLINE_COLOR;
278 public String getCalcId()
283 private static String CALC_ID = "jabaws21.JPred3Cons";
285 public static AlignAnalysisUIText getAlignAnalysisUITest()
287 return new AlignAnalysisUIText(
288 compbio.ws.client.Services.JpredWS.toString(),
289 jalview.ws.jws2.JPred301Client.class, CALC_ID, false, true,
290 true, "JPred Consensus",
291 "When checked, JPred consensus is updated automatically.",
292 "Change JPred Settings...",
293 "Modify settings for JPred calculations.");