--- /dev/null
+package compbio.data.sequence;\r
+\r
+import java.io.BufferedWriter;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+\r
+public class ScoreManager {\r
+\r
+ private List<ScoreHolder> seqScores;\r
+\r
+ private ScoreManager() {\r
+ // Default JAXB constructor\r
+ }\r
+\r
+ public int getNumberOfSeq() {\r
+ return seqScores.size();\r
+ }\r
+\r
+ public ScoreHolder getFirstSequenceScores() {\r
+ if (seqScores.isEmpty())\r
+ return null;\r
+ return seqScores.get(0);\r
+ }\r
+\r
+ public ScoreHolder getAnnotationForSequence(String seqId) {\r
+ for (ScoreHolder sch : seqScores) {\r
+ if (sch.id.equals(seqId)) {\r
+ return sch;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public void writeOut(OutputStream outStream) throws IOException {\r
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
+ outStream));\r
+ for (ScoreHolder oneSeqScores : seqScores) {\r
+ oneSeqScores.writeOut(outStream);\r
+ }\r
+ writer.flush();\r
+ }\r
+\r
+ public static class ScoreHolder {\r
+\r
+ public String id;\r
+ public HashSet<Score> scores;\r
+\r
+ public void writeOut(OutputStream outStream) throws IOException {\r
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
+ outStream));\r
+ writer.write(">" + id + "\n");\r
+ Score.write(scores, outStream);\r
+ }\r
+\r
+ public Score getFirstScore() {\r
+ if (scores.isEmpty())\r
+ return null;\r
+ return scores.iterator().next();\r
+ }\r
+\r
+ public Score getScoreByMethod(Enum<?> method) {\r
+ for (Score sc : scores) {\r
+ if (method == sc.getMethod()) {\r
+ return sc;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public int getNumberOfScores() {\r
+ return scores.size();\r
+ }\r
+ }\r
+}\r
14) Run build-server task in wsbuild file. Watch for errors. If cannot compile that means \r
that JAXB cannot serialize some of the data structures. Add appropriate annotations to your data types.\r
Check that \r
- - you do not have interfaces as fields\r
- - you have a default no args constructor (can be private if you do not need it) \r
+ - you do not have interfaces to serialize. JAXB cannot serialize them.\r
+ - you have a default no args constructor (can be private if you do not need it)\r
+ - JAXB cannot serialize a Map, use custom data structure instead!\r
+If you have the data on the server side, but nothing is coming through to the client, \r
+this is a JAXB serialization problem. They tend to be very silent and thus hard to debug. Check your \r
+data structure can be serialized! \r
\r
13) Modify the client to work with your web service. \r
\r
\r
\r
\r
-\r
If executable does not support parameters do not add a reference to the XXXParameter.xml \r
file into the Executable.properties file. Do the same for Presets\r
\r
import java.io.ByteArrayInputStream;\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
-import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.metadata.JobSubmissionException;\r
import compbio.metadata.Preset;\r
String jobId = client.presetAnalize(fastalist, preset);\r
\r
/* This method will block for the duration of the calculation */\r
- Map<String, HashSet<Score>> result = client.getAnnotation(jobId);\r
+ ScoreManager result = client.getAnnotation(jobId);\r
\r
/*\r
* This is a better way of obtaining results, it does not involve\r
import java.io.FileInputStream;\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
\r
import org.testng.annotations.BeforeTest;\r
import org.testng.annotations.Test;\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.ConservationMethod;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.metadata.JobSubmissionException;\r
import compbio.metadata.LimitExceededException;\r
System.out.println("Pres: " + msaws.getPresets().getPresets());\r
String jobId = msaws.analize(fsl);\r
System.out.println("J: " + jobId);\r
- Map<String, HashSet<Score>> result = msaws.getAnnotation(jobId);\r
+ ScoreManager result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 1);\r
- assertEquals(result.values().iterator().next().iterator().next()\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 1);\r
+\r
+ assertEquals(result.getFirstSequenceScores().getFirstScore()\r
.getMethod(), ConservationMethod.SHENKIN);\r
- List<Float> scores = result.values().iterator().next().iterator()\r
- .next().getScores();\r
+ List<Float> scores = result.getFirstSequenceScores()\r
+ .getFirstScore().getScores();\r
assertNotNull(scores);\r
assertEquals(scores.size(), 568);\r
\r
presets.getPresetByName("Quick conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 13);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
+ 13);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Slow conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 5);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 5);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Complete conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 18);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
+ 18);\r
\r
} catch (UnsupportedRuntimeException e) {\r
e.printStackTrace();\r
}\r
\r
}\r
-\r
@Test\r
public void testPresetAnalize() throws FileNotFoundException, IOException {\r
\r
PresetManager<AACon> presets = msaws.getPresets();\r
String jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Quick conservation"));\r
- Map<String, HashSet<Score>> result = msaws.getAnnotation(jobId);\r
+ ScoreManager result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 13);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
+ 13);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Slow conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 5);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 5);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Complete conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 18);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
+ 18);\r
\r
} catch (UnsupportedRuntimeException e) {\r
e.printStackTrace();\r
// .setDefaultValue("MAX_SCORE");\r
// options.getArgument("SMERFS Gap Threshhold").setDefaultValue("1");\r
String jobId = msaws.customAnalize(fsl, options.getArguments());\r
- Map<String, HashSet<Score>> result = msaws.getAnnotation(jobId);\r
+ ScoreManager result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 1);\r
- assertEquals(\r
- new ArrayList<Score>(result.values().iterator().next())\r
- .get(0).getScores().get(0), 0.698f);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 1);\r
+ assertEquals(result.getFirstSequenceScores().getFirstScore()\r
+ .getScores().get(0), 0.698f);\r
\r
options.getArgument("Calculation method").setDefaultValue("SMERFS");\r
options.removeArgument("Normalize");\r
jobId = msaws.customAnalize(fsl, options.getArguments());\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.size(), 1);\r
- assertEquals(\r
- new ArrayList<Score>(result.values().iterator().next())\r
- .get(0).getScores().get(0), 0.401f);\r
+ assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 1);\r
+ assertEquals(result.getFirstSequenceScores().getFirstScore()\r
+ .getScores().get(0), 0.401f);\r
\r
} catch (WrongParameterException e) {\r
e.printStackTrace();\r
package compbio.data.msa;\r
\r
import java.security.InvalidParameterException;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
import java.util.List;\r
\r
import javax.jws.WebMethod;\r
import javax.jws.WebService;\r
\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.metadata.JobSubmissionException;\r
import compbio.metadata.LimitExceededException;\r
import compbio.metadata.Option;\r
* \r
*/\r
@WebMethod\r
- HashMap<String, HashSet<Score>> getAnnotation(\r
- @WebParam(name = "jobId") String jobId)\r
+ ScoreManager getAnnotation(@WebParam(name = "jobId") String jobId)\r
throws ResultNotAvailableException;\r
/*\r
* The method should really return Map and Set, but unfortunately JAXB\r
import java.io.OutputStream;\r
import java.net.MalformedURLException;\r
import java.net.URL;\r
-import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
import java.util.logging.Level;\r
import java.util.logging.Logger;\r
\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.metadata.JobSubmissionException;\r
customOptions = MetadataHelper.processParameters(prms,\r
msaws.getRunnerOptions());\r
}\r
- Map<String, HashSet<Score>> result = null;\r
+ ScoreManager result = null;\r
if (inputFile != null) {\r
System.out.println("Calculating conservation...");\r
result = analize(inputFile, msaws, preset, customOptions);\r
* @param result\r
* the AACon scores to output\r
*/\r
- static void writeOut(OutputStream outStream,\r
- Map<String, HashSet<Score>> result) {\r
+ static void writeOut(OutputStream outStream, ScoreManager result) {\r
try {\r
- for (Map.Entry<String, ? extends Set<Score>> entry : result\r
- .entrySet()) {\r
- System.out.println(">" + entry.getKey());\r
- Score.write(entry.getValue(), outStream);\r
- }\r
+ result.writeOut(outStream);\r
} catch (IOException e) {\r
System.err\r
.println("Problems writing output file! Stack trace is below: ");\r
* @return Set<Score> the conservation scores\r
* @throws UnknownFileFormatException\r
*/\r
- static Map<String, HashSet<Score>> analize(File file,\r
- SequenceAnnotation<AAConWS> wsproxy, Preset<AAConWS> preset,\r
- List<Option<AAConWS>> customOptions) {\r
+ static ScoreManager analize(File file, SequenceAnnotation<AAConWS> wsproxy,\r
+ Preset<AAConWS> preset, List<Option<AAConWS>> customOptions) {\r
\r
List<FastaSequence> fastalist = null;\r
- Map<String, HashSet<Score>> scores = null;\r
+ ScoreManager scores = null;\r
try {\r
fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
\r
import java.io.IOException;\r
import java.io.OutputStream;\r
import java.util.ArrayList;\r
-import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
\r
import compbio.data.sequence.Alignment;\r
import compbio.data.sequence.ClustalAlignmentUtil;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
\r
public class IOHelper {\r
\r
* @param result\r
* the AACon scores to output\r
*/\r
- static void writeOut(OutputStream outStream,\r
- Map<String, HashSet<Score>> result) {\r
+ static void writeOut(OutputStream outStream, ScoreManager results) {\r
try {\r
- for (Map.Entry<String, HashSet<Score>> entry : result.entrySet()) {\r
- System.out.println(">" + entry.getKey());\r
- Score.write(entry.getValue(), outStream);\r
- }\r
+ results.writeOut(outStream);\r
} catch (IOException e) {\r
System.err\r
.println("Problems writing output file! Stack trace is below: ");\r
import java.net.MalformedURLException;\r
import java.net.URL;\r
import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
import java.util.logging.Level;\r
import java.util.logging.Logger;\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.Alignment;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.metadata.JobSubmissionException;\r
outStream = System.out;\r
}\r
if (service.getServiceType() == SequenceAnnotation.class) {\r
- Map<String, HashSet<Score>> result = analize(inputFile,\r
+ ScoreManager result = analize(inputFile,\r
((SequenceAnnotation<T>) msaws), preset, customOptions);\r
- assert !result.values().isEmpty() : "No Result reported!";\r
+\r
IOHelper.writeOut(outStream, result);\r
} else {\r
alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
* @return Set<Score> the conservation scores\r
* @throws UnknownFileFormatException\r
*/\r
- <T> HashMap<String, HashSet<Score>> analize(File file,\r
- SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
- List<Option<T>> customOptions) {\r
+ <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
+ Preset<T> preset, List<Option<T>> customOptions) {\r
\r
List<FastaSequence> fastalist = null;\r
- HashMap<String, HashSet<Score>> scores = null;\r
+ ScoreManager scores = null;\r
try {\r
fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
assert !fastalist.isEmpty() : "Input is empty!";\r
Thread.sleep(2000);\r
\r
scores = wsproxy.getAnnotation(jobId);\r
- assert scores != null && !scores.values().isEmpty() : "Scores are NULL for job: "\r
- + jobId;\r
\r
} catch (IOException e) {\r
System.err\r
\r
import java.io.File;\r
import java.util.Arrays;\r
-import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.List;\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.FastaSequence;\r
import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.engine.AsyncExecutor;\r
import compbio.engine.Configurator;\r
import compbio.engine.client.ConfiguredExecutable;\r
}\r
\r
@Override\r
- public HashMap<String, HashSet<Score>> getAnnotation(String jobId)\r
+ public ScoreManager getAnnotation(String jobId)\r
throws ResultNotAvailableException {\r
WSUtil.validateJobId(jobId);\r
AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
ConfiguredExecutable<AACon> aacon = (ConfiguredExecutable<AACon>) asyncEngine\r
.getResults(jobId);\r
HashSet<Score> mas = aacon.getResults();\r
- HashMap<String, HashSet<Score>> result = new HashMap<String, HashSet<Score>>();\r
- result.put("Alignment", mas);\r
+ // ScoreManager result = new HashMap<String, HashSet<Score>>();\r
+ // result.put("Alignment", mas);\r
log.trace(jobId + " getConservation : " + mas);\r
- return result;\r
+ // FIXME\r
+ return null;\r
}\r
/*\r
* @SuppressWarnings("unchecked") public JalviewAnnotation\r
package compbio.ws.server;\r
\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
import java.util.List;\r
\r
import javax.annotation.Resource;\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.engine.AsyncExecutor;\r
import compbio.engine.Configurator;\r
import compbio.engine.client.ConfiguredExecutable;\r
}\r
\r
@Override\r
- public HashMap<String, HashSet<Score>> getAnnotation(String jobId)\r
+ public ScoreManager getAnnotation(String jobId)\r
throws ResultNotAvailableException {\r
WSUtil.validateJobId(jobId);\r
AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
ConfiguredExecutable<Disembl> disembl = (ConfiguredExecutable<Disembl>) asyncEngine\r
.getResults(jobId);\r
- HashMap<String, HashSet<Score>> mas = disembl.getResults();\r
+ ScoreManager mas = disembl.getResults();\r
log.trace(jobId + " getDisorder : " + mas);\r
return mas;\r
}\r
package compbio.ws.server;\r
\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
import java.util.List;\r
\r
import javax.annotation.Resource;\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.engine.AsyncExecutor;\r
import compbio.engine.Configurator;\r
import compbio.engine.client.ConfiguredExecutable;\r
}\r
\r
@Override\r
- public HashMap<String, HashSet<Score>> getAnnotation(String jobId)\r
+ public ScoreManager getAnnotation(String jobId)\r
throws ResultNotAvailableException {\r
WSUtil.validateJobId(jobId);\r
AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
ConfiguredExecutable<GlobPlot> globPlot = (ConfiguredExecutable<GlobPlot>) asyncEngine\r
.getResults(jobId);\r
- HashMap<String, HashSet<Score>> mas = globPlot.getResults();\r
+ ScoreManager mas = globPlot.getResults();\r
log.trace(jobId + " getConservation : " + mas);\r
return mas;\r
}\r
package compbio.ws.server;\r
\r
import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
import java.util.List;\r
\r
import javax.annotation.Resource;\r
\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.engine.AsyncExecutor;\r
import compbio.engine.Configurator;\r
import compbio.engine.client.ConfiguredExecutable;\r
}\r
\r
@Override\r
- public HashMap<String, HashSet<Score>> getAnnotation(String jobId)\r
+ public ScoreManager getAnnotation(String jobId)\r
throws ResultNotAvailableException {\r
WSUtil.validateJobId(jobId);\r
AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
ConfiguredExecutable<Jronn> jronn = (ConfiguredExecutable<Jronn>) asyncEngine\r
.getResults(jobId);\r
- HashMap<String, HashSet<Score>> mas = jronn.getResults();\r
+ ScoreManager mas = jronn.getResults();\r
log.trace(jobId + " getConservation : " + mas);\r
return mas;\r
}\r