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