Simple datamodel for RNAalifold.exe output and method to convert from
[jabaws.git] / runner / compbio / runner / structure / RNAalifold.java
1 package compbio.runner.structure;
2
3
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.util.Arrays;
7 import java.util.List;
8
9 //imports for filereader method
10 import java.io.FileReader;
11 import java.io.BufferedReader;
12 import java.io.File;
13
14
15
16 import org.apache.log4j.Logger;
17
18 import compbio.data.sequence.RNAstruct;
19 import compbio.data.sequence.UnknownFileFormatException;
20 import compbio.engine.client.PipedExecutable;
21 import compbio.engine.client.SkeletalExecutable;
22 import compbio.metadata.ResultNotAvailableException;
23 import compbio.runner.Util;
24
25
26 import compbio.engine.client.CommandBuilder;
27
28 public class RNAalifold extends SkeletalExecutable<RNAalifold> 
29                 implements PipedExecutable<RNAalifold> {
30         
31         
32         private static Logger log = Logger.getLogger(RNAalifold.class);
33
34         
35         @Override
36         public RNAalifold setOutput(String outFile) {
37                 log.info("Set ouput file: " + outFile.toString());
38                 super.setOutput(outFile);
39                 return this;
40         }
41         
42         @Override
43         public RNAalifold setInput(String inFile) {
44                 log.info("Set input file: " + inFile.toString());
45                 cbuilder.setLast(inFile);
46                 super.setInput(inFile);
47                 return this;
48         }
49         
50         @SuppressWarnings("unchecked")
51         @Override
52         public Class<RNAalifold> getType() {
53                 return (Class<RNAalifold>) this.getClass();
54         }
55         
56         @SuppressWarnings("unchecked")
57         @Override
58         // PlaceHolder method
59         public RNAstruct getResults(String workDirectory)
60                         throws ResultNotAvailableException {
61                 try {
62                         // System.out.println("Specialread " + Util.readRNAStructFile(workDirectory, getOutput()).toString());
63                         return Util.readRNAStructFile(workDirectory, getOutput());
64                         
65                 } catch (FileNotFoundException e) {
66                         log.error(e.getMessage(), e.getCause());
67                         throw new ResultNotAvailableException(e);
68                 } catch (IOException e) {
69                         log.error(e.getMessage(), e.getCause());
70                         throw new ResultNotAvailableException(e);
71                 }
72         }
73
74
75         // OLD :- the new methods for reading are found in 
76         // - compbio.data.sequence.SequenceUtil and 
77         // - compbio.runner.Util
78         
79         // Simple and generic methods for reading a whole file
80         // Should surfice until a more detailed datamodel and parser are developed
81 //      private static String readRNAStruct(String workDirectory,
82 //                      String structFile) throws IOException, FileNotFoundException {
83 //              assert !compbio.util.Util.isEmpty(workDirectory);
84 //              assert !compbio.util.Util.isEmpty(structFile);
85 //              File sfile = new File(compbio.engine.client.Util.getFullPath(
86 //                              workDirectory, structFile));
87 //              log.trace("RNAALIFOLD OUTPUT FILE PATH: " + sfile.getAbsolutePath());
88 //              if(!(sfile.exists() && sfile.length() > 0)) {
89 //                      throw new FileNotFoundException("Result for the jobId "
90 //                                      + workDirectory + "with file name " + structFile
91 //                                      + " is not found!");
92 //              }
93 //              return readFile(sfile);
94 //      }
95 //      
96 //      private static BufferedReader input;
97 //      public static String readFile(File inputFile) throws 
98 //                      FileNotFoundException, IOException {
99 //              
100 //              input   = new BufferedReader(new FileReader(inputFile));
101 //              
102 //              String file = new String();
103 //              String line = new String();
104 //              
105 //              while (true) {
106 //                      line = input.readLine();
107 //                      
108 //                      if (line != null) {
109 //                              file = file + line + "\r\n";
110 //                      } else break;
111 //              }
112 //              // Close file
113 //              input.close();
114 //              return file;
115 //      }
116         
117 }