4c76854c6e9efbeca347c3a661a1d83fe2d9fa0c
[jabaws.git] / runner / compbio / runner / disorder / Disembl.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.runner.disorder;\r
20 \r
21 import java.io.FileNotFoundException;\r
22 import java.io.IOException;\r
23 import java.util.Arrays;\r
24 \r
25 import org.apache.log4j.Logger;\r
26 \r
27 import com.sun.xml.internal.bind.api.impl.NameConverter.Standard;\r
28 import compbio.data.sequence.Alignment;\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  * @see Standard DisEMBL DisEMBL.py smooth_frame peak_frame join_frame\r
40  *      fold_coils fold_hotloops fold_rem465 sequence_file print 'A default run\r
41  *      would be: ./DisEMBL.py 8 8 4 1.2 1.4 1.2 fasta_file > out'\r
42  * \r
43  *      new DisEMBL is at /homes/pvtroshin/soft/DisEMBL-1.4raw This is not a\r
44  *      standard DisEMBL! The script has been modified! DisEMBL.py smooth_frame\r
45  *      peak_frame join_frame fold_coils fold_hotloops fold_rem465 [mode] <\r
46  *      fasta_file > out print 'A default run would be: ./DisEMBL.py 8 8 4 1.2\r
47  *      1.4 1.2 < fasta_file' print 'Mode: "default"(nothing) or "scores" which\r
48  *      will give scores per residue in TAB separated format'\r
49  * \r
50  */\r
51 public class Disembl extends SkeletalExecutable<Disembl> implements\r
52         PipedExecutable<Disembl> {\r
53 \r
54     private static Logger log = Logger.getLogger(Disembl.class);\r
55 \r
56     // Cache for Limits information\r
57     private static LimitsManager<Disembl> limits;\r
58 \r
59     public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
60 \r
61     public Disembl() {\r
62         // remove default input to prevent it to appear in the parameters list\r
63         // that could happen if the parameters are set first\r
64         // super.setInput("");\r
65         addParameters(Arrays.asList("8", "8", "4", "1.2", "1.4", "1.2",\r
66                 "scores"));\r
67     }\r
68 \r
69     @SuppressWarnings("unchecked")\r
70     public Alignment getResults(String workDirectory)\r
71             throws ResultNotAvailableException {\r
72         try {\r
73             return Util.readClustalFile(workDirectory, getOutput());\r
74         } catch (FileNotFoundException e) {\r
75             log.error(e.getMessage(), e.getCause());\r
76             throw new ResultNotAvailableException(e);\r
77         } catch (IOException e) {\r
78             log.error(e.getMessage(), e.getCause());\r
79             throw new ResultNotAvailableException(e);\r
80         } catch (UnknownFileFormatException e) {\r
81             log.error(e.getMessage(), e.getCause());\r
82             throw new ResultNotAvailableException(e);\r
83         } catch (NullPointerException e) {\r
84             log.error(e.getMessage(), e.getCause());\r
85             throw new ResultNotAvailableException(e);\r
86         }\r
87     }\r
88 \r
89     @Override\r
90     public Disembl setInput(String inFile) {\r
91         super.setInput(inFile);\r
92         cbuilder.setLast(inFile);\r
93         return this;\r
94     }\r
95 \r
96     @Override\r
97     public Limit<Disembl> getLimit(String presetName) {\r
98         if (limits == null) {\r
99             limits = getLimits();\r
100         }\r
101 \r
102         Limit<Disembl> limit = null;\r
103         if (limits != null) {\r
104             // this returns default limit if preset is undefined!\r
105             limit = limits.getLimitByName(presetName);\r
106         }\r
107         // If limit is not defined for a particular preset, then return default\r
108         // limit\r
109         if (limit == null) {\r
110             log.debug("Limit for the preset " + presetName\r
111                     + " is not found. Using default");\r
112             limit = limits.getDefaultLimit();\r
113         }\r
114         return limit;\r
115     }\r
116 \r
117     @Override\r
118     public LimitsManager<Disembl> getLimits() {\r
119         // synchronise on static field\r
120         synchronized (log) {\r
121             if (limits == null) {\r
122                 limits = Util.getLimits(this.getClass());\r
123             }\r
124         }\r
125         return limits;\r
126     }\r
127 \r
128     @Override\r
129     public Class<? extends Executable<?>> getType() {\r
130         return this.getClass();\r
131     }\r
132 \r
133 }\r