37cb2c10396123e67ea513f9322b876e1a397b77
[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.ResultNotAvailableException;\r
32 import compbio.runner.Util;\r
33 \r
34 /**\r
35  * DisEMBL.py smooth_frame peak_frame join_frame fold_coils fold_hotloops\r
36  * fold_rem465 sequence_file print\r
37  * \r
38  * 'A default run would be: ./DisEMBL.py 8 8 4 1.2 1.4 1.2 fasta_file > out'\r
39  * \r
40  * This version of DisEMBL is 1.4 (latest available for download in Feb 2011)\r
41  * capable of outputting raw values\r
42  * \r
43  * The values of the parameters are hard coded in DisEMBL.py script.\r
44  * smooth_frame=8 peak_frame=8 join_frame=4 fold_coils=1.2 fold_hotloops=1.4\r
45  * fold_rem465=1.2\r
46  * \r
47  * Changing these values are not recommended by developers, apart from smoothing\r
48  * window. However, 5 orders of magnitude changes in this parameter does not\r
49  * change the output so allowing this change also seems pointless. Finally, the\r
50  * binary, DisEMBL depends on - Tisean is not happy with arbitruary changes to\r
51  * these values, so changing them can lead to problems.\r
52  * \r
53  * \r
54  * This is not a standard DisEMBL! The script has been modified!\r
55  * \r
56  */\r
57 public class Disembl extends SkeletalExecutable<Disembl>\r
58                 implements\r
59                         PipedExecutable<Disembl> {\r
60 \r
61         private static Logger log = Logger.getLogger(Disembl.class);\r
62 \r
63         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
64 \r
65         /**\r
66          * For the region to be considered disordered the values must exceed these\r
67          */\r
68         public final double COILS_EXPECTATION_THRESHOLD = 0.43;\r
69         public final double REM_EXPECTATION_THRESHOLD = 0.5;\r
70         public final double LOOPS_EXPECTATION_THRESHOLD = 0.086;\r
71 \r
72         /* The parameter list there must not contain same values! */\r
73         public Disembl() {\r
74                 // remove default input to prevent it to appear in the parameters list\r
75                 // that could happen if the parameters are set first\r
76                 // super.setInput("");\r
77         }\r
78 \r
79         @SuppressWarnings("unchecked")\r
80         @Override\r
81         public ScoreManager getResults(String workDirectory)\r
82                         throws ResultNotAvailableException {\r
83 \r
84                 InputStream inStream = null;\r
85                 ScoreManager results = null;\r
86 \r
87                 try {\r
88                         inStream = new FileInputStream(new File(workDirectory, getOutput()));\r
89                         results = ScoreManager.newInstance(SequenceUtil\r
90                                         .readDisembl(inStream));\r
91                         inStream.close();\r
92                 } catch (FileNotFoundException e) {\r
93                         log.error(e.getMessage(), e.getCause());\r
94                         throw new ResultNotAvailableException(e);\r
95                 } catch (IOException e) {\r
96                         log.error(e.getMessage(), e.getCause());\r
97                         throw new ResultNotAvailableException(e);\r
98                 } catch (UnknownFileFormatException e) {\r
99                         log.error(e.getMessage(), e.getCause());\r
100                         throw new ResultNotAvailableException(e);\r
101                 } catch (NullPointerException e) {\r
102                         log.error(e.getMessage(), e.getCause());\r
103                         throw new ResultNotAvailableException(e);\r
104                 }\r
105                 log.trace("DRESULTS: " + results);\r
106                 return results;\r
107         }\r
108         @Override\r
109         public Disembl setInput(String inFile) {\r
110                 super.setInput(inFile);\r
111                 cbuilder.setLast(inFile);\r
112                 return this;\r
113         }\r
114 \r
115         @SuppressWarnings("unchecked")\r
116         @Override\r
117         public Class<Executable<Disembl>> getType() {\r
118                 return (Class<Executable<Disembl>>) this.getClass();\r
119         }\r
120 \r
121 }\r