3 import jalview.bin.Cache;
4 import jalview.datamodel.SequenceI;
5 import jalview.gui.Preferences;
6 import jalview.util.MessageManager;
7 import jalview.viewmodel.AlignmentViewport;
8 import jalview.ws.params.ArgumentI;
9 import jalview.ws.params.ParamDatastoreI;
10 import jalview.ws.params.WsParamSetI;
11 import jalview.ws.params.simple.BooleanOption;
12 import jalview.ws.params.simple.DoubleParameter;
13 import jalview.ws.params.simple.IntegerParameter;
14 import jalview.ws.params.simple.LogarithmicParameter;
15 import jalview.ws.params.simple.Option;
16 import jalview.ws.params.simple.StringParameter;
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Scanner;
25 public final class HMMERParamStore implements ParamDatastoreI
27 private static final String HMMBUILD = "hmmbuild";
29 private static final String HMMALIGN = "hmmalign";
31 private static final String HMMSEARCH = "hmmsearch";
35 private List<WsParamSetI> presets = new ArrayList<>();
37 private AlignmentViewport viewport;
39 private HMMERParamStore(String nam, AlignmentViewport av)
45 public static HMMERParamStore forBuild(AlignmentViewport viewport)
47 return new HMMERParamStore(HMMBUILD, viewport);
50 public static HMMERParamStore forAlign(AlignmentViewport viewport)
52 return new HMMERParamStore(HMMALIGN, viewport);
55 public static HMMERParamStore forSearch(AlignmentViewport viewport)
57 return new HMMERParamStore(HMMSEARCH, viewport);
61 public List<WsParamSetI> getPresets()
67 public WsParamSetI getPreset(String nam)
73 public List<ArgumentI> getServiceParameters()
75 List<ArgumentI> args = new ArrayList<>();
79 getHMMSearchParams(args);
82 getHMMAlignParams(args);
85 getHMMBuildParams(args);
94 * Answers default parameters for hmmsearch, taking into account any
95 * configured as user preferences
99 private void getHMMSearchParams(List<ArgumentI> args)
104 addChoiceOfHmm(args);
106 String names = Cache.getProperty(Preferences.HMMSEARCH_DBS);
107 if (names != null && !names.isEmpty())
109 List<String> databases = new ArrayList<>();
110 databases.add(MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY));
111 Scanner nameScanner = new Scanner(names);
113 if (nameScanner.hasNext())
115 while (nameScanner.hasNext())
117 String next = nameScanner.next();
118 if ("null".equals(next))
120 Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
121 Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
130 args.add(new StringParameter(
131 MessageManager.getString(HMMSearch.DATABASE_KEY),
132 MessageManager.getString("label.database_for_hmmsearch"),
133 true, MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY),
134 MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY),
137 args.add(new BooleanOption(
138 MessageManager.getString(HMMSearch.AUTO_ALIGN_SEQS_KEY),
139 MessageManager.getString("label.auto_align_seqs_desc"), false,
141 args.add(new BooleanOption(
142 MessageManager.getString(HMMSearch.USE_ACCESSIONS_KEY),
143 MessageManager.getString("label.use_accessions_desc"), false,
145 args.add(new BooleanOption(
146 MessageManager.getString(HMMSearch.TRIM_TERMINI_KEY),
147 MessageManager.getString("label.trim_termini_desc"), false,
153 args.add(new IntegerParameter(
154 MessageManager.getString(HMMSearch.NUMBER_OF_RESULTS_KEY),
155 MessageManager.getString("label.number_of_results_desc"), true,
157 args.add(new StringParameter(
158 MessageManager.getString(HMMSearch.REPORTING_CUTOFF_KEY), null,
159 true, HMMSearch.CUTOFF_NONE, HMMSearch.CUTOFF_NONE,
160 Arrays.asList(HMMSearch.CUTOFF_NONE, HMMSearch.CUTOFF_EVALUE,
161 HMMSearch.CUTOFF_SCORE)));
162 args.add(new LogarithmicParameter(
163 MessageManager.getString(HMMSearch.SEQ_EVALUE_KEY),
164 MessageManager.getString("label.seq_e_value_desc"), false, 1D,
166 args.add(new LogarithmicParameter(
167 MessageManager.getString(HMMSearch.DOM_EVALUE_KEY),
168 MessageManager.getString("label.dom_e_value_desc"), false, 1D,
172 MessageManager.getString(HMMSearch.SEQ_SCORE_KEY),
173 MessageManager.getString("label.seq_score_desc"), false,
177 MessageManager.getString(HMMSearch.DOM_SCORE_KEY),
178 MessageManager.getString("label.dom_score_desc"), false,
183 * Answers default parameters for hmmalign, taking into account any configured
184 * as user preferences
188 private void getHMMAlignParams(List<ArgumentI> args)
190 addChoiceOfHmm(args);
192 boolean def = Cache.getDefault(Preferences.HMMALIGN_TRIM_TERMINI,
194 args.add(new BooleanOption(
195 MessageManager.getString("label.trim_termini"),
196 MessageManager.getString("label.trim_termini_desc"),
197 false, false, def, null));
201 * Adds an argument representing the choice of HMM sequences (profiles)
202 * against which to perform align or search, provided more than one is found
206 protected void addChoiceOfHmm(List<ArgumentI> args)
208 List<SequenceI> hmms = viewport.getAlignment().getHmmSequences();
211 List<String> options = new ArrayList<>();
212 for (SequenceI hmmSeq : hmms)
214 options.add(hmmSeq.getName());
216 String defseq = options.get(0);
217 ArgumentI arg = new StringParameter(
218 MessageManager.getString("label.use_hmm"), null, true, defseq,
225 * Answers default parameters for hmmbuild, taking into account any configured
226 * as user preferences
230 private void getHMMBuildParams(List<ArgumentI> args)
233 * name to give the computed alignment HMM consensus sequence
234 * (Jalview constructs group HMM consensus sequence names)
236 String defValue = "Alignment_HMM";
237 StringParameter nameParam = new StringParameter(MessageManager.getString("label.hmm_name"),
238 MessageManager.getString("label.hmm_name_desc"), true, defValue,
243 * only enable Use Reference Annotation if RF is present
245 if (viewport.hasReferenceAnnotation())
247 args.add(new BooleanOption(
248 MessageManager.getString("label.use_reference"),
249 MessageManager.getString("label.use_reference_desc"), true,
254 * choice of whether to compute HMM for alignment and/or group(s)
255 * - only if there are any groups
257 if (!viewport.getAlignment().getGroups().isEmpty())
259 Collection<String> options = new ArrayList<>();
260 options.add(MessageManager.getString("label.alignment"));
261 options.add(MessageManager.getString("label.groups_and_alignment"));
262 options.add(MessageManager.getString("label.groups"));
263 options.add(MessageManager.getString("label.selected_group"));
264 args.add(new Option(MessageManager.getString("label.hmmbuild_for"),
265 MessageManager.getString("label.hmmbuild_for_desc"), true,
266 MessageManager.getString("label.alignment"),
267 MessageManager.getString("label.alignment"), options, null));
272 public boolean presetExists(String forName)
278 public void deletePreset(String forName)
283 public void storePreset(String presetName, String text,
284 List<ArgumentI> jobParams)
289 public void updatePreset(String oldName, String presetName, String text,
290 List<ArgumentI> jobParams)
295 public WsParamSetI parseServiceParameterFile(String forName,
296 String description, String[] serviceURL, String parameters)
303 public String generateServiceParameterFile(WsParamSetI pset)