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.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.List;
38 import compbio.data.sequence.FastaSequence;
39 import compbio.data.sequence.JpredAlignment;
40 import compbio.metadata.Argument;
42 public class JPred301Client extends JabawsMsaInterfaceAlignCalcWorker
43 implements AlignCalcWorkerI
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);
87 public String getServiceActionText()
89 return "calculating consensus secondary structure prediction using JPred service";
91 private static HashMap<String, String[]> jpredRowLabels = new HashMap<String,String[]>();
92 private static HashSet<String>jpredRes_graph,jpredRes_ssonly;
94 jpredRes_ssonly=new HashSet();
95 jpredRes_ssonly.add("jnetpred".toLowerCase());
96 jpredRes_graph=new HashSet();
97 jpredRes_graph.add("jnetconf".toLowerCase());
101 * update the consensus annotation from the sequence profile data using
102 * current visualization settings.
104 public void updateResultAnnotation(boolean immediate)
106 if (immediate || !calcMan.isWorking(this) && msascoreset != null)
108 if (msascoreset instanceof compbio.data.sequence.JpredAlignment)
110 JpredAlignment jpres = (JpredAlignment) msascoreset;
111 int alWidth = alignViewport.getAlignment().getWidth();
112 ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
113 for (FastaSequence fsq:jpres.getJpredSequences())
115 String[] k = jpredRowLabels.get(fsq.getId());
118 k = new String[] { fsq.getId(), "JNet Output"};
120 createAnnotationRowFromString(ourAnnot, getCalcId(), alWidth,
122 jpredRes_graph.contains(fsq.getId()) ? AlignmentAnnotation.BAR_GRAPH : AlignmentAnnotation.NO_GRAPH, 0f, 0f,
126 for (FastaSequence fsq: jpres.getSequences())
128 if (fsq.getId().equalsIgnoreCase("QUERY"))
130 createAnnotationRowFromString(ourAnnot, getCalcId(), alWidth,
131 "Query", "JPred Reference Sequence",
132 AlignmentAnnotation.NO_GRAPH, 0f, 0f,
136 if (ourAnnot.size() > 0)
138 updateOurAnnots(ourAnnot);
144 private void createAnnotationRowFromString(
145 ArrayList<AlignmentAnnotation> ourAnnot, String calcId,
146 int alWidth, String label, String descr, int rowType, float min,
147 float max, String jpredPrediction)
149 // simple annotation row
150 AlignmentAnnotation annotation = alignViewport.getAlignment()
151 .findOrCreateAnnotation(label, calcId, true, null, null);
152 if (alWidth == gapMap.length) // scr.getScores().size())
154 annotation.label = new String(label);
155 annotation.description = new String(descr);
156 annotation.graph = rowType;
157 annotation.graphMin = min;
158 annotation.graphMax = max;
159 if (constructAnnotationFromString(annotation, jpredPrediction,
162 // created a valid annotation from the data
163 ourAnnot.add(annotation);
168 private boolean constructAnnotationFromString(
169 AlignmentAnnotation annotation, String sourceData, int alWidth,
172 if (sourceData.length()==0 && alWidth>0)
176 Annotation[] elm = new Annotation[alWidth];
178 for (int i = 0, iSize = sourceData.length(); i < iSize; i++)
180 char annot = sourceData.charAt(i);
181 // if we're at a gapped column then skip to next ungapped position
182 if (gapMap != null && gapMap.length > 0)
186 elm[i++] = new Annotation("", "", ' ', Float.NaN);
191 case AlignmentAnnotation.NO_GRAPH:
192 elm[i] = new Annotation("" + annot, "" + annot, annot, Float.NaN);
197 elm[i] = new Annotation("" + annot, "" + annot, annot,
198 Integer.valueOf(annot));
199 } catch (Exception x)
201 System.err.println("Expected numeric value in character '"
207 annotation.annotations = elm;
208 annotation.belowAlignment = true;
209 annotation.validateRangeAndDisplay();
214 public String getCalcId()
219 private static String CALC_ID = "jabaws21.JPred3Cons";
221 public static AlignAnalysisUIText getAlignAnalysisUITest()
223 return new AlignAnalysisUIText(
224 compbio.ws.client.Services.JpredWS.toString(),
225 jalview.ws.jws2.JPred301Client.class, CALC_ID, false, true,
226 true, "JPred Consensus",
227 "When checked, JPred consensus is updated automatically.",
228 "Change JPred Settings...",
229 "Modify settings for JPred calculations.");