package jalview.hmmer; import jalview.bin.Cache; import jalview.datamodel.SequenceI; import jalview.gui.Preferences; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.ArgumentI; import jalview.ws.params.ParamDatastoreI; import jalview.ws.params.WsParamSetI; import jalview.ws.params.simple.BooleanOption; import jalview.ws.params.simple.DoubleParameter; import jalview.ws.params.simple.FileParameter; import jalview.ws.params.simple.IntegerParameter; import jalview.ws.params.simple.LogarithmicParameter; import jalview.ws.params.simple.Option; import jalview.ws.params.simple.RadioChoiceParameter; import jalview.ws.params.simple.StringParameter; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public final class HMMERParamStore implements ParamDatastoreI { private static final String HMMBUILD = "hmmbuild"; private static final String HMMALIGN = "hmmalign"; private static final String HMMSEARCH = "hmmsearch"; private static final String JACKHMMER = "jackhmmer"; private String name; private List presets = new ArrayList<>(); private AlignmentViewport viewport; private HMMERParamStore(String nam, AlignmentViewport av) { this.viewport = av; this.name = nam; } public static HMMERParamStore forBuild(AlignmentViewport viewport) { return new HMMERParamStore(HMMBUILD, viewport); } public static HMMERParamStore forAlign(AlignmentViewport viewport) { return new HMMERParamStore(HMMALIGN, viewport); } public static HMMERParamStore forSearch(AlignmentViewport viewport) { return new HMMERParamStore(HMMSEARCH, viewport); } public static HMMERParamStore forJackhmmer(AlignmentViewport viewport) { return new HMMERParamStore(JACKHMMER, viewport); } @Override public List getPresets() { return presets; } @Override public WsParamSetI getPreset(String nam) { return null; } @Override public List getServiceParameters() { List args = new ArrayList<>(); switch (name) { case HMMSEARCH: getHMMSearchParams(args); break; case HMMALIGN: getHMMAlignParams(args); break; case HMMBUILD: getHMMBuildParams(args); break; case JACKHMMER: getJackhmmerParams(args); default: } return args; } /** * Answers default parameters for hmmsearch, taking into account any * configured as user preferences * * @param args */ private void getHMMSearchParams(List args) { /* * 'Options' */ args.add(new BooleanOption( MessageManager.getString(HMMSearch.AUTO_ALIGN_SEQS_KEY), MessageManager.getString("label.auto_align_seqs_desc"), false, false, false, null)); args.add(new BooleanOption( MessageManager.getString(HMMSearch.USE_ACCESSIONS_KEY), MessageManager.getString("label.use_accessions_desc"), false, false, true, null)); args.add(new BooleanOption( MessageManager.getString(HMMSearch.TRIM_TERMINI_KEY), MessageManager.getString("label.trim_termini_desc"), false, false, true, null)); args.add(new BooleanOption( MessageManager.getString(HMMSearch.RETURN_N_NEW_SEQ), MessageManager.getString("label.check_for_new_sequences_desc"), false, false, false, null)); /* * 'Parameters' */ addChoiceOfHmm(args); // addChoiceOfDatabase(args); String thisAlignment = MessageManager .getString(HMMSearch.THIS_ALIGNMENT_KEY); String database = MessageManager.getString("label.database"); args.add(new FileParameter(database, "", false, "", "")); args.add(new IntegerParameter( MessageManager.getString(HMMSearch.NUMBER_OF_RESULTS_KEY), MessageManager.getString("label.number_of_results_desc"), true, 100, 0, 100000)); args.add(new RadioChoiceParameter( MessageManager.getString(HMMSearch.REPORTING_CUTOFF_KEY), null, Arrays.asList(MessageManager.getString(HMMSearch.CUTOFF_EVALUE), MessageManager.getString(HMMSearch.CUTOFF_SCORE)), MessageManager.getString(HMMSearch.CUTOFF_EVALUE))); args.add(new LogarithmicParameter( MessageManager.getString(HMMSearch.REPORTING_SEQ_EVALUE_KEY), MessageManager.getString("label.reporting_seq_e_value_desc"), false, 1D, 1E-100, 10D)); args.add(new LogarithmicParameter( MessageManager.getString(HMMSearch.REPORTING_DOM_EVALUE_KEY), MessageManager.getString("label.reporting_dom_e_value_desc"), false, 1D, 1E-100, 10D)); args.add( new DoubleParameter( MessageManager .getString(HMMSearch.REPORTING_SEQ_SCORE_KEY), MessageManager.getString( "label.reporting_seq_score_desc"), false, 0d, 0d, 1000d)); args.add( new DoubleParameter( MessageManager .getString(HMMSearch.REPORTING_DOM_SCORE_KEY), MessageManager.getString( "label.reporting_dom_score_desc"), false, 0d, 0d, 1000d)); args.add(new RadioChoiceParameter( MessageManager.getString(HMMSearch.INCLUSION_THRESHOLD_KEY), null, Arrays.asList(MessageManager.getString(HMMSearch.CUTOFF_EVALUE), MessageManager.getString(HMMSearch.CUTOFF_SCORE)), MessageManager.getString(HMMSearch.CUTOFF_EVALUE))); args.add(new LogarithmicParameter( MessageManager.getString(HMMSearch.INCLUSION_SEQ_EVALUE_KEY), MessageManager.getString("label.inclusion_seq_e_value_desc"), false, 1D, 1E-100, 10D)); args.add(new LogarithmicParameter( MessageManager.getString(HMMSearch.INCLUSION_DOM_EVALUE_KEY), MessageManager.getString("label.inclusion_dom_e_value_desc"), false, 1D, 1E-100, 10D)); args.add(new DoubleParameter( MessageManager.getString(HMMSearch.INCLUSION_SEQ_SCORE_KEY), MessageManager.getString("label.inclusion_seq_score_desc"), false, 0d, 0d, 1000d)); args.add(new DoubleParameter( MessageManager.getString(HMMSearch.INCLUSION_DOM_SCORE_KEY), MessageManager.getString("label.inclusion_dom_score_desc"), false, 0d, 0d, 1000d)); } /** * Answers default parameters for jackhmmer, taking into account any configured * as user preferences * * @param args */ private void getJackhmmerParams(List args) { /* * 'Parameters' */ addChoiceOfSequence(args); // addChoiceOfDatabase(args); String database = MessageManager.getString("label.database"); args.add(new FileParameter(database, "", false, "", "")); args.add(new IntegerParameter( MessageManager.getString(HMMSearch.NUMBER_OF_ITERATIONS), MessageManager.getString("label.number_of_iterations_desc"), true, 5, 1, 20)); args.add(new RadioChoiceParameter( MessageManager.getString(JackHMMER.REPORTING_CUTOFF_KEY), null, Arrays.asList(MessageManager.getString(JackHMMER.CUTOFF_NONE), MessageManager.getString(JackHMMER.CUTOFF_EVALUE), MessageManager.getString(JackHMMER.CUTOFF_SCORE)), MessageManager.getString(JackHMMER.CUTOFF_EVALUE))); args.add(new LogarithmicParameter( MessageManager.getString(JackHMMER.REPORTING_SEQ_EVALUE_KEY), MessageManager.getString("label.reporting_seq_e_value_desc"), false, 1D, 1E-38, 10D)); args.add(new LogarithmicParameter( MessageManager.getString(JackHMMER.REPORTING_DOM_EVALUE_KEY), MessageManager.getString( "label.reporting_dom_e_value_desc"), false, 1D, 1E-38, 10D)); args.add(new DoubleParameter( MessageManager.getString(JackHMMER.REPORTING_SEQ_SCORE_KEY), MessageManager.getString("label.reporting_seq_score_desc"), false, 0d, 0d, 1000d)); args.add(new DoubleParameter( MessageManager.getString(JackHMMER.REPORTING_DOM_SCORE_KEY), MessageManager.getString("label.reporting_dom_score_desc"), false, 0d, 0d, 1000d)); args.add(new RadioChoiceParameter( MessageManager.getString(HMMSearch.INCLUSION_THRESHOLD_KEY), null, Arrays.asList(MessageManager.getString(HMMSearch.CUTOFF_EVALUE), MessageManager.getString(HMMSearch.CUTOFF_SCORE)), MessageManager.getString(HmmerCommand.CUTOFF_EVALUE))); args.add(new LogarithmicParameter( MessageManager.getString(HMMSearch.INCLUSION_SEQ_EVALUE_KEY), MessageManager.getString("label.inclusion_seq_e_value_desc"), false, 1D, 1E-100, 10D)); args.add(new LogarithmicParameter( MessageManager.getString(HMMSearch.INCLUSION_DOM_EVALUE_KEY), MessageManager.getString("label.inclusion_dom_e_value_desc"), false, 1D, 1E-100, 10D)); args.add(new DoubleParameter( MessageManager.getString(HMMSearch.INCLUSION_SEQ_SCORE_KEY), MessageManager.getString("label.inclusion_seq_score_desc"), false, 0d, 0d, 1000d)); args.add(new DoubleParameter( MessageManager.getString(HMMSearch.INCLUSION_DOM_SCORE_KEY), MessageManager.getString("label.inclusion_dom_score_desc"), false, 0d, 0d, 1000d)); } /** * Constructs a choice parameter for database to search; always includes 'this * alignment', and also includes any databases held under user preferences key * "HMMSEARCH_DBS" as a comma-delimited list * * @param args */ protected void addChoiceOfDatabase(List args) { String names = Cache.getProperty(Preferences.HMMSEARCH_DBS); if (names == null || names.isEmpty()) { return; } List filePaths = new ArrayList<>(); List fileNames = new ArrayList<>(); String thisAlignment = MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY); filePaths.add(thisAlignment); fileNames.add(thisAlignment); Scanner nameScanner = new Scanner(names); nameScanner.useDelimiter(Preferences.COMMA); while (nameScanner.hasNext()) { String next = nameScanner.next(); if ("null".equals(next)) { Cache.setProperty(Preferences.HMMSEARCH_DBS, ""); } else { filePaths.add(next); int pos = next.lastIndexOf(File.separator); String fileName = next.substring(pos + 1); fileNames.add(fileName); } } nameScanner.close(); ArgumentI databasesOption = new StringParameter( MessageManager.getString(HMMSearch.DATABASE_KEY), MessageManager.getString("label.database_for_hmmsearch"), true, thisAlignment, thisAlignment, filePaths, fileNames); args.add(databasesOption); } /** * Answers default parameters for hmmalign, taking into account any configured * as user preferences * * @param args */ private void getHMMAlignParams(List args) { addChoiceOfHmm(args); boolean def = Cache.getDefault(Preferences.HMMALIGN_TRIM_TERMINI, false); args.add(new BooleanOption( MessageManager.getString("label.trim_termini"), MessageManager.getString("label.trim_termini_desc"), false, false, def, null)); } /** * Adds an argument representing the choice of HMM sequences (profiles) * against which to perform align or search, provided at least one is found * * @param args */ protected void addChoiceOfHmm(List args) { List hmms = viewport.getAlignment().getHmmSequences(); if (!hmms.isEmpty()) { List options = new ArrayList<>(); for (SequenceI hmmSeq : hmms) { options.add(hmmSeq.getName()); } String defseq = options.get(0); ArgumentI arg = new StringParameter( MessageManager.getString("label.use_hmm"), null, true, defseq, defseq, options, null); args.add(arg); } } /** * Adds an argument representing the choice of sequence against which to perform * jackhmmer * * @param args */ protected void addChoiceOfSequence(List args) { List sequences = viewport.getAlignment().getSequences(); List options = new ArrayList<>(); for (SequenceI seq : sequences) { options.add(seq.getName()); } String defseq = options.get(0); ArgumentI arg = new StringParameter( MessageManager.getString("label.use_sequence"), null, true, defseq, defseq, options, null); args.add(arg); } /** * Answers default parameters for hmmbuild, taking into account any configured * as user preferences * * @param args */ private void getHMMBuildParams(List args) { /* * name to give the computed alignment HMM consensus sequence * (Jalview constructs group HMM consensus sequence names) */ String defValue = "Alignment_HMM"; StringParameter nameParam = new StringParameter(MessageManager.getString("label.hmm_name"), MessageManager.getString("label.hmm_name_desc"), true, defValue, defValue); args.add(nameParam); /* * only enable Use Reference Annotation if RF is present */ if (viewport.hasReferenceAnnotation()) { args.add(new BooleanOption( MessageManager.getString("label.use_reference"), MessageManager.getString("label.use_reference_desc"), true, true, true, null)); } /* * choice of whether to compute HMM for alignment and/or group(s) * - only if there are any groups */ if (!viewport.getAlignment().getGroups().isEmpty()) { List options = new ArrayList<>(); options.add(MessageManager.getString("label.alignment")); options.add(MessageManager.getString("label.groups_and_alignment")); options.add(MessageManager.getString("label.groups")); options.add(MessageManager.getString("label.selected_group")); args.add(new Option(MessageManager.getString("label.hmmbuild_for"), MessageManager.getString("label.hmmbuild_for_desc"), true, MessageManager.getString("label.alignment"), MessageManager.getString("label.alignment"), options, null)); } } @Override public boolean presetExists(String forName) { return false; } @Override public void deletePreset(String forName) { } @Override public void storePreset(String presetName, String text, List jobParams) { } @Override public void updatePreset(String oldName, String presetName, String text, List jobParams) { } @Override public WsParamSetI parseServiceParameterFile(String forName, String description, String[] serviceURL, String parameters) throws IOException { return null; } @Override public String generateServiceParameterFile(WsParamSetI pset) throws IOException { return null; } }