code stringlengths 3 1.18M | language stringclasses 1 value |
|---|---|
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.conrad.predict.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.AbstractConradPredictStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class PredictLSF 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(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF
.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(ConradConstants.CONRAD_EXE);
builder.addFlagCommand("predict");
builder.addFlagCommand(trainingFile.getAbsolutePath());
builder.addFlagCommand(workingDir.getAbsolutePath());
// necessary, because "result" parameter will result in a file named
// result.gtf. If we here hand over "result.gtf" we later receive
// file named "result.gtf.gtf"
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.common.lsf;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Alexander Kerner
* @ThreadSave stateless
* @lastVisit 2009-08-12
* @Exceptions nothing to do
*
*/
public class LSF {
public final static String BSUB_EXE = "bsub";
private LSF(){}
public static Map<String, String> getBsubValueCommandStrings(File workingDir) {
final File LSFout = new File(workingDir, "lsf-%J-%I.out");
final File LSFerr = new File(workingDir, "lsf-%J-%I.err");
final Map<String, String> map = new HashMap<String,String>();
// map.put("-m", "pcbcn64");
map.put("-m", "pcbcomputenodes");
// map.put("-R", "rusage[mem=4000:swp=2000]");
map.put("-R", "rusage[mem=4000]");
map.put("-eo", LSFerr.getAbsolutePath());
map.put("-oo", LSFout.getAbsolutePath());
return map;
}
public static List<String> getBsubFlagCommandStrings() {
final List<String> list = new ArrayList<String>();
list.add("-K");
return list;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.getresults;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
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;
public class GetResults extends AbstractGFF3AnnaStep {
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return false;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
logger.debug(this, "IM RUNNING!!");
return false;
}
public boolean isCyclic() {
return true;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.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.repeatmasker.common.AbstractStepRepeatMasker;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.RepeatMaskerConstants;
public class RepeatMaskerLSF 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() {
final CommandStringBuilder builder = new CommandStringBuilder(LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(new File(
executableDir, RepeatMaskerConstants.EXE).getAbsolutePath());
// builder.addAllFlagCommands("-s");
builder.addFlagCommand("-gff");
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.inputsequencereader;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
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 InputSequenceReader extends AbstractGFF3AnnaStep {
private final static String INFILE_KEY = "anna.step.inputsequencereader.infile";
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "no requirements needed");
return true;
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (data.viewData().getInputSequence().size() != 0);
logger.debug(this, "need to run:");
logger.debug(this, "\tinputSequences=" + inputSequences);
logger.debug(this, "\tinputSequencesSize=" + inputSequencesSize);
return (inputSequences && inputSequencesSize);
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final File inFile = new File(getStepProperties().getProperty(
INFILE_KEY));
logger.debug(this, "reading file " + inFile);
final Collection<? extends FASTAElement> fastas = NewFASTAFileImpl.parse(inFile).getElements();
if (fastas == null || fastas.size() == 0) {
logger.warn(this, "file " + inFile + " is invalid");
return false;
}
logger.debug(this, "got input sequences:"
+ fastas.iterator().next().getHeader() + " [...]");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setInputSequence(new ArrayList<FASTAElement>(fastas));
}
});
return true;
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
public class RepeatMaskerConstants {
private RepeatMaskerConstants(){}
public final static String WORKING_DIR_KEY = "anna.step.repeatMasker.workingDir";
public final static String EXE_DIR_KEY = "anna.step.repeatMasker.exeDir";
public final static String TMP_FILENAME = "repMask";
public final static String OUTFILE_POSTFIX = ".out.gff";
public final static String EXE = "RepeatMasker";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
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.file.FileUtils;
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.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public abstract class AbstractStepRepeatMasker extends AbstractGFF3AnnaStep {
protected File exeDir;
protected File workingDir;
@Override
public String toString() {
return this.getClass().getSimpleName();
}
@Override
protected synchronized void init(BundleContext context) throws StepExecutionException {
super.init(context);
assignProperties();
validateProperties();
printProperties();
}
private void assignProperties() {
exeDir = new File(getStepProperties().getProperty(RepeatMaskerConstants.EXE_DIR_KEY));
workingDir = new File(getStepProperties().getProperty(RepeatMaskerConstants.WORKING_DIR_KEY));
}
private void validateProperties() throws StepExecutionException {
if (!FileUtils.dirCheck(exeDir, false))
throw new StepExecutionException(
"cannot access repeatmasker working dir");
if (!FileUtils.dirCheck(workingDir, true))
throw new StepExecutionException("cannot access step working dir");
}
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tstepWorkingDir=" + workingDir);
logger.debug(this, "\texeDir=" + exeDir);
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
// must this two actions be atomar?
final boolean repeatGtf = (data.viewData().getRepeatMaskerGFF() != null);
final boolean repeatGtfSize = (data.viewData()
.getRepeatMaskerGFF().size() != 0);
return (repeatGtf && repeatGtfSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
// must this two actions be atomar?
final boolean sequence = (data.viewData().getInputSequence() != null);
final boolean sequenceSize = (data.viewData()
.getInputSequence().size() != 0);
return (sequence && sequenceSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "running");
final File inFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME);
final File outFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME
+ RepeatMaskerConstants.OUTFILE_POSTFIX);
logger.debug(this, "inFile="+inFile);
logger.debug(this, "outFile="+outFile);
final AbstractStepProcessBuilder worker = getProcess(inFile);
boolean success = true;
try{
new NewFASTAFileImpl(data.viewData().getInputSequence())
.write(inFile);
worker.addResultFile(true, outFile);
success = worker.createAndStartProcess();
if (success) {
update(data, outFile);
}
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return success;
}
private void update(DataProxy<GFF3DataBean> data, final File outFile) throws DataBeanAccessException, IOException, GFFFormatErrorException{
logger.debug(this, "updating data");
final ArrayList<NewGFFElement> result = new ArrayList<NewGFFElement>();
result.addAll(NewGFFFileImpl.parseFile(outFile).getElements());
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setRepeatMaskerGFF(result);
}
});
}
public boolean isCyclic() {
return false;
}
protected abstract AbstractStepProcessBuilder getProcess(File inFile);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
public interface DataModifier<V> {
void modifiyData(V v);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
public interface DataProxy<V> {
/**
*
* <p>
* Atomar operation on data. Data will be synchronized bevor and after this
* operation.
* </p>
*
* @param v
* Type of Data, that is accessed.
* @throws DataBeanAccessException
*/
void modifiyData(DataModifier<V> v) throws DataBeanAccessException;
/**
*
* <p>
* Use this method for reading data only. If you make changes to the data
* you get from this method, these changes will not be synchronized! If you
* want to write data, use {@link modifiyData()} instead.
*
* @return the data object.
* @throws DataBeanAccessException
*/
V viewData() throws DataBeanAccessException;
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
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;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
abstract class AbstractDiskSerialisation implements SerialisationStrategy {
protected final LogDispatcher logger;
AbstractDiskSerialisation() {
this.logger = new ConsoleLogger();
}
AbstractDiskSerialisation(LogDispatcher logger) {
this.logger = logger;
}
protected void objectToFile(Serializable s, File file) throws IOException {
if (s == null || file == null)
throw new NullPointerException(s + " + " + file
+ " must not be null");
OutputStream fos = null;
ObjectOutputStream outStream = null;
try {
fos = new FileOutputStream(file);
outStream = new ObjectOutputStream(fos);
outStream.writeObject(s);
} finally {
if (outStream != null)
outStream.close();
if (fos != null)
fos.close();
}
}
protected <V> V fileToObject(Class<V> c, File file) throws IOException,
ClassNotFoundException {
if (c == null || file == null)
throw new NullPointerException(c + " + " + file
+ " must not be null");
InputStream fis = null;
ObjectInputStream inStream = null;
try {
fis = new FileInputStream(file);
inStream = new ObjectInputStream(fis);
V v = c.cast(inStream.readObject());
return v;
} finally {
if (inStream != null)
inStream.close();
if (fis != null)
fis.close();
}
}
protected <V extends DataBean> V handleCorruptData(File file, Throwable t) {
logger.warn(this, file.toString() + " corrupt, returning new one");
if (file.delete()) {
logger.info(this, "deleted corrupted data");
} else {
logger.warn(this, "could not delete corrupt data " + file);
}
return getNewDataBean();
}
public synchronized <V extends DataBean> V readDataBean(File file,
Class<V> v) throws DataBeanAccessException {
try {
final V data = fileToObject(v, file);
logger.debug(this, "reading data from file");
return data;
} catch (EOFException e) {
logger.warn(this, e.getLocalizedMessage(), e);
return handleCorruptData(file, e);
} catch (StreamCorruptedException e) {
logger.warn(this, e.getLocalizedMessage(), e);
return handleCorruptData(file, e);
} catch (Throwable t) {
logger.error(this, t.getLocalizedMessage(), t);
throw new DataBeanAccessException(t);
}
}
public synchronized <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
try {
logger.debug(this, "writing data to file");
objectToFile(v, file);
} catch (IOException e) {
logger.error(this, e.toString(), e);
throw new DataBeanAccessException(e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
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.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.GFF3DataProxy;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
public class GFF3DataProxyImpl implements GFF3DataProxy{
final static String WORKING_DIR_KEY = "anna.server.data.workingDir";
final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration" + File.separatorChar + "data.properties");
final static String DATA_FILE_NAME = "data.ser";
private final SerialisationStrategy strategy;
private final Properties properties;
private final File workingDir;
private final File file;
private final LogDispatcher logger;
public GFF3DataProxyImpl(final SerialisationStrategy strategy) throws FileNotFoundException {
this.strategy = strategy;
this.logger = new ConsoleLogger();
properties = getPropertes();
workingDir = new File(properties.getProperty(WORKING_DIR_KEY));
if(!FileUtils.dirCheck(workingDir, true)){
final FileNotFoundException e = new FileNotFoundException("cannot access working dir " + workingDir);
logger.error(this, e, e);
throw e;
}
file = new File(workingDir, DATA_FILE_NAME);
printProperties();
}
public GFF3DataProxyImpl() throws FileNotFoundException {
this.strategy = new CachedDiskSerialisation();
properties = getPropertes();
this.logger = new ConsoleLogger();
workingDir = new File(properties.getProperty(WORKING_DIR_KEY));
if(!FileUtils.dirCheck(workingDir, true)){
final FileNotFoundException e = new FileNotFoundException("cannot access working dir " + workingDir);
logger.error(this, e, e);
throw e;
}
file = new File(workingDir, DATA_FILE_NAME);
printProperties();
}
private GFF3DataBean getData() throws DataBeanAccessException {
if(!FileUtils.fileCheck(file, false)){
logger.info(this, "file " + file + " not there, creating new data");
return strategy.getNewDataBean();
}
return strategy.readDataBean(file, GFF3DataBean.class);
}
private void setData(GFF3DataBean data) throws DataBeanAccessException {
strategy.writeDataBean(data, file);
}
public synchronized void modifiyData(DataModifier<GFF3DataBean> v)
throws DataBeanAccessException {
final GFF3DataBean data = getData();
v.modifiyData(data);
setData(data);
}
public GFF3DataBean viewData() throws DataBeanAccessException {
return getData();
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tdatafile=" + file);
}
private 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();
return pro;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
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.impl.GFF3DataBeanImpl;
public class GFF3DiskSerialisation extends AbstractDiskSerialisation {
protected volatile DataBean data = new GFF3DataBeanImpl();
GFF3DiskSerialisation() {
super();
}
GFF3DiskSerialisation(LogDispatcher logger) {
super(logger);
}
@SuppressWarnings("unchecked")
public <V extends DataBean> V getNewDataBean() {
// TODO: WHY CAST ?!?
return (V) new GFF3DataBeanImpl();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
public class SimpleDiskSerialisation extends GFF3DiskSerialisation {
public SimpleDiskSerialisation() {
super();
}
public SimpleDiskSerialisation(LogDispatcher logger) {
super(logger);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
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.dataproxy.GFF3DataProxy;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
public class GFF3DataProxyActivator implements BundleActivator {
private LogDispatcher logger = null;
public void start(BundleContext context) throws Exception {
logger = new LogDispatcherImpl(context);
GFF3DataProxy proxy = new GFF3DataProxyImpl(new CachedDiskSerialisation(logger));
context.registerService(GFF3DataProxy.class.getName(), proxy,
new Hashtable<Object, Object>());
}
public void stop(BundleContext context) throws Exception {
logger.debug(this, "service stopped!");
logger = null;
}
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
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.osgi.commons.logger.dispatcher.LogDispatcher;
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
*
*/
class CachedDiskSerialisation extends GFF3DiskSerialisation {
CachedDiskSerialisation() {
super();
}
CachedDiskSerialisation(LogDispatcher logger) {
super(logger);
}
private volatile boolean dirty = false;
@SuppressWarnings("unchecked")
@Override
public synchronized <V extends DataBean> V readDataBean(File file,
Class<V> v) throws DataBeanAccessException {
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 synchronized <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
this.dirty = true;
logger.debug(this, "writing data");
super.writeDataBean(v, file);
}
@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.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.common;
public class StepExecutionException extends Exception {
private static final long serialVersionUID = 5683856650378220175L;
public StepExecutionException() {
}
public StepExecutionException(String arg0) {
super(arg0);
}
public StepExecutionException(Throwable arg0) {
super(arg0);
}
public StepExecutionException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.common;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
/**
* @lastVisit 2009-08-12
* @ThreadSave stateless
* @author Alexander Kerner
* @Exceptions good
*
*/
public class StepUtils {
private StepUtils() {}
public static void handleException(Object 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(t);
}
}
public static void handleException(Object cause, Throwable t)
throws StepExecutionException {
t.printStackTrace();
throw new StepExecutionException(t);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.common;
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;
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;
}
public void addResultFile(boolean takeShortCutIfAlreadyThere,
String fileName) {
addResultFile(takeShortCutIfAlreadyThere, new File(fileName));
}
public void addAllResultFiles(Map<File, Boolean> m) {
if(m.isEmpty())
return;
outFiles.putAll(m);
}
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, "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);
}
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.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.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.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.step.getresults.repeatmasker;
import java.io.File;
import java.util.ArrayList;
import org.osgi.framework.BundleContext;
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.GFF3DataBean;
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 GetRepeatMaskerGFF extends AbstractGFF3AnnaStep {
private final static String OUT_DIR_KEY = "anna.step.getResults.outDir";
private final static String OUT_FILE_NAME_KEY = "anna.step.getResults.repeatMasker.fileName";
private LogDispatcher logger;
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
super.init(context);
this.logger = new LogDispatcherImpl(context);
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "cannot be skipped");
return false;
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final ArrayList<? extends NewGFFElement> elements = data.viewData()
.getRepeatMaskerGFF();
// TODO predicted genes may be size==0
logger.debug(this, "requirements satisfied="+(elements != null && elements.size() != 0));
return (elements != null && elements.size() != 0);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
boolean success = false;
try {
final File outDir = new File(super.getStepProperties().getProperty(
OUT_DIR_KEY));
final File outFile = new File(outDir, super.getStepProperties()
.getProperty(OUT_FILE_NAME_KEY));
success = checkOutDir(outDir);
if (success) {
System.out.println(this + ": writing repeatmasker gff to "
+ outFile);
final NewGFFFile file = new NewGFFFileImpl(data.viewData()
.getRepeatMaskerGFF());
file.write(outFile);
}
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return success;
}
private boolean checkOutDir(File outFile) {
if (!outFile.exists()) {
logger.info(this, ": " + outFile
+ " does not exist, creating");
final boolean b = outFile.mkdirs();
return b;
}
return outFile.canWrite();
}
@Override
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.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.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.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.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.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.getresults.predictedgenes;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import de.bioutils.gff.element.NewGFFElement;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
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.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public class GetPredictedGenes extends AbstractGFF3AnnaStep {
private final static String OUT_DIR_KEY = "anna.step.getResults.outDir";
private final static String OUT_FILE_NAME_KEY = "anna.step.getResults.predictedGenes.fileName";
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final ArrayList<? extends NewGFFElement> elements = data.viewData()
.getPredictedGenesGFF();
// TODO predicted genes may be size==0
return (elements != null && elements.size() != 0);
} catch (Throwable t) {
StepUtils.handleException(this, t);
// cannot be reached
return false;
}
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
return false;
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
boolean success = false;
try {
final File outDir = new File(super.getStepProperties().getProperty(
OUT_DIR_KEY));
success = checkOutDir(outDir);
if (success) {
writeAllToOne(outDir, data);
writeAllToSeparateFile(outDir, data);
}
} catch (Throwable t) {
StepUtils.handleException(this, t);
// cannot be reached
return false;
}
return success;
}
private void writeAllToSeparateFile(File outDir, DataProxy<GFF3DataBean> data) throws DataBeanAccessException, IOException {
ArrayList<? extends NewGFFElement> ele = data.viewData().getPredictedGenesGFF();
final NewGFFFile file = new NewGFFFileImpl(ele);
Map<String, List<NewGFFElement>> set = splitToSeqNames(file);
for(Entry<String, List<NewGFFElement>> e : set.entrySet()){
String fileName = super.getStepProperties()
.getProperty(OUT_FILE_NAME_KEY);
final int dot = fileName.lastIndexOf(".");
final String s1 = fileName.substring(0, dot);
final String s2 = fileName.substring(dot);
fileName = s1 + "_" + e.getKey() + s2;
final File outFile = new File(outDir, fileName);
logger.info(this, ": writing predicted genes to "
+ outFile);
final NewGFFFile file2 = new NewGFFFileImpl(e.getValue());
file2.write(outFile);
}
}
private static Map<String, List<NewGFFElement>> splitToSeqNames(NewGFFFile file) {
final Map<String, List<NewGFFElement>> map = new HashMap<String, List<NewGFFElement>>();
for(NewGFFElement e : file.getElements()){
final String id = e.getSeqName();
if(map.containsKey(id)){
map.get(id).add(e);
} else {
final List<NewGFFElement> l = new ArrayList<NewGFFElement>();
l.add(e);
map.put(id, l);
}
}
return map;
}
private void writeAllToOne(File outDir, DataProxy<GFF3DataBean> data) throws DataBeanAccessException, IOException {
final File outFile = new File(outDir, super.getStepProperties()
.getProperty(OUT_FILE_NAME_KEY));
logger.info(this, ": writing predicted genes to "
+ outFile);
final NewGFFFile file = new NewGFFFileImpl(data.viewData()
.getPredictedGenesGFF());
file.write(outFile);
}
private boolean checkOutDir(File outFile) {
if (!outFile.exists()) {
logger.info(this, outFile
+ " does not exist, creating");
final boolean b = outFile.mkdirs();
return b;
}
return outFile.canWrite();
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.estreader;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
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 ESTReader extends AbstractGFF3AnnaStep {
private final static String INFILE_KEY = "anna.step.estreader.infile";
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
boolean b = true;
try {
final Collection<FASTAElement> c = proxy.viewData().getESTs();
b = (c != null && c.size() != 0);
logger.debug(this, "can be skipped=" + b + "(" + c.size() + ") est fastas retrieved");
} catch (Exception e) {
StepUtils.handleException(this, e);
}
return b;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
try {
final File file = new File(
getStepProperties().getProperty(INFILE_KEY));
logger.debug(this, "reading file " + file);
final NewFASTAFile f = NewFASTAFileImpl.parse(file);
logger.debug(this, "reading file " + file + " done, updating data");
proxy.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setESTs(new ArrayList<FASTAElement>(f.getElements()));
logger.debug(this, "updating data done");
}
});
return true;
} catch (Throwable e) {
StepUtils.handleException(this, e);
return false;
}
}
public boolean isCyclic() {
// TODO Auto-generated method stub
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.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;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
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();
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 {
sb.append(s.requirementsNeeded());
} catch (Exception e) {
logger.error(this, "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(this, hans.toString());
}
@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.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractStepProcessBuilder;
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 {
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.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 |
package de.mpg.mpiz.koeln.anna.step.conrad.data.adapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import de.bioutils.Strand;
import de.bioutils.gff3.Type;
import de.bioutils.gff3.attribute.Attribute;
import de.bioutils.gff3.attribute.AttributeLine;
import de.bioutils.gff3.attribute.IDAttribute;
import de.bioutils.gff3.attribute.ParentAttribute;
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;
public class ConradGeneParentExtender implements GFF3FileExtender {
public GFF3File extend(GFF3File gff3File) {
final Map<IDAttribute, GFF3ElementGroup> mapToID = getElementsMappedToID(gff3File
.getElements());
final GFF3ElementGroup result = addParents(mapToID);
return new GFF3FileImpl(result);
}
private Map<IDAttribute, GFF3ElementGroup> getElementsMappedToID(
Collection<? extends GFF3Element> elements) {
final Map<IDAttribute, GFF3ElementGroup> result = new HashMap<IDAttribute, GFF3ElementGroup>();
for (GFF3Element e : elements) {
final AttributeLine l = e.getAttributeLine();
List<Attribute> atts = new ArrayList<Attribute>();
String id = null;
for (Attribute a : l.getAttributes()) {
// gene_id "contig00001G_1"; transcript_id "contig00001T_1.1";
// LOGGER.info("attribute is " + a);
if (a.getKey().equalsIgnoreCase("gene_id")) {
id = a.getValue();
atts.add(new IDAttribute(id));
}
atts.add(a);
}
if (result.containsKey(new IDAttribute(id))) {
GFF3ElementGroup g = result.get(new IDAttribute(id));
g.add(new GFF3ElementBuilder(e).setAttributeLine(
new AttributeLine(atts)).build());
result.put(new IDAttribute(id), g);
} else {
GFF3ElementGroup g = new GFF3ElementGroup();
g.add(new GFF3ElementBuilder(e).setAttributeLine(
new AttributeLine(atts)).build());
result.put(new IDAttribute(id), g);
}
}
return result;
}
private GFF3ElementGroup addParents(
Map<IDAttribute, GFF3ElementGroup> mapToID) {
// LOGGER.info("map " + mapToID);
final GFF3ElementGroup result = new GFF3ElementGroup();
for (Entry<IDAttribute, GFF3ElementGroup> e : mapToID.entrySet()) {
final IDAttribute id = new IDAttribute(e.getKey().getValue() + "_gene");
// LOGGER.info(e.getValue().toString());
result.addAll(addParentTag(id, e.getValue()));
final Strand s = getStrandForGene(e.getValue());
result.add(new GFF3ElementBuilder(e.getValue().getElements()
.iterator().next()).setType(Type.gene).setStart(e.getValue().getStart())
.setStop(e.getValue().getStop()).setStrand(s).setAttributeLine(
new AttributeLine(id)).build());
}
return result;
}
private Strand getStrandForGene(GFF3ElementGroup group) {
Strand s = null;
Strand last = null;
for(GFF3Element e : group){
last = s;
s = e.getStrand();
if(s.equals(last) || last == null){
// all good
} else {
// logger.debug("gene orientation is not ambigious");
}
}
return s;
}
private GFF3ElementGroup addParentTag(IDAttribute parentid, GFF3ElementGroup group) {
final GFF3ElementGroup result = new GFF3ElementGroup();
for(GFF3Element e : group){
final Collection<Attribute> nl = new ArrayList<Attribute>();
// System.out.println(parentid.getValue());
nl.add(new ParentAttribute(parentid.getValue()));
result.add(new GFF3ElementBuilder(e).setAttributeLine(new AttributeLine(nl)).build());
}
// System.out.println(result);
return result;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.data.adapter;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff3.file.GFF3File;
public interface GFF3Converter {
NewGFFFile convert(GFF3File file);
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.predict.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.AbstractConradPredictStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class PredictLSF 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(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF
.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(ConradConstants.CONRAD_EXE);
builder.addFlagCommand("predict");
builder.addFlagCommand(trainingFile.getAbsolutePath());
builder.addFlagCommand(workingDir.getAbsolutePath());
// necessary, because "result" parameter will result in a file named
// result.gtf. If we here hand over "result.gtf" we later receive
// file named "result.gtf.gtf"
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.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.AbstractConradPredictStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class PredictLSF 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(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF
.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(ConradConstants.CONRAD_EXE);
builder.addFlagCommand("predict");
builder.addFlagCommand(trainingFile.getAbsolutePath());
builder.addFlagCommand(workingDir.getAbsolutePath());
// necessary, because "result" parameter will result in a file named
// result.gtf. If we here hand over "result.gtf" we later receive
// file named "result.gtf.gtf"
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.mpiz.koeln.anna.step.common.lsf;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Alexander Kerner
* @ThreadSave stateless
* @lastVisit 2009-08-12
* @Exceptions nothing to do
*
*/
public class LSF {
public final static String BSUB_EXE = "bsub";
private LSF(){}
public static Map<String, String> getBsubValueCommandStrings(File workingDir) {
final File LSFout = new File(workingDir, "lsf-%J-%I.out");
final File LSFerr = new File(workingDir, "lsf-%J-%I.err");
final Map<String, String> map = new HashMap<String,String>();
// map.put("-m", "pcbcn64");
map.put("-m", "pcbcomputenodes");
// map.put("-R", "rusage[mem=4000:swp=2000]");
map.put("-R", "rusage[mem=4000]");
map.put("-eo", LSFerr.getAbsolutePath());
map.put("-oo", LSFout.getAbsolutePath());
return map;
}
public static List<String> getBsubFlagCommandStrings() {
final List<String> list = new ArrayList<String>();
list.add("-K");
return list;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.common.lsf;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Alexander Kerner
* @ThreadSave stateless
* @lastVisit 2009-08-12
* @Exceptions nothing to do
*
*/
public class LSF {
public final static String BSUB_EXE = "bsub";
private LSF(){}
public static Map<String, String> getBsubValueCommandStrings(File workingDir) {
final File LSFout = new File(workingDir, "lsf-%J-%I.out");
final File LSFerr = new File(workingDir, "lsf-%J-%I.err");
final Map<String, String> map = new HashMap<String,String>();
// map.put("-m", "pcbcn64");
map.put("-m", "pcbcomputenodes");
// map.put("-R", "rusage[mem=4000:swp=2000]");
map.put("-R", "rusage[mem=4000]");
map.put("-eo", LSFerr.getAbsolutePath());
map.put("-oo", LSFout.getAbsolutePath());
return map;
}
public static List<String> getBsubFlagCommandStrings() {
final List<String> list = new ArrayList<String>();
list.add("-K");
return list;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.getresults;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
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;
public class GetResults extends AbstractGFF3AnnaStep {
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return false;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
logger.debug(this, "IM RUNNING!!");
return false;
}
public boolean isCyclic() {
return true;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.getresults;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.kerner.commons.file.FileUtils;
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.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public class GetResults extends AbstractGFF3AnnaStep {
private final static String OUT_DIR_KEY = "anna.step.getResults.outDir";
private final static String OUT_FILE_NAME_KEY = "anna.step.getResults.fileName";
@Override
public boolean run(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
boolean success = false;
final File outDir = new File(super.getStepProperties().getProperty(
OUT_DIR_KEY));
logger.debug(this, "got outdir=" + outDir);
success = FileUtils.dirCheck(outDir, true);
try {
writeFile(outDir, proxy);
} catch (Exception e) {
StepUtils.handleException(this, e);
}
return success;
}
private void writeFile(File outDir, DataProxy<GFF3DataBean> proxy)
throws DataBeanAccessException, IOException {
logger.debug(this, "retrieving GFF for predicted genes");
final Collection<GFF3Element> predicted = proxy.viewData()
.getPredictedGenesGFF();
logger.debug(this, "retrieving GFF for predicted genes done (elements="
+ predicted.size() + ")");
logger.debug(this, "retrieving GFF for repetetive elements");
final Collection<GFF3Element> repeat = proxy.viewData()
.getRepeatMaskerGFF();
logger.debug(this,
"retrieving GFF for repetetive elements done (elements="
+ repeat.size() + ")");
logger.debug(this, "retrieving GFF for mapped ests");
final Collection<GFF3Element> ests = proxy.viewData()
.getMappedESTs();
logger.debug(this,
"retrieving GFF for mapped ests done (elements="
+ ests.size() + ")");
logger.debug(this, "merging");
final Collection<GFF3Element> merged = new ArrayList<GFF3Element>();
if(predicted.size() != 0)
merged.addAll(predicted);
if(repeat.size() != 0)
merged.addAll(repeat);
if(ests.size() != 0)
merged.addAll(ests);
logger.debug(this, "merging done (elements="
+ merged.size() + ")");
if(merged.size() == 0){
logger.info(this, "nothing to write");
return;
}
final File outFile = new File(outDir, super.getStepProperties()
.getProperty(OUT_FILE_NAME_KEY));
logger.info(this, "writing results to " + outFile);
new GFF3FileImpl(merged).write(outFile);
logger.debug(this, "done writing results to " + outFile);
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return false;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
public boolean isCyclic() {
return true;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.runtime.statistics;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import de.kerner.commons.file.FileUtils;
import de.mpg.koeln.anna.core.events.AnnaEvent;
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 Statistics extends AbstractEventListener {
public static final TimeUnit TIMEUNIT = TimeUnit.MILLISECONDS;
private final static String PRE_LINE = " RUNTIMES ++++++++++++++++++++++++++++++++++++++++++++++";
private final static String POST_LINE = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
private final Map<AnnaStep, StateRuntimes> stepToStateRuntimes = new ConcurrentHashMap<AnnaStep, StateRuntimes>();
public void eventOccoured(AnnaEvent event) {
for (AnnaStep s : event.getRegisteredSteps()) {
final State currentState = s.getState();
if (stepToStateRuntimes.containsKey(s)) {
final StateRuntimes r = stepToStateRuntimes.get(s);
r.update(currentState);
} else {
stepToStateRuntimes.put(s, new StateRuntimes(logger));
}
}
if (weAreDone(event))
printStatistics();
}
private void printStatistics() {
final StringBuilder sb = new StringBuilder();
sb.append(PRE_LINE);
sb.append(FileUtils.NEW_LINE);
if (stepToStateRuntimes.isEmpty()) {
// nothing
} else {
for (Entry<AnnaStep, StateRuntimes> e : stepToStateRuntimes
.entrySet()) {
final String s1 = e.getKey().toString();
final String s2 = e.getValue().toString();
sb.append(String.format("%-22s", s1));
sb.append(FileUtils.NEW_LINE);
if (!e.getValue().isEmpty())
sb.append(String.format("%-22s", s2));
}
}
sb.append(POST_LINE);
logger.info(this, sb.toString());
}
private boolean weAreDone(AnnaEvent event) {
final Collection<AnnaStep> eventList = event.getRegisteredSteps();
for (AnnaStep s : eventList) {
if (!(s.getState().isFinished())) {
return false;
}
}
return true;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.runtime.statistics;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import de.kerner.commons.StopWatch;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
class StateRuntimes {
private final LogDispatcher logger;
private volatile State lastState;
private final Map<State, StopWatch> stateToStopWatch = new ConcurrentHashMap<State, StopWatch>();
StateRuntimes(LogDispatcher logger) {
this.logger = logger;
}
boolean isEmpty(){
return stateToStopWatch.isEmpty();
}
void update(State state) {
if (stateToStopWatch.containsKey(state)) {
// current state already registered and stop watch should be
// running, ignore.
return;
}
// never have been in this state before, take time from last state and
// create new stop watch for new state.
if (lastState != null) {
final StopWatch oldWatch = stateToStopWatch.get(lastState);
if (oldWatch.isRunning()) {
// all good, get time and forget about this state.
oldWatch.stop();
} else {
logger.warn(this,
"inconsitent time measuring, stopwatch for state "
+ state + " not running!");
}
}
final StopWatch newWatch = new StopWatch();
if(!state.isFinished())
newWatch.start();
stateToStopWatch.put(state, newWatch);
this.lastState = state;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
for (Entry<State, StopWatch> e : stateToStopWatch.entrySet()) {
final String s1 = e.getKey().toString();
final long s2 = e.getValue().getElapsedTime(TimeUnit.MILLISECONDS)
.getDuration(TimeUnit.MILLISECONDS);
final String s3 = Boolean.toString(e.getValue().isRunning());
sb.append(String.format(
"\tstate\t%-22s\ttime[millisec]\t%,10d\trunning\t%6s", s1,
s2, s3).toString());
sb.append(FileUtils.NEW_LINE);
}
return sb.toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.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.repeatmasker.common.AbstractStepRepeatMasker;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.RepeatMaskerConstants;
public class RepeatMaskerLSF 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() {
final CommandStringBuilder builder = new CommandStringBuilder(LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(new File(
executableDir, RepeatMaskerConstants.EXE).getAbsolutePath());
// builder.addAllFlagCommands("-s");
builder.addFlagCommand("-gff");
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.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.repeatmasker.common.AbstractStepRepeatMasker;
import de.mpg.mpiz.koeln.anna.step.repeatmasker.common.RepeatMaskerConstants;
public class RepeatMaskerLSF 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() {
final CommandStringBuilder builder = new CommandStringBuilder(LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(new File(
executableDir, RepeatMaskerConstants.EXE).getAbsolutePath());
// builder.addAllFlagCommands("-s");
builder.addFlagCommand("-gff");
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.exonerate.lsf;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.mpg.mpiz.koeln.anna.step.common.lsf.LSF;
import de.mpg.mpiz.koeln.anna.step.exonerate.common.AbstractStepExonerate;
import de.mpg.mpiz.koeln.anna.step.exonerate.common.ExonerateConstants;
public class ExonerateLSF extends AbstractStepExonerate {
@Override
public List<String> getCmdList() {
final CommandStringBuilder builder = new CommandStringBuilder(LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(new File(
exeDir, ExonerateConstants.EXE).getAbsolutePath());
builder.addValueCommand("--showquerygff", "yes");
builder.addValueCommand("--showalignment", "false");
builder.addValueCommand("--bestn", "10");
final String infile = new File(workingDir,
ExonerateConstants.INSEQ_FILENAME).getAbsolutePath();
builder.addFlagCommand(infile);
final String ests = new File(workingDir,
ExonerateConstants.EST_FILENAME).getAbsolutePath();
builder.addFlagCommand(ests);
//builder.addFlagCommand("> " + new File(workingDir, ExonerateConstants.RESULT_FILENAME).getAbsolutePath());
return builder.getCommandList();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.annafinishedlistener;
import java.util.Collection;
import de.mpg.koeln.anna.core.events.AnnaEvent;
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 FinishedListener extends AbstractEventListener {
private final static String PRE_LINE = "!!!!!!!!!!!!!!!!!!!!!!";
private final static String POST_LINE = PRE_LINE;
private volatile boolean error = false;
public void eventOccoured(AnnaEvent event) {
if(areWeDone(event)){
logger.info(this, PRE_LINE);
if(error){
logger.info(this, "pipeline finished (with errors)!");
} else {
logger.info(this, "pipeline finished!");
}
logger.info(this, POST_LINE);
} else {
// ignore
}
}
private boolean areWeDone(AnnaEvent event){
final Collection<AnnaStep> eventList = event.getRegisteredSteps();
for(AnnaStep s : eventList){
if(!(s.getState().isFinished())){
return false;
}
if(s.getState().equals(State.ERROR)){
this.error = true;
}
}
return true;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.inputsequencereader;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
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 InputSequenceReader extends AbstractGFF3AnnaStep {
private final static String INFILE_KEY = "anna.step.inputsequencereader.infile";
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "no requirements needed");
return true;
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (data.viewData().getInputSequence().size() != 0);
logger.debug(this, "need to run:");
logger.debug(this, "\tinputSequences=" + inputSequences);
logger.debug(this, "\tinputSequencesSize=" + inputSequencesSize);
return (inputSequences && inputSequencesSize);
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final File inFile = new File(getStepProperties().getProperty(
INFILE_KEY));
logger.debug(this, "reading file " + inFile);
final Collection<? extends FASTAElement> fastas = NewFASTAFileImpl.parse(inFile).getElements();
if (fastas == null || fastas.size() == 0) {
logger.warn(this, "file " + inFile + " is invalid");
return false;
}
logger.debug(this, "got input sequences:"
+ fastas.iterator().next().getHeader() + " [...]");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setInputSequence(new ArrayList<FASTAElement>(fastas));
}
});
return true;
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.inputsequencereader;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
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 InputSequenceReader extends AbstractGFF3AnnaStep {
private final static String INFILE_KEY = "anna.step.inputsequencereader.infile";
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "no requirements needed");
return true;
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (data.viewData().getInputSequence().size() != 0);
logger.debug(this, "need to run:");
logger.debug(this, "\tinputSequences=" + inputSequences);
logger.debug(this, "\tinputSequencesSize=" + inputSequencesSize);
return (inputSequences && inputSequencesSize);
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
final File inFile = new File(getStepProperties().getProperty(
INFILE_KEY));
logger.debug(this, "reading file " + inFile);
final Collection<? extends FASTAElement> fastas = NewFASTAFileImpl.parse(inFile).getElements();
if (fastas == null || fastas.size() == 0) {
logger.warn(this, "file " + inFile + " is invalid");
return false;
}
logger.debug(this, "got input sequences:"
+ fastas.iterator().next().getHeader() + " [...]");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setInputSequence(new ArrayList<FASTAElement>(fastas));
}
});
return true;
} catch (Exception e) {
StepUtils.handleException(this, e, logger);
// cannot be reached
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.exonerate.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.mpg.mpiz.koeln.anna.step.exonerate.common.AbstractStepExonerate;
import de.mpg.mpiz.koeln.anna.step.exonerate.common.ExonerateConstants;
public class ExonerateLocal extends AbstractStepExonerate {
@Override
public List<String> getCmdList() {
final CommandStringBuilder builder = new CommandStringBuilder(new File(
exeDir, ExonerateConstants.EXE).getAbsolutePath());
builder.addValueCommand("--showquerygff", "yes");
builder.addValueCommand("--showalignment", "false");
builder.addValueCommand("--bestn", "10");
final String infile = new File(workingDir,
ExonerateConstants.INSEQ_FILENAME).getAbsolutePath();
builder.addFlagCommand(infile);
final String ests = new File(workingDir,
ExonerateConstants.EST_FILENAME).getAbsolutePath();
builder.addFlagCommand(ests);
// builder.addFlagCommand("> " + new File(workingDir, ExonerateConstants.RESULT_FILENAME).getAbsolutePath());
return builder.getCommandList();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
public class RepeatMaskerConstants {
private RepeatMaskerConstants(){}
public final static String WORKING_DIR_KEY = "anna.step.repeatMasker.workingDir";
public final static String EXE_DIR_KEY = "anna.step.repeatMasker.exeDir";
public final static String TMP_FILENAME = "repMask";
public final static String OUTFILE_POSTFIX = ".out.gff";
public final static String EXE = "RepeatMasker";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
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.file.FileUtils;
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.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public abstract class AbstractStepRepeatMasker extends AbstractGFF3AnnaStep {
protected File exeDir;
protected File workingDir;
@Override
public String toString() {
return this.getClass().getSimpleName();
}
@Override
protected synchronized void init(BundleContext context) throws StepExecutionException {
super.init(context);
assignProperties();
validateProperties();
printProperties();
}
private void assignProperties() {
exeDir = new File(getStepProperties().getProperty(RepeatMaskerConstants.EXE_DIR_KEY));
workingDir = new File(getStepProperties().getProperty(RepeatMaskerConstants.WORKING_DIR_KEY));
}
private void validateProperties() throws StepExecutionException {
if (!FileUtils.dirCheck(exeDir, false))
throw new StepExecutionException(
"cannot access repeatmasker working dir");
if (!FileUtils.dirCheck(workingDir, true))
throw new StepExecutionException("cannot access step working dir");
}
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tstepWorkingDir=" + workingDir);
logger.debug(this, "\texeDir=" + exeDir);
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
// must this two actions be atomar?
final boolean repeatGtf = (data.viewData().getRepeatMaskerGFF() != null);
final boolean repeatGtfSize = (data.viewData()
.getRepeatMaskerGFF().size() != 0);
return (repeatGtf && repeatGtfSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
// must this two actions be atomar?
final boolean sequence = (data.viewData().getInputSequence() != null);
final boolean sequenceSize = (data.viewData()
.getInputSequence().size() != 0);
return (sequence && sequenceSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "running");
final File inFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME);
final File outFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME
+ RepeatMaskerConstants.OUTFILE_POSTFIX);
logger.debug(this, "inFile="+inFile);
logger.debug(this, "outFile="+outFile);
final AbstractStepProcessBuilder worker = getProcess(inFile);
boolean success = true;
try{
new NewFASTAFileImpl(data.viewData().getInputSequence())
.write(inFile);
worker.addResultFile(true, outFile);
success = worker.createAndStartProcess();
if (success) {
update(data, outFile);
}
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return success;
}
private void update(DataProxy<GFF3DataBean> data, final File outFile) throws DataBeanAccessException, IOException, GFFFormatErrorException{
logger.debug(this, "updating data");
final ArrayList<NewGFFElement> result = new ArrayList<NewGFFElement>();
result.addAll(NewGFFFileImpl.parseFile(outFile).getElements());
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setRepeatMaskerGFF(result);
}
});
}
public boolean isCyclic() {
return false;
}
protected abstract AbstractStepProcessBuilder getProcess(File inFile);
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
public class RepeatMaskerConstants {
private RepeatMaskerConstants(){}
public final static String WORKING_DIR_KEY = "anna.step.repeatMasker.workingDir";
public final static String EXE_DIR_KEY = "anna.step.repeatMasker.exeDir";
public final static String TMP_FILENAME = "repMask";
public final static String OUTFILE_POSTFIX = ".out.gff";
public final static String EXE = "RepeatMasker";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractStepProcessBuilder;
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.repeatmasker.adapter.ResultsPreprocessor;
public abstract class AbstractStepRepeatMasker extends AbstractGFF3AnnaStep {
protected File exeDir;
protected File workingDir;
@Override
public String toString() {
return this.getClass().getSimpleName();
}
@Override
protected synchronized void init(BundleContext context) throws StepExecutionException {
super.init(context);
assignProperties();
validateProperties();
printProperties();
}
private void assignProperties() {
exeDir = new File(getStepProperties().getProperty(RepeatMaskerConstants.EXE_DIR_KEY));
workingDir = new File(getStepProperties().getProperty(RepeatMaskerConstants.WORKING_DIR_KEY));
}
private void validateProperties() throws StepExecutionException {
if (!FileUtils.dirCheck(exeDir, false))
throw new StepExecutionException(this,
"cannot access repeatmasker working dir");
if (!FileUtils.dirCheck(workingDir, true))
throw new StepExecutionException(this, "cannot access step working dir");
}
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tstepWorkingDir=" + workingDir);
logger.debug(this, "\texeDir=" + exeDir);
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
// must this two actions be atomar?
final boolean repeatGtf = (data.viewData().getRepeatMaskerGFF() != null);
final boolean repeatGtfSize = (data.viewData()
.getRepeatMaskerGFF().size() != 0);
return (repeatGtf && repeatGtfSize);
} 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 sequence = (data.viewData().getInputSequence() != null);
final boolean sequenceSize = (data.viewData()
.getInputSequence().size() != 0);
if(!sequence || !sequenceSize){
r.add("input sequences");
}
return r;
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
try {
// must this two actions be atomar?
final boolean sequence = (data.viewData().getInputSequence() != null);
final boolean sequenceSize = (data.viewData()
.getInputSequence().size() != 0);
return (sequence && sequenceSize);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public boolean run(DataProxy<GFF3DataBean> data)
throws StepExecutionException {
logger.debug(this, "running");
final File inFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME);
final File outFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME
+ RepeatMaskerConstants.OUTFILE_POSTFIX);
logger.debug(this, "inFile="+inFile);
logger.debug(this, "outFile="+outFile);
final AbstractStepProcessBuilder worker = getProcess(inFile);
boolean success = true;
try{
new NewFASTAFileImpl(data.viewData().getInputSequence())
.write(inFile);
worker.addResultFile(true, outFile);
success = worker.createAndStartProcess();
if (success) {
update(data, outFile);
}
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return success;
}
private void update(DataProxy<GFF3DataBean> data, final File outFile) throws DataBeanAccessException, IOException, GFFFormatErrorException{
logger.debug(this, "updating data");
final ArrayList<GFF3Element> result = new ArrayList<GFF3Element>();
new ResultsPreprocessor().process(outFile, outFile);
result.addAll(GFF3FileImpl.convertFromGFF(outFile).getElements());
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setRepeatMaskerGFF(result);
}
});
}
public boolean isCyclic() {
return false;
}
protected abstract AbstractStepProcessBuilder getProcess(File inFile);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
public interface DataModifier<V> {
void modifiyData(V v);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
public interface DataProxy<V> {
/**
*
* <p>
* Atomar operation on data. Data will be synchronized bevor and after this
* operation.
* </p>
*
* @param v
* Type of Data, that is accessed.
* @throws DataBeanAccessException
*/
void modifiyData(DataModifier<V> v) throws DataBeanAccessException;
/**
*
* <p>
* Use this method for reading data only. If you make changes to the data
* you get from this method, these changes will not be synchronized! If you
* want to write data, use {@link modifiyData()} instead.
*
* @return the data object.
* @throws DataBeanAccessException
*/
V viewData() throws DataBeanAccessException;
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
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;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
abstract class AbstractDiskSerialisation implements SerialisationStrategy {
protected final LogDispatcher logger;
AbstractDiskSerialisation() {
this.logger = new ConsoleLogger();
}
AbstractDiskSerialisation(LogDispatcher logger) {
this.logger = logger;
}
protected void objectToFile(Serializable s, File file) throws IOException {
if (s == null || file == null)
throw new NullPointerException(s + " + " + file
+ " must not be null");
OutputStream fos = null;
ObjectOutputStream outStream = null;
try {
fos = new FileOutputStream(file);
outStream = new ObjectOutputStream(fos);
outStream.writeObject(s);
} finally {
if (outStream != null)
outStream.close();
if (fos != null)
fos.close();
}
}
protected <V> V fileToObject(Class<V> c, File file) throws IOException,
ClassNotFoundException {
if (c == null || file == null)
throw new NullPointerException(c + " + " + file
+ " must not be null");
InputStream fis = null;
ObjectInputStream inStream = null;
try {
fis = new FileInputStream(file);
inStream = new ObjectInputStream(fis);
V v = c.cast(inStream.readObject());
return v;
} finally {
if (inStream != null)
inStream.close();
if (fis != null)
fis.close();
}
}
protected <V extends DataBean> V handleCorruptData(File file, Throwable t) {
logger.warn(this, file.toString() + " corrupt, returning new one");
if (file.delete()) {
logger.info(this, "deleted corrupted data");
} else {
logger.warn(this, "could not delete corrupt data " + file);
}
return getNewDataBean();
}
public synchronized <V extends DataBean> V readDataBean(File file,
Class<V> v) throws DataBeanAccessException {
try {
final V data = fileToObject(v, file);
logger.debug(this, "reading data from file");
return data;
} catch (EOFException e) {
logger.warn(this, e.getLocalizedMessage(), e);
return handleCorruptData(file, e);
} catch (StreamCorruptedException e) {
logger.warn(this, e.getLocalizedMessage(), e);
return handleCorruptData(file, e);
} catch (Throwable t) {
logger.error(this, t.getLocalizedMessage(), t);
throw new DataBeanAccessException(t);
}
}
public synchronized <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
try {
logger.debug(this, "writing data to file");
objectToFile(v, file);
} catch (IOException e) {
logger.error(this, e.toString(), e);
throw new DataBeanAccessException(e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
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.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.GFF3DataProxy;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
public class GFF3DataProxyImpl implements GFF3DataProxy{
final static String WORKING_DIR_KEY = "anna.server.data.workingDir";
final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration" + File.separatorChar + "data.properties");
final static String DATA_FILE_NAME = "data.ser";
private final SerialisationStrategy strategy;
private final Properties properties;
private final File workingDir;
private final File file;
private final LogDispatcher logger;
public GFF3DataProxyImpl(final SerialisationStrategy strategy) throws FileNotFoundException {
this.strategy = strategy;
this.logger = new ConsoleLogger();
properties = getPropertes();
workingDir = new File(properties.getProperty(WORKING_DIR_KEY));
if(!FileUtils.dirCheck(workingDir, true)){
final FileNotFoundException e = new FileNotFoundException("cannot access working dir " + workingDir);
logger.error(this, e, e);
throw e;
}
file = new File(workingDir, DATA_FILE_NAME);
printProperties();
}
public GFF3DataProxyImpl() throws FileNotFoundException {
this.strategy = new CachedDiskSerialisation();
properties = getPropertes();
this.logger = new ConsoleLogger();
workingDir = new File(properties.getProperty(WORKING_DIR_KEY));
if(!FileUtils.dirCheck(workingDir, true)){
final FileNotFoundException e = new FileNotFoundException("cannot access working dir " + workingDir);
logger.error(this, e, e);
throw e;
}
file = new File(workingDir, DATA_FILE_NAME);
printProperties();
}
private GFF3DataBean getData() throws DataBeanAccessException {
if(!FileUtils.fileCheck(file, false)){
logger.info(this, "file " + file + " not there, creating new data");
return strategy.getNewDataBean();
}
return strategy.readDataBean(file, GFF3DataBean.class);
}
private void setData(GFF3DataBean data) throws DataBeanAccessException {
strategy.writeDataBean(data, file);
}
public synchronized void modifiyData(DataModifier<GFF3DataBean> v)
throws DataBeanAccessException {
final GFF3DataBean data = getData();
v.modifiyData(data);
setData(data);
}
public GFF3DataBean viewData() throws DataBeanAccessException {
return getData();
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tdatafile=" + file);
}
private 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();
return pro;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
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.impl.GFF3DataBeanImpl;
public class GFF3DiskSerialisation extends AbstractDiskSerialisation {
protected volatile DataBean data = new GFF3DataBeanImpl();
GFF3DiskSerialisation() {
super();
}
GFF3DiskSerialisation(LogDispatcher logger) {
super(logger);
}
@SuppressWarnings("unchecked")
public <V extends DataBean> V getNewDataBean() {
// TODO: WHY CAST ?!?
return (V) new GFF3DataBeanImpl();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
public class SimpleDiskSerialisation extends GFF3DiskSerialisation {
public SimpleDiskSerialisation() {
super();
}
public SimpleDiskSerialisation(LogDispatcher logger) {
super(logger);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
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.dataproxy.GFF3DataProxy;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
public class GFF3DataProxyActivator implements BundleActivator {
private LogDispatcher logger = null;
public void start(BundleContext context) throws Exception {
logger = new LogDispatcherImpl(context);
GFF3DataProxy proxy = new GFF3DataProxyImpl(new CachedDiskSerialisation(logger));
context.registerService(GFF3DataProxy.class.getName(), proxy,
new Hashtable<Object, Object>());
}
public void stop(BundleContext context) throws Exception {
logger.debug(this, "service stopped!");
logger = null;
}
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
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.osgi.commons.logger.dispatcher.LogDispatcher;
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
*
*/
class CachedDiskSerialisation extends GFF3DiskSerialisation {
CachedDiskSerialisation() {
super();
}
CachedDiskSerialisation(LogDispatcher logger) {
super(logger);
}
private volatile boolean dirty = false;
@SuppressWarnings("unchecked")
@Override
public synchronized <V extends DataBean> V readDataBean(File file,
Class<V> v) throws DataBeanAccessException {
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 synchronized <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
this.dirty = true;
logger.debug(this, "writing data");
super.writeDataBean(v, file);
}
@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.server.dataproxy;
public interface DataModifier<V> {
void modifiyData(V v);
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
// TODO: should be <V extends DataBean>
public interface DataProxy<V> {
/**
*
* <p>
* Atomar operation on data. Data will be synchronized bevor and after this
* operation.
* </p>
*
* @param v
* Type of Data, that is accessed.
* @throws DataBeanAccessException
*/
void modifiyData(DataModifier<V> v) throws DataBeanAccessException;
/**
*
* <p>
* Use this method for reading data only. If you make changes to the data
* you get from this method, these changes will not be updated! If you
* want to write data, use {@link modifiyData()} instead.
*
* @return the data object.
* @throws DataBeanAccessException
*/
V viewData() throws DataBeanAccessException;
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
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;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
abstract class AbstractDiskSerialisation implements SerialisationStrategy {
protected final LogDispatcher logger;
AbstractDiskSerialisation() {
this.logger = new ConsoleLogger();
}
AbstractDiskSerialisation(LogDispatcher logger) {
this.logger = logger;
}
protected void objectToFile(Serializable s, File file) throws IOException {
if (s == null || file == null)
throw new NullPointerException(s + " + " + file
+ " must not be null");
OutputStream fos = null;
ObjectOutputStream outStream = null;
try {
fos = new FileOutputStream(file);
outStream = new ObjectOutputStream(fos);
outStream.writeObject(s);
} finally {
if (outStream != null)
outStream.close();
if (fos != null)
fos.close();
}
}
protected <V> V fileToObject(Class<V> c, File file) throws IOException,
ClassNotFoundException {
if (c == null || file == null)
throw new NullPointerException(c + " + " + file
+ " must not be null");
InputStream fis = null;
ObjectInputStream inStream = null;
try {
fis = new FileInputStream(file);
inStream = new ObjectInputStream(fis);
V v = c.cast(inStream.readObject());
return v;
} finally {
if (inStream != null)
inStream.close();
if (fis != null)
fis.close();
}
}
protected <V extends DataBean> V handleCorruptData(File file, Throwable t) {
logger.warn(this, file.toString() + " corrupt, returning new one");
if (file.delete()) {
logger.info(this, "deleted corrupted data");
} else {
logger.warn(this, "could not delete corrupt data " + file);
}
return getNewDataBean();
}
public synchronized <V extends DataBean> V readDataBean(File file,
Class<V> v) throws DataBeanAccessException {
try {
final V data = fileToObject(v, file);
logger.debug(this, "reading data from file");
return data;
} catch (EOFException e) {
logger.warn(this, e.getLocalizedMessage(), e);
return handleCorruptData(file, e);
} catch (StreamCorruptedException e) {
logger.warn(this, e.getLocalizedMessage(), e);
return handleCorruptData(file, e);
} catch (Throwable t) {
logger.error(this, t.getLocalizedMessage(), t);
throw new DataBeanAccessException(t);
}
}
public synchronized <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
try {
logger.debug(this, "writing data to file");
objectToFile(v, file);
} catch (IOException e) {
logger.error(this, e.toString(), e);
throw new DataBeanAccessException(e);
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
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.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.GFF3DataProxy;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
public class GFF3DataProxyImpl implements GFF3DataProxy{
final static String WORKING_DIR_KEY = "anna.server.data.workingDir";
final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration" + File.separatorChar + "data.properties");
final static String DATA_FILE_NAME = "data.ser";
private final SerialisationStrategy strategy;
private final Properties properties;
private final File workingDir;
private final File file;
private final LogDispatcher logger;
public GFF3DataProxyImpl(final SerialisationStrategy strategy) throws FileNotFoundException {
this.strategy = strategy;
this.logger = new ConsoleLogger();
properties = getPropertes();
workingDir = new File(properties.getProperty(WORKING_DIR_KEY));
if(!FileUtils.dirCheck(workingDir, true)){
final FileNotFoundException e = new FileNotFoundException("cannot access working dir " + workingDir);
logger.error(this, e, e);
throw e;
}
file = new File(workingDir, DATA_FILE_NAME);
printProperties();
}
public GFF3DataProxyImpl() throws FileNotFoundException {
this.strategy = new CachedDiskSerialisation();
properties = getPropertes();
this.logger = new ConsoleLogger();
workingDir = new File(properties.getProperty(WORKING_DIR_KEY));
if(!FileUtils.dirCheck(workingDir, true)){
final FileNotFoundException e = new FileNotFoundException("cannot access working dir " + workingDir);
logger.error(this, e, e);
throw e;
}
file = new File(workingDir, DATA_FILE_NAME);
printProperties();
}
private GFF3DataBean getData() throws DataBeanAccessException {
if(!FileUtils.fileCheck(file, false)){
logger.info(this, "file " + file + " not there, creating new data");
return strategy.getNewDataBean();
}
return strategy.readDataBean(file, GFF3DataBean.class);
}
private void setData(GFF3DataBean data) throws DataBeanAccessException {
strategy.writeDataBean(data, file);
}
public synchronized void modifiyData(DataModifier<GFF3DataBean> v)
throws DataBeanAccessException {
final GFF3DataBean data = getData();
v.modifiyData(data);
setData(data);
}
public GFF3DataBean viewData() throws DataBeanAccessException {
return getData();
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
private void printProperties() {
logger.debug(this, " created, properties:");
logger.debug(this, "\tdatafile=" + file);
}
private 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();
return pro;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
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.impl.GFF3DataBeanImpl;
public class GFF3DiskSerialisation extends AbstractDiskSerialisation {
protected volatile DataBean data = new GFF3DataBeanImpl();
GFF3DiskSerialisation() {
super();
}
GFF3DiskSerialisation(LogDispatcher logger) {
super(logger);
}
@SuppressWarnings("unchecked")
public <V extends DataBean> V getNewDataBean() {
// TODO: WHY CAST ?!?
return (V) new GFF3DataBeanImpl();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
public class SimpleDiskSerialisation extends GFF3DiskSerialisation {
public SimpleDiskSerialisation() {
super();
}
public SimpleDiskSerialisation(LogDispatcher logger) {
super(logger);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
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.dataproxy.GFF3DataProxy;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
public class GFF3DataProxyActivator implements BundleActivator {
private LogDispatcher logger = null;
public void start(BundleContext context) throws Exception {
logger = new LogDispatcherImpl(context);
GFF3DataProxy proxy = new GFF3DataProxyImpl(new CachedDiskSerialisation(logger));
context.registerService(GFF3DataProxy.class.getName(), proxy,
new Hashtable<Object, Object>());
}
public void stop(BundleContext context) throws Exception {
logger.debug(this, "service stopped!");
logger = null;
}
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.