code stringlengths 3 1.18M | language stringclasses 1 value |
|---|---|
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import de.mpg.mpiz.koeln.anna.server.data.DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
interface SerialisationStrategy {
<V extends DataBean> V readDataBean(File file, Class<V> v) throws DataBeanAccessException;
<V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException;
<V extends DataBean> V getNewDataBean();
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.server.data.DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.impl.GFF3DataBeanImpl;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
* @threadSave no need to synchronize (data is volatile), methods from "super"
* already are threadsave.
*
*/
class CachedDiskSerialisation extends GFF3DiskSerialisation {
CachedDiskSerialisation() {
super();
}
CachedDiskSerialisation(LogDispatcher logger) {
super(logger);
}
private volatile boolean dirty = true;
@SuppressWarnings("unchecked")
@Override
public <V extends DataBean> V readDataBean(File file, Class<V> v)
throws DataBeanAccessException {
if (FileUtils.fileCheck(file, true))
;
if (dirty) {
logger.debug(this, "data dirty, reading from disk");
data = super.readDataBean(file, v);
dirty = false;
} else {
logger.debug(this, "reading data from cache");
}
return (V) data;
}
public <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
try {
super.writeDataBean(v, file);
} finally {
this.dirty = true;
}
}
protected <V extends DataBean> V handleCorruptData(File file, Throwable t) {
dirty = true;
data = new GFF3DataBeanImpl();
return super.handleCorruptData(file, t);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
public interface GFF3DataProxy extends DataProxy<GFF3DataBean>{
}
| Java |
package de.mpg.mpiz.koeln.anna.core.starter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class Activator implements BundleActivator {
private class BundleStarter implements Callable<Void> {
private final Collection<Bundle> installedBundles;
BundleStarter(Collection<Bundle> installedBundles) {
this.installedBundles = installedBundles;
}
public Void call() throws Exception {
startBundles(installedBundles);
return null;
}
private void startBundles(Collection<Bundle> installedBundles)
throws BundleException {
if (installedBundles.size() == 0) {
System.err.println("no plugins started");
return;
}
for (Bundle b : installedBundles) {
synchronized (Activator.class) {
b.start();
}
}
}
}
private class BundleInstaller implements Callable<Collection<Bundle>> {
private final File path;
private final BundleContext context;
BundleInstaller(final BundleContext context, final File path) {
this.path = path;
this.context = context;
}
public Collection<Bundle> call() throws Exception {
final Collection<String> bundlePathes = getBundlePathes(path);
final Collection<Bundle> installedBundles = installBundles(bundlePathes);
return installedBundles;
}
private Collection<Bundle> installBundles(
Collection<String> bundlePathes) throws BundleException {
if (bundlePathes.size() == 0) {
System.err.println("no plugins installed");
return Collections.emptyList();
}
synchronized (Activator.class) {
final List<Bundle> result = new ArrayList<Bundle>();
for (String p : bundlePathes) {
System.err.println("installing " + p);
synchronized (context) {
final Bundle b = context.installBundle(p);
result.add(b);
}
}
return result;
}
}
private Collection<String> getBundlePathes(File path)
throws NoPluginsFoundException {
final List<String> result = new ArrayList<String>();
final File[] content = path.listFiles();
if (content == null || content.length == 0) {
System.err.println("content of dir =" + content);
// throw new
// NoPluginsFoundException("Could not find any plugins in " +
// path);
return Collections.emptyList();
} else {
for (File f : content) {
if (f.isFile()) {
if (f.canRead()) {
final String s = f.toURI().toString();
if (s.endsWith(".jar")) {
System.err.println("Adding " + f
+ " to known plugins list.");
result.add(s);
}
} else {
System.err.println("Cannot read " + f
+ ". Skipping.");
}
} else {
// ignore dirs
}
}
}
return result;
}
}
private final static String PLUGINS_PATH_1 = System.getProperty("user.dir")
+ "/01-libs/";
private final static String PLUGINS_PATH_2 = System.getProperty("user.dir")
+ "/02-anna-libs/";
private final static String PLUGINS_PATH_3 = System.getProperty("user.dir")
+ "/03-anna-core/";
private final static String PLUGINS_PATH_4 = System.getProperty("user.dir")
+ "/04-anna-dataserver/";
private final static String PLUGINS_PATH_5 = System.getProperty("user.dir")
+ "/05-anna-server/";
private final static String PLUGINS_PATH_6 = System.getProperty("user.dir")
+ "/06-anna-steps/";
private final ExecutorService exe = Executors.newSingleThreadExecutor();
public void start(final BundleContext context) throws Exception {
exe.submit(new Runnable() {
public void run() {
try {
// new BundleStarter(new BundleInstaller(context, new
// File(PLUGINS_PATH_0)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_1)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_2)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_3)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_4)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_5)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_6)).call()).call();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void stop(BundleContext context) throws Exception {
System.err.println(this + " stopping");
}
}
| Java |
package de.mpg.mpiz.koeln.anna.core.starter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class Activator implements BundleActivator {
private class BundleStarter implements Callable<Void> {
private final Collection<Bundle> installedBundles;
BundleStarter(Collection<Bundle> installedBundles) {
this.installedBundles = installedBundles;
}
public Void call() throws Exception {
startBundles(installedBundles);
return null;
}
private void startBundles(Collection<Bundle> installedBundles)
throws BundleException {
if (installedBundles.size() == 0) {
System.err.println("no plugins started");
return;
}
for (Bundle b : installedBundles) {
synchronized (Activator.class) {
b.start();
}
}
}
}
private class BundleInstaller implements Callable<Collection<Bundle>> {
private final File path;
private final BundleContext context;
BundleInstaller(final BundleContext context, final File path) {
this.path = path;
this.context = context;
}
public Collection<Bundle> call() throws Exception {
final Collection<String> bundlePathes = getBundlePathes(path);
final Collection<Bundle> installedBundles = installBundles(bundlePathes);
return installedBundles;
}
private Collection<Bundle> installBundles(
Collection<String> bundlePathes) throws BundleException {
if (bundlePathes.size() == 0) {
System.err.println("no plugins installed");
return Collections.emptyList();
}
synchronized (Activator.class) {
final List<Bundle> result = new ArrayList<Bundle>();
for (String p : bundlePathes) {
// System.err.println("installing " + p);
synchronized (context) {
try{
final Bundle b = context.installBundle(p);
result.add(b);
}catch(Exception e){
System.err.println(e.getLocalizedMessage());
}
}
}
return result;
}
}
private Collection<String> getBundlePathes(File path) {
final List<String> result = new ArrayList<String>();
final File[] content = path.listFiles();
if (content == null || content.length == 0) {
System.err.println("content of dir =" + content);
// throw new
// NoPluginsFoundException("Could not find any plugins in " +
// path);
return Collections.emptyList();
} else {
for (File f : content) {
if (f.isFile()) {
if (f.canRead()) {
final String s = f.toURI().toString();
if (s.endsWith(".jar")) {
// System.err.println("Adding " + f
// + " to known plugins list.");
result.add(s);
}
} else {
System.err.println("Cannot read " + f
+ ". Skipping.");
}
} else {
// ignore dirs
}
}
}
return result;
}
}
private final static String PLUGINS_PATH_1 = System.getProperty("user.dir")
+ "/01-libs00/";
private final static String PLUGINS_PATH_2 = System.getProperty("user.dir")
+ "/01-libs01/";
private final static String PLUGINS_PATH_3 = System.getProperty("user.dir")
+ "/02-anna-libs/";
private final static String PLUGINS_PATH_4 = System.getProperty("user.dir")
+ "/03-anna-core/";
private final static String PLUGINS_PATH_5 = System.getProperty("user.dir")
+ "/04-anna-dataserver/";
private final static String PLUGINS_PATH_6 = System.getProperty("user.dir")
+ "/05-anna-server/";
private final static String PLUGINS_PATH_7 = System.getProperty("user.dir")
+ "/06-anna-listeners/";
private final static String PLUGINS_PATH_8 = System.getProperty("user.dir")
+ "/07-anna-steps/";
private final ExecutorService exe = Executors.newSingleThreadExecutor();
public void start(final BundleContext context) throws Exception {
exe.submit(new Runnable() {
public void run() {
try {
// new BundleStarter(new BundleInstaller(context, new
// File(PLUGINS_PATH_0)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_1)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_2)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_3)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_4)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_5)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_6)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_7)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_8)).call()).call();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void stop(BundleContext context) throws Exception {
System.err.println(this + " stopping");
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.adapter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.kerner.commons.file.AbstractLineByLineReader;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.file.LazyStringWriter;
/**
* <p>
* Try to change line from
* <blockquote>
* contig00001 RepeatMasker similarity 3920 4097 33.7 +Target "Motif:(CGG)n" 3 180
* </blockquote>
* to
* <blockquote>
* contig00001 RepeatMasker similarity 3920 4097 33.7 + Target "Motif:(CGG)n" 3 180
* </blockquote>
* </p>
* @author Alexander Kerner
*
*/
public class ResultsPreprocessor {
private final static String PATTERN_PREFIX = ".+";
private final static String PATTERN_POSTFIX = ".+";
private final static Pattern P_PLUS = Pattern.compile(PATTERN_PREFIX
+ "[\\+]Target" + PATTERN_POSTFIX, Pattern.CASE_INSENSITIVE);
private final static Pattern P_MINUS = Pattern.compile(PATTERN_PREFIX
+ "[-]Target" + PATTERN_POSTFIX, Pattern.CASE_INSENSITIVE);
private class Hans extends AbstractLineByLineReader {
private final List<String> lines = new ArrayList<String>();
@Override
public void handleLine(String line) {
final Matcher m_plus = P_PLUS.matcher(line);
final Matcher m_minus = P_MINUS.matcher(line);
if(m_plus.matches()){
lines.add(line.replace("+Target", "+\tTarget\t"));
} else if(m_minus.matches()) {
lines.add(line.replace("-Target", "-\tTarget\t"));
}else {
lines.add(line);
}
}
public void write(File out) throws IOException{
final StringBuilder b = new StringBuilder(lines.size());
for(String s : lines){
b.append(s);
b.append(FileUtils.NEW_LINE);
}
new LazyStringWriter(b.toString()).write(out);
}
}
public void process(File in, File out) throws IOException{
final Hans hans = new Hans();
hans.read(in);
hans.write(out);
}
public static void main(String[] args){
File inFile = new File("/home/pcb/kerner/anna6/repeatMasker/repMask.out.gff.bak");
File outFile = new File("/home/pcb/kerner/anna6/repeatMasker/repMask.out.gff3");
try {
new ResultsPreprocessor().process(inFile, outFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.lsf;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.lsf.LSF;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradTrainStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class TrainLSF extends AbstractConradTrainStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir,
LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF
.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(ConradConstants.CONRAD_EXE);
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(trainingFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
final Process p = new Process(exeDir, workingDir, logger);
// p.addResultFile(true, trainingFile);
return p;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.lsf;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.lsf.LSF;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradTrainStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class TrainLSF extends AbstractConradTrainStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir,
LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF
.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(ConradConstants.CONRAD_EXE);
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(trainingFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
final Process p = new Process(exeDir, workingDir, logger);
// p.addResultFile(true, trainingFile);
return p;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff.element.NewGFFElement;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
/**
* @lastVisit 2009-08-12
* @ThreadSave custom
* @Exceptions all try-catch-throwable
* @Strings good
* @author Alexander Kerner
*
*/
public abstract class AbstractConradPredictStep extends AbstractConradStep {
protected final static String TRAIN_PREFIX_KEY = "predict.";
protected final static String WORKING_DIR_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ TRAIN_PREFIX_KEY + "workingDir";
// assigned in init(), after that only read
protected File trainingFile;
// assigned in init(), after that only read
protected File resultFile;
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
try {
super.init(context);
logger.debug(this, "doing initialisation");
workingDir = new File(super.getStepProperties().getProperty(
WORKING_DIR_KEY));
logger.debug(this, StringUtils.getString("got working dir=",
workingDir.getAbsolutePath()));
if (!FileUtils.dirCheck(workingDir.getAbsoluteFile(), true))
throw new FileNotFoundException(StringUtils.getString(
"cannot access working dir ", workingDir
.getAbsolutePath()));
process = getProcess();
trainingFile = new File(workingDir, "trainingFile.bin");
resultFile = new File(workingDir, "result.gtf");
logger.debug(this, StringUtils.getString("init done: workingDir=",
workingDir.getAbsolutePath()));
logger
.debug(this, StringUtils.getString(
"init done: trainingFile=", trainingFile
.getAbsolutePath()));
logger.debug(this, StringUtils.getString("init done: process=",
process));
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
System.err.println("dataproxy="+data);
System.err.println("databean="+data.viewData());
final boolean predictedGtf = (data.viewData().getPredictedGenesGFF() != null);
final boolean predictedGtfSize = (data.viewData()
.getPredictedGenesGFF().size() != 0);
logger.debug(this, StringUtils.getString(
"need to run: predictedGtf=", predictedGtf));
logger.debug(this, StringUtils.getString(
"need to run: predictedGtfSize=", predictedGtfSize));
return (predictedGtf && predictedGtfSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean trainingFile = (data.viewData().getCustom().get(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom().get(TRAINING_FILE)).exists());
final boolean trainingFileRead = (data.viewData().getCustom().get(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom().get(TRAINING_FILE)).canRead());
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (data.viewData().getInputSequence().size() != 0);
logger.debug(this, StringUtils.getString(
"requirements: trainingFile=", data.viewData()
.getCustom().get(TRAINING_FILE)));
logger.debug(this, StringUtils.getString(
"requirements: trainingFile=", trainingFile));
logger.debug(this, StringUtils.getString(
"requirements: trainingFileRead=", trainingFileRead));
logger.debug(this, StringUtils.getString(
"requirements: inputSequences=", inputSequences));
logger.debug(this, StringUtils.getString(
"requirements: inputSequencesSize=", inputSequencesSize));
return (trainingFile && trainingFileRead && inputSequences && inputSequencesSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
@Override
public boolean run(DataProxy<GFF3DataBean> data) throws StepExecutionException {
boolean success = true;
try {
createFiles(data);
process.addResultFile(true, resultFile.getAbsoluteFile());
success = process.createAndStartProcess();
if (success)
update(resultFile.getAbsoluteFile(), data);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return success;
}
private void update(File resultFile, DataProxy<GFF3DataBean> data)
throws IOException, GFFFormatErrorException,
DataBeanAccessException {
final Collection<? extends NewGFFElement> c = NewGFFFileImpl.parseFile(
resultFile).getElements();
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setPredictedGenesGFF(new ArrayList<NewGFFElement>(c));
}
});
}
private void createFiles(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
final File file = new File(workingDir, "ref.fasta");
new NewFASTAFileImpl(data.viewData().getInputSequence()).write(file);
final File file2 = (File) data.viewData().getCustom().get(
TRAINING_FILE);
logger.debug(this, StringUtils
.getString("got ", file2,
" as training file from data proxy (size=", file2
.length(), ")"));
// copying does not work for some reason.
// take "original" file for now
trainingFile = file2;
// try {
// new LazyFileCopier(file2, trainingFile).copy();
// } catch (Throwable t) {
// t.printStackTrace();
// }
// logger.debug(this, "copied files: old=" + file2.length() + ",new="
// + trainingFile.length());
// trainingFile.deleteOnExit();
file.deleteOnExit();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.element.NewGFFElement;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
/**
* @lastVisit 2009-08-12
* @Strings
* @Excetions
* @ThreadSave
* @author Alexander Kerner
*
*/
public abstract class AbstractConradTrainStep extends AbstractConradStep {
protected final static String TRAIN_PREFIX_KEY = "train.";
protected final static String WORKING_DIR_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ TRAIN_PREFIX_KEY + "workingDir";
protected File inFasta;
protected File inGff;
protected File trainingFile;
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
try {
super.init(context);
logger.debug(this, "doing initialisation");
workingDir = new File(super.getStepProperties().getProperty(
WORKING_DIR_KEY));
logger.debug(this, StringUtils.getString("got working dir=",
workingDir.getAbsolutePath()));
if (!FileUtils.dirCheck(workingDir.getAbsoluteFile(), true))
throw new FileNotFoundException(StringUtils.getString(
"cannot access working dir ", workingDir
.getAbsolutePath()));
process = getProcess();
trainingFile = new File(workingDir, "trainingFile.bin");
logger.debug(this, StringUtils.getString("init done: workingDir=",
workingDir.getAbsolutePath()));
logger
.debug(this, StringUtils.getString(
"init done: trainingFile=", trainingFile
.getAbsolutePath()));
logger.debug(this, StringUtils.getString("init done: process=",
process));
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
logger.debug(this, "initialisation done");
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean trainingFile = (data.viewData().getCustom().get(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom().get(TRAINING_FILE)).exists());
final boolean trainingFileRead = (data.viewData().getCustom().get(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom().get(TRAINING_FILE)).canRead());
logger.debug(this, "need to run: trainingFile=" + trainingFile);
logger.debug(this, "need to run: trainingFileRead="
+ trainingFileRead);
return trainingFile && trainingFileRead;
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
final boolean fastasSize = (data.viewData().getVerifiedGenesFasta().size() != 0);
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
final boolean gtfSize = (data.viewData().getVerifiedGenesGFF().size() != 0);
logger.debug(this, "requirements: fastas=" + fastas);
logger.debug(this, "requirements: fastasSize=" + fastasSize);
logger.debug(this, "requirements: gtf=" + gtf);
logger.debug(this, "requirements: gtfSize=" + gtfSize);
return (fastas && fastasSize && gtf && gtfSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
private void createFiles(DataProxy<GFF3DataBean> data) throws DataBeanAccessException,
IOException {
try {
inFasta = new File(workingDir, "ref.fasta");
logger.debug(this, "ref.fasta=" + inFasta);
logger.debug(this, "getting fastas for veryfied genes");
final ArrayList<? extends FASTAElement> fastas = data.viewData()
.getVerifiedGenesFasta();
final NewFASTAFile fastaFile = new NewFASTAFileImpl(fastas);
logger.debug(this, "writing fastas to " + inFasta);
fastaFile.write(inFasta);
final File inGff = new File(workingDir, "ref.gtf");
logger.debug(this, "ref.gtf=" + inGff);
logger.debug(this, "getting gtfs for veryfied genes");
final ArrayList<? extends NewGFFElement> gtfs = data.viewData()
.getVerifiedGenesGFF();
final NewGFFFile gtfFile = new NewGFFFileImpl(gtfs);
logger.debug(this, "writing gtfs to " + inGff);
gtfFile.write(inGff);
// inFasta.deleteOnExit();
// inGff.deleteOnExit();
} catch (Throwable t) {
t.printStackTrace();
System.exit(15);
}
}
@Override
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "running");
boolean success = true;
try {
logger.debug(this, "creating ref.* files");
createFiles(data);
logger.debug(this, "starting process");
process.addResultFile(true, trainingFile.getAbsoluteFile());
success = process.createAndStartProcess();
if (success) {
logger.debug(this, "process sucessfull, updating data bean");
update(data);
}
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
logger.debug(this, "process sucessfull=" + success);
return success;
}
protected void update(DataProxy<GFF3DataBean> data) throws DataBeanAccessException {
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
logger.debug(this, "using custom slot: key=" + TRAINING_FILE + ", value="+trainingFile.getAbsoluteFile());
v.getCustom().put(TRAINING_FILE, trainingFile.getAbsoluteFile());
}
});
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
/**
*
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class ConradConstants {
private ConradConstants(){}
public final static String PROPERTIES_KEY_PREFIX = "anna.step.conrad.";
public final static String CONRAD_DIR_KEY = PROPERTIES_KEY_PREFIX
+ "conradWorkingDir";
public final static String CONRAD_EXE = "bin/conrad.sh";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
import java.io.File;
import org.osgi.framework.BundleContext;
import de.kerner.commons.StringUtils;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
/**
* @lastVisit 2009-08-12
* @ThreadSave custom
* @author Alexander Kerner
* @Exceptions try without
* @Strings good
*
*/
public abstract class AbstractConradStep extends AbstractGFF3AnnaStep {
public static final String TRAINING_FILE = "conrad.trainingfile";
// assigned in init(), after that only read
protected File exeDir;
// TODO dangerous. must be initialized by extending class
// TODO not synchronized
protected AbstractStepProcessBuilder process;
// TODO dangerous. must be initialized by extending class
protected File workingDir;
protected synchronized void init(BundleContext context) throws StepExecutionException {
super.init(context);
exeDir = new File(super.getStepProperties()
.getProperty(ConradConstants.CONRAD_DIR_KEY));
logger.debug(this, StringUtils.getString("got exe dir=",exeDir));
}
protected abstract AbstractStepProcessBuilder getProcess();
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.bioutils.gff3.converter.BasicConverter;
import de.bioutils.gff3.converter.UniqueIDExtender;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.file.GFF3File;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
import de.mpg.mpiz.koeln.anna.step.conrad.data.adapter.ConradGeneParentExtender;
/**
* @lastVisit 2009-08-12
* @ThreadSave custom
* @Exceptions all try-catch-throwable
* @Strings good
* @author Alexander Kerner
*
*/
public abstract class AbstractConradPredictStep extends AbstractConradStep {
protected final static String TRAIN_PREFIX_KEY = "predict.";
protected final static String WORKING_DIR_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ TRAIN_PREFIX_KEY + "workingDir";
// assigned in init(), after that only read
protected volatile File trainingFile;
// assigned in init(), after that only read
protected volatile File resultFile;
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
try {
super.init(context);
logger.debug(this, "doing initialisation");
workingDir = new File(super.getStepProperties().getProperty(
WORKING_DIR_KEY));
logger.debug(this, StringUtils.getString("got working dir=",
workingDir.getAbsolutePath()));
if (!FileUtils.dirCheck(workingDir.getAbsoluteFile(), true))
throw new FileNotFoundException(StringUtils.getString(
"cannot access working dir ", workingDir
.getAbsolutePath()));
process = getProcess();
trainingFile = new File(workingDir, "trainingFile.bin");
resultFile = new File(workingDir, "result.gtf");
logger.debug(this, StringUtils.getString("init done: workingDir=",
workingDir.getAbsolutePath()));
logger
.debug(this, StringUtils.getString(
"init done: trainingFile=", trainingFile
.getAbsolutePath()));
logger.debug(this, StringUtils.getString("init done: process=",
process));
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean predictedGtf = (data.viewData()
.getPredictedGenesGFF() != null);
final boolean predictedGtfSize = (data.viewData()
.getPredictedGenesGFF().size() != 0);
logger.debug(this, StringUtils.getString(
"need to run: predictedGtf=", predictedGtf));
logger.debug(this, StringUtils.getString(
"need to run: predictedGtfSize=", predictedGtfSize));
return (predictedGtf && predictedGtfSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
@Override
public List<String> requirementsNeeded(DataProxy<GFF3DataBean> data) throws DataBeanAccessException {
final List<String> r = new ArrayList<String>();
final boolean trainingFileRead = (data.viewData()
.getCustom(TRAINING_FILE)) != null
&& ((File) data.viewData().getCustom(TRAINING_FILE))
.canRead();
if(!trainingFileRead){
r.add("training file");
}
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (data.viewData()
.getInputSequence().size() != 0);
if(!inputSequences || !inputSequencesSize){
r.add("input sequence");
}
return r;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean trainingFile = (data.viewData().getCustom(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom(TRAINING_FILE)).exists());
final boolean trainingFileRead = (data.viewData()
.getCustom(TRAINING_FILE)) != null
&& ((File) data.viewData().getCustom(TRAINING_FILE))
.canRead();
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (data.viewData()
.getInputSequence().size() != 0);
logger.debug(this, StringUtils.getString(
"requirements: trainingFile=", data.viewData().getCustom(
TRAINING_FILE)));
logger.debug(this, StringUtils.getString(
"requirements: trainingFile=", trainingFile));
logger.debug(this, StringUtils.getString(
"requirements: trainingFileRead=", trainingFileRead));
logger.debug(this, StringUtils.getString(
"requirements: inputSequences=", inputSequences));
logger.debug(this, StringUtils.getString(
"requirements: inputSequencesSize=", inputSequencesSize));
return (trainingFile && trainingFileRead && inputSequences && inputSequencesSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
@Override
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
boolean success = true;
try {
createFiles(data);
process.addResultFile(true, resultFile.getAbsoluteFile());
success = process.createAndStartProcess();
if (success)
update(data);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return success;
}
private void update(DataProxy<GFF3DataBean> data)
throws IOException, GFFFormatErrorException,
DataBeanAccessException {
// TODO: dirty workaround for a "FileNotFoundException" thrown, if we dont wait.
synchronized(resultFile){
checkFile();
while(!resultFile.canRead()){
try {
logger.debug(this, "file not there, sleeping");
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
checkFile();
logger.debug(this, "file there!");
}
/////// dirty workaround /////////
final NewGFFFile file = NewGFFFileImpl
.parseFile(resultFile.getAbsoluteFile());
final BasicConverter converter = new BasicConverter();
converter.clearElementExtenders();
converter.addGFF3ElementExtender(new UniqueIDExtender(true));
converter.addGFF3ElementExtender(new ConradGeneParentExtender());
final GFF3File file2 = converter.convert(file);
final Collection<? extends GFF3Element> c = file2.getElements();
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setPredictedGenesGFF(new ArrayList<GFF3Element>(c));
}
});
}
private void checkFile() {
logger.debug(this, "file is=" + resultFile.getAbsolutePath());
logger.debug(this, "file is there=" + resultFile.exists());
logger.debug(this, "file is file=" + resultFile.isFile());
logger.debug(this, "file can read=" + resultFile.canRead());
logger.debug(this, "file can write=" + resultFile.canWrite());
}
private void createFiles(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
final File file = new File(workingDir, "ref.fasta");
new NewFASTAFileImpl(data.viewData().getInputSequence()).write(file);
final File file2 = (File) data.viewData().getCustom(TRAINING_FILE);
logger.debug(this, StringUtils
.getString("got ", file2,
" as training file from data proxy (size=", file2
.length(), ")"));
// copying does not work for some reason.
// take "original" file for now
trainingFile = file2;
// try {
// new LazyFileCopier(file2, trainingFile).copy();
// } catch (Throwable t) {
// t.printStackTrace();
// }
// logger.debug(this, "copied files: old=" + file2.length() + ",new="
// + trainingFile.length());
// trainingFile.deleteOnExit();
// file.deleteOnExit();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.file.GFF3File;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
import de.mpg.mpiz.koeln.anna.step.conrad.data.adapter.GFF3ConverterImpl;
/**
* @lastVisit 2009-08-12
* @Strings
* @Excetions
* @ThreadSave
* @author Alexander Kerner
*
*/
public abstract class AbstractConradTrainStep extends AbstractConradStep {
protected final static String TRAIN_PREFIX_KEY = "train.";
protected final static String WORKING_DIR_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ TRAIN_PREFIX_KEY + "workingDir";
protected File inFasta;
protected File inGff;
protected File trainingFile;
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
try {
super.init(context);
logger.debug(this, "doing initialisation");
workingDir = new File(super.getStepProperties().getProperty(
WORKING_DIR_KEY));
logger.debug(this, StringUtils.getString("got working dir=",
workingDir.getAbsolutePath()));
if (!FileUtils.dirCheck(workingDir.getAbsoluteFile(), true))
throw new FileNotFoundException(StringUtils.getString(
"cannot access working dir ", workingDir
.getAbsolutePath()));
process = getProcess();
trainingFile = new File(workingDir, "trainingFile.bin");
logger.debug(this, StringUtils.getString("init done: workingDir=",
workingDir.getAbsolutePath()));
logger
.debug(this, StringUtils.getString(
"init done: trainingFile=", trainingFile
.getAbsolutePath()));
logger.debug(this, StringUtils.getString("init done: process=",
process));
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
logger.debug(this, "initialisation done");
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean trainingFile = (data.viewData().getCustom(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom(TRAINING_FILE)).exists());
final boolean trainingFileRead = (data.viewData().getCustom(
TRAINING_FILE) != null && ((File) data.viewData()
.getCustom(TRAINING_FILE)).canRead());
logger.debug(this, "need to run: trainingFile=" + trainingFile);
logger.debug(this, "need to run: trainingFileRead="
+ trainingFileRead);
return trainingFile && trainingFileRead;
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
@Override
public List<String> requirementsNeeded(DataProxy<GFF3DataBean> data)
throws Exception {
final List<String> r = new ArrayList<String>();
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
final boolean fastasSize = (data.viewData().getVerifiedGenesFasta()
.size() != 0);
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
final boolean gtfSize = (data.viewData().getVerifiedGenesGFF()
.size() != 0);
if(!fastas || !fastasSize){
r.add("verified genes sequences");
}
if(!gtf || !gtfSize){
r.add("verified genes annotations");
}
return r;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
final boolean fastasSize = (data.viewData().getVerifiedGenesFasta()
.size() != 0);
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
final boolean gtfSize = (data.viewData().getVerifiedGenesGFF()
.size() != 0);
logger.debug(this, "requirements: fastas=" + fastas);
logger.debug(this, "requirements: fastasSize=" + fastasSize);
logger.debug(this, "requirements: gtf=" + gtf);
logger.debug(this, "requirements: gtfSize=" + gtfSize);
return (fastas && fastasSize && gtf && gtfSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
private void createFiles(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
try {
createFastas(data);
createGFFs(data);
// inFasta.deleteOnExit();
// inGff.deleteOnExit();
} catch (Throwable t) {
t.printStackTrace();
System.exit(15);
}
}
private void createGFFs(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
final File inGff = new File(workingDir, "ref.gtf");
logger.debug(this, "ref.gtf=" + inGff);
logger.debug(this, "getting gtfs for veryfied genes");
final Collection<? extends GFF3Element> gtfs = data.viewData()
.getVerifiedGenesGFF();
final GFF3File gtfFile = new GFF3FileImpl(gtfs);
final NewGFFFile newFile = new GFF3ConverterImpl().convert(gtfFile);
logger.debug(this, "writing gtfs to " + inGff);
newFile.write(inGff);
}
private void createFastas(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
inFasta = new File(workingDir, "ref.fasta");
logger.debug(this, "ref.fasta=" + inFasta);
logger.debug(this, "getting fastas for veryfied genes");
final Collection<? extends FASTAElement> fastas = data.viewData()
.getVerifiedGenesFasta();
final NewFASTAFile fastaFile = new NewFASTAFileImpl(fastas);
logger.debug(this, "writing fastas to " + inFasta);
fastaFile.write(inFasta);
}
@Override
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "running");
boolean success = true;
try {
logger.debug(this, "creating ref.* files");
createFiles(data);
logger.debug(this, "starting process");
process.addResultFile(true, trainingFile.getAbsoluteFile());
success = process.createAndStartProcess();
if (success) {
logger.debug(this, "process sucessfull, updating data bean");
update(data);
}
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
logger.debug(this, "process sucessfull=" + success);
return success;
}
protected void update(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException {
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
logger.debug(this, "using custom slot: key=" + TRAINING_FILE
+ ", value=" + trainingFile.getAbsoluteFile());
v.addCustom(TRAINING_FILE, trainingFile.getAbsoluteFile());
}
});
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
/**
*
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class ConradConstants {
private ConradConstants(){}
public final static String PROPERTIES_KEY_PREFIX = "anna.step.conrad.";
public final static String CONRAD_DIR_KEY = PROPERTIES_KEY_PREFIX
+ "conradWorkingDir";
public final static String CONRAD_EXE = "bin/conrad.sh";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.common;
import java.io.File;
import org.osgi.framework.BundleContext;
import de.kerner.commons.StringUtils;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
/**
* @lastVisit 2009-08-12
* @ThreadSave custom
* @author Alexander Kerner
* @Exceptions try without
* @Strings good
*
*/
public abstract class AbstractConradStep extends AbstractGFF3AnnaStep {
public static final String TRAINING_FILE = "conrad.trainingfile";
// assigned in init(), after that only read
protected volatile File exeDir;
// TODO dangerous. must be initialized by extending class
// TODO not synchronized
protected volatile AbstractStepProcessBuilder process;
// TODO dangerous. must be initialized by extending class
protected volatile File workingDir;
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
exeDir = new File(super.getStepProperties()
.getProperty(ConradConstants.CONRAD_DIR_KEY));
logger.debug(this, StringUtils.getString("got exe dir=",exeDir));
}
protected abstract AbstractStepProcessBuilder getProcess();
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradTrainStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 0992-07-28
* @author Alexander Kerner
*
*/
public class TrainLocal extends AbstractConradTrainStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir, LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(
new File(executableDir, ConradConstants.CONRAD_EXE)
.getAbsolutePath());
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(trainingFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
final Process p = new Process(exeDir.getAbsoluteFile(), workingDir.getAbsoluteFile(), logger);
// p.addResultFile(true, trainingFile);
return p;
}
} | Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradTrainStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 0992-07-28
* @author Alexander Kerner
*
*/
public class TrainLocal extends AbstractConradTrainStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir, LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(
new File(executableDir, ConradConstants.CONRAD_EXE)
.getAbsolutePath());
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(trainingFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
final Process p = new Process(exeDir.getAbsoluteFile(), workingDir.getAbsoluteFile(), logger);
// p.addResultFile(true, trainingFile);
return p;
}
} | Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
public abstract class AbstractAnnaStep<V> implements BundleActivator, AnnaStep {
private final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration" + File.separatorChar + "step.properties");
private volatile ServiceTracker tracker;
private volatile Properties properties;
protected volatile LogDispatcher logger = new ConsoleLogger();
private State state = State.LOOSE;
protected void init(BundleContext context) throws StepExecutionException {
this.logger = new LogDispatcherImpl(context);
tracker = new ServiceTracker(context, AnnaServer.class.getName(), null);
tracker.open();
try {
properties = getPropertes();
} catch (Exception e) {
logger.error(this, StringUtils.getString(
"could not load settings from ", PROPERTIES_FILE
.getAbsolutePath(), ", using defaults"));
}
}
public void start(BundleContext context) throws Exception {
logger.debug(this, "starting step " + this);
init(context);
try{
getAnnaServer().registerStep(this);
}catch(Exception e){
final AbstractAnnaStep<?> as = new DummyStep(this.toString());
as.setState(AbstractAnnaStep.State.ERROR);
getAnnaServer().registerStep(as);
}
}
public void stop(BundleContext context) throws Exception {
logger.debug(this, "stopping service");
tracker.close();
tracker = null;
}
public AnnaServer getAnnaServer() throws ServiceNotAvailabeException{
AnnaServer server = (AnnaServer) tracker.getService();
if(server == null)
throw new ServiceNotAvailabeException();
return server;
}
public abstract DataProxy<V> getDataProxy() throws ServiceNotAvailabeException;
public abstract boolean requirementsSatisfied(DataProxy<V> proxy)
throws StepExecutionException;
public abstract boolean canBeSkipped(DataProxy<V> proxy)
throws StepExecutionException;
public abstract boolean run(DataProxy<V> proxy)
throws StepExecutionException;
public boolean requirementsSatisfied() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(e);
}
return requirementsSatisfied(proxy);
}
public boolean canBeSkipped() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(e);
}
return canBeSkipped(proxy);
}
public boolean run() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(e);
}
return run(proxy);
}
public synchronized Properties getStepProperties() {
return properties;
}
private Properties getPropertes() throws IOException {
final Properties defaultProperties = initDefaults();
final Properties pro = new Properties(defaultProperties);
FileInputStream fi = null;
try {
logger.info(this, StringUtils.getString("loading settings from ",
PROPERTIES_FILE));
fi = new FileInputStream(PROPERTIES_FILE);
pro.load(fi);
} finally {
if (fi != null)
fi.close();
}
return pro;
}
private Properties initDefaults() {
final Properties pro = new Properties();
return pro;
}
public final synchronized State getState() {
return state;
}
public final synchronized void setState(State state) {
this.state = state;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.server.dataproxy.GFF3DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
public abstract class AbstractGFF3AnnaStep extends
AbstractAnnaStep<GFF3DataBean> {
private volatile ServiceTracker tracker;
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
tracker = new ServiceTracker(context, GFF3DataProxy.class.getName(),
null);
tracker.open();
}
@Override
public DataProxy<GFF3DataBean> getDataProxy()
throws ServiceNotAvailabeException {
GFF3DataProxy proxy = (GFF3DataProxy) tracker.getService();
if (proxy == null)
throw new ServiceNotAvailabeException();
return proxy;
}
@Override
protected void finalize() throws Throwable {
this.tracker.close();
tracker = null;
super.finalize();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
class DummyStep extends AbstractGFF3AnnaStep {
private final String name;
DummyStep(String name){
this.name = name;
}
public String toString() {
return "(dummy)"+name;
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws StepExecutionException {
// TODO Auto-generated method stub
return false;
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
public abstract class AbstractAnnaStep<V> implements BundleActivator, AnnaStep {
private final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration" + File.separatorChar + "step.properties");
private volatile ServiceTracker tracker;
private volatile Properties properties;
protected volatile LogDispatcher logger = new ConsoleLogger();
private State state = State.LOOSE;
// fields volatile
protected void init(BundleContext context) throws StepExecutionException {
this.logger = new LogDispatcherImpl(context);
tracker = new ServiceTracker(context, AnnaServer.class.getName(), null);
tracker.open();
try {
properties = getPropertes();
} catch (Exception e) {
logger.error(this, StringUtils.getString(
"could not load settings from ", PROPERTIES_FILE
.getAbsolutePath(), ", using defaults"));
}
}
public void start(BundleContext context) throws Exception {
logger.debug(this, "starting step " + this);
init(context);
try{
getAnnaServer().registerStep(this);
}catch(Exception e){
final AbstractAnnaStep<?> as = new DummyStep(this.toString());
as.setState(AbstractAnnaStep.State.ERROR);
getAnnaServer().registerStep(as);
}
}
public void stop(BundleContext context) throws Exception {
logger.debug(this, "stopping service");
tracker.close();
tracker = null;
}
public AnnaServer getAnnaServer() throws ServiceNotAvailabeException{
AnnaServer server = (AnnaServer) tracker.getService();
if(server == null)
throw new ServiceNotAvailabeException();
return server;
}
public abstract DataProxy<V> getDataProxy() throws ServiceNotAvailabeException;
public abstract boolean requirementsSatisfied(DataProxy<V> proxy)
throws StepExecutionException;
public abstract boolean canBeSkipped(DataProxy<V> proxy)
throws StepExecutionException;
public abstract boolean run(DataProxy<V> proxy)
throws StepExecutionException;
public boolean requirementsSatisfied() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(this, e);
}
return requirementsSatisfied(proxy);
}
public boolean canBeSkipped() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(this, e);
}
return canBeSkipped(proxy);
}
public boolean run() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(this, e);
}
return run(proxy);
}
public synchronized Properties getStepProperties() {
return properties;
}
private Properties getPropertes() throws IOException {
final Properties defaultProperties = initDefaults();
final Properties pro = new Properties(defaultProperties);
FileInputStream fi = null;
try {
logger.info(this, StringUtils.getString("loading settings from ",
PROPERTIES_FILE));
fi = new FileInputStream(PROPERTIES_FILE);
pro.load(fi);
} finally {
if (fi != null)
fi.close();
}
return pro;
}
private Properties initDefaults() {
final Properties pro = new Properties();
return pro;
}
public final synchronized State getState() {
return state;
}
public final synchronized void setState(State state) {
this.state = state;
}
public List<String> requirementsNeeded(DataProxy<V> proxy) throws Exception{
return Collections.emptyList();
}
public List<String> requirementsNeeded() {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (Exception e) {
logger.error(this, e.getLocalizedMessage(), e);
final ArrayList<String> r = new ArrayList<String>();
r.add("error while receiving dataproxy");
return r;
}
try {
return requirementsNeeded(proxy);
} catch (Exception e) {
logger.error(this, e.getLocalizedMessage(), e);
final ArrayList<String> r = new ArrayList<String>();
r.add("error while getting requirements informations");
return r;
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.server.dataproxy.GFF3DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
public abstract class AbstractGFF3AnnaStep extends
AbstractAnnaStep<GFF3DataBean> {
private volatile ServiceTracker tracker;
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
tracker = new ServiceTracker(context, GFF3DataProxy.class.getName(),
null);
tracker.open();
}
@Override
public DataProxy<GFF3DataBean> getDataProxy()
throws ServiceNotAvailabeException {
GFF3DataProxy proxy = (GFF3DataProxy) tracker.getService();
if (proxy == null)
throw new ServiceNotAvailabeException();
return proxy;
}
@Override
protected void finalize() throws Throwable {
this.tracker.close();
tracker = null;
super.finalize();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
class DummyStep extends AbstractGFF3AnnaStep {
private final String name;
DummyStep(String name){
this.name = name;
}
public String toString() {
return "(dummy)"+name;
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws StepExecutionException {
// TODO Auto-generated method stub
return false;
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
/**
* <p>
* Helper class to create a WrapperStep for an external programm.
* </p>
*
* @author Alexander Kerner
* @threadSave custom
* @lastVisit 2009-10-02
* @param <T>
* type of {@link de.mpg.mpiz.koeln.anna.server.data.DataBean}
*/
public abstract class AbstractWrapperStep<T> extends AbstractAnnaStep<T> {
private class ThreaddedProcess implements Callable<Boolean> {
private final AbstractStepProcessBuilder ps;
private final OutputStream out, err;
ThreaddedProcess(File executableDir, File workingDir, OutputStream out, OutputStream err,
LogDispatcher logger){
this.out = out;
this.err = err;
ps = new AbstractStepProcessBuilder(
executableDir, workingDir, logger) {
@Override
protected List<String> getCommandList() {
return getCmdList();
}
};
}
public Boolean call() throws Exception {
return ps.createAndStartProcess(out, err);
}
}
private final ExecutorService exe = Executors.newSingleThreadExecutor();
private final static long TIMEOUT = 1000;
protected volatile File exeDir;
protected volatile File workingDir;
private volatile File outFile = null;
private volatile File errFile = null;
protected List<File> shortCutFiles = new ArrayList<File>();
protected List<File> resultFilesToWaitFor = new ArrayList<File>();
/**
* <p>
* Finally start this Step.
* </p>
*
* @throws StepExecutionException
*/
public boolean start() throws StepExecutionException {
boolean success = false;
try {
printProperties();
validateProperties();
prepare();
if (takeShortCut()) {
success = true;
} else {
success = doItFinally();
}
if (success) {
waitForFiles();
final boolean hh = update();
if (hh) {
logger.debug(this, "updated databean");
} else {
logger.warn(this, "updating databean failed!");
}
success = hh;
}
} catch (Exception e) {
StepUtils.handleException(this, e);
}
return success;
}
private void waitForFiles() throws InterruptedException {
if(resultFilesToWaitFor.isEmpty()){
logger.debug(this, "no files to wait for");
return;
}
for(File f : resultFilesToWaitFor){
synchronized (f) {
while(!f.exists()){
logger.debug(this, "waiting for file \"" + f + " \"");
Thread.sleep(TIMEOUT);
}
}
}
}
// fields volatile
private boolean doItFinally() throws StepExecutionException {
boolean success = false;
try {
OutputStream out = System.out;
OutputStream err = System.err;
if (outFile != null) {
out = FileUtils.getBufferedOutputStreamForFile(outFile);
}
if (errFile != null) {
err = FileUtils.getBufferedOutputStreamForFile(errFile);
}
success = exe.submit(new ThreaddedProcess(exeDir, workingDir, out, err, logger)).get();
if (outFile != null) {
out.close();
}
if (errFile != null) {
err.close();
}
} catch (Exception e) {
StepUtils.handleException(this, e);
}
return success;
}
private synchronized boolean takeShortCut() {
logger.debug(this, "checking for shortcut available");
if (shortCutFiles.isEmpty()) {
logger.debug(this, "no shortcut files defined");
return false;
}
for (File f : shortCutFiles) {
final boolean fileCheck = FileUtils.fileCheck(f, false);
logger.debug(this, "file " + f.getAbsolutePath() + " there="
+ fileCheck);
if (!(fileCheck)) {
logger.debug(this, "cannot skip");
return false;
}
}
logger.debug(this, "skip available");
return true;
}
/**
* <p>
* Preparation for running wrapped process. (e.g. creating required files in
* working directory)
* </p>
*
* @throws Exception
*/
public abstract void prepare() throws Exception;
/**
* @return List of command line arguments, that will passed to wrapped step.
*/
public abstract List<String> getCmdList();
public abstract boolean update() throws StepExecutionException;
public synchronized void addShortCutFile(File file) {
shortCutFiles.add(file);
}
public synchronized void addResultFileToWaitFor(File file) {
resultFilesToWaitFor.add(file);
}
public void redirectOutStreamToFile(File file) {
this.outFile = file;
}
public void redirectErrStreamToFile(File file) {
this.errFile = file;
}
// fields volatile
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tstepWorkingDir=" + workingDir);
logger.debug(this, "\texeDir=" + exeDir);
}
// fields volatile
private void validateProperties() throws StepExecutionException {
if (!FileUtils.dirCheck(exeDir, false))
throw new StepExecutionException(this, "cannot access exe dir");
if (!FileUtils.dirCheck(workingDir, true))
throw new StepExecutionException(this, "cannot access working dir");
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
/**
* @lastVisit 2009-08-12
* @author Alexander Kerner
* @ThreadSave state final, ConcurrentHashMap
* @Exceptions nothing to do, abstract class
*
*/
public abstract class AbstractStepProcessBuilder {
protected final File executableDir;
protected final File workingDir;
private final LogDispatcher logger;
// TODO: remove this. Let this completely be handled from "WrapperStep"
private final Map<File, Boolean> outFiles = new ConcurrentHashMap<File, Boolean>();
protected AbstractStepProcessBuilder(File executableDir, File workingDir) {
this.executableDir = executableDir;
this.workingDir = workingDir;
this.logger = new ConsoleLogger();
}
protected AbstractStepProcessBuilder(File executableDir, File workingDir,
LogDispatcher logger) {
this.executableDir = executableDir;
this.workingDir = workingDir;
this.logger = logger;
}
@Deprecated
public void addResultFile(boolean takeShortCutIfAlreadyThere,
String fileName) {
addResultFile(takeShortCutIfAlreadyThere, new File(fileName));
}
@Deprecated
public void addAllResultFiles(Map<File, Boolean> m) {
if(m.isEmpty())
return;
outFiles.putAll(m);
}
@Deprecated
public void addResultFile(boolean takeShortCutIfAlreadyThere, File file) {
if (file == null)
throw new NullPointerException(
"file must not be null");
outFiles
.put(file, takeShortCutIfAlreadyThere);
}
public boolean createAndStartProcess(final OutputStream out,
final OutputStream err) {
if (takeShortCut()){
logger.info(this, "file(s) there, taking shortcut");
return true;
}
logger.debug(this, "file(s) not there, cannot take shortcut");
final List<String> processCommandList = getCommandList();
final ProcessBuilder processBuilder = new ProcessBuilder(
processCommandList);
logger.debug(this, "creating process " + processBuilder.command());
processBuilder.directory(executableDir);
logger.debug(this, "executable dir of process: " + processBuilder.directory());
processBuilder.redirectErrorStream(true);
try {
Process p = processBuilder.start();
logger.debug(this, "started process " + p);
FileUtils.inputStreamToOutputStream(p.getInputStream(), out);
FileUtils.inputStreamToOutputStream(p.getErrorStream(), err);
final int exit = p.waitFor();
// logger.debug(this, "performing LSF buffer timeout...");
// Thread.sleep(1000);
// logger.debug(this, "continuing");
logger.debug(this, "process " + p + " exited with exit code " + exit);
if (exit != 0)
return false;
return true;
} catch (Exception e){
e.printStackTrace();
logger.error(this, e.getLocalizedMessage(), e);
return false;
}
}
public boolean createAndStartProcess() {
return createAndStartProcess(System.out, System.err);
}
@Deprecated
private boolean takeShortCut() {
logger.debug(this, "checking for shortcut available");
if(outFiles.isEmpty()){
logger.debug(this, "no outfiles defined");
return false;
}
for (Entry<File, Boolean> e : outFiles.entrySet()) {
final boolean fileCheck = FileUtils.fileCheck(e.getKey(), false);
final boolean skipIt = e.getValue();
logger.debug(this, "file " + e.getKey().getAbsolutePath() + " there="+fileCheck);
logger.debug(this, "file " + e.getKey() + " skip="+skipIt);
if(!(fileCheck && skipIt)){
logger.debug(this, "cannot skip");
return false;
}
}
logger.debug(this, "skip available");
return true;
}
protected abstract List<String> getCommandList();
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.server.dataproxy.GFF3DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
// TODO: class implementation is duplicate to "AbstractGFF3AnnaStep". That is bad!
public abstract class AbstractGFF3WrapperStep extends AbstractWrapperStep<GFF3DataBean>{
private volatile ServiceTracker tracker;
// tracker volatile
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
tracker = new ServiceTracker(context, GFF3DataProxy.class.getName(),
null);
tracker.open();
}
// tracker volatile
@Override
public DataProxy<GFF3DataBean> getDataProxy()
throws ServiceNotAvailabeException {
GFF3DataProxy proxy = (GFF3DataProxy) tracker.getService();
if (proxy == null)
throw new ServiceNotAvailabeException();
return proxy;
}
@Override
protected void finalize() throws Throwable {
this.tracker.close();
tracker = null;
super.finalize();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.verifiedgenes.reader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff.element.NewGFFElement;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public class VerifiedGenesReader extends AbstractGFF3AnnaStep {
private final static String FASTA_KEY = "anna.step.verified.fasta";
private final static String GTF_KEY = "anna.step.verified.gtf";
private File fasta;
private File gtf;
private LogDispatcher logger = null;
public VerifiedGenesReader() {
// use "init()" instead, to make sure "logger" is initiated
}
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
super.init(context);
logger = new LogDispatcherImpl(context);
initFiles();
}
private void initFiles() {
final String fastaPath = super.getStepProperties().getProperty(
FASTA_KEY);
logger.debug(this, "got path for FASTA: " + fastaPath);
final String gtfPath = super.getStepProperties().getProperty(GTF_KEY);
logger.debug(this, "got path for GTF: " + gtfPath);
fasta = new File(fastaPath);
gtf = new File(gtfPath);
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data) {
logger.info(this, "no requirements needed");
return true;
}
public boolean run(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
doFasta(data);
doGtf(data);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return true;
}
private void doGtf(DataProxy<GFF3DataBean> data) throws IOException,
GFFFormatErrorException, DataBeanAccessException {
logger.info(this, "reading GTF file " + gtf);
final NewGFFFile gtfFile = NewGFFFileImpl.parseFile(gtf);
final Collection<? extends NewGFFElement> elements = gtfFile
.getElements();
logger.info(this, "done reading gtf");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesGFF(new ArrayList<NewGFFElement>(elements));
}
});
}
private void doFasta(DataProxy<GFF3DataBean> data) throws IOException,
DataBeanAccessException, StepExecutionException {
try{
logger.info(this, "reading FASTA file " + fasta);
final NewFASTAFile fastaFile = NewFASTAFileImpl.parse(fasta);
final Collection<? extends FASTAElement> sequences = fastaFile.getElements();
logger.info(this, "done reading fasta");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesFasta(new ArrayList<FASTAElement>(sequences));
}
});
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
// TODO size == 0 sub-optimal indicator
final Collection<? extends FASTAElement> list1 = data.viewData()
.getVerifiedGenesFasta();
final Collection<? extends NewGFFElement> list2 = data.viewData()
.getVerifiedGenesGFF();
return (list1 != null && list1.size() != 0 && list2 != null && list2
.size() != 0);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.verifiedgenes.reader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.file.GFF3File;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public class VerifiedGenesReader extends AbstractGFF3AnnaStep {
private final static String FASTA_KEY = "anna.step.verified.fasta";
private final static String GTF_KEY = "anna.step.verified.gtf";
private File fasta;
private File gtf;
private LogDispatcher logger = null;
public VerifiedGenesReader() {
// use "init()" instead, to make sure "logger" is initiated
}
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
super.init(context);
logger = new LogDispatcherImpl(context);
initFiles();
}
private void initFiles() {
final String fastaPath = super.getStepProperties().getProperty(
FASTA_KEY);
logger.debug(this, "got path for FASTA: " + fastaPath);
final String gtfPath = super.getStepProperties().getProperty(GTF_KEY);
logger.debug(this, "got path for GTF: " + gtfPath);
fasta = new File(fastaPath);
gtf = new File(gtfPath);
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data) {
logger.info(this, "no requirements needed");
return true;
}
public boolean run(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
doFasta(data);
doGtf(data);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return true;
}
private void doGtf(DataProxy<GFF3DataBean> data) throws IOException,
GFFFormatErrorException, DataBeanAccessException {
logger.info(this, "reading GTF file " + gtf);
final GFF3File gtfFile = GFF3FileImpl.convertFromGFF(gtf);
final Collection<? extends GFF3Element> elements = gtfFile
.getElements();
logger.info(this, "done reading gtf");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesGFF(new ArrayList<GFF3Element>(elements));
}
});
}
private void doFasta(DataProxy<GFF3DataBean> data) throws IOException,
DataBeanAccessException, StepExecutionException {
try{
logger.info(this, "reading FASTA file " + fasta);
final NewFASTAFile fastaFile = NewFASTAFileImpl.parse(fasta);
final Collection<? extends FASTAElement> sequences = fastaFile.getElements();
logger.info(this, "done reading fasta");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesFasta(new ArrayList<FASTAElement>(sequences));
}
});
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
// TODO size == 0 sub-optimal indicator
final Collection<? extends FASTAElement> list1 = data.viewData()
.getVerifiedGenesFasta();
final Collection<? extends GFF3Element> list2 = data.viewData()
.getVerifiedGenesGFF();
return (list1 != null && list1.size() != 0 && list2 != null && list2
.size() != 0);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.predict.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradPredictStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class PredictLocal extends AbstractConradPredictStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir,
LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(new File(
executableDir, ConradConstants.CONRAD_EXE).getAbsolutePath());
builder.addFlagCommand("predict");
builder.addFlagCommand(trainingFile.getAbsolutePath());
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(resultFile.getParentFile().getAbsolutePath() + File.separator + "result");
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
return new Process(exeDir, workingDir, logger);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.predict.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradPredictStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class PredictLocal extends AbstractConradPredictStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir,
LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected synchronized List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(new File(
executableDir, ConradConstants.CONRAD_EXE).getAbsolutePath());
builder.addFlagCommand("predict");
builder.addFlagCommand(trainingFile.getAbsolutePath());
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(resultFile.getParentFile().getAbsolutePath() + File.separator + "result");
return builder.getCommandList();
}
}
@Override
protected synchronized AbstractStepProcessBuilder getProcess() {
return new Process(exeDir, workingDir, logger);
}
}
| Java |
package de.mpg.koeln.anna.core.events;
import java.util.Collection;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public class StepStateChangeEvent extends AnnaEvent {
private static final long serialVersionUID = 4513665226131110643L;
private final AnnaStep step;
public StepStateChangeEvent(Object source, Collection<AnnaStep> steps, AnnaStep step) {
super(source, steps);
this.step = step;
}
public AnnaStep getStep() {
return step;
}
public State getState() {
return step.getState();
}
@Override
public String toString() {
return new StringBuilder().append(super.toString()).append("[").append(
"step").append("=").append(step).append("]").append("[").append(
"state").append("=").append(step.getState()).append("]").toString();
}
}
| Java |
package de.mpg.koeln.anna.core.events;
import java.util.Collection;
import java.util.EventObject;
import java.util.HashSet;
import java.util.Set;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public class AnnaEvent extends EventObject {
private static final long serialVersionUID = 1551843380559471696L;
private final Set<AnnaStep> registeredSteps = new HashSet<AnnaStep>();
public AnnaEvent(Object source, Collection<? extends AnnaStep> registeredSteps) {
super(source);
this.registeredSteps.clear();
this.registeredSteps.addAll(registeredSteps);
}
public Collection<AnnaStep> getRegisteredSteps(){
return new HashSet<AnnaStep>(registeredSteps);
}
@Override
public String toString() {
return new StringBuilder().append(super.toString().substring(super.toString().lastIndexOf("."))).append("[").append(
"stepReg").append("=").append(registeredSteps).append("]").toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
class ImmediateStepSheduler extends StepSheduler {
ImmediateStepSheduler(AnnaStep step, EventHandler handler,
LogDispatcher logger) {
super(step, handler, logger);
}
public Void call() throws Exception {
// call "call()" directly to run in same thread
synchronized (this) {
exe.call();
}
return null;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
* <p> Simple helper class </p>
* @threadSave all sync to this
* @author Alexander Kerner
* @lastVisit 2009-09-22
*
*/
class EventHandler {
private final Collection<AnnaEventListener> observers = new ArrayList<AnnaEventListener>();
private final Collection<AnnaStep> registeredSteps;
public EventHandler(Collection<AnnaStep> registeredSteps) {
this.registeredSteps = registeredSteps;
}
public void stepStateChanged(AnnaStep step){
broadcastEvent(new StepStateChangeEvent(this, registeredSteps, step));
}
private synchronized void broadcastEvent(AnnaEvent event) {
if (observers.isEmpty())
return;
for (AnnaEventListener l : observers) {
l.eventOccoured(event);
}
}
synchronized void addEventListener(AnnaEventListener observer) {
observers.add(observer);
}
synchronized void removeEventListener(AnnaEventListener observer) {
observers.remove(observer);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.concurrent.Callable;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
*
*/
public abstract class StepSheduler implements Callable<Void> {
protected final AnnaStep step;
protected final EventHandler handler;
protected final LogDispatcher logger;
protected AnnaSepExecutor exe;
StepSheduler(AnnaStep step, EventHandler handler, LogDispatcher logger) {
this.step = step;
this.handler = handler;
this.logger = logger;
this.exe = new AnnaSepExecutor(step, handler, logger);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + ":"
+ exe.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ExecutableStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
public class AnnaServerImpl implements AnnaServer {
// TODO path
private final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration"
+ File.separatorChar + "server.properties");
private final Collection<AnnaStep> registeredSteps = new HashSet<AnnaStep>();
private final EventHandler handler;
private final Properties properties;
private final ExecutorService exe = Executors.newCachedThreadPool();
private final LogDispatcher logger;
AnnaServerImpl(final LogDispatcher logger) {
if (logger != null)
this.logger = logger;
else
this.logger = new ConsoleLogger();
properties = getPropertes();
logger.debug(this, "loaded properties: " + properties);
handler = new EventHandler(registeredSteps);
}
public void unregisterStep(ExecutableStep step) {
// TODO Auto-generated method stub
}
// threadsave
public void registerStep(ExecutableStep step) {
registeredSteps.add((AnnaStep) step);
((AnnaStep) step).setState(State.REGISTERED);
logger.debug(this, "registered step " + step);
StepSheduler ss;
if(step.isCyclic()){
ss = new CyclicStepSheduler((AnnaStep) step, handler, logger);
} else {
ss = new ImmediateStepSheduler((AnnaStep) step, handler, logger);
}
synchronized (exe) {
exe.submit(ss);
}
}
public synchronized Properties getServerProperties() {
return new Properties(properties);
}
// handler threadsave
public void addEventListener(AnnaEventListener observer) {
handler.addEventListener(observer);
}
// handler threadsave
public void removeEventListener(AnnaEventListener observer) {
handler.removeEventListener(observer);
}
public String toString() {
return this.getClass().getSimpleName();
}
private synchronized Properties getPropertes() {
final Properties defaultProperties = initDefaults();
final Properties pro = new Properties(defaultProperties);
try {
System.out.println(this + ": loading settings from "
+ PROPERTIES_FILE);
final FileInputStream fi = new FileInputStream(PROPERTIES_FILE);
pro.load(fi);
fi.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println(this + ": could not load settings from "
+ PROPERTIES_FILE.getAbsolutePath() + ", using defaults");
} catch (IOException e) {
e.printStackTrace();
System.out.println(this + ": could not load settings from "
+ PROPERTIES_FILE.getAbsolutePath() + ", using defaults");
}
return pro;
}
private synchronized Properties initDefaults() {
Properties pro = new Properties();
// pro.setProperty(WORKING_DIR_KEY, WORKING_DIR_VALUE);
return pro;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
public class CyclicStepSheduler extends StepSheduler implements
AnnaEventListener {
CyclicStepSheduler(AnnaStep step, EventHandler handler, LogDispatcher logger) {
super(step, handler, logger);
handler.addEventListener(this);
}
public Void call() throws Exception {
synchronized (this) {
while (true) {
logger.debug(this,"running " + step);
this.exe = new AnnaSepExecutor(step, handler, logger);
exe.call();
logger.debug(this,"done, waiting");
this.wait();
logger.debug(this,"awake again");
}
}
}
public void eventOccoured(AnnaEvent event) {
if (event instanceof StepStateChangeEvent) {
StepStateChangeEvent c = (StepStateChangeEvent) event;
if (!c.getStep().equals(this)) {
synchronized (this) {
this.notifyAll();
}
}
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
/**
* @lastVisit 2009-09-18
* @author Alexander Kerner
*
*/
public class AnnaServerActivator implements BundleActivator {
private LogDispatcher logger = null;
public void start(BundleContext context) throws Exception {
logger = new LogDispatcherImpl(context);
final AnnaServer service = new AnnaServerImpl(logger);
context.registerService(AnnaServer.class.getName(), service,
new Hashtable<Object, Object>());
logger.debug(this, "activated");
}
public void stop(BundleContext context) throws Exception {
// TODO method stub
}
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.concurrent.Callable;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.Server;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
class AnnaSepExecutor implements Callable<Boolean> {
private final AnnaStep step;
private final LogDispatcher logger;
private final EventHandler handler;
AnnaSepExecutor(AnnaStep step, EventHandler handler, LogDispatcher logger) {
this.step = step;
this.logger = logger;
this.handler = handler;
}
public Boolean call() throws Exception {
boolean success = true;
try {
stepStateChanged(step, State.CHECK_NEED_TO_RUN);
final boolean b = step.canBeSkipped();
if (b) {
logger.info(this, "step " + step
+ " does not need to run, skipping");
stepStateChanged(step, State.SKIPPED);
// success == true;
return success;
}
logger.debug(this, "step " + step + " needs to run");
stepStateChanged(step, State.WAIT_FOR_REQ);
synchronized (Server.class) {
while (!step.requirementsSatisfied()) {
logger.debug(this, "requirements for step " + step
+ " not satisfied, putting it to sleep");
Server.class.wait();
}
logger.debug(this, "requirements for step " + step
+ " satisfied");
logger.debug(this, "notifying others");
Server.class.notifyAll();
}
success = runStep();
stepFinished(success);
} catch (Exception e) {
logger.info(this, "executing step " + step + " was erroneous", e);
stepStateChanged(step, State.ERROR);
}
return success;
}
private synchronized boolean runStep() throws StepExecutionException {
logger.debug(this, "step " + step + "running");
stepStateChanged(step, State.RUNNING);
return step.run();
}
private synchronized void stepStateChanged(AnnaStep step, State state){
step.setState(state);
handler.stepStateChanged(step);
}
private void stepFinished(boolean success) {
logger.debug(this, "step " + step + "done running");
if (success) {
stepStateChanged(step, State.DONE);
} else {
stepStateChanged(step, State.ERROR);
}
synchronized (Server.class) {
logger.debug(this, "notifying others");
Server.class.notifyAll();
}
}
public String toString() {
return this.getClass().getSimpleName() + ":"
+ step.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import de.mpg.mpiz.koeln.anna.step.ExecutableStep;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface ExecutorServer extends Server {
void registerStep(ExecutableStep step);
void unregisterStep(ExecutableStep step);
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import java.util.EventListener;
import de.mpg.koeln.anna.core.events.AnnaEvent;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface AnnaEventListener extends EventListener {
void eventOccoured(AnnaEvent event);
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface AnnaServer extends ExecutorServer {
final static String PROPERTIES_KEY_PREFIX = "anna.server.";
final static String WORKING_DIR_KEY = PROPERTIES_KEY_PREFIX
+ "workingdir";
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import java.util.Properties;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface Server {
Properties getServerProperties();
void addEventListener(AnnaEventListener observer);
void removeEventListener(AnnaEventListener observer);
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
public interface AnnaStep extends ExecutableStep, ObservableStep {
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
import java.util.Properties;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
public interface ExecutableStep {
boolean requirementsSatisfied() throws StepExecutionException;
boolean canBeSkipped() throws StepExecutionException;
boolean run() throws StepExecutionException;
Properties getStepProperties();
boolean isCyclic();
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
public interface ObservableStep {
public enum State {
LOOSE, REGISTERED, CHECK_NEED_TO_RUN, WAIT_FOR_REQ, RUNNING, DONE,
ERROR, SKIPPED
}
State getState();
void setState(State state);
}
| Java |
package de.mpg.koeln.anna.core.events;
import java.util.Collection;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public class StepStateChangeEvent extends AnnaEvent {
private static final long serialVersionUID = 4513665226131110643L;
private final AnnaStep step;
public StepStateChangeEvent(Object source, Collection<AnnaStep> steps, AnnaStep step) {
super(source, steps);
this.step = step;
}
public AnnaStep getStep() {
return step;
}
public State getState() {
return step.getState();
}
@Override
public String toString() {
return new StringBuilder().append(super.toString()).append("[").append(
"step").append("=").append(step).append("]").append("[").append(
"state").append("=").append(step.getState()).append("]").toString();
}
}
| Java |
package de.mpg.koeln.anna.core.events;
import java.util.Collection;
import java.util.EventObject;
import java.util.HashSet;
import java.util.Set;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public class AnnaEvent extends EventObject {
private static final long serialVersionUID = 1551843380559471696L;
private final Set<AnnaStep> registeredSteps = new HashSet<AnnaStep>();
public AnnaEvent(Object source, Collection<? extends AnnaStep> registeredSteps) {
super(source);
this.registeredSteps.clear();
this.registeredSteps.addAll(registeredSteps);
}
public Collection<AnnaStep> getRegisteredSteps(){
return new HashSet<AnnaStep>(registeredSteps);
}
@Override
public String toString() {
return new StringBuilder().append(super.toString().substring(super.toString().lastIndexOf("."))).append("[").append(
"stepReg").append("=").append(registeredSteps).append("]").toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
class ImmediateStepSheduler extends StepSheduler {
ImmediateStepSheduler(AnnaStep step, EventHandler handler,
LogDispatcher logger) {
super(step, handler, logger);
}
public Void call() throws Exception {
start();
return null;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.ArrayList;
import java.util.Collection;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
* <p> Simple helper class </p>
* @threadSave all sync to this
* @author Alexander Kerner
* @lastVisit 2009-09-22
*
*/
class EventHandler {
private final Collection<AnnaEventListener> observers = new ArrayList<AnnaEventListener>();
private final Collection<AnnaStep> registeredSteps;
public EventHandler(Collection<AnnaStep> registeredSteps) {
this.registeredSteps = registeredSteps;
}
public synchronized void stepStateChanged(AnnaStep step){
broadcastEvent(new StepStateChangeEvent(this, registeredSteps, step));
}
private void broadcastEvent(AnnaEvent event) {
if (observers.isEmpty())
return;
for (AnnaEventListener l : observers) {
l.eventOccoured(event);
}
}
synchronized void addEventListener(AnnaEventListener observer) {
observers.add(observer);
}
synchronized void removeEventListener(AnnaEventListener observer) {
observers.remove(observer);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
*
*/
public abstract class StepSheduler implements Callable<Void> {
private final ExecutorService pool = Executors.newSingleThreadExecutor();
protected final AnnaStep step;
protected final EventHandler handler;
protected final LogDispatcher logger;
protected volatile AnnaSepExecutor exe;
StepSheduler(AnnaStep step, EventHandler handler, LogDispatcher logger) {
this.step = step;
this.handler = handler;
this.logger = logger;
this.exe = new AnnaSepExecutor(step, handler, logger);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + ":"
+ exe.getClass().getSimpleName();
}
public synchronized void start(){
pool.submit(exe);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ExecutableStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
public class AnnaServerImpl implements AnnaServer {
// TODO path
private final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration"
+ File.separatorChar + "server.properties");
private final Collection<AnnaStep> registeredSteps = new HashSet<AnnaStep>();
private final EventHandler handler;
private final Properties properties;
private final ExecutorService exe = Executors.newCachedThreadPool();
private final LogDispatcher logger;
AnnaServerImpl(final LogDispatcher logger) {
if (logger != null)
this.logger = logger;
else
this.logger = new ConsoleLogger();
properties = getPropertes();
logger.debug(this, "loaded properties: " + properties);
handler = new EventHandler(registeredSteps);
handler.addEventListener(new NotifyOthersListener(logger));
}
public synchronized void unregisterStep(ExecutableStep step) {
// TODO Auto-generated method stub
}
public synchronized void registerStep(ExecutableStep step) {
registeredSteps.add((AnnaStep) step);
setStepState(step, State.REGISTERED);
logger.debug(this, "registered step " + step);
StepSheduler ss;
if(step.isCyclic()){
ss = new CyclicStepSheduler((AnnaStep) step, handler, logger);
} else {
ss = new ImmediateStepSheduler((AnnaStep) step, handler, logger);
}
exe.submit(ss);
}
public synchronized Properties getServerProperties() {
return new Properties(properties);
}
// handler threadsave
public void addEventListener(AnnaEventListener observer) {
handler.addEventListener(observer);
}
// handler threadsave
public void removeEventListener(AnnaEventListener observer) {
handler.removeEventListener(observer);
}
public String toString() {
return this.getClass().getSimpleName();
}
private synchronized Properties getPropertes() {
final Properties defaultProperties = initDefaults();
final Properties pro = new Properties(defaultProperties);
try {
System.out.println(this + ": loading settings from "
+ PROPERTIES_FILE);
final FileInputStream fi = new FileInputStream(PROPERTIES_FILE);
pro.load(fi);
fi.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println(this + ": could not load settings from "
+ PROPERTIES_FILE.getAbsolutePath() + ", using defaults");
} catch (IOException e) {
e.printStackTrace();
System.out.println(this + ": could not load settings from "
+ PROPERTIES_FILE.getAbsolutePath() + ", using defaults");
}
return pro;
}
private Properties initDefaults() {
Properties pro = new Properties();
// pro.setProperty(WORKING_DIR_KEY, WORKING_DIR_VALUE);
return pro;
}
private void setStepState(ExecutableStep step, State state) {
((AnnaStep) step).setState(state);
handler.stepStateChanged((AnnaStep) step);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep;
public class CyclicStepSheduler extends ImmediateStepSheduler implements
AnnaEventListener {
CyclicStepSheduler(AnnaStep step, EventHandler handler, LogDispatcher logger) {
super(step, handler, logger);
handler.addEventListener(this);
}
@Override
public Void call() throws Exception {
// do nothing until some other steps are done
return null;
}
public void eventOccoured(AnnaEvent event) {
if (event instanceof StepStateChangeEvent) {
logger.debug(this, "received step state changed event " + event);
final StepStateChangeEvent c = (StepStateChangeEvent) event;
if (c.getStep().equals(step)) {
logger.debug(this, "it was us, ignoring");
} else if (!(c.getStep().getState().equals(
ObservableStep.State.DONE) || c.getStep().getState()
.equals(ObservableStep.State.SKIPPED))) {
logger.debug(this, "step state change was not to state "
+ ObservableStep.State.DONE + "/"
+ ObservableStep.State.SKIPPED + ", ignoring");
} else {
logger.debug(this, "someone else finished, starting");
exe = new AnnaSepExecutor(step, handler, logger);
start();
}
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
* <p> Helper class, to release lock when step finished.</p>
* @author Alexander Kerner
*
*/
class NotifyOthersListener implements AnnaEventListener {
private final LogDispatcher logger;
NotifyOthersListener(LogDispatcher logger) {
this.logger = logger;
}
public void eventOccoured(AnnaEvent event) {
if(event instanceof StepStateChangeEvent){
final State state = ((StepStateChangeEvent) event).getState();
// state "SKIPPED" not needed, because skipped steps never acquire lock
if(state.equals(State.DONE) || state.equals(State.ERROR)){
synchronized (AnnaSepExecutor.LOCK) {
logger.debug(this, "notifying others");
AnnaSepExecutor.LOCK.notifyAll();
}
} else {
// nothing
}
}else {
// nothing
}
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
/**
* @lastVisit 2009-09-18
* @author Alexander Kerner
*
*/
public class AnnaServerActivator implements BundleActivator {
private LogDispatcher logger = null;
public void start(BundleContext context) throws Exception {
logger = new LogDispatcherImpl(context);
final AnnaServer service = new AnnaServerImpl(logger);
context.registerService(AnnaServer.class.getName(), service,
new Hashtable<Object, Object>());
logger.debug(this, "activated");
}
public void stop(BundleContext context) throws Exception {
// TODO method stub
}
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.serverimpl;
import java.util.concurrent.Callable;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.server.Server;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-22
* @thradSave custom
*
*/
class AnnaSepExecutor implements Callable<Void> {
public final static Object LOCK = Server.class;
private final AnnaStep step;
private final LogDispatcher logger;
private final EventHandler handler;
AnnaSepExecutor(AnnaStep step, EventHandler handler, LogDispatcher logger) {
this.step = step;
this.logger = logger;
this.handler = handler;
}
public Void call() throws Exception {
boolean success = true;
stepStateChanged(State.CHECK_NEED_TO_RUN);
final boolean b = step.canBeSkipped();
if (b) {
logger.info(this, "step " + step
+ " does not need to run, skipping");
stepStateChanged(State.SKIPPED);
stepFinished(success);
return null;
}
logger.debug(this, "step " + step + " needs to run");
stepStateChanged(State.WAIT_FOR_REQ);
synchronized (LOCK) {
while (!step.requirementsSatisfied()) {
logger.debug(this, "requirements for step " + step
+ " not satisfied, putting it to sleep");
LOCK.wait();
}
logger.debug(this, "requirements for step " + step + " satisfied");
}
try {
success = runStep();
} catch (Exception e) {
if (e instanceof StepExecutionException) {
logger.warn(this, e.getLocalizedMessage(), e);
} else {
logger.error(this, e.getLocalizedMessage(), e);
}
stepStateChanged(State.ERROR);
success = false;
}
stepFinished(success);
return null;
}
private boolean runStep() throws StepExecutionException {
logger.debug(this, "step " + step + " running");
stepStateChanged(State.RUNNING);
return step.run();
}
private void stepStateChanged(State state) {
step.setState(state);
handler.stepStateChanged(step);
}
private void stepFinished(boolean success) {
logger.debug(this, "step " + step + " done running");
if (success && !(step.getState().equals(ObservableStep.State.SKIPPED))) {
stepStateChanged(ObservableStep.State.DONE);
} else if (!success
&& !(step.getState().equals(ObservableStep.State.SKIPPED))) {
stepStateChanged(ObservableStep.State.ERROR);
}
}
public String toString() {
return this.getClass().getSimpleName() + ":"
+ step.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import de.mpg.mpiz.koeln.anna.step.ExecutableStep;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface ExecutorServer extends Server {
void registerStep(ExecutableStep step);
void unregisterStep(ExecutableStep step);
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import java.util.EventListener;
import de.mpg.koeln.anna.core.events.AnnaEvent;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface AnnaEventListener extends EventListener {
void eventOccoured(AnnaEvent event);
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface AnnaServer extends ExecutorServer {
final static String PROPERTIES_KEY_PREFIX = "anna.server.";
final static String WORKING_DIR_KEY = PROPERTIES_KEY_PREFIX
+ "workingdir";
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import java.util.Properties;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface Server {
Properties getServerProperties();
// TODO: AnnaEventListener does not match this interface abstraction
void addEventListener(AnnaEventListener observer);
void removeEventListener(AnnaEventListener observer);
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
public interface AnnaStep extends ExecutableStep, ObservableStep {
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
import java.util.Properties;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
public interface ExecutableStep {
boolean requirementsSatisfied() throws StepExecutionException;
boolean canBeSkipped() throws StepExecutionException;
boolean run() throws StepExecutionException;
Properties getStepProperties();
boolean isCyclic();
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
import java.util.List;
public interface ObservableStep {
public enum State {
// non-finished steps
LOOSE, REGISTERED, CHECK_NEED_TO_RUN, WAIT_FOR_REQ, RUNNING,
// finished steps
DONE, ERROR, SKIPPED;
public boolean isFinished(){
switch (this) {
case DONE:
return true;
case ERROR:
return true;
case SKIPPED:
return true;
default:
return false;
}
}
}
State getState();
void setState(State state);
List<String> requirementsNeeded();
}
| Java |
package de.mpg.mpiz.koeln.anna.step.common;
import de.mpg.mpiz.koeln.anna.step.ExecutableStep;
public class StepExecutionException extends Exception {
private static final long serialVersionUID = 5683856650378220175L;
private final ExecutableStep step;
public StepExecutionException(ExecutableStep step) {
this.step = step;
}
public StepExecutionException(ExecutableStep step, String arg0) {
super(arg0);
this.step = step;
}
public StepExecutionException(ExecutableStep step, Throwable arg0) {
super(arg0);
this.step = step;
}
public StepExecutionException(ExecutableStep step, String arg0, Throwable arg1) {
super(arg0, arg1);
this.step = step;
}
public ExecutableStep getStep(){
return step;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.common;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.ExecutableStep;
/**
* @lastVisit 2009-08-12
* @ThreadSave stateless
* @author Alexander Kerner
* @Exceptions good
*
*/
public class StepUtils {
private StepUtils() {}
public static void handleException(ExecutableStep cause, Throwable t,
LogDispatcher logger) throws StepExecutionException {
if (logger == null) {
handleException(cause, t);
} else {
// t.printStackTrace();
logger.error(cause, t.getLocalizedMessage(), t);
throw new StepExecutionException(cause, t);
}
}
public static void handleException(ExecutableStep cause, Throwable t)
throws StepExecutionException {
t.printStackTrace();
throw new StepExecutionException(cause, t);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data;
public class DataBeanAccessException extends Exception {
private static final long serialVersionUID = 4002480662305683330L;
public DataBeanAccessException() {
}
public DataBeanAccessException(String arg0) {
super(arg0);
}
public DataBeanAccessException(Throwable arg0) {
super(arg0);
}
public DataBeanAccessException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.gff.element.NewGFFElement;
public interface GFF3DataBean extends DataBean{
public ArrayList<FASTAElement> getInputSequence();
public void setInputSequence(ArrayList<FASTAElement> inputSequence);
public ArrayList<FASTAElement> getVerifiedGenesFasta();
public void setVerifiedGenesFasta(ArrayList<FASTAElement> verifiedGenesFasta);
public ArrayList<NewGFFElement> getVerifiedGenesGFF();
public void setVerifiedGenesGFF(ArrayList<NewGFFElement> verifiedGenesGFF);
public ArrayList<NewGFFElement> getPredictedGenesGFF();
public void setPredictedGenesGFF(ArrayList<NewGFFElement> predictedGenesGFF);
public ArrayList<NewGFFElement> getRepeatMaskerGFF();
public void setRepeatMaskerGFF(ArrayList<NewGFFElement> repeatMaskerGFF);
public Map<String, Serializable> getCustom();
public void setCustom(Map<String, Serializable> custom);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.gff.element.NewGFFElement;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
public class GFF3DataBeanImpl implements GFF3DataBean {
private static final long serialVersionUID = -8241571899555002582L;
private ArrayList<FASTAElement> inputSequence = new ArrayList<FASTAElement>();
private ArrayList<FASTAElement> verifiedGenesFasta = new ArrayList<FASTAElement>();
private ArrayList<NewGFFElement> verifiedGenesGFF = new ArrayList<NewGFFElement>();
private ArrayList<NewGFFElement> predictedGenesGFF = new ArrayList<NewGFFElement>();
private ArrayList<NewGFFElement> repeatMaskerGFF = new ArrayList<NewGFFElement>();
private Map<String, Serializable> custom = new HashMap<String, Serializable>();
public ArrayList<FASTAElement> getInputSequence() {
return inputSequence;
}
public void setInputSequence(ArrayList<FASTAElement> inputSequence) {
this.inputSequence = inputSequence;
}
public ArrayList<FASTAElement> getVerifiedGenesFasta() {
return verifiedGenesFasta;
}
public void setVerifiedGenesFasta(ArrayList<FASTAElement> verifiedGenesFasta) {
this.verifiedGenesFasta = verifiedGenesFasta;
}
public ArrayList<NewGFFElement> getVerifiedGenesGFF() {
return verifiedGenesGFF;
}
public void setVerifiedGenesGFF(ArrayList<NewGFFElement> verifiedGenesGFF) {
this.verifiedGenesGFF = verifiedGenesGFF;
}
public ArrayList<NewGFFElement> getPredictedGenesGFF() {
return predictedGenesGFF;
}
public void setPredictedGenesGFF(ArrayList<NewGFFElement> predictedGenesGFF) {
this.predictedGenesGFF = predictedGenesGFF;
}
public ArrayList<NewGFFElement> getRepeatMaskerGFF() {
return repeatMaskerGFF;
}
public void setRepeatMaskerGFF(ArrayList<NewGFFElement> repeatMaskerGFF) {
this.repeatMaskerGFF = repeatMaskerGFF;
}
public Map<String, Serializable> getCustom() {
return custom;
}
public void setCustom(Map<String, Serializable> custom) {
this.custom = custom;
}
@Override
public String toString(){
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data;
import java.io.Serializable;
import java.util.Map;
public interface DataBean extends Serializable {
public Map<String, Serializable> getCustom();
public void setCustom(Map<String, Serializable> custom);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data;
public class DataBeanAccessException extends Exception {
private static final long serialVersionUID = 4002480662305683330L;
public DataBeanAccessException() {
}
public DataBeanAccessException(String arg0) {
super(arg0);
}
public DataBeanAccessException(Throwable arg0) {
super(arg0);
}
public DataBeanAccessException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data;
import java.util.Collection;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.gff3.element.GFF3Element;
public interface GFF3DataBean extends DataBean {
public Collection<FASTAElement> getInputSequence();
public void setInputSequence(Collection<FASTAElement> inputSequence);
public Collection<FASTAElement> getVerifiedGenesFasta();
public void setVerifiedGenesFasta(Collection<FASTAElement> verifiedGenesFasta);
public Collection<GFF3Element> getVerifiedGenesGFF();
public void setVerifiedGenesGFF(Collection<GFF3Element> verifiedGenesGFF);
public Collection<GFF3Element> getPredictedGenesGFF();
public void setPredictedGenesGFF(Collection<GFF3Element> predictedGenesGFF);
public Collection<GFF3Element> getRepeatMaskerGFF();
public void setRepeatMaskerGFF(Collection<GFF3Element> repeatMaskerGFF);
public Collection<FASTAElement> getESTs();
public void setESTs(Collection<FASTAElement> ests);
public Collection<GFF3Element> getMappedESTs();
public void setMappedESTs(Collection<GFF3Element> mappedESTs);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.gff3.element.GFF3Element;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
public class GFF3DataBeanImpl implements GFF3DataBean {
private static final long serialVersionUID = -8241571899555002582L;
private ArrayList<FASTAElement> inputSequence = new ArrayList<FASTAElement>();
private ArrayList<FASTAElement> ests = new ArrayList<FASTAElement>();
private ArrayList<FASTAElement> verifiedGenesFasta = new ArrayList<FASTAElement>();
private ArrayList<GFF3Element> verifiedGenesGFF = new ArrayList<GFF3Element>();
private ArrayList<GFF3Element> predictedGenesGFF = new ArrayList<GFF3Element>();
private ArrayList<GFF3Element> repeatMaskerGFF = new ArrayList<GFF3Element>();
private ArrayList<GFF3Element> mappedESTs = new ArrayList<GFF3Element>();
private Map<String, Serializable> custom = new ConcurrentHashMap<String, Serializable>();
public Collection<FASTAElement> getInputSequence() {
return inputSequence;
}
public void setInputSequence(Collection<FASTAElement> inputSequence) {
this.inputSequence.clear();
this.inputSequence.addAll(inputSequence);
}
public Collection<FASTAElement> getVerifiedGenesFasta() {
return verifiedGenesFasta;
}
public void setVerifiedGenesFasta(Collection<FASTAElement> verifiedGenesFasta) {
this.verifiedGenesFasta.clear();
this.verifiedGenesFasta.addAll(verifiedGenesFasta);
}
public Collection<GFF3Element> getVerifiedGenesGFF() {
return verifiedGenesGFF;
}
public void setVerifiedGenesGFF(Collection<GFF3Element> verifiedGenesGFF) {
this.verifiedGenesGFF.clear();
this.verifiedGenesGFF.addAll(verifiedGenesGFF);
}
public Collection<GFF3Element> getPredictedGenesGFF() {
return predictedGenesGFF;
}
public void setPredictedGenesGFF(Collection<GFF3Element> predictedGenesGFF) {
this.predictedGenesGFF.clear();
this.predictedGenesGFF.addAll(predictedGenesGFF);
}
public Collection<GFF3Element> getRepeatMaskerGFF() {
return repeatMaskerGFF;
}
public void setRepeatMaskerGFF(Collection<GFF3Element> repeatMaskerGFF) {
this.repeatMaskerGFF.clear();
this.repeatMaskerGFF.addAll(repeatMaskerGFF);
}
public Serializable getCustom(String ident) {
return custom.get(ident);
}
public void addCustom(String ident, Serializable custom) {
this.custom.put(ident, custom);
}
@Override
public String toString(){
return this.getClass().getSimpleName();
}
public Collection<FASTAElement> getESTs() {
return ests;
}
public void setESTs(Collection<FASTAElement> ests) {
this.ests.clear();
this.ests.addAll(ests);
}
public Collection<GFF3Element> getMappedESTs() {
return mappedESTs;
}
public void setMappedESTs(Collection<GFF3Element> mappedESTs) {
this.mappedESTs.clear();
this.mappedESTs.addAll(mappedESTs);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.data;
import java.io.Serializable;
public interface DataBean extends Serializable {
public Serializable getCustom(String ident);
public void addCustom(String ident, Serializable custom);
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.abstractlistener;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.kerner.osgi.commons.utils.ServiceRetriever;
import de.kerner.osgi.commons.utils.ServiceRetrieverImpl;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
public abstract class AbstractEventListener implements BundleActivator, AnnaEventListener {
private volatile ServiceRetriever<AnnaServer> retriever;
protected LogDispatcher logger;
public void start(BundleContext context) throws Exception {
this.retriever = new ServiceRetrieverImpl<AnnaServer>(context, AnnaServer.class);
AnnaServer s = retriever.getService();
s.addEventListener(this);
logger = new LogDispatcherImpl(context);
}
public void stop(BundleContext context) throws Exception {
retriever = null;
logger = null;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.abstractlistener;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.kerner.osgi.commons.utils.ServiceRetriever;
import de.kerner.osgi.commons.utils.ServiceRetrieverImpl;
import de.mpg.mpiz.koeln.anna.server.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
public abstract class AbstractEventListener implements BundleActivator, AnnaEventListener {
private volatile ServiceRetriever<AnnaServer> retriever;
protected LogDispatcher logger;
public void start(BundleContext context) throws Exception {
this.retriever = new ServiceRetrieverImpl<AnnaServer>(context, AnnaServer.class);
AnnaServer s = retriever.getService();
s.addEventListener(this);
logger = new LogDispatcherImpl(context);
}
public void stop(BundleContext context) throws Exception {
retriever = null;
logger = null;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.exonerate.common;
public class ExonerateConstants {
private ExonerateConstants(){}
public final static String WORKING_DIR_KEY = "anna.step.exonerate.workingDir";
public final static String EXE_DIR_KEY = "anna.step.exonerate.exeDir";
public final static String EXE = "exonerate";
public static final String EST_FILENAME = "ests.fasta";
public static final String INSEQ_FILENAME = "inputsequence.fasta";
public static final String RESULT_FILENAME = "exonerate-result.gff";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.exonerate.common;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.bioutils.gff3.converter.GFF3FileExtender;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.element.GFF3ElementBuilder;
import de.bioutils.gff3.element.GFF3ElementGroup;
import de.bioutils.gff3.file.GFF3File;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3WrapperStep;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public abstract class AbstractStepExonerate extends AbstractGFF3WrapperStep {
private final class DataAdapter implements GFF3FileExtender {
public GFF3File extend(GFF3File gff3File) {
final GFF3ElementGroup g = new GFF3ElementGroup();
for (GFF3Element e : gff3File.getElements()) {
final String source = e.getSource();
final String sourceNew = source.replaceAll(":", "");
logger.debug(this, "changing source identifier from \""
+ source + "\" to \"" + sourceNew + "\"");
g.add(new GFF3ElementBuilder(e).setSource(sourceNew).build());
}
return new GFF3FileImpl(g);
}
}
// fields volatile
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
workingDir = new File(getStepProperties().getProperty(
ExonerateConstants.WORKING_DIR_KEY));
exeDir = new File(getStepProperties().getProperty(
ExonerateConstants.EXE_DIR_KEY));
}
public void prepare() throws Exception {
createInputFile();
createESTFasta();
}
// workingDir volatile
private void createESTFasta() throws DataBeanAccessException,
ServiceNotAvailabeException, IOException {
final Collection<FASTAElement> ests = (Collection<FASTAElement>) getDataProxy()
.viewData().getESTs();
final File f2 = new File(workingDir, ExonerateConstants.EST_FILENAME);
new NewFASTAFileImpl(ests).write(f2);
logger.debug(this, "created tmp file for est fasta: "
+ f2.getAbsolutePath());
}
// workingDir volatile
private void createInputFile() throws Exception {
final Collection<FASTAElement> inFastas = getDataProxy().viewData()
.getInputSequence();
final File f1 = new File(workingDir, ExonerateConstants.INSEQ_FILENAME);
new NewFASTAFileImpl(inFastas).write(f1);
logger.debug(this, "created tmp file input sequence(s): "
+ f1.getAbsolutePath());
}
// workingDir volatile
public boolean update() throws StepExecutionException {
try {
DataProxy<GFF3DataBean> p = getDataProxy();
GFF3File file = GFF3FileImpl.convertFromGFF(new File(workingDir,
ExonerateConstants.RESULT_FILENAME));
file = new DataAdapter().extend(file);
final Collection<? extends GFF3Element> result = file.getElements();
p.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setMappedESTs(new ArrayList<GFF3Element>(result));
}
});
return true;
} catch (Exception e) {
StepUtils.handleException(this, e);
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
logger.debug(this, "starting");
final File file = new File(workingDir,
ExonerateConstants.RESULT_FILENAME);
if (FileUtils.fileCheck(file, false) && outFileIsValid(file)) {
super.addShortCutFile(file);
} else {
logger.info(this, file + " is not there or invalid, will not do shortcut");
}
super.redirectOutStreamToFile(file);
super.addResultFileToWaitFor(new File(workingDir,
ExonerateConstants.RESULT_FILENAME));
return super.start();
}
private boolean outFileIsValid(File file) {
NewGFFFile gff;
try {
gff = NewGFFFileImpl.parseFile(file);
// TODO: size == 0 does not really indicate an invalid file
if (gff.getElements() == null || gff.getElements().size() == 0)
return false;
return true;
} catch (Exception e) {
logger.debug(this, e.getLocalizedMessage(), e);
return false;
}
}
public boolean isCyclic() {
return false;
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean b = (data.viewData().getMappedESTs() != null && data
.viewData().getMappedESTs().size() != 0);
logger.debug(this, StringUtils.getString("need to run: ests=", b));
return b;
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
@Override
public List<String> requirementsNeeded(DataProxy<GFF3DataBean> data)
throws Exception {
final List<String> r = new ArrayList<String>();
final boolean ests = (data.viewData().getESTs() != null && (data
.viewData().getESTs().size() != 0));
final boolean inseq = (data.viewData().getInputSequence() != null && data
.viewData().getInputSequence().size() != 0);
if(!ests){
r.add("EST sequences");
}
if(!inseq){
r.add("input sequence(s)");
}
return r;
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final boolean ests = (data.viewData().getESTs() != null && (data
.viewData().getESTs().size() != 0));
final boolean inseq = (data.viewData().getInputSequence() != null && data
.viewData().getInputSequence().size() != 0);
logger.debug(this, StringUtils.getString("requirements: ests=",
ests));
logger.debug(this, StringUtils.getString("requirements: inseq=",
inseq));
return (ests && inseq);
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.util.ArrayList;
import de.kerner.commons.workflow.WorkFlow;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
public class ExecutionWorkflow implements WorkFlow {
private final ArrayList<WorkFlowElement> elements = new ArrayList<WorkFlowElement>();
public synchronized void addElement(WorkFlowElement e){
elements.add(e);
}
public void work() throws WorkFlowException {
for(WorkFlowElement e : elements){
e.work();
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import de.kerner.commons.file.HumanReadableFileSizePrinter;
import de.kerner.commons.logging.Log;
public class UploadBacking {
/**
* <p> For example "#{userBean}" </p>
*/
public static String getIdentString(){
return "#{uploadBacking}";
}
private final static Log log = new Log(UploadBacking.class);
private UploadedFile myFile;
public void setMyFile(UploadedFile myFile) {
this.myFile = myFile;
}
public UploadedFile getMyFile() {
return myFile;
}
public String getFileSize(){
if(myFile == null)
return null;
final long size = myFile.getSize();
return new HumanReadableFileSizePrinter(size, false).toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import de.kerner.commons.workflow.WorkFlowException;
public class InformByFacesMessageWorkFlowException extends WorkFlowException {
private static final long serialVersionUID = -6001010151572002001L;
public InformByFacesMessageWorkFlowException() {
}
public InformByFacesMessageWorkFlowException(String message) {
super(message);
}
public InformByFacesMessageWorkFlowException(Throwable cause) {
super(cause);
}
public InformByFacesMessageWorkFlowException(String message, Throwable cause) {
super(message, cause);
}
@Override
public void doSomething() {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(getLocalizedMessage()));
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
public class ArabidobsisBean extends TrainingSpeciesBean {
ArabidobsisBean(){
super();
setName("arabidopsis-thaliana");
setPath("/home/proj/kerner/diplom/anna/page/trainingFiles/arabidopsis-thaliana");
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
public class FusariumBean extends TrainingSpeciesBean {
FusariumBean(){
super();
setName("fusarium-graminearum");
setPath("/home/proj/kerner/diplom/anna/page/trainingFiles/fusarium-graminearum");
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.io.File;
import de.kerner.commons.eee.JSFUtil;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
import de.kerner.commons.zip.ZipUtils;
public class Extractor implements WorkFlowElement {
private final File dir;
public Extractor(File dir){
this.dir = dir;
}
public void work() throws WorkFlowException {
final ConfigBean config = JSFUtil.getManagedObject(ConfigBean
.getIdentString(), ConfigBean.class);
final String path = config.getWorkingDir();
final String zipName = config.getZipName();
try {
ZipUtils.extractToDir(new File(path, zipName), dir);
} catch (Exception e) {
throw new InformByFacesMessageWorkFlowException(e.getLocalizedMessage(), e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
public class ConfigBean {
/**
* <p> For example "#{userBean}" </p>
*/
public static String getIdentString(){
return "#{configBean}";
}
private String workingDir;
private String zipName;
private String trainingFileName;;
public String getWorkingDir() {
return workingDir;
}
public void setWorkingDir(String workingDir) {
this.workingDir = workingDir;
}
public String getZipName() {
return zipName;
}
public void setZipName(String zipName) {
this.zipName = zipName;
}
public String getTrainingFileName() {
return trainingFileName;
}
public void setTrainingFileName(String trainingFileName) {
this.trainingFileName = trainingFileName;
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.io.File;
import de.kerner.commons.eee.JSFUtil;
import de.kerner.commons.logging.Log;
import de.kerner.commons.workflow.WorkFlowException;
public class RunBacking {
private final static Log log = new Log(RunBacking.class);
private volatile File sessionDir = null;
public synchronized String run() {
assignSessionDir();
final ExecutionWorkflow work = new ExecutionWorkflow();
work.addElement(new CheckIfFileWasUploaded());
work.addElement(new SessionDirCreator());
work.addElement(new Extractor(sessionDir));
work.addElement(new CreateInputSequence(sessionDir));
work.addElement(new PropertiesAssigner(sessionDir));
work
.addElement(new TrainingFileCopier(
sessionDir,
new File(
"/home/proj/kerner/diplom/anna/annaWorkingDir/trainingFiles/fusarium-graminearum/trainingFile.bin")));
try {
work.work();
} catch (WorkFlowException e1) {
final InformByFacesMessageWorkFlowException ex = (InformByFacesMessageWorkFlowException) e1;
ex.doSomething();
return "fail";
}
return "success";
}
private void assignSessionDir() {
final ConfigBean config = JSFUtil.getManagedObject(ConfigBean
.getIdentString(), ConfigBean.class);
final String id = JSFUtil.getCurrentSession().getId();
final String path = config.getWorkingDir();
sessionDir = new File(path, id);
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
public class SelectTrainingSpeciesBacking {
private List<SelectItem> list = new ArrayList<SelectItem>();
// Constructor //
public SelectTrainingSpeciesBacking(){
list.add(getSelectItemFromTrainingSpeciesBean(new FusariumBean()));
list.add(getSelectItemFromTrainingSpeciesBean(new ArabidobsisBean()));
}
// Private //
private SelectItem getSelectItemFromTrainingSpeciesBean(TrainingSpeciesBean b){
return new SelectItem(b, b.getName());
}
// Getter / Setter //
public int getSize() {
return list.size();
}
public List<SelectItem> getList() {
return list;
}
public void setList(List<SelectItem> list) {
this.list = list;
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.io.File;
import java.io.IOException;
import de.kerner.commons.eee.JSFUtil;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
public class CreateInputSequence implements WorkFlowElement {
private final File sessionDir;
public CreateInputSequence(File sessionDir) {
this.sessionDir = sessionDir;
}
public void work() throws WorkFlowException {
// assume, that check for file has already be performed
try {
final UploadBacking u = JSFUtil.getManagedObject(UploadBacking
.getIdentString(), UploadBacking.class);
final File inputSeq = new File(sessionDir, "anna/input/inputSeq.fasta");
FileUtils.writeStreamToFile(u.getMyFile().getInputStream(), inputSeq);
} catch (IOException e) {
throw new InformByFacesMessageWorkFlowException(e.getLocalizedMessage(), e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.model.SelectItem;
public class TrainingSpeciesConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
throws ConverterException {
return arg1;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
throws ConverterException {
return arg2.toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.io.File;
import java.io.IOException;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
public class TrainingFileCopier implements WorkFlowElement {
private final File sessionDir;
private final File trainingFile;
public TrainingFileCopier(File sessionDir, File trainingFile) {
this.sessionDir = sessionDir;
this.trainingFile = trainingFile;
}
public void work() throws WorkFlowException {
final File tf = new File(sessionDir, "anna/data/conrad/trainingFile.bin");
try {
FileUtils.copyFile(trainingFile, tf);
} catch (Exception e) {
throw new InformByFacesMessageWorkFlowException(e.getLocalizedMessage(), e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
public class TrainingSpeciesBean {
private String name;
private String path;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.io.File;
import de.kerner.commons.eee.JSFUtil;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
public class SessionDirCreator implements WorkFlowElement {
public void work() throws WorkFlowException {
final ConfigBean config = JSFUtil.getManagedObject(ConfigBean
.getIdentString(), ConfigBean.class);
final String id = JSFUtil.getCurrentSession().getId();
final String path = config.getWorkingDir();
final File sessionDir = new File(path, id);
if (sessionDir.exists()) {
throw new InformByFacesMessageWorkFlowException("Currently only one job at a time per user is possible. Sorry!");
}
if (new File(path, id).mkdir()) {
// all good
} else {
throw new InformByFacesMessageWorkFlowException("could not create dir \"" + new File(path, id) + "\"");
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import de.kerner.commons.eee.JSFUtil;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
public class CheckIfFileWasUploaded implements WorkFlowElement {
public void work() throws WorkFlowException {
final UploadBacking u = JSFUtil.getManagedObject(UploadBacking
.getIdentString(), UploadBacking.class);
if (u.getMyFile() == null) {
throw new InformByFacesMessageWorkFlowException("No Sequence file provided");
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna;
import java.io.File;
import java.util.Properties;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.workflow.WorkFlowElement;
import de.kerner.commons.workflow.WorkFlowException;
public class PropertiesAssigner implements WorkFlowElement {
private final File sessionDir;
public PropertiesAssigner(File sessionDir) {
this.sessionDir = sessionDir;
}
public void work() throws WorkFlowException {
final Properties p = new Properties();
p.setProperty("anna.step.inputsequencereader.infile",
"input/inputSeq.fasta");
// not needed, since training will be skipped anyhow.
p.setProperty("anna.step.verified.fasta", "input/dummy.fasta");
p.setProperty("anna.step.verified.gtf", "input/dummy.gff3");
// TODO adaptations necessary if we do not run training?
p.setProperty("anna.step.conrad.adapter.offset", "200");
p.setProperty("anna.step.conrad.adapter.maxElementLength", "5000");
p.setProperty("anna.step.conrad.adapter.maxElementNumber", "5000");
p.setProperty("anna.step.repeatMasker.workingDir", "repeatMasker/");
p.setProperty("anna.step.repeatMasker.exeDir",
"/opt/share/common/science/RepeatMasker/");
p.setProperty("anna.step.repeatMasker.outstream.file", "out");
p.setProperty("anna.step.getResults.outDir", "results/");
p.setProperty("anna.step.getResults.fileName", "results.gff3");
try {
p.store(FileUtils.getOutputStreamForFile(new File(sessionDir,
"anna/configuration/step.properties")), null);
} catch (Exception e) {
throw new InformByFacesMessageWorkFlowException(e
.getLocalizedMessage(), e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.estreader;
import java.io.File;
import de.bioutils.DNABasicAlphabet;
import de.bioutils.fasta.FASTAElementGroup;
import de.bioutils.fasta.FASTAElementGroupImpl;
import de.bioutils.fasta.FastaUtils;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
public class ESTReader extends AbstractGFF3AnnaStep {
private final static String INFILE_KEY = "anna.step.estreader.infile";
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy) throws Throwable {
boolean b = true;
final FASTAElementGroup c = proxy.viewData().getESTs();
b = (c != null && c.asList().size() != 0);
logger.debug("can be skipped=" + b + "(" + c.asList().size()
+ ") est fastas retrieved");
return b;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws Throwable {
final File file = new File(getStepProperties().getProperty(INFILE_KEY));
logger.debug("reading file " + file);
NewFASTAFile f = NewFASTAFileImpl.parse(file);
logger.debug("reading file " + file + " done, updating data");
f = trimmFasta(f);
logger.debug("checking for valid alphabet");
final FASTAElementGroup sequencesNew = FastaUtils.adaptToAlphabet(
f.getElements(), new DNABasicAlphabet());
proxy.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setESTs(new FASTAElementGroupImpl(sequencesNew));
logger.debug("updating data done");
}
});
return true;
}
private NewFASTAFile trimmFasta(NewFASTAFile fastas) {
final String tmpHeader = fastas.getElements().iterator().next().getHeader();
logger.debug("trimming fasta headers");
fastas = FastaUtils.trimHeader(fastas);
logger.debug("done trimming fasta headers");
logger.debug("old header: \"" + tmpHeader + "\", new header: \""
+ fastas.getElements().iterator().next().getHeader() + "\"");
return fastas;
}
public boolean isCyclic() {
return false;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.progresslistener;
import java.util.Collection;
import java.util.Formatter;
import de.kerner.commons.file.FileUtils;
import de.mpg.koeln.anna.core.events.AnnaEvent;
import de.mpg.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.listener.abstractlistener.AbstractEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
public class ProgressMonitor extends AbstractEventListener {
private final static String PRE_LINE = "+++++++++++++++ MONITOR +++++++++++++++";
private final static String POST_LINE = "+++++++++++++++++++++++++++++++++++++++";
public void eventOccoured(AnnaEvent event) {
AnnaStep lastChanged = null;
if (event instanceof StepStateChangeEvent){
lastChanged = ((StepStateChangeEvent) event).getStep();
} else {
logger.info(this, event);
}
printStepStates(event, lastChanged);
}
private synchronized void printStepStates(AnnaEvent event, AnnaStep lastChangedStep) {
final Collection<AnnaStep> steps = event.getRegisteredSteps();
logger.info(this, PRE_LINE);
for (AnnaStep s :steps) {
final String s1 = s.toString();
final String s2 = "state=" + s.getState();
final StringBuilder sb = new StringBuilder();
// TODO better: String.format();
final Formatter f = new Formatter();
sb.append(f.format("\t%-28s\t%-22s", s1, s2).toString());
if (lastChangedStep != null && lastChangedStep.equals(s)) {
sb.append("\t(changed)");
}
logger.info(this, sb.toString());
}
logger.info(this, POST_LINE);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.progresslistener;
import java.util.Collection;
import java.util.Formatter;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEvent;
import de.mpg.mpiz.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.listener.abstractlistener.AbstractEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
public class ProgressListener extends AbstractEventListener {
private final static Log logger = new Log(ProgressListener.class);
private final static String PRE_LINE = " MONITOR ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
private final static String POST_LINE = "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
public void eventOccoured(AnnaEvent event) {
AnnaStep lastChanged = null;
if (event instanceof StepStateChangeEvent){
lastChanged = ((StepStateChangeEvent) event).getStep();
} else {
logger.info(event);
}
printStepStates(event, lastChanged);
}
private synchronized void printStepStates(AnnaEvent event, AnnaStep lastChangedStep) {
final Collection<AnnaStep> steps = event.getRegisteredSteps();
final StringBuilder hans = new StringBuilder();
hans.append(PRE_LINE);
hans.append(FileUtils.NEW_LINE);
for (AnnaStep s :steps) {
final String s1 = s.toString();
final String s2 = "state=" + s.getState();
final StringBuilder sb = new StringBuilder();
// TODO better: String.format();
final Formatter f = new Formatter();
sb.append(f.format("\t%-28s\t%-22s", s1, s2).toString());
if(s.getState().equals(State.WAIT_FOR_REQ)){
try {
if(s.requirementsNeeded().isEmpty()){
// skip
} else
sb.append(s.requirementsNeeded().iterator().next());
} catch (Exception e) {
logger.debug("cannot print needed requirements for step " + s, e);
}
}
if (lastChangedStep != null && lastChangedStep.equals(s)) {
sb.append("\t(changed)");
}
hans.append(sb.toString());
hans.append(FileUtils.NEW_LINE);
}
hans.append(POST_LINE);
logger.info(hans);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.AbstractStepRepeatMasker;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.RepeatMaskerConstants;
public class StepRepeatMaskerLocal extends AbstractStepRepeatMasker {
private class Process extends AbstractStepProcessBuilder {
private final File inFile;
protected Process(File executableDir, File stepWorkingDir,
LogDispatcher logger, File inFile) {
super(executableDir, stepWorkingDir, logger);
this.inFile = inFile;
}
public String toString() {
return this.getClass().getSimpleName();
}
@Override
protected List<String> getCommandList() {
// ./RepeatMasker -pa 2 -s -gff
// /home/proj/kerner/diplom/conrad/trainingAndCrossValidationWithProvidedData/test3/ref.fasta
final CommandStringBuilder builder = new CommandStringBuilder(new File(
executableDir, RepeatMaskerConstants.EXE).getAbsolutePath());
// builder.addValueCommand("-pa", "2");
// builder.addAllFlagCommands("-s");
builder.addFlagCommand("-gff");
builder.addFlagCommand("-qq");
builder.addFlagCommand(inFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess(File inFile) {
return new Process(exeDir, workingDir
, logger, inFile);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.AbstractStepRepeatMasker;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.RepeatMaskerConstants;
public class RepeatMaskerLocal extends AbstractStepRepeatMasker {
@Override
public List<String> getCmdList() {
final CommandStringBuilder builder = new CommandStringBuilder(new File(
exeDir, RepeatMaskerConstants.EXE).getAbsolutePath());
builder.addAllFlagCommands(RepeatMaskerConstants.OPTIONS_FLAG);
builder.addAllValueCommands(RepeatMaskerConstants.OPTIONS_VALUE);
// builder.addValueCommand("-pa", "2");
// builder.addAllFlagCommands("-s");
// builder.addFlagCommand("-gff");
// builder.addFlagCommand("-qq");
builder.addFlagCommand(inFile.getAbsolutePath());
return builder.getCommandList();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.data.adapter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff.element.NewGFFElement;
import de.bioutils.gff.element.NewGFFElementBuilder;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.bioutils.gff3.attribute.AttributeLine;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.file.GFF3File;
import de.bioutils.gff3.file.GFF3FileImpl;
public class GFF3ConverterImpl implements GFF3Converter {
public NewGFFFile convert(GFF3File file) {
final ArrayList<NewGFFElement> result = new ArrayList<NewGFFElement>();
for (GFF3Element e : file.getElements()) {
final NewGFFElementBuilder b = new NewGFFElementBuilder(e);
String s = e.getAttributeLine().toString();
s = s.replaceAll("=", " ");
final List<String> l = Arrays.asList(s.split(AttributeLine.ATTRIBUTE_SEPARATOR));
b.setAttributes(new ArrayList<String>(l));
result.add(b.build());
}
return new NewGFFFileImpl(result);
}
public static void main(String[] args) {
final File f = new File("/home/pcb/kerner/Desktop/ref.gtf");
final File f3 = new File("/home/pcb/kerner/Desktop/ref.new");
try {
final GFF3File f2 = GFF3FileImpl.convertFromGFF(f);
final NewGFFFile f4 = new GFF3ConverterImpl().convert(f2);
f4.write(f3);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GFFFormatErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.