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.
21 package jalview.ws.jws2;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.Annotation;
25 import jalview.gui.AlignFrame;
26 import jalview.ws.jws2.jabaws2.Jws2Instance;
27 import jalview.ws.params.ArgumentI;
28 import jalview.ws.params.OptionI;
29 import jalview.ws.params.WsParamSetI;
30 import jalview.ws.uimodel.AlignAnalysisUIText;
32 import java.awt.Color;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.List;
40 import compbio.data.sequence.FastaSequence;
41 import compbio.data.sequence.JpredAlignment;
42 import compbio.metadata.Argument;
44 public class JPred301Client extends JabawsMsaInterfaceAlignCalcWorker
48 * @return default args for this service when run as dynamic web service
50 public List<Argument> selectDefaultArgs()
52 List<ArgumentI> rgs = new ArrayList<ArgumentI>();
53 for (ArgumentI argi : service.getParamStore().getServiceParameters())
55 if (argi instanceof OptionI)
57 List<String> o = ((OptionI) argi).getPossibleValues();
58 if (o.contains("-pred-nohits"))
60 OptionI cpy = ((OptionI) argi).copy();
61 cpy.setValue("-pred-nohits");
66 return JabaParamStore.getJabafromJwsArgs(rgs);
69 public JPred301Client(Jws2Instance service, AlignFrame alignFrame,
70 WsParamSetI preset, List<Argument> paramset)
72 super(service, alignFrame, preset, paramset);
75 nucleotidesAllowed = false;
76 proteinAllowed = true;
77 gapMap = new boolean[0];
78 updateParameters(null, selectDefaultArgs());
82 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
84 return (seqs.size() > 1);
88 public String getServiceActionText()
90 return "calculating consensus secondary structure prediction using JPred service";
93 private static Map<String, String[]> jpredRowLabels = new HashMap<String, String[]>();
95 private static final Set<String> jpredRes_graph;
97 private static final Set<String> jpredRes_ssonly;
100 jpredRes_ssonly = new HashSet<String>();
101 jpredRes_ssonly.add("jnetpred".toLowerCase());
102 jpredRes_ssonly.add("jnetpssm".toLowerCase());
103 jpredRes_ssonly.add("jnethmm".toLowerCase());
104 jpredRes_graph = new HashSet<String>();
105 jpredRes_graph.add("jnetconf".toLowerCase());
106 jpredRes_graph.add("jnet burial".toLowerCase());
110 * update the consensus annotation from the sequence profile data using
111 * current visualization settings.
114 public void updateResultAnnotation(boolean immediate)
116 if (immediate || !calcMan.isWorking(this) && msascoreset != null)
118 if (msascoreset instanceof compbio.data.sequence.JpredAlignment)
120 JpredAlignment jpres = (JpredAlignment) msascoreset;
121 int alWidth = alignViewport.getAlignment().getWidth();
122 ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
123 char[] sol = new char[jpres.getJpredSequences().get(0).getLength()];
124 boolean firstsol = true;
125 for (FastaSequence fsq : jpres.getJpredSequences())
127 String[] k = jpredRowLabels.get(fsq.getId());
130 k = new String[] { fsq.getId(), "JNet Output" };
132 if (fsq.getId().startsWith("JNETSOL"))
134 char amnt = (fsq.getId().endsWith("25") ? "3" : fsq.getId()
135 .endsWith("5") ? "6" : "9").charAt(0);
136 char[] vseq = fsq.getSequence().toCharArray();
137 for (int spos = 0, sposL = fsq.getLength(); spos < sposL; spos++)
143 if (vseq[spos] == 'B'
144 && (sol[spos] == '0' || sol[spos] < amnt))
153 createAnnotationRowFromString(
159 jpredRes_graph.contains(fsq.getId()) ? AlignmentAnnotation.BAR_GRAPH
160 : AlignmentAnnotation.NO_GRAPH, 0f, 9f,
165 createAnnotationRowFromString(
170 "<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>",
171 AlignmentAnnotation.BAR_GRAPH, 0f, 9f, new String(sol));
172 for (FastaSequence fsq : jpres.getSequences())
174 if (fsq.getId().equalsIgnoreCase("QUERY"))
176 createAnnotationRowFromString(ourAnnot, getCalcId(), alWidth,
177 "Query", "JPred Reference Sequence",
178 AlignmentAnnotation.NO_GRAPH, 0f, 0f, fsq.getSequence());
181 if (ourAnnot.size() > 0)
183 updateOurAnnots(ourAnnot);
189 private void createAnnotationRowFromString(
190 ArrayList<AlignmentAnnotation> ourAnnot, String calcId,
191 int alWidth, String label, String descr, int rowType, float min,
192 float max, String jpredPrediction)
194 // simple annotation row
195 AlignmentAnnotation annotation = alignViewport.getAlignment()
196 .findOrCreateAnnotation(label, calcId, true, null, null);
197 if (alWidth == gapMap.length) // scr.getScores().size())
199 annotation.label = new String(label);
200 annotation.description = new String(descr);
201 annotation.graph = rowType;
202 annotation.graphMin = min;
203 annotation.graphMax = max;
204 if (constructAnnotationFromString(annotation, jpredPrediction,
207 // created a valid annotation from the data
208 ourAnnot.add(annotation);
209 // annotation.validateRangeAndDisplay();
214 private boolean constructAnnotationFromString(
215 AlignmentAnnotation annotation, String sourceData, int alWidth,
218 if (sourceData.length() == 0 && alWidth > 0)
222 Annotation[] elm = new Annotation[alWidth];
223 boolean ssOnly = jpredRes_ssonly.contains(annotation.label
225 boolean graphOnly = rowType != AlignmentAnnotation.NO_GRAPH;
226 if (!ssOnly && !graphOnly)
229 annotation.showAllColLabels = true;
232 for (int i = 0, iSize = sourceData.length(); i < iSize; i++)
234 char annot = sourceData.charAt(i);
235 // if we're at a gapped column then skip to next ungapped position
236 if (gapMap != null && gapMap.length > 0)
240 elm[i++] = new Annotation("", "", ' ', Float.NaN);
245 case AlignmentAnnotation.NO_GRAPH:
246 elm[i] = ssOnly ? new Annotation("", "", annot, Float.NaN,
247 colourSS(annot)) : new Annotation("" + annot, "" + annot,
253 elm[i] = new Annotation("" + annot, "" + annot, annot,
254 Integer.valueOf("" + annot));
255 } catch (Exception x)
257 System.err.println("Expected numeric value in character '"
263 annotation.annotations = elm;
264 annotation.belowAlignment = true;
265 annotation.validateRangeAndDisplay();
269 private Color colourSS(char annot)
274 return jalview.renderer.AnnotationRenderer.HELIX_COLOUR;
276 return jalview.renderer.AnnotationRenderer.SHEET_COLOUR;
278 return jalview.renderer.AnnotationRenderer.GLYPHLINE_COLOR;
282 public String getCalcId()
287 private static String CALC_ID = "jabaws21.JPred3Cons";
289 public static AlignAnalysisUIText getAlignAnalysisUITest()
291 return new AlignAnalysisUIText(
292 compbio.ws.client.Services.JpredWS.toString(),
293 jalview.ws.jws2.JPred301Client.class, CALC_ID, false, true,
294 true, "JPred Consensus",
295 "When checked, JPred consensus is updated automatically.",
296 "Change JPred Settings...",
297 "Modify settings for JPred calculations.");