Webservice which implements FoldWS and returns String. Parameters.xml file
[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.RNAstruct;
16 import compbio.data.sequence.UnknownFileFormatException;
17 import compbio.engine.client.PipedExecutable;
18 import compbio.engine.client.SkeletalExecutable;
19 import compbio.metadata.ResultNotAvailableException;
20 import compbio.runner.Util;
21
22
23 import compbio.engine.client.CommandBuilder;
24
25 public class RNAalifold extends SkeletalExecutable<RNAalifold> 
26                 implements PipedExecutable<RNAalifold> {
27         
28         
29         private static Logger log = Logger.getLogger(RNAalifold.class);
30
31         // May not be necessary as defult is "<space>" but still dont know
32         // How to deal with different key value separators for different params
33         public static final String KEY_VALUE_SEPARATOR = " ";
34         
35         public RNAalifold() {
36                 super(KEY_VALUE_SEPARATOR);
37         }
38         
39         @Override
40         public RNAalifold setOutput(String outFile) {
41                 super.setOutput(outFile);
42                 return this;
43         }
44         
45         @Override
46         public RNAalifold setInput(String inFile) {
47                 cbuilder.setLast(inFile);
48                 super.setInput(inFile);
49                 return this;
50         }
51         
52         @SuppressWarnings("unchecked")
53         @Override
54         public Class<RNAalifold> getType() {
55                 return (Class<RNAalifold>) this.getClass();
56         }
57         
58         @SuppressWarnings("unchecked")
59         @Override
60         // PlaceHolder method
61         public String getResults(String workDirectory)
62                         throws ResultNotAvailableException {
63                 try {
64                         return Util.readRNAStruct(workDirectory, getOutput());
65                         
66                 } catch (FileNotFoundException e) {
67                         log.error(e.getMessage(), e.getCause());
68                         throw new ResultNotAvailableException(e);
69                 } catch (IOException e) {
70                         log.error(e.getMessage(), e.getCause());
71                         throw new ResultNotAvailableException(e);
72                 }
73         }
74
75
76         // the new currently used methods for reading are found in 
77         // - compbio.data.sequence.SequenceUtil and 
78         // - compbio.runner.Util
79         
80         // Simple and generic methods for reading a whole file
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 }