1 package compbio.runner.structure;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.util.Arrays;
9 //imports for filereader method
10 import java.io.FileReader;
11 import java.io.BufferedReader;
14 import org.apache.log4j.Logger;
16 import compbio.data.sequence.Alignment;
17 import compbio.data.sequence.UnknownFileFormatException;
18 import compbio.engine.client.PipedExecutable;
19 import compbio.engine.client.SkeletalExecutable;
20 import compbio.metadata.ResultNotAvailableException;
21 import compbio.runner.Util;
24 import compbio.engine.client.CommandBuilder;
26 public class RNAalifold extends SkeletalExecutable<RNAalifold>
27 implements PipedExecutable<RNAalifold> {
30 private static Logger log = Logger.getLogger(RNAalifold.class);
34 public RNAalifold setOutput(String outFile) {
35 log.info("Set ouput file: " + outFile.toString());
36 super.setOutput(outFile);
41 public RNAalifold setInput(String inFile) {
42 log.info("Set input file: " + inFile.toString());
43 cbuilder.setLast(inFile);
44 super.setInput(inFile);
48 @SuppressWarnings("unchecked")
50 public Class<RNAalifold> getType() {
51 return (Class<RNAalifold>) this.getClass();
54 @SuppressWarnings("unchecked")
57 public String getResults(String workDirectory)
58 throws ResultNotAvailableException {
60 // System.out.print(readRNAStruct(workDirectory, getOutput()));
61 return readRNAStruct(workDirectory, getOutput());
62 } catch (FileNotFoundException e) {
63 log.error(e.getMessage(), e.getCause());
64 throw new ResultNotAvailableException(e);
65 } catch (IOException e) {
66 log.error(e.getMessage(), e.getCause());
67 throw new ResultNotAvailableException(e);
72 // Simple and generic methods for reading a whole file
73 // Should surfice until a more detailed datamodel and parser are developed
74 private static String readRNAStruct(String workDirectory,
75 String structFile) throws IOException, FileNotFoundException {
76 assert !compbio.util.Util.isEmpty(workDirectory);
77 assert !compbio.util.Util.isEmpty(structFile);
78 File sfile = new File(compbio.engine.client.Util.getFullPath(
79 workDirectory, structFile));
80 log.trace("RNAALIFOLD OUTPUT FILE PATH: " + sfile.getAbsolutePath());
81 if(!(sfile.exists() && sfile.length() > 0)) {
82 throw new FileNotFoundException("Result for the jobId "
83 + workDirectory + "with file name " + structFile
86 return readFile(sfile);
89 private static BufferedReader input;
90 public static String readFile(File inputFile) throws
91 FileNotFoundException, IOException {
93 input = new BufferedReader(new FileReader(inputFile));
95 String file = new String();
96 String line = new String();
99 line = input.readLine();
102 file = file + line + "\r\n";