1 package jalview.ws.rest.params;
3 import jalview.datamodel.AlignmentI;
4 import jalview.ws.rest.InputType;
5 import jalview.ws.rest.NoValidInputDataException;
6 import jalview.ws.rest.RestJob;
7 import jalview.ws.rest.RestServiceDescription;
8 import jalview.ws.rest.InputType.molType;
10 import java.io.UnsupportedEncodingException;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.apache.http.entity.mime.content.ContentBody;
15 import org.apache.http.entity.mime.content.StringBody;
18 * format a jalview annotation file for input to a rest service.
22 public class AnnotationFile extends InputType {
23 public AnnotationFile()
25 super(new Class[] { AlignmentI.class} );
28 * standard jalview annotation file
30 final String JVANNOT="JalviewAnnotation";
32 * export annotation row as simple csv
34 final String CSVANNOT="CsvAnnotationRow";
36 * format of annotation file
38 String format=JVANNOT;
39 // TODO verify annotation file format enumeration
41 public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
43 AlignmentI al = rj.getAlignmentForInput(token,molType.MIX);
44 if (format.equals(JVANNOT))
45 {return new StringBody(new jalview.io.AnnotationFile().printAnnotations(al.getAlignmentAnnotation(),
46 al.getGroups(),al.getProperties()));
48 if (!format.equals(CSVANNOT))
50 throw new UnsupportedEncodingException("Unrecognised format for exporting Annotation ("+format+")");
52 return new StringBody(new jalview.io.AnnotationFile().printCSVAnnotations(al.getAlignmentAnnotation()));
56 public List<String> getURLEncodedParameter()
58 ArrayList<String> prms = new ArrayList<String>();
59 super.addBaseParams(prms);
60 prms.add("format='"+format+"'");
64 public String getURLtokenPrefix()
66 return "ALANNOTATION";
69 public boolean configureProperty(String tok, String val,
70 StringBuffer warnings)
73 if (tok.startsWith("format"))
75 for (String fmt : new String[] { CSVANNOT, JVANNOT})
77 if (val.equalsIgnoreCase(fmt))
83 warnings.append("Invalid annotation file format '" + val
84 + "'. Must be one of (");
85 for (String fmt : new String[] { CSVANNOT, JVANNOT})
87 warnings.append(" " + fmt);
89 warnings.append(")\n");