--- /dev/null
+/* Copyright (c) 2013 Alexander Sherstnev\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 3.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
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+\r
+package compbio.runner.predictors;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.util.Arrays;\r
+import java.util.List;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.sequence.ScoreManager;\r
+import compbio.data.sequence.SequenceUtil;\r
+import compbio.engine.client.CommandBuilder;\r
+import compbio.engine.client.Executable;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.metadata.ResultNotAvailableException;\r
+\r
+/**\r
+ * Command line\r
+ * \r
+ * jpred.pl -in d16vpa_.fas -out res_d16vpa_ -dbname ported_db -dbpath /data/UNIREFdb -ncpu 4\r
+ * \r
+ * @author asherstnev\r
+ * \r
+ */\r
+public class Jpred extends SkeletalExecutable<Jpred> {\r
+\r
+ private static Logger log = Logger.getLogger(Jpred.class);\r
+\r
+ /**\r
+ * Number of cores to use, defaults to 1 for local execution or the value of\r
+ * "jpred.cluster.cpunum" property for cluster execution\r
+ */\r
+ private int ncoreNumber = 0;\r
+\r
+ public static final String KEY_VALUE_SEPARATOR = " ";\r
+ public static final String STAT_FILE = "stat.txt";\r
+\r
+ public Jpred() {\r
+// addParameters(Arrays.asList());\r
+ }\r
+ // HashMap<Method, float[]>\r
+ @Override\r
+ public ScoreManager getResults(String workDirectory)\r
+ throws ResultNotAvailableException {\r
+ ScoreManager annotations = null;\r
+ try {\r
+ InputStream inStream = new FileInputStream(new File(workDirectory, getOutput()));\r
+ annotations = ScoreManager.newInstanceSingleSequence(SequenceUtil.readAAConResults(inStream));\r
+ inStream.close();\r
+ } catch (FileNotFoundException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ } catch (IOException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ } catch (NullPointerException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ }\r
+ return annotations;\r
+ }\r
+\r
+ @Override\r
+ public List<String> getCreatedFiles() {\r
+ return Arrays.asList(getOutput(), getError());\r
+ }\r
+\r
+ @Override\r
+ public Jpred setInput(String inFile) {\r
+ super.setInput(inFile);\r
+ cbuilder.setParam("-in " + inFile);\r
+ return this;\r
+ }\r
+\r
+ @Override\r
+ public Jpred setOutput(String outFile) {\r
+ super.setOutput(outFile);\r
+ cbuilder.setParam("-out " + outFile);\r
+ return this;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public Class<Jpred> getType() {\r
+ return (Class<Jpred>) this.getClass();\r
+ }\r
+\r
+ public static String getStatFile() {\r
+ return STAT_FILE;\r
+ }\r
+\r
+ public void setNCore(int ncoreNumber) {\r
+ if (0 < ncoreNumber && ncoreNumber < 9) {\r
+ this.ncoreNumber = ncoreNumber;\r
+ cbuilder.setParam("-ncpu " + Integer.toString(getNCore()));\r
+ } else {\r
+ throw new IndexOutOfBoundsException("Number of cores must be between 1 and 8 ");\r
+ }\r
+ }\r
+\r
+ int getNCore() {\r
+ return ncoreNumber;\r
+ }\r
+\r
+ @Override\r
+ public CommandBuilder<Jpred> getParameters(ExecProvider provider) {\r
+ // If number of cores is provided, set it for the cluster execution only!\r
+ if (provider == Executable.ExecProvider.Cluster) {\r
+ int cpunum = SkeletalExecutable.getClusterCpuNum(getType());\r
+ cpunum = (cpunum == 0) ? 1 : cpunum;\r
+ setNCore(cpunum);\r
+ } else {\r
+ // Limit number of cores to 1 for ANY execution which does not set\r
+ // Ncores explicitly using setNCore method or is run on local VM\r
+ if (ncoreNumber == 0) {\r
+ setNCore(1);\r
+ }\r
+ }\r
+ return super.getParameters(provider);\r
+ }\r
+\r
+}\r