1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.rest.params; |
22 |
|
|
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; |
29 |
|
|
30 |
|
import java.io.UnsupportedEncodingException; |
31 |
|
import java.util.ArrayList; |
32 |
|
import java.util.Arrays; |
33 |
|
import java.util.List; |
34 |
|
|
35 |
|
import org.apache.http.entity.mime.content.ContentBody; |
36 |
|
import org.apache.http.entity.mime.content.StringBody; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@author |
42 |
|
|
43 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 10 |
Complexity Density: 0.4 |
|
44 |
|
public class AnnotationFile extends InputType |
45 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
0 |
public AnnotationFile()... |
47 |
|
{ |
48 |
0 |
super(new Class[] { AlignmentI.class }); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
final String JVANNOT = "JalviewAnnotation"; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
final String CSVANNOT = "CsvAnnotationRow"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
String format = JVANNOT; |
65 |
|
|
66 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
67 |
0 |
@Override... |
68 |
|
public ContentBody formatForInput(RestJob rj) |
69 |
|
throws UnsupportedEncodingException, NoValidInputDataException |
70 |
|
{ |
71 |
0 |
AlignmentI al = rj.getAlignmentForInput(token, molType.MIX); |
72 |
0 |
if (format.equals(JVANNOT)) |
73 |
|
{ |
74 |
0 |
return new StringBody(new jalview.io.AnnotationFile() |
75 |
|
.printAnnotationsForAlignment(al)); |
76 |
|
} |
77 |
|
else |
78 |
|
{ |
79 |
0 |
if (!format.equals(CSVANNOT)) |
80 |
|
{ |
81 |
0 |
throw new UnsupportedEncodingException( |
82 |
|
"Unrecognised format for exporting Annotation (" + format |
83 |
|
+ ")"); |
84 |
|
} |
85 |
0 |
return new StringBody(new jalview.io.AnnotationFile() |
86 |
|
.printCSVAnnotations(al.getAlignmentAnnotation())); |
87 |
|
} |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
90 |
0 |
@Override... |
91 |
|
public List<String> getURLEncodedParameter() |
92 |
|
{ |
93 |
0 |
ArrayList<String> prms = new ArrayList<String>(); |
94 |
0 |
super.addBaseParams(prms); |
95 |
0 |
prms.add("format='" + format + "'"); |
96 |
0 |
return prms; |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0 |
@Override... |
100 |
|
public String getURLtokenPrefix() |
101 |
|
{ |
102 |
0 |
return "ALANNOTATION"; |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
105 |
0 |
@Override... |
106 |
|
public boolean configureProperty(String tok, String val, |
107 |
|
StringBuffer warnings) |
108 |
|
{ |
109 |
|
|
110 |
0 |
if (tok.startsWith("format")) |
111 |
|
{ |
112 |
0 |
for (String fmt : new String[] { CSVANNOT, JVANNOT }) |
113 |
|
{ |
114 |
0 |
if (val.equalsIgnoreCase(fmt)) |
115 |
|
{ |
116 |
0 |
format = fmt; |
117 |
0 |
return true; |
118 |
|
} |
119 |
|
} |
120 |
0 |
warnings.append("Invalid annotation file format '" + val |
121 |
|
+ "'. Must be one of ("); |
122 |
0 |
for (String fmt : new String[] { CSVANNOT, JVANNOT }) |
123 |
|
{ |
124 |
0 |
warnings.append(" " + fmt); |
125 |
|
} |
126 |
0 |
warnings.append(")\n"); |
127 |
|
} |
128 |
0 |
return false; |
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
131 |
0 |
@Override... |
132 |
|
public List<OptionI> getOptions() |
133 |
|
{ |
134 |
|
|
135 |
0 |
List<OptionI> lst = getBaseOptions(); |
136 |
0 |
lst.add(new Option("format", "Alignment annotation upload format", true, |
137 |
|
JVANNOT, format, Arrays.asList(new String[] |
138 |
|
{ JVANNOT, CSVANNOT }), null)); |
139 |
0 |
return lst; |
140 |
|
} |
141 |
|
} |