3871ea97407c423794237aea531cb1be6ff3c2ae
[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         // May not be necessary as defult is "<space>" but still dont know
35         // How to deal with different key value separators for different params
36         public static final String KEY_VALUE_SEPARATOR = " ";
37         
38         public RNAalifold() {
39                 super(KEY_VALUE_SEPARATOR);
40         }
41         
42         @Override
43         public RNAalifold setOutput(String outFile) {
44                 super.setOutput(outFile);
45                 return this;
46         }
47         
48         @Override
49         public RNAalifold setInput(String inFile) {
50                 cbuilder.setLast(inFile);
51                 super.setInput(inFile);
52                 return this;
53         }
54         
55         @SuppressWarnings("unchecked")
56         @Override
57         public Class<RNAalifold> getType() {
58                 return (Class<RNAalifold>) this.getClass();
59         }
60         
61         @SuppressWarnings("unchecked")
62         @Override
63         // PlaceHolder method
64         public RNAstruct getResults(String workDirectory)
65                         throws ResultNotAvailableException {
66                 try {
67                         // System.out.println("Specialread " + Util.readRNAStructFile(workDirectory, getOutput()).toString());
68                         return Util.readRNAStructFile(workDirectory, getOutput());
69                         
70                 } catch (FileNotFoundException e) {
71                         log.error(e.getMessage(), e.getCause());
72                         throw new ResultNotAvailableException(e);
73                 } catch (IOException e) {
74                         log.error(e.getMessage(), e.getCause());
75                         throw new ResultNotAvailableException(e);
76                 }
77         }
78
79
80         // the new currently used methods for reading are found in 
81         // - compbio.data.sequence.SequenceUtil and 
82         // - compbio.runner.Util
83         
84         // Simple and generic methods for reading a whole file
85 //      private static String readRNAStruct(String workDirectory,
86 //                      String structFile) throws IOException, FileNotFoundException {
87 //              assert !compbio.util.Util.isEmpty(workDirectory);
88 //              assert !compbio.util.Util.isEmpty(structFile);
89 //              File sfile = new File(compbio.engine.client.Util.getFullPath(
90 //                              workDirectory, structFile));
91 //              log.trace("RNAALIFOLD OUTPUT FILE PATH: " + sfile.getAbsolutePath());
92 //              if(!(sfile.exists() && sfile.length() > 0)) {
93 //                      throw new FileNotFoundException("Result for the jobId "
94 //                                      + workDirectory + "with file name " + structFile
95 //                                      + " is not found!");
96 //              }
97 //              return readFile(sfile);
98 //      }
99 //      
100 //      private static BufferedReader input;
101 //      public static String readFile(File inputFile) throws 
102 //                      FileNotFoundException, IOException {
103 //              
104 //              input   = new BufferedReader(new FileReader(inputFile));
105 //              
106 //              String file = new String();
107 //              String line = new String();
108 //              
109 //              while (true) {
110 //                      line = input.readLine();
111 //                      
112 //                      if (line != null) {
113 //                              file = file + line + "\r\n";
114 //                      } else break;
115 //              }
116 //              // Close file
117 //              input.close();
118 //              return file;
119 //      }
120         
121 }