Parameters Tester updated. Untested webservice code. generate xsd/wsdl?
[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 import org.apache.log4j.Logger;
15
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;
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         
33         @Override
34         public RNAalifold setOutput(String outFile) {
35                 log.info("Set ouput file: " + outFile.toString());
36                 super.setOutput(outFile);
37                 return this;
38         }
39         
40         @Override
41         public RNAalifold setInput(String inFile) {
42                 log.info("Set input file: " + inFile.toString());
43                 cbuilder.setLast(inFile);
44                 super.setInput(inFile);
45                 return this;
46         }
47         
48         @SuppressWarnings("unchecked")
49         @Override
50         public Class<RNAalifold> getType() {
51                 return (Class<RNAalifold>) this.getClass();
52         }
53         
54         @SuppressWarnings("unchecked")
55         @Override
56         // PlaceHolder method
57         public String getResults(String workDirectory)
58                         throws ResultNotAvailableException {
59                 try {
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);
68                 }
69         }
70
71         
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
84                                         + " is not found!");
85                 }
86                 return readFile(sfile);
87         }
88         
89         private static BufferedReader input;
90         public static String readFile(File inputFile) throws 
91                         FileNotFoundException, IOException {
92                 
93                 input   = new BufferedReader(new FileReader(inputFile));
94                 
95                 String file = new String();
96                 String line = new String();
97                 
98                 while (true) {
99                         line = input.readLine();
100                         
101                         if (line != null) {
102                                 file = file + line + "\r\n";
103                         } else break;
104                 }
105                 // Close file
106                 input.close();
107                 return file;
108         }
109         
110 }