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.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;
41 import compbio.data.sequence.FastaSequence;
42 import compbio.data.sequence.JpredAlignment;
43 import compbio.metadata.Argument;
45 public class JPred301Client extends JabawsMsaInterfaceAlignCalcWorker
46 implements AlignCalcWorkerI
51 * @return default args for this service when run as dynamic web service
53 public List<Argument> selectDefaultArgs()
55 List<ArgumentI> rgs = new ArrayList<ArgumentI>();
56 for (ArgumentI argi : service.getParamStore().getServiceParameters())
58 if (argi instanceof OptionI)
60 List<String> o = ((OptionI) argi).getPossibleValues();
61 if (o.contains("-pred-nohits"))
63 OptionI cpy = ((OptionI) argi).copy();
64 cpy.setValue("-pred-nohits");
69 return JabaParamStore.getJabafromJwsArgs(rgs);
72 public JPred301Client(Jws2Instance service, AlignFrame alignFrame,
73 WsParamSetI preset, List<Argument> paramset)
75 super(service, alignFrame, preset, paramset);
78 nucleotidesAllowed = false;
79 proteinAllowed = true;
80 gapMap = new boolean[0];
81 updateParameters(null, selectDefaultArgs());
85 boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
87 return (seqs.size() > 1);
90 public String getServiceActionText()
92 return "calculating consensus secondary structure prediction using JPred service";
95 private static Map<String, String[]> jpredRowLabels = new HashMap<String, String[]>();
97 private static final Set<String> jpredRes_graph;
99 private static final Set<String> jpredRes_ssonly;
102 jpredRes_ssonly = new HashSet<String>();
103 jpredRes_ssonly.add("jnetpred".toLowerCase());
104 jpredRes_ssonly.add("jnetpssm".toLowerCase());
105 jpredRes_ssonly.add("jnethmm".toLowerCase());
106 jpredRes_graph = new HashSet<String>();
107 jpredRes_graph.add("jnetconf".toLowerCase());
108 jpredRes_graph.add("jnet burial".toLowerCase());
112 * update the consensus annotation from the sequence profile data using
113 * current visualization settings.
115 public void updateResultAnnotation(boolean immediate)
117 if (immediate || !calcMan.isWorking(this) && msascoreset != null)
119 if (msascoreset instanceof compbio.data.sequence.JpredAlignment)
121 JpredAlignment jpres = (JpredAlignment) msascoreset;
122 int alWidth = alignViewport.getAlignment().getWidth();
123 ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
124 char[] sol = new char[jpres.getJpredSequences().get(0).getLength()];
125 boolean firstsol = true;
126 for (FastaSequence fsq : jpres.getJpredSequences())
128 String[] k = jpredRowLabels.get(fsq.getId());
131 k = new String[] { fsq.getId(), "JNet Output" };
133 if (fsq.getId().startsWith("JNETSOL"))
135 char amnt = (fsq.getId().endsWith("25") ? "3" : fsq.getId()
136 .endsWith("5") ? "6" : "9").charAt(0);
137 char[] vseq = fsq.getSequence().toCharArray();
138 for (int spos = 0, sposL = fsq.getLength(); spos < sposL; spos++)
144 if (vseq[spos] == 'B'
145 && (sol[spos] == '0' || sol[spos] < amnt))
154 createAnnotationRowFromString(
160 jpredRes_graph.contains(fsq.getId()) ? AlignmentAnnotation.BAR_GRAPH
161 : AlignmentAnnotation.NO_GRAPH, 0f, 9f,
166 createAnnotationRowFromString(
171 "<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>",
172 AlignmentAnnotation.BAR_GRAPH, 0f, 9f, new String(sol));
173 for (FastaSequence fsq : jpres.getSequences())
175 if (fsq.getId().equalsIgnoreCase("QUERY"))
177 createAnnotationRowFromString(ourAnnot, getCalcId(), alWidth,
178 "Query", "JPred Reference Sequence",
179 AlignmentAnnotation.NO_GRAPH, 0f, 0f, fsq.getSequence());
182 if (ourAnnot.size() > 0)
184 updateOurAnnots(ourAnnot);
190 private void createAnnotationRowFromString(
191 ArrayList<AlignmentAnnotation> ourAnnot, String calcId,
192 int alWidth, String label, String descr, int rowType, float min,
193 float max, String jpredPrediction)
195 // simple annotation row
196 AlignmentAnnotation annotation = alignViewport.getAlignment()
197 .findOrCreateAnnotation(label, calcId, true, null, null);
198 if (alWidth == gapMap.length) // scr.getScores().size())
200 annotation.label = new String(label);
201 annotation.description = new String(descr);
202 annotation.graph = rowType;
203 annotation.graphMin = min;
204 annotation.graphMax = max;
205 if (constructAnnotationFromString(annotation, jpredPrediction,
208 // created a valid annotation from the data
209 ourAnnot.add(annotation);
210 // annotation.validateRangeAndDisplay();
215 private boolean constructAnnotationFromString(
216 AlignmentAnnotation annotation, String sourceData, int alWidth,
219 if (sourceData.length() == 0 && alWidth > 0)
223 Annotation[] elm = new Annotation[alWidth];
224 boolean ssOnly = jpredRes_ssonly.contains(annotation.label
226 boolean graphOnly = rowType != AlignmentAnnotation.NO_GRAPH;
227 if (!ssOnly && !graphOnly)
230 annotation.showAllColLabels = true;
233 for (int i = 0, iSize = sourceData.length(); i < iSize; i++)
235 char annot = sourceData.charAt(i);
236 // if we're at a gapped column then skip to next ungapped position
237 if (gapMap != null && gapMap.length > 0)
241 elm[i++] = new Annotation("", "", ' ', Float.NaN);
246 case AlignmentAnnotation.NO_GRAPH:
247 elm[i] = ssOnly ? new Annotation("", "", annot, Float.NaN,
248 colourSS(annot)) : new Annotation("" + annot, "" + annot,
254 elm[i] = new Annotation("" + annot, "" + annot, annot,
255 Integer.valueOf("" + annot));
256 } catch (Exception x)
258 System.err.println("Expected numeric value in character '"
264 annotation.annotations = elm;
265 annotation.belowAlignment = true;
266 annotation.validateRangeAndDisplay();
270 private Color colourSS(char annot)
275 return jalview.renderer.AnnotationRenderer.HELIX_COLOUR;
277 return jalview.renderer.AnnotationRenderer.SHEET_COLOUR;
279 return jalview.renderer.AnnotationRenderer.GLYPHLINE_COLOR;
283 public String getCalcId()
288 private static String CALC_ID = "jabaws21.JPred3Cons";
290 public static AlignAnalysisUIText getAlignAnalysisUITest()
292 return new AlignAnalysisUIText(
293 compbio.ws.client.Services.JpredWS.toString(),
294 jalview.ws.jws2.JPred301Client.class, CALC_ID, false, true,
295 true, "JPred Consensus",
296 "When checked, JPred consensus is updated automatically.",
297 "Change JPred Settings...",
298 "Modify settings for JPred calculations.");