Adding AAConWS
[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.io.FileNotFoundException;\r
18 import java.io.IOException;\r
19 import java.util.Arrays;\r
20 \r
21 import org.apache.log4j.Logger;\r
22 \r
23 import compbio.data.sequence.Alignment;\r
24 import compbio.data.sequence.UnknownFileFormatException;\r
25 import compbio.engine.client.Executable;\r
26 import compbio.engine.client.PipedExecutable;\r
27 import compbio.engine.client.SkeletalExecutable;\r
28 import compbio.metadata.Limit;\r
29 import compbio.metadata.LimitsManager;\r
30 import compbio.metadata.ResultNotAvailableException;\r
31 import compbio.runner.Util;\r
32 \r
33 /**\r
34  * @see DisEMBL\r
35  * \r
36  *      DisEMBL.py smooth_frame peak_frame join_frame fold_coils fold_hotloops\r
37  *      fold_rem465 sequence_file print 'A default run would be: ./DisEMBL.py 8\r
38  *      8 4 1.2 1.4 1.2 fasta_file > out' new DisEMBL is at\r
39  *      /homes/pvtroshin/soft/DisEMBL-1.4raw\r
40  * \r
41  *      This is not a standard DisEMBL! The script has been modified! DisEMBL.py\r
42  *      smooth_frame peak_frame join_frame fold_coils fold_hotloops fold_rem465\r
43  *      [mode] < fasta_file > out print\r
44  * \r
45  *      'A default run would be: ./DisEMBL.py 8 8 4 1.2 1.4 1.2 < fasta_file'\r
46  *      print 'Mode: "default"(nothing) or "scores" which will give scores per\r
47  *      residue in TAB separated format'\r
48  */\r
49 public class Disembl extends SkeletalExecutable<Disembl> implements\r
50                 PipedExecutable<Disembl> {\r
51 \r
52         private static Logger log = Logger.getLogger(Disembl.class);\r
53 \r
54         // Cache for Limits information\r
55         private static LimitsManager<Disembl> limits;\r
56 \r
57         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
58 \r
59         public Disembl() {\r
60                 // remove default input to prevent it to appear in the parameters list\r
61                 // that could happen if the parameters are set first\r
62                 // super.setInput("");\r
63                 addParameters(Arrays.asList("8", "8", "4", "1.2", "1.4", "1.2",\r
64                                 "scores"));\r
65         }\r
66 \r
67         @SuppressWarnings("unchecked")\r
68         public Alignment getResults(String workDirectory)\r
69                         throws ResultNotAvailableException {\r
70                 try {\r
71                         return Util.readClustalFile(workDirectory, getOutput());\r
72                 } catch (FileNotFoundException e) {\r
73                         log.error(e.getMessage(), e.getCause());\r
74                         throw new ResultNotAvailableException(e);\r
75                 } catch (IOException e) {\r
76                         log.error(e.getMessage(), e.getCause());\r
77                         throw new ResultNotAvailableException(e);\r
78                 } catch (UnknownFileFormatException e) {\r
79                         log.error(e.getMessage(), e.getCause());\r
80                         throw new ResultNotAvailableException(e);\r
81                 } catch (NullPointerException e) {\r
82                         log.error(e.getMessage(), e.getCause());\r
83                         throw new ResultNotAvailableException(e);\r
84                 }\r
85         }\r
86 \r
87         @Override\r
88         public Disembl setInput(String inFile) {\r
89                 super.setInput(inFile);\r
90                 cbuilder.setLast(inFile);\r
91                 return this;\r
92         }\r
93 \r
94         @Override\r
95         public Limit<Disembl> getLimit(String presetName) {\r
96                 if (limits == null) {\r
97                         limits = getLimits();\r
98                 }\r
99 \r
100                 Limit<Disembl> limit = null;\r
101                 if (limits != null) {\r
102                         // this returns default limit if preset is undefined!\r
103                         limit = limits.getLimitByName(presetName);\r
104                 }\r
105                 // If limit is not defined for a particular preset, then return default\r
106                 // limit\r
107                 if (limit == null) {\r
108                         log.debug("Limit for the preset " + presetName\r
109                                         + " is not found. Using default");\r
110                         limit = limits.getDefaultLimit();\r
111                 }\r
112                 return limit;\r
113         }\r
114 \r
115         @Override\r
116         public LimitsManager<Disembl> getLimits() {\r
117                 // synchronise on static field\r
118                 synchronized (log) {\r
119                         if (limits == null) {\r
120                                 limits = Util.getLimits(this.getClass());\r
121                         }\r
122                 }\r
123                 return limits;\r
124         }\r
125 \r
126         @Override\r
127         public Class<? extends Executable<?>> getType() {\r
128                 return this.getClass();\r
129         }\r
130 \r
131 }\r