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