8f4256f9ed38400a629ff754fd3e12d2f2ce9328
[jabaws.git] / runner / compbio / runner / disorder / Disembl.java
1 /*\r
2  * Copyright (c) 2009 Peter Troshin JAva Bioinformatics Analysis Web Services\r
3  * (JABAWS) @version: 1.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.util.Arrays;\r
18 import java.util.Map;\r
19 \r
20 import org.apache.log4j.Logger;\r
21 \r
22 import compbio.data.sequence.Score;\r
23 import compbio.engine.client.CommandBuilder;\r
24 import compbio.engine.client.Executable;\r
25 import compbio.engine.client.PipedExecutable;\r
26 import compbio.engine.client.SkeletalExecutable;\r
27 import compbio.metadata.Limit;\r
28 import compbio.metadata.LimitsManager;\r
29 import compbio.metadata.ResultNotAvailableException;\r
30 import compbio.runner.Util;\r
31 \r
32 /**\r
33  * @see DisEMBL\r
34  * \r
35  *      DisEMBL.py smooth_frame peak_frame join_frame fold_coils fold_hotloops\r
36  *      fold_rem465 sequence_file print 'A default run would be: ./DisEMBL.py 8\r
37  *      8 4 1.2 1.4 1.2 fasta_file > out' new DisEMBL is at\r
38  *      /homes/pvtroshin/soft/DisEMBL-1.4raw\r
39  * \r
40  *      This is not a standard DisEMBL! The script has been modified! DisEMBL.py\r
41  *      smooth_frame peak_frame join_frame fold_coils fold_hotloops fold_rem465\r
42  *      [mode] < fasta_file > out print\r
43  * \r
44  *      'A default run would be: ./DisEMBL.py 8 8 4 1.2 1.4 1.2 < fasta_file'\r
45  *      print 'Mode: "default"(nothing) or "scores" which will give scores per\r
46  *      residue in TAB separated format'\r
47  * \r
48  *      Internal parameters names are: sj\r
49  * \r
50  *      //TODO? pw jd ct rt lt\r
51  * \r
52  *      the order is preserved\r
53  */\r
54 public class Disembl extends SkeletalExecutable<Disembl>\r
55                 implements\r
56                         PipedExecutable<Disembl> {\r
57 \r
58         private static Logger log = Logger.getLogger(Disembl.class);\r
59 \r
60         // Cache for Limits information\r
61         private static LimitsManager<Disembl> limits;\r
62 \r
63         // CHECK THIS !!!\r
64         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
65 \r
66         public Disembl() {\r
67                 // remove default input to prevent it to appear in the parameters list\r
68                 // that could happen if the parameters are set first\r
69                 // super.setInput("");\r
70                 addParameters(Arrays.asList("8", "8", "4", "1.2", "1.4", "1.2",\r
71                                 "scores"));\r
72         }\r
73 \r
74         @SuppressWarnings("unchecked")\r
75         public Map<String, Score> getResults(String workDirectory)\r
76                         throws ResultNotAvailableException {\r
77 \r
78                 return null;\r
79         }\r
80 \r
81         @Override\r
82         public Disembl setInput(String inFile) {\r
83                 super.setInput(inFile);\r
84                 cbuilder.setLast(inFile);\r
85                 return this;\r
86         }\r
87 \r
88         @Override\r
89         public Limit<Disembl> getLimit(String presetName) {\r
90                 if (limits == null) {\r
91                         limits = getLimits();\r
92                 }\r
93 \r
94                 Limit<Disembl> limit = null;\r
95                 if (limits != null) {\r
96                         // this returns default limit if preset is undefined!\r
97                         limit = limits.getLimitByName(presetName);\r
98                 }\r
99                 // If limit is not defined for a particular preset, then return default\r
100                 // limit\r
101                 if (limit == null) {\r
102                         log.debug("Limit for the preset " + presetName\r
103                                         + " is not found. Using default");\r
104                         limit = limits.getDefaultLimit();\r
105                 }\r
106                 return limit;\r
107         }\r
108 \r
109         @Override\r
110         public LimitsManager<Disembl> getLimits() {\r
111                 // synchronise on static field\r
112                 synchronized (log) {\r
113                         if (limits == null) {\r
114                                 limits = Util.getLimits(this.getClass());\r
115                         }\r
116                 }\r
117                 return limits;\r
118         }\r
119 \r
120         @Override\r
121         public Class<? extends Executable<?>> getType() {\r
122                 return this.getClass();\r
123         }\r
124 \r
125         @Override\r
126         public CommandBuilder<Disembl> getParameters(ExecProvider provider) {\r
127                 // If Savitzky-Golay smoothing parameter is specified then set it\r
128                 String val = cbuilder.getParamValue("sg");\r
129                 log.info("DisEMBL sav-gol value: " + val);\r
130                 if (val != null) {\r
131                         cbuilder.removeParam("sg");\r
132                         cbuilder.setFirst(val);\r
133                 }\r
134                 return super.getParameters(provider);\r
135         }\r
136 }\r