Simple datamodel for RNAalifold.exe output and method to convert from
[jabaws.git] / runner / compbio / runner / Util.java
index 41bddd4..f033bf0 100644 (file)
@@ -1,6 +1,6 @@
-/* Copyright (c) 2009 Peter Troshin\r
+/* Copyright (c) 2011 Peter Troshin\r
  *  \r
- *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
  * \r
  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
  *  Apache License version 2 as published by the Apache Software Foundation\r
@@ -19,6 +19,7 @@
 package compbio.runner;\r
 \r
 import java.io.File;\r
+import java.io.FileInputStream;\r
 import java.io.FileNotFoundException;\r
 import java.io.FileOutputStream;\r
 import java.io.IOException;\r
@@ -30,6 +31,7 @@ import org.apache.log4j.Logger;
 import compbio.data.sequence.Alignment;\r
 import compbio.data.sequence.ClustalAlignmentUtil;\r
 import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.RNAstruct;\r
 import compbio.data.sequence.Score;\r
 import compbio.data.sequence.SequenceUtil;\r
 import compbio.data.sequence.UnknownFileFormatException;\r
@@ -130,5 +132,41 @@ public final class Util {
                                                        + e.getLocalizedMessage(), e);\r
                }\r
        }\r
+       \r
+       public static void writeClustalInput(List<FastaSequence> sequences,\r
+                       ConfiguredExecutable<?> exec, char gapChar) throws JobSubmissionException {\r
+               \r
+               try {\r
+                       File filein = new File(exec.getInput());\r
+                       FileOutputStream fout = new FileOutputStream(filein);\r
+                       log.debug("File path: " + filein.getAbsolutePath());\r
+                       SequenceUtil.writeClustal(fout, sequences, gapChar);\r
+                       fout.close();\r
+               } catch (IOException e) {\r
+                       log.error("IOException while writing input file into the disk: "\r
+                                       + e.getLocalizedMessage(), e);\r
+                       throw new JobSubmissionException(\r
+                                       "We are sorry but JABAWS server seems to have a problem! "\r
+                                               + e.getLocalizedMessage(), e);\r
+               }\r
+       }\r
+       \r
+       public static final RNAstruct readRNAStructFile(String workDirectory,\r
+                       String structFile) throws IOException, FileNotFoundException {\r
+               assert !compbio.util.Util.isEmpty(workDirectory);\r
+               assert !compbio.util.Util.isEmpty(structFile);\r
+               File sfile = new File(compbio.engine.client.Util.getFullPath(\r
+                               workDirectory, structFile));\r
+               log.trace("RNAALIFOLD OUTPUT FILE PATH: " + sfile.getAbsolutePath());\r
+               if(!(sfile.exists() && sfile.length() > 0)) {\r
+                       throw new FileNotFoundException("Result for the jobId "\r
+                                       + workDirectory + "with file name " + structFile\r
+                                       + " is not found!");\r
+               }\r
+               return compbio.data.sequence.SequenceUtil.readRNAalifoldResults(\r
+                               new FileInputStream(sfile));\r
+       }\r
+       \r
+       \r
 \r
 }\r