2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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/>.
18 package jalview.ws.rest.params;
20 import jalview.datamodel.AlignmentI;
21 import jalview.ws.params.OptionI;
22 import jalview.ws.params.simple.Option;
23 import jalview.ws.rest.InputType;
24 import jalview.ws.rest.NoValidInputDataException;
25 import jalview.ws.rest.RestJob;
27 import java.io.UnsupportedEncodingException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
32 import org.apache.http.entity.mime.content.ContentBody;
33 import org.apache.http.entity.mime.content.StringBody;
36 * format a jalview annotation file for input to a rest service.
41 public class AnnotationFile extends InputType
43 public AnnotationFile()
46 { AlignmentI.class });
50 * standard jalview annotation file
52 final String JVANNOT = "JalviewAnnotation";
55 * export annotation row as simple csv
57 final String CSVANNOT = "CsvAnnotationRow";
60 * format of annotation file
62 String format = JVANNOT;
64 // TODO verify annotation file format enumeration
66 public ContentBody formatForInput(RestJob rj)
67 throws UnsupportedEncodingException, NoValidInputDataException
69 AlignmentI al = rj.getAlignmentForInput(token, molType.MIX);
70 if (format.equals(JVANNOT))
72 return new StringBody(
73 new jalview.io.AnnotationFile().printAnnotations(
74 al.getAlignmentAnnotation(), al.getGroups(),
79 if (!format.equals(CSVANNOT))
81 throw new UnsupportedEncodingException(
82 "Unrecognised format for exporting Annotation (" + format
85 return new StringBody(
86 new jalview.io.AnnotationFile().printCSVAnnotations(al
87 .getAlignmentAnnotation()));
92 public List<String> getURLEncodedParameter()
94 ArrayList<String> prms = new ArrayList<String>();
95 super.addBaseParams(prms);
96 prms.add("format='" + format + "'");
101 public String getURLtokenPrefix()
103 return "ALANNOTATION";
107 public boolean configureProperty(String tok, String val,
108 StringBuffer warnings)
111 if (tok.startsWith("format"))
113 for (String fmt : new String[]
114 { 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[]
125 { CSVANNOT, JVANNOT })
127 warnings.append(" " + fmt);
129 warnings.append(")\n");
135 public List<OptionI> getOptions()
137 // TODO - consider disregarding base options here.
138 List<OptionI> lst = getBaseOptions();
139 lst.add(new Option("format", "Alignment annotation upload format",
140 true, JVANNOT, format, Arrays.asList(new String[]
141 { JVANNOT, CSVANNOT }), null));