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
15 package compbio.runner.disorder;
\r
17 import java.io.File;
\r
18 import java.io.FileNotFoundException;
\r
19 import java.io.IOException;
\r
20 import java.util.Arrays;
\r
21 import java.util.List;
\r
22 import java.util.Map;
\r
23 import java.util.Set;
\r
24 import java.util.TreeMap;
\r
25 import java.util.TreeSet;
\r
27 import org.apache.log4j.Logger;
\r
29 import compbio.data.sequence.Score;
\r
30 import compbio.data.sequence.ScoreManager;
\r
31 import compbio.data.sequence.SequenceUtil;
\r
32 import compbio.data.sequence.UnknownFileFormatException;
\r
33 import compbio.engine.client.SkeletalExecutable;
\r
34 import compbio.metadata.ResultNotAvailableException;
\r
35 import compbio.runner.msa.Mafft;
\r
38 * iupred sequenceFile <short long glob >
\r
40 * Maximum sequence length is 40000 chars. Single string length max is a 1000
\r
44 public class IUPred extends SkeletalExecutable<IUPred> {
\r
46 private static Logger log = Logger.getLogger(IUPred.class);
\r
47 private static final String GLOB_OUTPUT = "out.glob";
\r
48 private static final String SHORT_OUTPUT = "out.short";
\r
49 private static final String LONG_OUTPUT = "out.long";
\r
53 @SuppressWarnings("unchecked")
\r
54 public ScoreManager getResults(String workDirectory)
\r
55 throws ResultNotAvailableException {
\r
57 ScoreManager results = null;
\r
59 Map<String, Set<Score>> combined = new TreeMap<String, Set<Score>>();
\r
61 File shortf = new File(workDirectory, SHORT_OUTPUT);
\r
62 if(shortf.exists()) {
\r
63 combineScores(combined, SequenceUtil.readIUPred(shortf));
\r
65 File longf = new File(workDirectory, LONG_OUTPUT);
\r
66 if(longf.exists()) {
\r
67 combineScores(combined, SequenceUtil.readIUPred(longf));
\r
70 File glob = new File(workDirectory, GLOB_OUTPUT);
\r
72 combineScores(combined, SequenceUtil.readIUPred(glob));
\r
74 if(combined.isEmpty()) {
\r
75 throw new ResultNotAvailableException("Could not find any result " +
\r
76 "files for the job: " + workDirectory);
\r
78 results = ScoreManager.newInstance(combined);
\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
93 void combineScores(Map<String, Set<Score>> combined, Map<String, Score> scores) {
\r
97 if (combined.isEmpty()) {
\r
98 for (String key : scores.keySet()) {
\r
99 Set<Score> allScores = new TreeSet<Score>();
\r
100 combined.put(key, allScores);
\r
103 for (String key : scores.keySet()) {
\r
104 Set<Score> allScores= combined.get(key);
\r
105 assert allScores!=null;
\r
106 Score score = scores.get(key);
\r
107 allScores.add(score);
\r
108 combined.put(key, allScores);
\r
115 public IUPred setInput(String inFile) {
\r
116 super.setInput(inFile);
\r
117 cbuilder.setFirst(inFile);
\r
123 public IUPred setOutput(String outFile) {
\r
124 log.warn("IUpred output is predefined and cannot be set!");
\r
128 UnsupportedOperationException newUnsupportedOutputException() {
\r
129 return new UnsupportedOperationException("The outputs from this executable " +
\r
130 "are always either of those 3 files (depending on the method called): " + GLOB_OUTPUT + ", "
\r
131 + SHORT_OUTPUT + ", "+ LONG_OUTPUT);
\r
134 public String getOutput() {
\r
135 log.warn("IUpred output is predefined and is one of the three files " +
\r
136 "(depending on the method called): " + GLOB_OUTPUT + ", "
\r
137 + SHORT_OUTPUT + ", "+ LONG_OUTPUT);
\r
138 return LONG_OUTPUT;
\r
141 @SuppressWarnings("unchecked")
\r
143 public Class<IUPred> getType() {
\r
144 return (Class<IUPred>) this.getClass();
\r