Change header template for a new version
[jabaws.git] / webservices / compbio / ws / server / SequenceAnnotationService.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.ws.server;\r
19 \r
20 import java.util.List;\r
21 \r
22 import org.apache.log4j.Logger;\r
23 \r
24 import compbio.data.sequence.FastaSequence;\r
25 import compbio.data.sequence.ScoreManager;\r
26 import compbio.engine.client.ConfiguredExecutable;\r
27 import compbio.engine.client.SkeletalExecutable;\r
28 import compbio.metadata.JobSubmissionException;\r
29 import compbio.metadata.Limit;\r
30 import compbio.metadata.LimitExceededException;\r
31 import compbio.metadata.Option;\r
32 import compbio.metadata.Preset;\r
33 import compbio.metadata.ResultNotAvailableException;\r
34 import compbio.metadata.UnsupportedRuntimeException;\r
35 import compbio.metadata.WrongParameterException;\r
36 import compbio.runner.conservation.AACon;\r
37 \r
38 /**\r
39  * Common methods for all SequenceAnnotation web services\r
40  * \r
41  * @author pvtroshin\r
42  * \r
43  * @param <T>\r
44  * \r
45  * @version 1.0 June 2011\r
46  * @since 2.0\r
47  */\r
48 public abstract class SequenceAnnotationService<T> extends GenericMetadataService {\r
49 \r
50         /*\r
51          * FIXME - instances of the Runner (?) and their types should be defined in\r
52          * Executable IF\r
53          */\r
54         SequenceAnnotationService(SkeletalExecutable<T> exec, Logger log) {\r
55                 super(exec, log);\r
56         }\r
57 \r
58         public ScoreManager getAnnotation(String jobId)\r
59                         throws ResultNotAvailableException {\r
60                 return WSUtil.getAnnotation(jobId, log);\r
61         }\r
62 \r
63         public String analize(List<FastaSequence> sequences)\r
64                         throws UnsupportedRuntimeException, LimitExceededException,\r
65                         JobSubmissionException {\r
66                 WSUtil.validateFastaInput(sequences);\r
67                 ConfiguredExecutable<T> confIUPred = init(sequences);\r
68                 return WSUtil.analize(sequences, confIUPred, log, "analize",\r
69                                 getLimit(""));\r
70         }\r
71 \r
72         public String customAnalize(List<FastaSequence> sequences,\r
73                         List<Option<T>> options) throws UnsupportedRuntimeException,\r
74                         LimitExceededException, JobSubmissionException,\r
75                         WrongParameterException {\r
76                 WSUtil.validateAAConInput(sequences);\r
77                 ConfiguredExecutable<T> confAACon = init(sequences);\r
78                 // Could not do that! Space separated values\r
79                 // will all be treated as keys! thus duplicates removed\r
80                 // String params = cbuilder.getCommand();\r
81                 List<String> params = WSUtil.getCommands(options,\r
82                                 AACon.KEY_VALUE_SEPARATOR);\r
83                 confAACon.addParameters(params);\r
84                 return WSUtil.analize(sequences, confAACon, log, "customAnalize",\r
85                                 getLimit(""));\r
86         }\r
87 \r
88         public String presetAnalize(List<FastaSequence> sequences, Preset<T> preset)\r
89                         throws UnsupportedRuntimeException, LimitExceededException,\r
90                         JobSubmissionException, WrongParameterException {\r
91                 WSUtil.validateAAConInput(sequences);\r
92                 if (preset == null) {\r
93                         throw new WrongParameterException("Preset must be provided!");\r
94                 }\r
95                 ConfiguredExecutable<T> confAAcon = init(sequences);\r
96                 confAAcon.addParameters(preset.getOptions());\r
97                 Limit<T> limit = getLimit(preset.getName());\r
98                 return WSUtil\r
99                                 .analize(sequences, confAAcon, log, "presetAnalize", limit);\r
100         }\r
101 \r
102 }\r