import jalview.schemes.ResidueColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.util.MessageManager;
-import jalview.util.StringUtils;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
-import java.util.Scanner;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
return true;
}
+ /**
+ * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
+ * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
+ * comma-separated list)
+ */
@Override
public void addDatabase_actionPerformed() throws IOException
{
- if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null)
+ if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
{
Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
- Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
}
String path = openFileChooser(false);
if (format == FileFormat.Fasta || format == FileFormat.Stockholm
|| format == FileFormat.Pfam)
{
- String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS);
String currentDbPaths = Cache
- .getProperty(Preferences.HMMSEARCH_DB_PATHS);
- currentDbPaths += " " + path;
-
- String fileName = StringUtils.getLastToken(path, File.separator);
- Scanner scanner = new Scanner(fileName).useDelimiter(".");
- String name = scanner.next();
- scanner.close();
- currentDbs += " " + path; // TODO remove path from file name
- scanner.close();
-
- Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths);
+ .getProperty(Preferences.HMMSEARCH_DBS);
+ currentDbPaths += Preferences.COMMA + path;
Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
}
else
add(enabled);
}
- val = new JComboBox<>();
- for (String str : opt.getPossibleValues())
- {
- val.addItem(str);
- }
+ /*
+ * construct the choice box with possible values,
+ * or their display names if provided
+ */
+ val = buildComboBox(opt);
val.setSelectedItem(opt.getValue());
+
+ /*
+ * only show the choicebox if there is more than one option,
+ * or the option is mandatory
+ */
if (opt.getPossibleValues().size() > 1 || opt.isRequired())
{
val.addActionListener(this);
poparent.argSetModified(this, !notmod);
}
- public OptionI getOptionIfEnabled()
+ /**
+ * Answers null if the option is not selected, else a new Option holding the
+ * selected value
+ *
+ * @return
+ */
+ public ArgumentI getSelectedOption()
{
if (!enabled.isSelected())
{
return null;
}
+ String value = getSelectedValue(option, val.getSelectedIndex());
OptionI opt = option.copy();
- if (opt.getPossibleValues() != null
- && opt.getPossibleValues().size() == 1)
- {
- // Hack to make sure the default value for an enabled option with only
- // one value is actually returned
- opt.setValue(opt.getPossibleValues().get(0));
- }
- if (val.getSelectedItem() != null)
- {
- opt.setValue((String) val.getSelectedItem());
- }
- else
- {
- if (option.getValue() != null)
- {
- opt.setValue(option.getValue());
- }
- }
+ opt.setValue(value);
return opt;
}
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
- public ParameterI getParameter()
+ /**
+ * Answers an argument holding the value entered or selected in the dialog
+ *
+ * @return
+ */
+ public ArgumentI getParameter()
{
ParameterI prm = parameter.copy();
if (isChoiceParameter)
{
- prm.setValue((String) choicebox.getSelectedItem());
+ String value = getSelectedValue(this.parameter, choicebox.getSelectedIndex());
+ prm.setValue(value);
}
else
{
{
if (isChoiceParameter)
{
- choicebox = new JComboBox<>();
- choicebox.addActionListener(this);
+ choicebox = buildComboBox(parm);
controlsPanel.add(choicebox, BorderLayout.CENTER);
}
else
}
}
- if (parm != null)
+ if (!isChoiceParameter && parm != null)
{
- if (isChoiceParameter)
- {
- if (init)
- {
- for (String val : parm.getPossibleValues())
- {
- choicebox.addItem(val);
- }
- }
- if (parm.getValue() != null)
- {
- choicebox.setSelectedItem(parm.getValue());
- }
- }
- else
- {
- valueField.setText(parm.getValue());
- }
+ valueField.setText(parm.getValue());
}
lastVal = updateSliderFromValueField();
adjusting = false;
{
if (isChoiceParameter)
{
- return choicebox.getSelectedItem();
+ return getSelectedValue(this.parameter, choicebox.getSelectedIndex());
}
slider.setVisible(false);
return valueField.getText().trim();
}
/**
- * recover options and parameters from GUI
+ * Answers a list of arguments representing all the options and arguments
+ * selected on the dialog, holding their chosen or input values. Optional
+ * parameters which were not selected are not included.
*
* @return
*/
List<ArgumentI> argSet = new ArrayList<>();
for (OptionBox opts : getOptSet().values())
{
- OptionI opt = opts.getOptionIfEnabled();
+ ArgumentI opt = opts.getSelectedOption();
if (opt != null)
{
argSet.add(opt);
}
for (ParamBox parambox : getParamSet().values())
{
- ParameterI parm = parambox.getParameter();
+ ArgumentI parm = parambox.getParameter();
if (parm != null)
{
argSet.add(parm);
return argSet;
}
+
+ /**
+ * A helper method that constructs and returns a CombBox for choice of the
+ * possible option values. If display names are provided, then these are added
+ * as options, otherwise the actual values are added.
+ *
+ * @param opt
+ * @return
+ */
+ protected JComboBox<String> buildComboBox(OptionI opt)
+ {
+ JComboBox<String> cb = null;
+ List<String> displayNames = opt.getDisplayNames();
+ if (displayNames != null)
+ {
+ cb = JvSwingUtils.buildComboWithTooltips(displayNames,
+ opt.getPossibleValues());
+ }
+ else
+ {
+ cb = new JComboBox<>();
+ for (String v : opt.getPossibleValues())
+ {
+ cb.addItem(v);
+ }
+ }
+ return cb;
+ }
+
+ /*
+ * Answers the value corresponding to the selected item in the choice combo
+ * box. If display names were not provided, this is simply the selected
+ * value. If display names were provided, it is the value corresponding to
+ * the selected item index.
+ *
+ * @return
+ */
+ protected static String getSelectedValue(OptionI opt, int sel)
+ {
+ List<String> possibleValues = opt.getPossibleValues();
+ String value = null;
+ if (possibleValues != null && possibleValues.size() == 1)
+ {
+ // Hack to make sure the default value for an enabled option with only
+ // one value is actually returned even if this.val is not displayed
+ value = possibleValues.get(0);
+ }
+ else
+ {
+ if (sel >= 0 && sel < possibleValues.size())
+ {
+ value = possibleValues.get(sel);
+ }
+ else
+ {
+ value = opt.getValue();
+ }
+ }
+ return value;
+ }
}
*/
public class Preferences extends GPreferences
{
+ // suggested list delimiter character
+ public static final String COMMA = ",";
+
public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT";
public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND";
public static final String CYGWIN_PATH = "CYGWIN_PATH";
- public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS";
-
public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
import jalview.ws.params.simple.Option;
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.Collection;
import java.util.List;
import java.util.Scanner;
/*
* 'Options'
*/
- addChoiceOfHmm(args);
-
- String names = Cache.getProperty(Preferences.HMMSEARCH_DBS);
- if (names != null && !names.isEmpty())
- {
- List<String> databases = new ArrayList<>();
- databases.add(MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY));
- Scanner nameScanner = new Scanner(names);
-
- if (nameScanner.hasNext())
- {
- while (nameScanner.hasNext())
- {
- String next = nameScanner.next();
- if ("null".equals(next))
- {
- Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
- Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
- }
- else
- {
- databases.add(next);
- }
- }
- }
- nameScanner.close();
- args.add(new StringParameter(
- MessageManager.getString(HMMSearch.DATABASE_KEY),
- MessageManager.getString("label.database_for_hmmsearch"),
- true, MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY),
- MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY),
- databases));
- }
args.add(new BooleanOption(
MessageManager.getString(HMMSearch.AUTO_ALIGN_SEQS_KEY),
MessageManager.getString("label.auto_align_seqs_desc"), false,
/*
* 'Parameters'
*/
+ addChoiceOfHmm(args);
+
+ addChoiceOfDatabase(args);
+
args.add(new IntegerParameter(
MessageManager.getString(HMMSearch.NUMBER_OF_RESULTS_KEY),
MessageManager.getString("label.number_of_results_desc"), true,
MessageManager.getString(HMMSearch.REPORTING_CUTOFF_KEY), null,
true, HMMSearch.CUTOFF_NONE, HMMSearch.CUTOFF_NONE,
Arrays.asList(HMMSearch.CUTOFF_NONE, HMMSearch.CUTOFF_EVALUE,
- HMMSearch.CUTOFF_SCORE)));
+ HMMSearch.CUTOFF_SCORE),
+ null));
args.add(new LogarithmicParameter(
MessageManager.getString(HMMSearch.SEQ_EVALUE_KEY),
MessageManager.getString("label.seq_e_value_desc"), false, 1D,
}
/**
+ * 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<ArgumentI> args)
+ {
+ String names = Cache.getProperty(Preferences.HMMSEARCH_DBS);
+ if (names == null || names.isEmpty())
+ {
+ return;
+ }
+
+ List<String> filePaths = new ArrayList<>();
+ List<String> 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
*
String defseq = options.get(0);
ArgumentI arg = new StringParameter(
MessageManager.getString("label.use_hmm"), null, true, defseq,
- defseq, options);
+ defseq, options, null);
args.add(arg);
}
}
*/
if (!viewport.getAlignment().getGroups().isEmpty())
{
- Collection<String> options = new ArrayList<>();
+ List<String> options = new ArrayList<>();
options.add(MessageManager.getString("label.alignment"));
options.add(MessageManager.getString("label.groups_and_alignment"));
options.add(MessageManager.getString("label.groups"));
}
/**
- * Returns the last part of 'input' after the last occurrence of 'token'. For
- * example to extract only the filename from a full path or URL.
- *
- * @param input
- * @param token
- * a delimiter which must be in regular expression format
- * @return
- */
- public static String getLastToken(String input, String token)
- {
- if (input == null)
- {
- return null;
- }
- if (token == null)
- {
- return input;
- }
- String[] st = input.split(token);
- return st[st.length - 1];
- }
-
- /**
* Parses the input string into components separated by the delimiter. Unlike
* String.split(), this method will ignore occurrences of the delimiter which
* are nested within single quotes in name-value pair values, e.g. a='b,c'.
{
return null;
}
- List<String> jv = new ArrayList<String>();
+ List<String> jv = new ArrayList<>();
int cp = 0, pos, escape;
boolean wasescaped = false, wasquoted = false;
String lstitem = null;
for (SequenceGroup group : alignment.getGroups())
{
hmmSeqs = group.getHmmSequences();
- ProfilesI profiles = group.getHmmProfiles();
- float m = updateInformationAnnotation(hmmSeqs.get(0), profiles, group,
- infos);
- maxInformation = Math.max(maxInformation, m);
+ if (!hmmSeqs.isEmpty())
+ {
+ ProfilesI profiles = group.getHmmProfiles();
+ float m = updateInformationAnnotation(hmmSeqs.get(0), profiles,
+ group, infos);
+ maxInformation = Math.max(maxInformation, m);
+ }
}
/*
return opt;
}
+ @Override
+ public List<String> getDisplayNames()
+ {
+ return null; // not supported for Jaba options
+ }
+
}
public interface OptionI extends ArgumentI
{
-
+ /**
+ * Answers a URL with further details for this option, or null if none is
+ * known
+ *
+ * @return
+ */
URL getFurtherDetails();
+ /**
+ * Answers true if the option is mandatory (a value must be chosen), false if
+ * it is optional
+ *
+ * @return
+ */
boolean isRequired();
+ /**
+ * Answers the description of the option
+ *
+ * @return
+ */
String getDescription();
+ /**
+ * Answers a list of possible values that may be chosen for the option (or
+ * null if not applicable)
+ *
+ * @return
+ */
List<String> getPossibleValues();
- OptionI copy();
+ /**
+ * Answers a list of display names corresponding to the possible values that
+ * may be chosen for the option (or null if not applicable)
+ *
+ * @return
+ */
+ List<String> getDisplayNames();
+ /**
+ * Answers a new Option with a copy of the settings of this one
+ *
+ * @return
+ */
+ OptionI copy();
}
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
public class Option implements OptionI
String description;
- ArrayList<String> possibleVals = new ArrayList<>();
+ List<String> possibleVals;
+
+ /*
+ * optional display names corresponding to possibleVals
+ */
+ List<String> displayVals;
boolean required;
URL fdetails;
+ /**
+ * Copy constructor
+ *
+ * @param opt
+ */
+ public Option(Option opt)
+ {
+ name = opt.name;
+ value = opt.value;
+ defvalue = opt.defvalue;
+ description = opt.description;
+ if (opt.possibleVals != null)
+ {
+ possibleVals = new ArrayList<>(opt.possibleVals);
+ }
+ required = opt.required;
+ // URLs are singletons - so we copy by reference. nasty but true.
+ fdetails = opt.fdetails;
+ }
+
+ public Option()
+ {
+ }
+
+ /**
+ * Constructor including display names for possible values
+ *
+ * @param name2
+ * @param description2
+ * @param isrequired
+ * @param defValue
+ * @param val
+ * @param possibleVals
+ * @param fdetails
+ */
+ public Option(String name2, String description2, boolean isrequired,
+ String defValue, String val, List<String> possibleVals,
+ List<String> displayNames, URL fdetails)
+ {
+ name = name2;
+ description = description2;
+ this.value = val;
+ this.required = isrequired;
+ this.defvalue = defValue;
+ if (possibleVals != null)
+ {
+ this.possibleVals = new ArrayList<>(possibleVals);
+ }
+ if (displayNames != null)
+ {
+ this.displayVals = new ArrayList<>(displayNames);
+ }
+ this.fdetails = fdetails;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param name2
+ * @param description2
+ * @param isrequired
+ * @param defValue
+ * @param val
+ * @param possibleVals
+ * @param fdetails
+ */
+ public Option(String name2, String description2, boolean isrequired,
+ String defValue, String val, List<String> possibleVals,
+ URL fdetails)
+ {
+ this(name2, description2, isrequired, defValue, val, possibleVals, null,
+ fdetails);
+ }
+
+ @Override
+ public OptionI copy()
+ {
+ Option opt = new Option(this);
+ return opt;
+ }
+
+ /**
+ * toString method to help identify options in the debugger only
+ */
+ @Override
+ public String toString()
+ {
+ return this.getClass().getName() + ":" + name;
+ }
+
@Override
public String getName()
{
return possibleVals;
}
- public Option(Option opt)
- {
- name = new String(opt.name);
- if (opt.value != null)
- {
- value = new String(opt.value);
- }
- if (opt.defvalue != null)
- {
- defvalue = new String(opt.defvalue);
- }
- if (opt.description != null)
- {
- description = new String(opt.description);
- }
- if (opt.possibleVals != null)
- {
- possibleVals = (ArrayList<String>) opt.possibleVals.clone();
- }
- required = opt.required;
- // URLs are singletons - so we copy by reference. nasty but true.
- fdetails = opt.fdetails;
- }
-
- public Option()
- {
- }
-
- public Option(String name2, String description2, boolean isrequired,
- String defValue, String value, Collection<String> possibleVals,
- URL fdetails)
- {
- name = name2;
- description = description2;
- this.value = value;
- this.required = isrequired;
- this.defvalue = defValue;
- if (possibleVals != null)
- {
- this.possibleVals = new ArrayList<>();
- this.possibleVals.addAll(possibleVals);
- }
- this.fdetails = fdetails;
- }
-
@Override
- public OptionI copy()
- {
- Option opt = new Option(this);
- return opt;
- }
-
- /**
- * toString method to help identify options in the debugger only
- */
- @Override
- public String toString()
+ public List<String> getDisplayNames()
{
- return this.getClass().getName() + ":" + name;
+ return displayVals;
}
}
import jalview.ws.params.ParameterI;
import jalview.ws.params.ValueConstrainI;
-import java.util.Collection;
+import java.util.List;
public class StringParameter extends Option implements ParameterI
{
{
this.name = parm.name;
this.defvalue = parm.defvalue;
+ this.possibleVals = parm.possibleVals;
+ this.displayVals = parm.displayVals;
}
public StringParameter(String name, String description, boolean required,
}
/**
- * Constructor for a parameter with a list of possible values
+ * Constructor for a parameter with a list of possible values and (optionally)
+ * corresponding display names
*
* @param name2
* @param description2
* @param defValue
* @param value
* @param possibleVals
+ * @param displayNames
*/
public StringParameter(String name2, String description2,
boolean isrequired, String defValue, String value,
- Collection<String> possibleVals)
+ List<String> possibleVals, List<String> displayNames)
{
super(name2, description2, isrequired, defValue, value, possibleVals,
- null);
+ displayNames, null);
}
}
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
{
NUC, PROT, MIX;
- public static Collection<String> toStringValues()
+ public static List<String> toStringValues()
{
- Collection<String> c = new ArrayList<String>();
+ List<String> c = new ArrayList<>();
for (molType type : values())
{
c.add(type.toString());
public int max = 0; // unbounded
- protected ArrayList<Class> inputData = new ArrayList<Class>();
+ protected List<Class> inputData = new ArrayList<>();
/**
* initialise the InputType with a list of jalview data classes that the
public boolean validFor(RestJob restJob)
{
if (!validFor(restJob.rsd))
+ {
return false;
+ }
for (Class cl : inputData)
{
if (!restJob.hasDataOfType(cl))
public boolean validFor(RestServiceDescription restServiceDescription)
{
if (!restServiceDescription.inputParams.values().contains(this))
+ {
return false;
+ }
return true;
}
public List<OptionI> getBaseOptions()
{
- ArrayList<OptionI> opts = new ArrayList<OptionI>();
+ ArrayList<OptionI> opts = new ArrayList<>();
opts.add(new IntegerParameter("min",
"Minimum number of data of this type", true, 1, min, 0, -1));
opts.add(new IntegerParameter("max",
public void configureFromArgumentI(List<ArgumentI> currentSettings)
throws InvalidArgumentException
{
- ArrayList<String> urltoks = new ArrayList<String>();
+ List<String> urltoks = new ArrayList<>();
String rg;
for (ArgumentI arg : currentSettings)
{
}
@Test(groups = { "Functional" })
- public void testGetLastToken()
- {
- assertNull(StringUtils.getLastToken(null, null));
- assertNull(StringUtils.getLastToken(null, "/"));
- assertEquals("a", StringUtils.getLastToken("a", null));
-
- assertEquals("abc", StringUtils.getLastToken("abc", "/"));
- assertEquals("c", StringUtils.getLastToken("abc", "b"));
- assertEquals("file1.dat", StringUtils.getLastToken(
- "file://localhost:8080/data/examples/file1.dat", "/"));
- }
-
- @Test(groups = { "Functional" })
public void testSeparatorListToArray()
{
String[] result = StringUtils.separatorListToArray(
public void testListToDelimitedString()
{
assertEquals("", StringUtils.listToDelimitedString(null, ";"));
- List<String> list = new ArrayList<String>();
+ List<String> list = new ArrayList<>();
assertEquals("", StringUtils.listToDelimitedString(list, ";"));
list.add("now");
assertEquals("now", StringUtils.listToDelimitedString(list, ";"));