import java.io.File;\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
import java.util.TreeMap;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.engine.client.SkeletalExecutable;\r
import compbio.metadata.ResultNotAvailableException;\r
+import compbio.runner.msa.Mafft;\r
\r
/**\r
* iupred sequenceFile <short long glob >\r
public class IUPred extends SkeletalExecutable<IUPred> {\r
\r
private static Logger log = Logger.getLogger(IUPred.class);\r
- private static final String GLOB_SUFFIX = ".glob";\r
- private static final String SHORT_SUFFIX = ".short";\r
- private static final String LONG_SUFFIX = ".long";\r
+ private static final String GLOB_OUTPUT = "out.glob";\r
+ private static final String SHORT_OUTPUT = "out.short";\r
+ private static final String LONG_OUTPUT = "out.long";\r
\r
+ \r
@Override\r
@SuppressWarnings("unchecked")\r
public ScoreManager getResults(String workDirectory)\r
\r
ScoreManager results = null;\r
try {\r
-\r
- Map<String, Score> globScores = SequenceUtil.readIUPred(new File(\r
- workDirectory, getOutput() + GLOB_SUFFIX));\r
- Map<String, Score> shortScores = SequenceUtil.readIUPred(new File(\r
- workDirectory, getOutput() + SHORT_SUFFIX));\r
- Map<String, Score> longScores = SequenceUtil.readIUPred(new File(\r
- workDirectory, getOutput() + LONG_SUFFIX));\r
Map<String, Set<Score>> combined = new TreeMap<String, Set<Score>>();\r
- for (String key : globScores.keySet()) {\r
- Set<Score> all = new TreeSet<Score>();\r
- Score globsc = globScores.get(key);\r
- assert globsc != null;\r
- Score shortsc = shortScores.get(key);\r
- assert shortsc != null;\r
- all.add(shortsc);\r
- Score longsc = longScores.get(key);\r
- assert longsc != null;\r
- all.add(longsc);\r
- combined.put(key, all);\r
+ \r
+ File shortf = new File(workDirectory, SHORT_OUTPUT);\r
+ if(shortf.exists()) {\r
+ combineScores(combined, SequenceUtil.readIUPred(shortf));\r
+ }\r
+ File longf = new File(workDirectory, LONG_OUTPUT);\r
+ if(longf.exists()) {\r
+ combineScores(combined, SequenceUtil.readIUPred(longf));\r
+ } \r
+ \r
+ File glob = new File(workDirectory, GLOB_OUTPUT);\r
+ if(glob.exists()) {\r
+ combineScores(combined, SequenceUtil.readIUPred(glob));\r
+ }\r
+ if(combined.isEmpty()) {\r
+ throw new ResultNotAvailableException("Could not find any result " +\r
+ "files for the job: " + workDirectory); \r
}\r
results = ScoreManager.newInstance(combined);\r
\r
- } catch (FileNotFoundException e) {\r
- log.error(e.getMessage(), e.getCause());\r
- throw new ResultNotAvailableException(e);\r
} catch (IOException e) {\r
log.error(e.getMessage(), e.getCause());\r
throw new ResultNotAvailableException(e);\r
return results;\r
}\r
\r
+ void combineScores(Map<String, Set<Score>> combined, Map<String, Score> scores) { \r
+ if(scores==null) { \r
+ return; \r
+ }\r
+ if (combined.isEmpty()) {\r
+ for (String key : scores.keySet()) {\r
+ Set<Score> allScores = new TreeSet<Score>();\r
+ combined.put(key, allScores);\r
+ }\r
+ }\r
+ for (String key : scores.keySet()) {\r
+ Set<Score> allScores= combined.get(key);\r
+ assert allScores!=null; \r
+ Score score = scores.get(key);\r
+ allScores.add(score);\r
+ combined.put(key, allScores);\r
+ }\r
+ }\r
+\r
+ \r
+ \r
@Override\r
public IUPred setInput(String inFile) {\r
super.setInput(inFile);\r
cbuilder.setFirst(inFile);\r
return this;\r
+ } \r
+\r
+ \r
+ @Override\r
+ public IUPred setOutput(String outFile) {\r
+ log.warn("IUpred output is predefined and cannot be set!"); \r
+ return this; \r
+ }\r
+\r
+ UnsupportedOperationException newUnsupportedOutputException() { \r
+ return new UnsupportedOperationException("The outputs from this executable " +\r
+ "are always either of those 3 files (depending on the method called): " + GLOB_OUTPUT + ", " \r
+ + SHORT_OUTPUT + ", "+ LONG_OUTPUT);\r
+ }\r
+ @Override\r
+ public String getOutput() {\r
+ log.warn("IUpred output is predefined and is one of the three files " +\r
+ "(depending on the method called): " + GLOB_OUTPUT + ", " \r
+ + SHORT_OUTPUT + ", "+ LONG_OUTPUT);\r
+ return LONG_OUTPUT;\r
}\r
\r
@SuppressWarnings("unchecked")\r