2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.rest.params;
23 import jalview.datamodel.AlignmentI;
24 import jalview.ws.params.OptionI;
25 import jalview.ws.params.simple.Option;
26 import jalview.ws.rest.InputType;
27 import jalview.ws.rest.NoValidInputDataException;
28 import jalview.ws.rest.RestJob;
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;
39 * format a jalview annotation file for input to a rest service.
44 public class AnnotationFile extends InputType
46 public AnnotationFile()
48 super(new Class[] { AlignmentI.class });
52 * standard jalview annotation file
54 final String JVANNOT = "JalviewAnnotation";
57 * export annotation row as simple csv
59 final String CSVANNOT = "CsvAnnotationRow";
62 * format of annotation file
64 String format = JVANNOT;
66 // TODO verify annotation file format enumeration
68 public ContentBody formatForInput(RestJob rj)
69 throws UnsupportedEncodingException, NoValidInputDataException
71 AlignmentI al = rj.getAlignmentForInput(token, molType.MIX);
72 if (format.equals(JVANNOT))
74 return new StringBody(
75 new jalview.io.AnnotationFile()
76 .printAnnotationsForAlignment(al));
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[] { CSVANNOT, JVANNOT })
116 if (val.equalsIgnoreCase(fmt))
122 warnings.append("Invalid annotation file format '" + val
123 + "'. Must be one of (");
124 for (String fmt : new String[] { CSVANNOT, JVANNOT })
126 warnings.append(" " + fmt);
128 warnings.append(")\n");
134 public List<OptionI> getOptions()
136 // TODO - consider disregarding base options here.
137 List<OptionI> lst = getBaseOptions();
138 lst.add(new Option("format", "Alignment annotation upload format",
139 true, JVANNOT, format, Arrays.asList(new String[] { JVANNOT,