30e87763212bc51039e808e722ec9b00a3ba8a9e
[jabaws.git] / runner / compbio / runner / disorder / IUPred.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.FileNotFoundException;\r
19 import java.io.IOException;\r
20 import java.util.Map;\r
21 import java.util.Set;\r
22 import java.util.TreeMap;\r
23 import java.util.TreeSet;\r
24 \r
25 import org.apache.log4j.Logger;\r
26 \r
27 import compbio.data.sequence.Score;\r
28 import compbio.data.sequence.ScoreManager;\r
29 import compbio.data.sequence.SequenceUtil;\r
30 import compbio.data.sequence.UnknownFileFormatException;\r
31 import compbio.engine.client.SkeletalExecutable;\r
32 import compbio.metadata.ResultNotAvailableException;\r
33 \r
34 /**\r
35  * iupred sequenceFile <short long glob >\r
36  * \r
37  * Maximum sequence length is 40000 chars. Single string length max is a 1000\r
38  * chars!\r
39  * \r
40  */\r
41 public class IUPred extends SkeletalExecutable<IUPred> {\r
42 \r
43         private static Logger log = Logger.getLogger(IUPred.class);\r
44         private static final String GLOB_SUFFIX = ".glob";\r
45         private static final String SHORT_SUFFIX = ".short";\r
46         private static final String LONG_SUFFIX = ".long";\r
47 \r
48         @Override\r
49         @SuppressWarnings("unchecked")\r
50         public ScoreManager getResults(String workDirectory)\r
51                         throws ResultNotAvailableException {\r
52 \r
53                 ScoreManager results = null;\r
54                 try {\r
55 \r
56                         Map<String, Score> globScores = SequenceUtil.readIUPred(new File(\r
57                                         workDirectory, getOutput() + GLOB_SUFFIX));\r
58                         Map<String, Score> shortScores = SequenceUtil.readIUPred(new File(\r
59                                         workDirectory, getOutput() + SHORT_SUFFIX));\r
60                         Map<String, Score> longScores = SequenceUtil.readIUPred(new File(\r
61                                         workDirectory, getOutput() + LONG_SUFFIX));\r
62                         Map<String, Set<Score>> combined = new TreeMap<String, Set<Score>>();\r
63                         for (String key : globScores.keySet()) {\r
64                                 Set<Score> all = new TreeSet<Score>();\r
65                                 Score globsc = globScores.get(key);\r
66                                 assert globsc != null;\r
67                                 Score shortsc = shortScores.get(key);\r
68                                 assert shortsc != null;\r
69                                 all.add(shortsc);\r
70                                 Score longsc = longScores.get(key);\r
71                                 assert longsc != null;\r
72                                 all.add(longsc);\r
73                                 combined.put(key, all);\r
74                         }\r
75                         results = ScoreManager.newInstance(combined);\r
76 \r
77                 } catch (FileNotFoundException e) {\r
78                         log.error(e.getMessage(), e.getCause());\r
79                         throw new ResultNotAvailableException(e);\r
80                 } catch (IOException e) {\r
81                         log.error(e.getMessage(), e.getCause());\r
82                         throw new ResultNotAvailableException(e);\r
83                 } catch (UnknownFileFormatException e) {\r
84                         log.error(e.getMessage(), e.getCause());\r
85                         throw new ResultNotAvailableException(e);\r
86                 } catch (NullPointerException e) {\r
87                         log.error(e.getMessage(), e.getCause());\r
88                         throw new ResultNotAvailableException(e);\r
89                 }\r
90                 return results;\r
91         }\r
92 \r
93         @Override\r
94         public IUPred setInput(String inFile) {\r
95                 super.setInput(inFile);\r
96                 cbuilder.setFirst(inFile);\r
97                 return this;\r
98         }\r
99 \r
100         @SuppressWarnings("unchecked")\r
101         @Override\r
102         public Class<IUPred> getType() {\r
103                 return (Class<IUPred>) this.getClass();\r
104         }\r
105 \r
106 }\r