1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 *******************************************************************************/
18 package jalview.ws.rest.params;
20 import jalview.datamodel.AlignmentI;
21 import jalview.datamodel.SequenceI;
22 import jalview.ws.params.OptionI;
23 import jalview.ws.params.simple.Option;
24 import jalview.ws.rest.InputType;
25 import jalview.ws.rest.NoValidInputDataException;
26 import jalview.ws.rest.RestJob;
27 import jalview.ws.rest.RestServiceDescription;
28 import jalview.ws.rest.InputType.molType;
30 import java.io.UnsupportedEncodingException;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.List;
34 import java.util.regex.Matcher;
35 import java.util.regex.Pattern;
37 import org.apache.http.entity.mime.content.ContentBody;
38 import org.apache.http.entity.mime.content.StringBody;
41 * input a list of sequence IDs separated by some separator
46 public class SeqIdVector extends InputType
51 { AlignmentI.class });
55 * separator for list of sequence IDs - default is ','
62 public ContentBody formatForInput(RestJob rj)
63 throws UnsupportedEncodingException, NoValidInputDataException
65 StringBuffer idvector = new StringBuffer();
67 for (SequenceI seq : rj.getSequencesForInput(token, type))
73 idvector.append(seq.getName());
75 return new StringBody(idvector.toString());
79 public List<String> getURLEncodedParameter()
81 ArrayList<String> prms = new ArrayList<String>();
82 super.addBaseParams(prms);
83 prms.add("sep='" + sep + "'");
86 prms.add("type='"+type+"'");
92 public String getURLtokenPrefix()
98 public boolean configureProperty(String tok, String val,
99 StringBuffer warnings)
101 if (tok.startsWith("sep"))
106 if (tok.startsWith("type"))
110 type = molType.valueOf(val);
112 } catch (Exception x)
114 warnings.append("Invalid molecule type '" + val
115 + "'. Must be one of (");
116 for (molType v : molType.values())
118 warnings.append(" " + v);
120 warnings.append(")\n");
127 public List<OptionI> getOptions()
129 List<OptionI> lst = getBaseOptions();
130 lst.add(new Option("sep",
131 "Separator character between elements of vector", true, ",",
132 sep, Arrays.asList(new String[]
133 { " ", ",", ";", "\t", "|" }), null));
134 lst.add(createMolTypeOption("type", "Sequence type", false, type,