| 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.io.FileFormat; |
| 25 |
|
import jalview.io.FileFormatI; |
| 26 |
|
import jalview.io.FileFormats; |
| 27 |
|
import jalview.io.FormatAdapter; |
| 28 |
|
import jalview.ws.params.OptionI; |
| 29 |
|
import jalview.ws.params.simple.BooleanOption; |
| 30 |
|
import jalview.ws.params.simple.Option; |
| 31 |
|
import jalview.ws.rest.InputType; |
| 32 |
|
import jalview.ws.rest.NoValidInputDataException; |
| 33 |
|
import jalview.ws.rest.RestJob; |
| 34 |
|
|
| 35 |
|
import java.io.BufferedOutputStream; |
| 36 |
|
import java.io.File; |
| 37 |
|
import java.io.FileOutputStream; |
| 38 |
|
import java.io.OutputStreamWriter; |
| 39 |
|
import java.io.PrintWriter; |
| 40 |
|
import java.io.UnsupportedEncodingException; |
| 41 |
|
import java.util.ArrayList; |
| 42 |
|
import java.util.List; |
| 43 |
|
|
| 44 |
|
import org.apache.http.entity.mime.content.ContentBody; |
| 45 |
|
import org.apache.http.entity.mime.content.FileBody; |
| 46 |
|
import org.apache.http.entity.mime.content.StringBody; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@author |
| 52 |
|
|
| 53 |
|
|
| |
|
| 51.3% |
Uncovered Elements: 38 (78) |
Complexity: 18 |
Complexity Density: 0.33 |
|
| 54 |
|
public class Alignment extends InputType |
| 55 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 56 |
378 |
public Alignment()... |
| 57 |
|
{ |
| 58 |
378 |
super(new Class[] { AlignmentI.class }); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
FileFormatI format = FileFormat.Fasta; |
| 62 |
|
|
| 63 |
|
molType type; |
| 64 |
|
|
| 65 |
|
boolean jvsuffix = false; |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
public boolean writeAsFile = false; |
| 71 |
|
|
| |
|
| 64.3% |
Uncovered Elements: 5 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 72 |
2 |
@Override... |
| 73 |
|
public ContentBody formatForInput(RestJob rj) |
| 74 |
|
throws UnsupportedEncodingException, NoValidInputDataException |
| 75 |
|
{ |
| 76 |
2 |
AlignmentI alignment = rj.getAlignmentForInput(token, type); |
| 77 |
2 |
if (writeAsFile) |
| 78 |
|
{ |
| 79 |
2 |
try |
| 80 |
|
{ |
| 81 |
2 |
File fa = File.createTempFile("jvmime", ".fa"); |
| 82 |
2 |
PrintWriter pw = new PrintWriter(new OutputStreamWriter( |
| 83 |
|
new BufferedOutputStream(new FileOutputStream(fa)), |
| 84 |
|
"UTF-8")); |
| 85 |
2 |
pw.append(new FormatAdapter().formatSequences(format, alignment, |
| 86 |
|
jvsuffix)); |
| 87 |
2 |
pw.close(); |
| 88 |
2 |
return new FileBody(fa, "text/plain"); |
| 89 |
|
} catch (Exception ex) |
| 90 |
|
{ |
| 91 |
0 |
throw new NoValidInputDataException( |
| 92 |
|
"Couldn't write out alignment to file.", ex); |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
else |
| 96 |
|
{ |
| 97 |
0 |
FormatAdapter fa = new FormatAdapter(); |
| 98 |
0 |
fa.setNewlineString("\r\n"); |
| 99 |
0 |
return new StringBody( |
| 100 |
|
(fa.formatSequences(format, alignment, jvsuffix))); |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 5 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 108 |
26 |
@Override... |
| 109 |
|
public List<String> getURLEncodedParameter() |
| 110 |
|
{ |
| 111 |
26 |
List<String> prms = new ArrayList<String>(); |
| 112 |
26 |
prms.add("format='" + format.getName() + "'"); |
| 113 |
26 |
if (type != null) |
| 114 |
|
{ |
| 115 |
0 |
prms.add("type='" + type.toString() + "'"); |
| 116 |
|
} |
| 117 |
26 |
if (jvsuffix) |
| 118 |
|
{ |
| 119 |
0 |
prms.add("jvsuffix"); |
| 120 |
|
} |
| 121 |
26 |
if (writeAsFile) |
| 122 |
|
{ |
| 123 |
26 |
prms.add("writeasfile"); |
| 124 |
|
} |
| 125 |
26 |
return prms; |
| 126 |
|
} |
| 127 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 128 |
383 |
@Override... |
| 129 |
|
public String getURLtokenPrefix() |
| 130 |
|
{ |
| 131 |
383 |
return "ALIGNMENT"; |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 41.2% |
Uncovered Elements: 20 (34) |
Complexity: 8 |
Complexity Density: 0.33 |
|
| 134 |
370 |
@Override... |
| 135 |
|
public boolean configureProperty(String tok, String val, |
| 136 |
|
StringBuffer warnings) |
| 137 |
|
{ |
| 138 |
370 |
if (tok.startsWith("jvsuffix")) |
| 139 |
|
{ |
| 140 |
0 |
jvsuffix = true; |
| 141 |
0 |
return true; |
| 142 |
|
} |
| 143 |
370 |
if (tok.startsWith("writeasfile")) |
| 144 |
|
{ |
| 145 |
185 |
writeAsFile = true; |
| 146 |
185 |
return true; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
185 |
if (tok.startsWith("format")) |
| 150 |
|
{ |
| 151 |
185 |
for (FileFormatI fmt : FileFormats.getInstance().getFormats()) |
| 152 |
|
{ |
| 153 |
185 |
if (fmt.isWritable() && val.equalsIgnoreCase(fmt.getName())) |
| 154 |
|
{ |
| 155 |
185 |
format = fmt; |
| 156 |
185 |
return true; |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
0 |
warnings.append( |
| 160 |
|
"Invalid alignment format '" + val + "'. Must be one of ("); |
| 161 |
0 |
for (String fmt : FileFormats.getInstance().getWritableFormats(true)) |
| 162 |
|
{ |
| 163 |
0 |
warnings.append(" ").append(fmt); |
| 164 |
|
} |
| 165 |
0 |
warnings.append(")\n"); |
| 166 |
|
} |
| 167 |
0 |
if (tok.startsWith("type")) |
| 168 |
|
{ |
| 169 |
0 |
try |
| 170 |
|
{ |
| 171 |
0 |
type = molType.valueOf(val); |
| 172 |
0 |
return true; |
| 173 |
|
} catch (Exception x) |
| 174 |
|
{ |
| 175 |
0 |
warnings.append( |
| 176 |
|
"Invalid molecule type '" + val + "'. Must be one of ("); |
| 177 |
0 |
for (molType v : molType.values()) |
| 178 |
|
{ |
| 179 |
0 |
warnings.append(" " + v); |
| 180 |
|
} |
| 181 |
0 |
warnings.append(")\n"); |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
0 |
return false; |
| 185 |
|
} |
| 186 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 187 |
0 |
@Override... |
| 188 |
|
public List<OptionI> getOptions() |
| 189 |
|
{ |
| 190 |
0 |
List<OptionI> lst = getBaseOptions(); |
| 191 |
0 |
lst.add(new BooleanOption("jvsuffix", |
| 192 |
|
"Append jalview style /start-end suffix to ID", false, false, |
| 193 |
|
jvsuffix, null)); |
| 194 |
0 |
lst.add(new BooleanOption("writeasfile", |
| 195 |
|
"Append jalview style /start-end suffix to ID", false, false, |
| 196 |
|
writeAsFile, null)); |
| 197 |
|
|
| 198 |
0 |
List<String> writable = FileFormats.getInstance() |
| 199 |
|
.getWritableFormats(true); |
| 200 |
0 |
lst.add(new Option("format", "Alignment upload format", true, |
| 201 |
|
FileFormat.Fasta.toString(), format.getName(), writable, null)); |
| 202 |
0 |
lst.add(createMolTypeOption("type", "Sequence type", false, type, |
| 203 |
|
null)); |
| 204 |
|
|
| 205 |
0 |
return lst; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
} |