Change header template for a new version
[jabaws.git] / runner / compbio / runner / Util.java
index a3c86c6..8d77864 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
@@ -23,127 +23,112 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;\r
 import java.io.IOException;\r
 import java.util.List;\r
+import java.util.Map;\r
 \r
 import org.apache.log4j.Logger;\r
 \r
 import compbio.data.sequence.Alignment;\r
 import compbio.data.sequence.ClustalAlignmentUtil;\r
 import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.Score;\r
 import compbio.data.sequence.SequenceUtil;\r
 import compbio.data.sequence.UnknownFileFormatException;\r
 import compbio.engine.client.ConfExecutable;\r
 import compbio.engine.client.ConfiguredExecutable;\r
 import compbio.engine.client.Executable;\r
 import compbio.engine.conf.PropertyHelperManager;\r
-import compbio.metadata.LimitsManager;\r
+import compbio.metadata.JobSubmissionException;\r
 import compbio.metadata.PresetManager;\r
 import compbio.metadata.RunnerConfig;\r
 import compbio.util.PropertyHelper;\r
 \r
 public final class Util {\r
 \r
-    private static Logger log = Logger.getLogger(Util.class);\r
-\r
-    private static final PropertyHelper ph = PropertyHelperManager\r
-           .getPropertyHelper();\r
-\r
-    public static final String SPACE = " ";\r
-\r
-    /**\r
-     * For now just assume that all parameters which came in needs setting it\r
-     * will be a client responsibility to prepare RunnerConfig object then\r
-     * \r
-     * @param rconfig\r
-     * @return\r
-     * \r
-     *         public static List<String> toOptionString(RunnerConfig<?>\r
-     *         rconfig) { String option = ""; List<String> options = new\r
-     *         ArrayList<String>(); for (Parameter<?> par :\r
-     *         rconfig.getParameters()) { if (par.getPossibleValues().isEmpty())\r
-     *         { option = par.getOptionName(); } else { option =\r
-     *         par.getOptionName() + "=" + par.getPossibleValues().get(0); } //\r
-     *         separate options options.add(option); } return options; }\r
-     */\r
-\r
-    public static <T> LimitsManager<T> getLimits(\r
-           Class<? extends Executable<T>> clazz) {\r
-       LimitsManager<T> limits = null;\r
-       try {\r
-           limits = ConfExecutable.getRunnerLimits(clazz);\r
-           if (limits == null) {\r
+       public static Logger log = Logger.getLogger(Util.class);\r
+\r
+       private static final PropertyHelper ph = PropertyHelperManager\r
+                       .getPropertyHelper();\r
+\r
+       public static final String SPACE = " ";\r
+\r
+       public static synchronized <T> RunnerConfig<T> getSupportedOptions(\r
+                       Class<? extends Executable<T>> clazz) {\r
+               try {\r
+                       return ConfExecutable.getRunnerOptions(clazz);\r
+               } catch (FileNotFoundException e) {\r
+                       log.error(\r
+                                       "Could not load " + clazz + " Parameters !"\r
+                                                       + e.getMessage(), e.getCause());\r
+               } catch (IOException e) {\r
+                       log.error("IO exception while reading " + clazz + " Parameters !"\r
+                                       + e.getMessage(), e.getCause());\r
+               }\r
                return null;\r
-           }\r
-       } catch (FileNotFoundException e) {\r
-           log.warn("No limits are found for " + clazz + " executable! "\r
-                   + e.getLocalizedMessage(), e.getCause());\r
-           return null;\r
-       } catch (IOException e) {\r
-           log.warn("IO exception while attempting to read limits for "\r
-                   + clazz + " executable! " + e.getLocalizedMessage(), e\r
-                   .getCause());\r
-           return null;\r
        }\r
-       return limits;\r
-    }\r
 \r
-    public static synchronized <T> RunnerConfig<T> getSupportedOptions(\r
-           Class<? extends Executable<T>> clazz) {\r
-       try {\r
-           return ConfExecutable.getRunnerOptions(clazz);\r
-       } catch (FileNotFoundException e) {\r
-           log.error("Could not load " + clazz + " Parameters !"\r
-                   + e.getMessage(), e.getCause());\r
-       } catch (IOException e) {\r
-           log.error("IO exception while reading " + clazz + " Parameters !"\r
-                   + e.getMessage(), e.getCause());\r
+       public static <T> PresetManager<T> getPresets(\r
+                       Class<? extends Executable<T>> clazz) {\r
+               try {\r
+                       return ConfExecutable.getRunnerPresets(clazz);\r
+               } catch (FileNotFoundException e) {\r
+                       log.warn(\r
+                                       "No presets are found for " + clazz + " executable! "\r
+                                                       + e.getLocalizedMessage(), e.getCause());\r
+               } catch (IOException e) {\r
+                       log.warn("IO exception while reading presents! for " + clazz\r
+                                       + " executable! " + e.getLocalizedMessage(), e.getCause());\r
+               }\r
+               return null;\r
        }\r
-       return null;\r
-    }\r
 \r
-    public static <T> PresetManager<T> getPresets(\r
-           Class<? extends Executable<T>> clazz) {\r
-       try {\r
-           return ConfExecutable.getRunnerPresets(clazz);\r
-       } catch (FileNotFoundException e) {\r
-           log.warn("No presets are found for " + clazz + " executable! "\r
-                   + e.getLocalizedMessage(), e.getCause());\r
-       } catch (IOException e) {\r
-           log.warn("IO exception while reading presents! for " + clazz\r
-                   + " executable! " + e.getLocalizedMessage(), e.getCause());\r
+       public static final Alignment readClustalFile(String workDirectory,\r
+                       String clustFile) throws UnknownFileFormatException, IOException,\r
+                       FileNotFoundException, NullPointerException {\r
+               assert !compbio.util.Util.isEmpty(workDirectory);\r
+               assert !compbio.util.Util.isEmpty(clustFile);\r
+               File cfile = new File(compbio.engine.client.Util.getFullPath(\r
+                               workDirectory, clustFile));\r
+               log.trace("CLUSTAL OUTPUT FILE PATH: " + cfile.getAbsolutePath());\r
+               if (!(cfile.exists() && cfile.length() > 0)) {\r
+                       throw new FileNotFoundException("Result for the jobId "\r
+                                       + workDirectory + " with file name " + clustFile\r
+                                       + " is not found!");\r
+               }\r
+               return ClustalAlignmentUtil.readClustalFile(cfile);\r
        }\r
-       return null;\r
-    }\r
 \r
-    public static final Alignment readClustalFile(String workDirectory,\r
-           String clustFile) throws UnknownFileFormatException, IOException,\r
-           FileNotFoundException, NullPointerException {\r
-       assert !compbio.util.Util.isEmpty(workDirectory);\r
-       assert !compbio.util.Util.isEmpty(clustFile);\r
-       File cfile = new File(compbio.engine.client.Util.getFullPath(\r
-               workDirectory, clustFile));\r
-       log.trace("CLUSTAL OUTPUT FILE PATH: " + cfile.getAbsolutePath());\r
-       if (!(cfile.exists() && cfile.length() > 0)) {\r
-           throw new FileNotFoundException("Result for the jobId "\r
-                   + workDirectory + " with file name " + clustFile\r
-                   + " is not found!");\r
+       public static final Map<String, Score> readJronnFile(String workDirectory,\r
+                       String clustFile) throws UnknownFileFormatException, IOException,\r
+                       FileNotFoundException, NullPointerException {\r
+               assert !compbio.util.Util.isEmpty(workDirectory);\r
+               assert !compbio.util.Util.isEmpty(clustFile);\r
+               File cfile = new File(compbio.engine.client.Util.getFullPath(\r
+                               workDirectory, clustFile));\r
+               log.trace("Jronn OUTPUT FILE PATH: " + cfile.getAbsolutePath());\r
+               if (!(cfile.exists() && cfile.length() > 0)) {\r
+                       throw new FileNotFoundException("Result for the jobId "\r
+                                       + workDirectory + " with file name " + clustFile\r
+                                       + " is not found!");\r
+               }\r
+               return SequenceUtil.readJRonn(cfile);\r
        }\r
-       return ClustalAlignmentUtil.readClustalFile(cfile);\r
-    }\r
-\r
-    public static void writeInput(List<FastaSequence> sequences,\r
-           ConfiguredExecutable<?> exec) {\r
 \r
-       File filein = new File(exec.getInput());\r
-       try {\r
-           FileOutputStream fout = new FileOutputStream(filein);\r
-           log.debug("File path: " + filein.getAbsolutePath());\r
-           SequenceUtil.writeFasta(fout, sequences);\r
-           fout.close();\r
-       } catch (FileNotFoundException e) {\r
-           e.printStackTrace();\r
-       } catch (IOException e) {\r
-           e.printStackTrace();\r
+       public static void writeInput(List<FastaSequence> sequences,\r
+                       ConfiguredExecutable<?> exec) 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.writeFasta(fout, sequences);\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 by JABAWS server seems to have a problem! "\r
+                                                       + e.getLocalizedMessage(), e);\r
+               }\r
        }\r
-    }\r
 \r
 }\r