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;
35 import org.apache.http.entity.mime.content.ContentBody;
36 import org.apache.http.entity.mime.content.StringBody;
37 import org.jmol.util.ArrayUtil;
40 * input a list of sequences separated by some separator
44 public class SeqVector extends InputType {
49 super(new Class[] { AlignmentI.class} );
53 public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
55 StringBuffer idvector = new StringBuffer();
57 for (SequenceI seq:rj.getSequencesForInput(token, type))
63 idvector.append(seq.getSequence());
65 return new StringBody(idvector.toString());
68 public List<String> getURLEncodedParameter()
70 ArrayList<String> prms = new ArrayList<String>();
71 super.addBaseParams(prms);
72 prms.add("sep='"+ sep+"'");
75 prms.add("type='"+type+"'");
81 public String getURLtokenPrefix()
87 public boolean configureProperty(String tok, String val,
88 StringBuffer warnings)
91 if (tok.startsWith("sep"))
96 if (tok.startsWith("type"))
99 type=molType.valueOf(val);
101 } catch (Exception x)
103 warnings.append("Invalid molecule type '"+val+"'. Must be one of (");
104 for (molType v:molType.values())
106 warnings.append(" "+v);
108 warnings.append(")\n");
115 public List<OptionI> getOptions()
117 List<OptionI> lst = getBaseOptions();
118 lst.add(new Option("sep",
119 "Separator character between elements of vector", true, ",",
120 sep, Arrays.asList(new String[]
121 { " ", ",", ";", "\t", "|" }), null));
122 lst.add(createMolTypeOption("type", "Sequence type", false, type,