Finally, the new web services are working
[jabaws.git] / runner / compbio / runner / disorder / Disembl.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  * DisEMBL.py smooth_frame peak_frame join_frame fold_coils fold_hotloops\r
38  * fold_rem465 sequence_file print\r
39  * \r
40  * 'A default run would be: ./DisEMBL.py 8 8 4 1.2 1.4 1.2 fasta_file > out'\r
41  * \r
42  * This version of DisEMBL is 1.4 (latest available for download in Feb 2011)\r
43  * capable of outputting raw values\r
44  * \r
45  * The values of the parameters are hard coded in DisEMBL.py script.\r
46  * smooth_frame=8 peak_frame=8 join_frame=4 fold_coils=1.2 fold_hotloops=1.4\r
47  * fold_rem465=1.2\r
48  * \r
49  * Changing these values are not recommended by developers, apart from smoothing\r
50  * window. However, 5 orders of magnitude changes in this parameter does not\r
51  * change the output so allowing this change also seems pointless. Finally, the\r
52  * binary, DisEMBL depends on - Tisean is not happy with arbitruary changes to\r
53  * these values, so changing them can lead to problems.\r
54  * \r
55  * \r
56  * This is not a standard DisEMBL! The script has been modified!\r
57  * \r
58  */\r
59 public class Disembl extends SkeletalExecutable<Disembl>\r
60                 implements\r
61                         PipedExecutable<Disembl> {\r
62 \r
63         private static Logger log = Logger.getLogger(Disembl.class);\r
64 \r
65         // Cache for Limits information\r
66         private static LimitsManager<Disembl> limits;\r
67 \r
68         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
69 \r
70         /**\r
71          * For the region to be considered disordered the values must exceed these\r
72          */\r
73         public final double COILS_EXPECTATION_THRESHOLD = 0.43;\r
74         public final double REM_EXPECTATION_THRESHOLD = 0.5;\r
75         public final double LOOPS_EXPECTATION_THRESHOLD = 0.086;\r
76 \r
77         /* The parameter list there must not contain same values! */\r
78         public Disembl() {\r
79                 // remove default input to prevent it to appear in the parameters list\r
80                 // that could happen if the parameters are set first\r
81                 // super.setInput("");\r
82         }\r
83 \r
84         @SuppressWarnings("unchecked")\r
85         @Override\r
86         public ScoreManager getResults(String workDirectory)\r
87                         throws ResultNotAvailableException {\r
88 \r
89                 InputStream inStream = null;\r
90                 ScoreManager results = null;\r
91 \r
92                 try {\r
93                         inStream = new FileInputStream(new File(workDirectory, getOutput()));\r
94                         results = ScoreManager.newInstance(SequenceUtil\r
95                                         .readDisembl(inStream));\r
96                         inStream.close();\r
97                 } catch (FileNotFoundException e) {\r
98                         log.error(e.getMessage(), e.getCause());\r
99                         throw new ResultNotAvailableException(e);\r
100                 } catch (IOException e) {\r
101                         log.error(e.getMessage(), e.getCause());\r
102                         throw new ResultNotAvailableException(e);\r
103                 } catch (UnknownFileFormatException e) {\r
104                         log.error(e.getMessage(), e.getCause());\r
105                         throw new ResultNotAvailableException(e);\r
106                 } catch (NullPointerException e) {\r
107                         log.error(e.getMessage(), e.getCause());\r
108                         throw new ResultNotAvailableException(e);\r
109                 }\r
110                 log.trace("DRESULTS: " + results);\r
111                 return results;\r
112         }\r
113         @Override\r
114         public Disembl setInput(String inFile) {\r
115                 super.setInput(inFile);\r
116                 cbuilder.setLast(inFile);\r
117                 return this;\r
118         }\r
119 \r
120         @Override\r
121         public Limit<Disembl> getLimit(String presetName) {\r
122                 if (limits == null) {\r
123                         limits = getLimits();\r
124                 }\r
125 \r
126                 Limit<Disembl> limit = null;\r
127                 if (limits != null) {\r
128                         // this returns default limit if preset is undefined!\r
129                         limit = limits.getLimitByName(presetName);\r
130                 }\r
131                 // If limit is not defined for a particular preset, then return default\r
132                 // limit\r
133                 if (limit == null) {\r
134                         log.debug("Limit for the preset " + presetName\r
135                                         + " is not found. Using default");\r
136                         limit = limits.getDefaultLimit();\r
137                 }\r
138                 return limit;\r
139         }\r
140 \r
141         @Override\r
142         public LimitsManager<Disembl> getLimits() {\r
143                 // synchronise on static field\r
144                 synchronized (log) {\r
145                         if (limits == null) {\r
146                                 limits = Util.getLimits(this.getClass());\r
147                         }\r
148                 }\r
149                 return limits;\r
150         }\r
151 \r
152         @Override\r
153         public Class<? extends Executable<?>> getType() {\r
154                 return this.getClass();\r
155         }\r
156 \r
157 }\r