Finally, the new web services are working
[jabaws.git] / runner / compbio / runner / disorder / GlobPlot.java
1 /*\r
2  * Copyright (c) 2011 Peter Troshin JAva Bioinformatics Analysis Web Services\r
3  * (JABAWS) @version: 2.0 This library is free software; you can redistribute it\r
4  * and/or modify it under the terms of the Apache License version 2 as published\r
5  * by the Apache Software Foundation This library is distributed in the hope\r
6  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
7  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
8  * Apache License for more details. A copy of the license is in\r
9  * apache_license.txt. It is also available here:\r
10  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or\r
11  * derived work distributed in source code form must include this copyright and\r
12  * license notice.\r
13  */\r
14 \r
15 package compbio.runner.disorder;\r
16 \r
17 import java.io.File;\r
18 import java.io.FileInputStream;\r
19 import java.io.FileNotFoundException;\r
20 import java.io.IOException;\r
21 import java.io.InputStream;\r
22 \r
23 import org.apache.log4j.Logger;\r
24 \r
25 import compbio.data.sequence.ScoreManager;\r
26 import compbio.data.sequence.SequenceUtil;\r
27 import compbio.data.sequence.UnknownFileFormatException;\r
28 import compbio.engine.client.Executable;\r
29 import compbio.engine.client.PipedExecutable;\r
30 import compbio.engine.client.SkeletalExecutable;\r
31 import compbio.metadata.Limit;\r
32 import compbio.metadata.LimitsManager;\r
33 import compbio.metadata.ResultNotAvailableException;\r
34 import compbio.runner.Util;\r
35 \r
36 /**\r
37  * ./GlobPipe.py SmoothFrame DOMjoinFrame DOMpeakFrame DISjoinFrame DISpeakFrame\r
38  * \r
39  * FASTAfile' Optimised for ELM: ./GlobPlot.py 10 8 75 8 8 sequence_file'\r
40  * Webserver settings: ./GlobPlot.py 10 15 74 4 5 sequence_file'\r
41  * \r
42  * Hard-coded values are 10 15 74 4 5.\r
43  * \r
44  * Changing these values are not recommended by developers, apart from smoothing\r
45  * window. However, the binary, GlobPlot depends on - Tisean which is not happy\r
46  * with arbitrary changes to these values, so changing them can lead to\r
47  * problems. May be we can offer preset?\r
48  * \r
49  * This is not a standard GlobPlot! The script has been modified!\r
50  * \r
51  */\r
52 public class GlobPlot extends SkeletalExecutable<GlobPlot>\r
53                 implements\r
54                         PipedExecutable<GlobPlot> {\r
55 \r
56         private static Logger log = Logger.getLogger(GlobPlot.class);\r
57 \r
58         // Cache for Limits information\r
59         private static LimitsManager<GlobPlot> limits;\r
60 \r
61         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
62 \r
63         /* The parameter list there must not contain same values! */\r
64         public GlobPlot() {\r
65                 // remove default input to prevent it to appear in the parameters list\r
66                 // that could happen if the parameters are set first\r
67                 // super.setInput("");\r
68         }\r
69 \r
70         @SuppressWarnings("unchecked")\r
71         public ScoreManager getResults(String workDirectory)\r
72                         throws ResultNotAvailableException {\r
73 \r
74                 InputStream inStream = null;\r
75                 ScoreManager results = null;\r
76                 // How about getting ranges?\r
77                 try {\r
78                         inStream = new FileInputStream(new File(workDirectory, getOutput()));\r
79                         results = ScoreManager.newInstance(SequenceUtil\r
80                                         .readGlobPlot(inStream));\r
81                         inStream.close();\r
82                 } catch (FileNotFoundException e) {\r
83                         log.error(e.getMessage(), e.getCause());\r
84                         throw new ResultNotAvailableException(e);\r
85                 } catch (IOException e) {\r
86                         log.error(e.getMessage(), e.getCause());\r
87                         throw new ResultNotAvailableException(e);\r
88                 } catch (UnknownFileFormatException e) {\r
89                         log.error(e.getMessage(), e.getCause());\r
90                         throw new ResultNotAvailableException(e);\r
91                 } catch (NullPointerException e) {\r
92                         log.error(e.getMessage(), e.getCause());\r
93                         throw new ResultNotAvailableException(e);\r
94                 }\r
95 \r
96                 return results;\r
97         }\r
98 \r
99         @Override\r
100         public GlobPlot setInput(String inFile) {\r
101                 super.setInput(inFile);\r
102                 cbuilder.setLast(inFile);\r
103                 return this;\r
104         }\r
105 \r
106         @Override\r
107         public Limit<GlobPlot> getLimit(String presetName) {\r
108                 if (limits == null) {\r
109                         limits = getLimits();\r
110                 }\r
111 \r
112                 Limit<GlobPlot> limit = null;\r
113                 if (limits != null) {\r
114                         // this returns default limit if preset is undefined!\r
115                         limit = limits.getLimitByName(presetName);\r
116                 }\r
117                 // If limit is not defined for a particular preset, then return default\r
118                 // limit\r
119                 if (limit == null) {\r
120                         log.debug("Limit for the preset " + presetName\r
121                                         + " is not found. Using default");\r
122                         limit = limits.getDefaultLimit();\r
123                 }\r
124                 return limit;\r
125         }\r
126 \r
127         @Override\r
128         public LimitsManager<GlobPlot> getLimits() {\r
129                 // synchronise on static field\r
130                 synchronized (log) {\r
131                         if (limits == null) {\r
132                                 limits = Util.getLimits(this.getClass());\r
133                         }\r
134                 }\r
135                 return limits;\r
136         }\r
137 \r
138         @Override\r
139         public Class<? extends Executable<?>> getType() {\r
140                 return this.getClass();\r
141         }\r
142 \r
143 }\r