1 package jalview.ws.rest.params;
3 import jalview.datamodel.AlignmentI;
4 import jalview.ws.params.OptionI;
5 import jalview.ws.params.simple.Option;
6 import jalview.ws.rest.InputType;
7 import jalview.ws.rest.NoValidInputDataException;
8 import jalview.ws.rest.RestJob;
9 import jalview.ws.rest.RestServiceDescription;
10 import jalview.ws.rest.InputType.molType;
12 import java.io.UnsupportedEncodingException;
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.List;
17 import org.apache.http.entity.mime.content.ContentBody;
18 import org.apache.http.entity.mime.content.StringBody;
21 * format a jalview annotation file for input to a rest service.
25 public class AnnotationFile extends InputType {
26 public AnnotationFile()
28 super(new Class[] { AlignmentI.class} );
31 * standard jalview annotation file
33 final String JVANNOT="JalviewAnnotation";
35 * export annotation row as simple csv
37 final String CSVANNOT="CsvAnnotationRow";
39 * format of annotation file
41 String format=JVANNOT;
42 // TODO verify annotation file format enumeration
44 public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
46 AlignmentI al = rj.getAlignmentForInput(token,molType.MIX);
47 if (format.equals(JVANNOT))
48 {return new StringBody(new jalview.io.AnnotationFile().printAnnotations(al.getAlignmentAnnotation(),
49 al.getGroups(),al.getProperties()));
51 if (!format.equals(CSVANNOT))
53 throw new UnsupportedEncodingException("Unrecognised format for exporting Annotation ("+format+")");
55 return new StringBody(new jalview.io.AnnotationFile().printCSVAnnotations(al.getAlignmentAnnotation()));
59 public List<String> getURLEncodedParameter()
61 ArrayList<String> prms = new ArrayList<String>();
62 super.addBaseParams(prms);
63 prms.add("format='"+format+"'");
67 public String getURLtokenPrefix()
69 return "ALANNOTATION";
72 public boolean configureProperty(String tok, String val,
73 StringBuffer warnings)
76 if (tok.startsWith("format"))
78 for (String fmt : new String[] { CSVANNOT, JVANNOT})
80 if (val.equalsIgnoreCase(fmt))
86 warnings.append("Invalid annotation file format '" + val
87 + "'. Must be one of (");
88 for (String fmt : new String[] { CSVANNOT, JVANNOT})
90 warnings.append(" " + fmt);
92 warnings.append(")\n");
97 public List<OptionI> getOptions()
99 // TODO - consider disregarding base options here.
100 List<OptionI> lst = getBaseOptions();
101 lst.add(new Option("format",
102 "Alignment annotation upload format", true, JVANNOT,
103 format, Arrays.asList(new String[]
104 { JVANNOT, CSVANNOT}), null));