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