Fix copyright header
[jabaws.git] / runner / compbio / runner / disorder / RonnWrapper.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 import java.util.List;\r
25 \r
26 import org.apache.log4j.Logger;\r
27 \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 public class RonnWrapper extends SkeletalExecutable<RonnWrapper> implements\r
39         PipedExecutable<RonnWrapper> {\r
40     /*\r
41      * RONN does not accept stdin the file name must be defined as parameter It\r
42      * can only analyse ONE sequence per run! (or may be not, but the results\r
43      * gets overriden!) FASTA format is accepted.\r
44      * \r
45      * To run it do the following:\r
46      * \r
47      * 1) copy ronn executables and task file to work directory\r
48      * \r
49      * 2) execute run processes one by one for each sequence\r
50      */\r
51 \r
52     private static final String command = "/homes/pvtroshin/soft/RONNv3_fasta/Ronn_runner.sh";\r
53 \r
54     private static Logger log = Logger.getLogger(RonnWrapper.class);\r
55 \r
56     // Cache for Limits information\r
57     private static LimitsManager<RonnWrapper> limits;\r
58 \r
59     public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
60 \r
61     @SuppressWarnings("unchecked")\r
62     @Override\r
63     public Alignment getResults(String workDirectory)\r
64             throws ResultNotAvailableException {\r
65         try {\r
66             return Util.readClustalFile(workDirectory, getOutput());\r
67         } catch (FileNotFoundException e) {\r
68             log.error(e.getMessage(), e.getCause());\r
69             throw new ResultNotAvailableException(e);\r
70         } catch (IOException e) {\r
71             log.error(e.getMessage(), e.getCause());\r
72             throw new ResultNotAvailableException(e);\r
73         } catch (UnknownFileFormatException e) {\r
74             log.error(e.getMessage(), e.getCause());\r
75             throw new ResultNotAvailableException(e);\r
76         } catch (NullPointerException e) {\r
77             log.error(e.getMessage(), e.getCause());\r
78             throw new ResultNotAvailableException(e);\r
79         }\r
80     }\r
81 \r
82     @Override\r
83     public List<String> getCreatedFiles() {\r
84         return Arrays.asList(getOutput(), getError());\r
85     }\r
86 \r
87     @Override\r
88     public RonnWrapper setInput(String inFile) {\r
89         String input = getInput();\r
90         super.setInput(inFile);\r
91         return this;\r
92     }\r
93 \r
94     @Override\r
95     public Limit<RonnWrapper> getLimit(String presetName) {\r
96         if (limits == null) {\r
97             limits = getLimits();\r
98         }\r
99         Limit<RonnWrapper> limit = null;\r
100         if (limits != null) {\r
101             // this returns default limit if preset is undefined!\r
102             limit = limits.getLimitByName(presetName);\r
103         }\r
104         // If limit is not defined for a particular preset, then return default\r
105         // limit\r
106         if (limit == null) {\r
107             log.debug("Limit for the preset " + presetName\r
108                     + " is not found. Using default");\r
109             limit = limits.getDefaultLimit();\r
110         }\r
111         return limit;\r
112     }\r
113 \r
114     @Override\r
115     public LimitsManager<RonnWrapper> getLimits() {\r
116         // synchronise on static field\r
117         synchronized (log) {\r
118             if (limits == null) {\r
119                 limits = Util.getLimits(this.getClass());\r
120             }\r
121         }\r
122         return limits;\r
123     }\r
124 \r
125     @Override\r
126     public Class<? extends Executable<?>> getType() {\r
127         return this.getClass();\r
128     }\r
129 }\r