2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3 * Copyright (C) 2014 The Jalview Authors
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 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.rest.params;
21 import jalview.datamodel.AlignmentI;
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;
28 import java.io.UnsupportedEncodingException;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.List;
33 import org.apache.http.entity.mime.content.ContentBody;
34 import org.apache.http.entity.mime.content.StringBody;
37 * format a jalview annotation file for input to a rest service.
42 public class AnnotationFile extends InputType
44 public AnnotationFile()
47 { AlignmentI.class });
51 * standard jalview annotation file
53 final String JVANNOT = "JalviewAnnotation";
56 * export annotation row as simple csv
58 final String CSVANNOT = "CsvAnnotationRow";
61 * format of annotation file
63 String format = JVANNOT;
65 // TODO verify annotation file format enumeration
67 public ContentBody formatForInput(RestJob rj)
68 throws UnsupportedEncodingException, NoValidInputDataException
70 AlignmentI al = rj.getAlignmentForInput(token, molType.MIX);
71 if (format.equals(JVANNOT))
73 return new StringBody(
74 new jalview.io.AnnotationFile().printAnnotations(
75 al.getAlignmentAnnotation(), al.getGroups(),
80 if (!format.equals(CSVANNOT))
82 throw new UnsupportedEncodingException(
83 "Unrecognised format for exporting Annotation (" + format
86 return new StringBody(
87 new jalview.io.AnnotationFile().printCSVAnnotations(al
88 .getAlignmentAnnotation()));
93 public List<String> getURLEncodedParameter()
95 ArrayList<String> prms = new ArrayList<String>();
96 super.addBaseParams(prms);
97 prms.add("format='" + format + "'");
102 public String getURLtokenPrefix()
104 return "ALANNOTATION";
108 public boolean configureProperty(String tok, String val,
109 StringBuffer warnings)
112 if (tok.startsWith("format"))
114 for (String fmt : new String[]
115 { CSVANNOT, JVANNOT })
117 if (val.equalsIgnoreCase(fmt))
123 warnings.append("Invalid annotation file format '" + val
124 + "'. Must be one of (");
125 for (String fmt : new String[]
126 { CSVANNOT, JVANNOT })
128 warnings.append(" " + fmt);
130 warnings.append(")\n");
136 public List<OptionI> getOptions()
138 // TODO - consider disregarding base options here.
139 List<OptionI> lst = getBaseOptions();
140 lst.add(new Option("format", "Alignment annotation upload format",
141 true, JVANNOT, format, Arrays.asList(new String[]
142 { JVANNOT, CSVANNOT }), null));