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.IOException;
\r
19 import java.util.Map;
\r
20 import java.util.Set;
\r
21 import java.util.TreeMap;
\r
22 import java.util.TreeSet;
\r
24 import org.apache.log4j.Logger;
\r
26 import compbio.data.sequence.Score;
\r
27 import compbio.data.sequence.ScoreManager;
\r
28 import compbio.data.sequence.SequenceUtil;
\r
29 import compbio.data.sequence.UnknownFileFormatException;
\r
30 import compbio.engine.client.SkeletalExecutable;
\r
31 import compbio.metadata.ResultNotAvailableException;
\r
34 * iupred sequenceFile <short long glob >
\r
36 * Maximum sequence length is 40000 chars. Single string length max is a 1000
\r
40 public class IUPred extends SkeletalExecutable<IUPred> {
\r
42 private static Logger log = Logger.getLogger(IUPred.class);
\r
43 private static final String GLOB_OUTPUT = "out.glob";
\r
44 private static final String SHORT_OUTPUT = "out.short";
\r
45 private static final String LONG_OUTPUT = "out.long";
\r
48 @SuppressWarnings("unchecked")
\r
49 public ScoreManager getResults(String workDirectory)
\r
50 throws ResultNotAvailableException {
\r
52 ScoreManager results = null;
\r
54 Map<String, Set<Score>> combined = new TreeMap<String, Set<Score>>();
\r
56 File shortf = new File(workDirectory, SHORT_OUTPUT);
\r
57 if(shortf.exists()) {
\r
58 combineScores(combined, SequenceUtil.readIUPred(shortf));
\r
60 File longf = new File(workDirectory, LONG_OUTPUT);
\r
61 if(longf.exists()) {
\r
62 combineScores(combined, SequenceUtil.readIUPred(longf));
\r
65 File glob = new File(workDirectory, GLOB_OUTPUT);
\r
67 combineScores(combined, SequenceUtil.readIUPred(glob));
\r
69 if(combined.isEmpty()) {
\r
70 throw new ResultNotAvailableException("Could not find any result " +
\r
71 "files for the job: " + workDirectory);
\r
73 results = ScoreManager.newInstance(combined);
\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
88 void combineScores(Map<String, Set<Score>> combined, Map<String, Score> scores) {
\r
92 if (combined.isEmpty()) {
\r
93 for (String key : scores.keySet()) {
\r
94 Set<Score> allScores = new TreeSet<Score>();
\r
95 combined.put(key, allScores);
\r
98 for (String key : scores.keySet()) {
\r
99 Set<Score> allScores= combined.get(key);
\r
100 assert allScores!=null;
\r
101 Score score = scores.get(key);
\r
102 allScores.add(score);
\r
103 combined.put(key, allScores);
\r
108 public IUPred setInput(String inFile) {
\r
109 super.setInput(inFile);
\r
110 cbuilder.setFirst(inFile);
\r
115 public IUPred setOutput(String outFile) {
\r
116 log.warn("IUpred output is predefined and cannot be set!");
\r
120 UnsupportedOperationException newUnsupportedOutputException() {
\r
121 return new UnsupportedOperationException("The outputs from this executable " +
\r
122 "are always either of those 3 files (depending on the method called): " + GLOB_OUTPUT + ", "
\r
123 + SHORT_OUTPUT + ", "+ LONG_OUTPUT);
\r
127 public String getOutput() {
\r
128 log.warn("IUpred output is predefined and is one of the three files " +
\r
129 "(depending on the method called): " + GLOB_OUTPUT + ", "
\r
130 + SHORT_OUTPUT + ", "+ LONG_OUTPUT);
\r
131 return LONG_OUTPUT;
\r
134 @SuppressWarnings("unchecked")
\r
136 public Class<IUPred> getType() {
\r
137 return (Class<IUPred>) this.getClass();
\r