code stringlengths 3 1.18M | language stringclasses 1 value |
|---|---|
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.mpg.mpiz.koeln.anna.step.common.lsf.LSF;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
import de.mpg.mpiz.koeln.anna.step.conrad.predict.common.AbstractPredict;
/**
* @author Alexander Kerner
*
*/
public class PredictLSF extends AbstractPredict {
@Override
public synchronized List<String> getCmdList() {
final CommandStringBuilder builder = new CommandStringBuilder(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStrings(workingDir));
builder.addAllFlagCommands(ConradConstants.getConradCmdString());
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();
}
}
| 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> getBsubValueCommandStringsFailSave(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", "wspcb015.mpiz-koeln.mpg.de");
map.put("-q", "ubuntutest");
map.put("-R", "rusage[mem=2000]");
map.put("-eo", LSFerr.getAbsolutePath());
map.put("-oo", LSFout.getAbsolutePath());
return map;
}
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", "pcbcomputenodes");
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");
list.add("-r");
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 de.bioutils.gff3.element.GFF3ElementGroup;
import de.bioutils.gff3.element.GFF3ElementGroupImpl;
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.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
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";
// Implement //
public boolean run(DataProxy<GFF3DataBean> proxy) throws Throwable {
boolean success = false;
final File outDir = new File(super.getStepProperties().getProperty(
OUT_DIR_KEY));
logger.debug("got outdir=" + outDir);
success = FileUtils.dirCheck(outDir, true);
if(success)
writeFile(outDir, proxy);
return success;
}
private void writeFile(File outDir, DataProxy<GFF3DataBean> proxy)
throws DataBeanAccessException, IOException {
logger.debug("reading GFF for predicted genes");
final GFF3ElementGroup predicted = proxy.viewData()
.getPredictedGenesGFF();
logger.debug("reading GFF for predicted genes done (elements="
+ predicted.getSize() + ")");
logger.debug("reading GFF for repetetive elements");
final GFF3ElementGroup repeat = proxy.viewData()
.getRepeatMaskerGFF();
logger.debug("reading GFF for repetetive elements done (elements="
+ repeat.getSize() + ")");
logger.debug("reading GFF for mapped ests");
final GFF3ElementGroup ests = proxy.viewData().getMappedESTs();
logger.debug("reading GFF for mapped ests done (elements="
+ ests.getSize() + ")");
logger.debug("merging");
// TODO is that really sorted??
final GFF3ElementGroup merged = new GFF3ElementGroupImpl(true);
merged.addAll(predicted);
merged.addAll(repeat);
merged.addAll(ests);
logger.debug("merging done (elements=" + merged.getSize() + ")");
if (merged.getSize() == 0) {
logger.info("nothing to write");
return;
}
final File outFile = new File(outDir, super.getStepProperties()
.getProperty(OUT_FILE_NAME_KEY));
logger.info("writing results to " + outFile);
new GFF3FileImpl(merged).write(outFile);
logger.debug("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.kerner.commons.logging.Log;
import de.mpg.mpiz.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 {
private final static Log logger = new Log(Statistics.class);
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());
}
}
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(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.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
class StateRuntimes {
private final static Log logger = new Log(StateRuntimes.class);
private volatile State lastState;
private final Map<State, StopWatch> stateToStopWatch = new ConcurrentHashMap<State, StopWatch>();
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("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.listener.statistics.prediction;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEvent;
import de.mpg.mpiz.koeln.anna.listener.abstractlistener.AbstractEventListener;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
public class PredictionStatistics extends AbstractEventListener {
private final static Log logger = new Log(PredictionStatistics.class);
private final static String PRE_LINE = " PREDICTS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
private final static String POST_LINE = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
public void eventOccoured(AnnaEvent event) {
if(weAreDone(event)){
final StringBuilder sb = new StringBuilder();
sb.append(PRE_LINE);
sb.append(FileUtils.NEW_LINE);
} else {
// nothing
}
}
private boolean weAreDone(AnnaEvent event) {
final Collection<AnnaStep> eventList = event.getRegisteredSteps();
for (AnnaStep s : eventList) {
if (!(s.getState().isFinished())) {
return false;
}
}
return true;
}
}
| Java |
package de.mpg.mpiz.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.mpiz.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("[").append(
"stepReg").append("=").append(registeredSteps).append("]").toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.core.events;
import java.util.EventListener;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface AnnaEventListener extends EventListener {
void eventOccoured(AnnaEvent event);
}
| 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);
void shutdown();
}
| 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.impl;
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) {
super(step, handler);
}
public Void call() throws Exception {
start();
return null;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
import java.util.ArrayList;
import java.util.Collection;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEvent;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
* <p> Simple helper class </p>
* @threadSave all sync to this
* @author Alexander Kerner
* @lastVisit 2009-09-22
*
*/
class EventHandler {
private final Collection<AnnaEventListener> observers = new ArrayList<AnnaEventListener>();
private final Collection<AnnaStep> registeredSteps;
public EventHandler(Collection<AnnaStep> registeredSteps) {
this.registeredSteps = registeredSteps;
}
public synchronized void stepStateChanged(AnnaStep step){
broadcastEvent(new StepStateChangeEvent(this, registeredSteps, step));
}
private void broadcastEvent(AnnaEvent event) {
if (observers.isEmpty())
return;
for (AnnaEventListener l : observers) {
l.eventOccoured(event);
}
}
synchronized void addEventListener(AnnaEventListener observer) {
observers.add(observer);
}
synchronized void removeEventListener(AnnaEventListener observer) {
observers.remove(observer);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-11-12
*
*/
public abstract class StepSheduler implements Callable<Void> {
// private final static Log logger = new Log(StepSheduler.class);
private final ExecutorService pool = Executors.newSingleThreadExecutor();
protected final AnnaStep step;
protected final EventHandler handler;
protected volatile AnnaSepExecutor exe;
StepSheduler(AnnaStep step, EventHandler handler) {
this.step = step;
this.handler = handler;
this.exe = new AnnaSepExecutor(step, handler);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + ":"
+ exe.getClass().getSimpleName();
}
public synchronized void start(){
pool.submit(exe);
// we cannot shutdown the pool here, because of cyclic steps.
// TODO when do we shutdown pool??
//pool.shutdown();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
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.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEvent;
import de.mpg.mpiz.koeln.anna.core.events.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-11-12
* @thradSave custom
*
*/
public class AnnaServerImpl implements AnnaServer {
private class Terminator extends Thread {
private Collection<AnnaStep> registeredSteps;
private final long timeout = 5000;
Terminator(Collection<AnnaStep> registeredSteps) {
this.registeredSteps = registeredSteps;
}
@Override
public void run() {
// TODO: ugly workaround to terminate whole app.
logger.debug("doing dirty shutdown");
try {
sleep(timeout);
while (!areWeDone()) {
sleep(timeout);
}
exe.shutdown();
activator.shutdown();
System.exit(0);
} catch (Exception e) {
System.err.println("dirty shutdown failed! ("
+ e.getLocalizedMessage() + ")");
}
}
private boolean areWeDone() {
synchronized (registeredSteps) {
for (AnnaStep s : registeredSteps) {
if (!(s.getState().isFinished())) {
return false;
}
}
return true;
}
}
}
private final static Log logger = new Log(AnnaServerImpl.class);
// 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 AnnaServerActivator activator;
AnnaServerImpl(AnnaServerActivator activator) {
properties = getPropertes();
logger.debug("loaded properties: " + properties);
handler = new EventHandler(registeredSteps);
handler.addEventListener(new NotifyOthersListener());
this.activator = activator;
}
public void shutdown() {
logger.debug("starting shutting down");
new Terminator(registeredSteps).start();
}
public synchronized void unregisterStep(ExecutableStep step) {
logger.debug("TODO");
// TODO Auto-generated method stub
}
public synchronized void registerStep(ExecutableStep step) {
registeredSteps.add((AnnaStep) step);
setStepState(step, State.REGISTERED);
logger.debug("registered step " + step);
if (((AnnaStep) step).getState().equals(State.ERROR)) {
logger.debug("step is dummy, will not execute");
return;
}
StepSheduler ss;
if (step.isCyclic()) {
ss = new CyclicStepSheduler((AnnaStep) step, handler);
} else {
ss = new ImmediateStepSheduler((AnnaStep) step, handler);
}
synchronized (AnnaSepExecutor.LOCK) {
logger.debug("notifying others (new step)");
AnnaSepExecutor.LOCK.notifyAll();
}
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 {
logger.debug("loading settings from " + PROPERTIES_FILE);
final FileInputStream fi = new FileInputStream(PROPERTIES_FILE);
pro.load(fi);
fi.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.warn(this + ": could not load settings from "
+ PROPERTIES_FILE.getAbsolutePath() + ", using defaults");
} catch (IOException e) {
e.printStackTrace();
logger.warn(this + ": could not load settings from "
+ PROPERTIES_FILE.getAbsolutePath() + ", using defaults");
}
return pro;
}
private Properties initDefaults() {
Properties pro = new Properties();
// pro.setProperty(WORKING_DIR_KEY, WORKING_DIR_VALUE);
return pro;
}
private void setStepState(ExecutableStep step, State state) {
// logger.debug("changing step state, step="+step + ", state="+state);
if (!((AnnaStep) step).getState().equals(State.ERROR))
((AnnaStep) step).setState(state);
else
logger.debug("step was errorgenious, will not change state");
handler.stepStateChanged((AnnaStep) step);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEvent;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.ObservableStep;
public class CyclicStepSheduler extends ImmediateStepSheduler implements
AnnaEventListener {
private final static Log logger = new Log(CyclicStepSheduler.class);
CyclicStepSheduler(AnnaStep step, EventHandler handler) {
super(step, handler);
handler.addEventListener(this);
}
@Override
public Void call() throws Exception {
// do nothing until some other steps are done
return null;
}
public void eventOccoured(AnnaEvent event) {
if (event instanceof StepStateChangeEvent) {
logger.debug("received step state changed event " + event);
final StepStateChangeEvent c = (StepStateChangeEvent) event;
if (c.getStep().equals(step)) {
logger.debug("it was us, ignoring");
} else if (!(c.getStep().getState().equals(
ObservableStep.State.DONE) || c.getStep().getState()
.equals(ObservableStep.State.SKIPPED))) {
logger.debug("step state change was not to state "
+ ObservableStep.State.DONE + "/"
+ ObservableStep.State.SKIPPED + ", ignoring");
} else {
logger.debug("someone else finished, starting");
exe = new AnnaSepExecutor(step, handler);
start();
}
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEvent;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEventListener;
import de.mpg.mpiz.koeln.anna.core.events.StepStateChangeEvent;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
* <p> Helper class, to release lock when step finished.</p>
* @author Alexander Kerner
*
*/
class NotifyOthersListener implements AnnaEventListener {
private final static Log logger = new Log(NotifyOthersListener.class);
NotifyOthersListener() {
}
public void eventOccoured(AnnaEvent event) {
if(event instanceof StepStateChangeEvent){
final State state = ((StepStateChangeEvent) event).getState();
// state "SKIPPED" not needed, because skipped steps never acquire lock
if(state.equals(State.DONE) || state.equals(State.ERROR)){
synchronized (AnnaSepExecutor.LOCK) {
logger.debug("notifying others");
AnnaSepExecutor.LOCK.notifyAll();
}
} else {
// nothing
}
}else {
// nothing
}
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
/**
* @lastVisit 2009-11-12
* @author Alexander Kerner
*
*/
public class AnnaServerActivator implements BundleActivator {
private final static Log logger = new Log(AnnaServerActivator.class);
private volatile BundleContext context;
public void start(BundleContext context) throws Exception {
this.context = context;
final AnnaServer service = new AnnaServerImpl(this);
context.registerService(AnnaServer.class.getName(), service,
new Hashtable<Object, Object>());
logger.debug("server started");
}
public void stop(BundleContext context) throws Exception {
logger.debug("stopping (TODO implement)");
// TODO implement
}
public String toString() {
return this.getClass().getSimpleName();
}
synchronized void shutdown() {
// TODO: this should be obsolete (services do not need to be unregistered in order to shutdown OSGi)
// logger.debug("shutting down server");
// final ServiceReference reference = context.getServiceReference(AnnaServer.class.getName());
// final boolean b = context.ungetService(reference);
// if(b){
// logger.debug("server down");
// } else {
// logger.debug("server was not running");
// }
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.impl;
import java.util.concurrent.Callable;
import de.kerner.commons.logging.Log;
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.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-11-12
* @thradSave custom
*
*/
class AnnaSepExecutor implements Callable<Void> {
private final static Log log = new Log(AnnaSepExecutor.class);
public final static Object LOCK = Server.class;
private final AnnaStep step;
private final EventHandler handler;
AnnaSepExecutor(AnnaStep step, EventHandler handler) {
this.step = step;
this.handler = handler;
}
public Void call() throws Exception {
boolean success = true;
stepStateChanged(State.CHECK_NEED_TO_RUN);
final boolean b = step.canBeSkipped();
if (b) {
log.info("step " + step
+ " does not need to run, skipping");
stepStateChanged(State.SKIPPED);
stepFinished(success);
return null;
}
log.debug("step " + step + " needs to run");
stepStateChanged(State.WAIT_FOR_REQ);
synchronized (LOCK) {
while (!step.requirementsSatisfied()) {
log.debug("requirements for step " + step
+ " not satisfied, putting it to sleep");
LOCK.wait();
}
log.debug("requirements for step " + step + " satisfied");
}
try {
success = runStep();
} catch (Exception e) {
if (e instanceof StepExecutionException) {
log.warn(e.getLocalizedMessage(), e);
} else {
log.error(e.getLocalizedMessage(), e);
}
stepStateChanged(State.ERROR);
success = false;
}
stepFinished(success);
return null;
}
private boolean runStep() throws StepExecutionException {
log.debug("step " + step + " running");
stepStateChanged(State.RUNNING);
return step.run();
}
private void stepStateChanged(State state) {
step.setState(state);
handler.stepStateChanged(step);
}
private void stepFinished(boolean success) {
log.debug("step " + step + " done running");
if (success && !(step.getState().equals(ObservableStep.State.SKIPPED))) {
stepStateChanged(ObservableStep.State.DONE);
} else if (!success
&& !(step.getState().equals(ObservableStep.State.SKIPPED))) {
stepStateChanged(ObservableStep.State.ERROR);
}
}
public String toString() {
return this.getClass().getSimpleName() + ":"
+ step.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server;
import java.util.Properties;
import de.mpg.mpiz.koeln.anna.core.events.AnnaEventListener;
/**
*
* @lastVisit 2009-09-22
* @author Alexander Kerner
*
*/
public interface Server {
Properties getServerProperties();
// TODO: AnnaEventListener does not match this interface abstraction
void addEventListener(AnnaEventListener observer);
void removeEventListener(AnnaEventListener observer);
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
public class StepExecutionException extends Exception {
private static final long serialVersionUID = 5683856650378220175L;
private final ExecutableStep step;
public StepExecutionException(ExecutableStep step) {
this.step = step;
}
public StepExecutionException(ExecutableStep step, String arg0) {
super(arg0);
this.step = step;
}
public StepExecutionException(ExecutableStep step, Throwable arg0) {
super(arg0);
this.step = step;
}
public StepExecutionException(ExecutableStep step, String arg0, Throwable arg1) {
super(arg0, arg1);
this.step = step;
}
public ExecutableStep getStep(){
return step;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
public interface AnnaStep extends ExecutableStep, ObservableStep {
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
import java.util.Properties;
public interface ExecutableStep {
boolean requirementsSatisfied() throws StepExecutionException;
boolean canBeSkipped() throws StepExecutionException;
boolean run() throws StepExecutionException;
Properties getStepProperties();
boolean isCyclic();
}
| Java |
package de.mpg.mpiz.koeln.anna.step;
import java.util.Collection;
import java.util.List;
public interface ObservableStep {
public enum State {
LOOSE,
// active steps
REGISTERED, CHECK_NEED_TO_RUN, RUNNING,
// well... might wait forever.
WAIT_FOR_REQ,
// finished steps
DONE, ERROR, SKIPPED;
public boolean isFinished(){
switch (this) {
case DONE:
return true;
case ERROR:
return true;
case SKIPPED:
return true;
default:
return false;
}
}
public boolean isActive(){
switch(this){
case REGISTERED:
return true;
case CHECK_NEED_TO_RUN:
return true;
case RUNNING:
return true;
default:
return false;
}
}
}
State getState();
void setState(State state);
List<String> requirementsNeeded();
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.predict.common;
import java.io.File;
import java.io.Serializable;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff3.GFF3Utils;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.element.GFF3ElementBuilder;
import de.bioutils.gff3.element.GFF3ElementGroup;
import de.bioutils.gff3.element.GFF3ElementGroupImpl;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3WrapperStep;
import de.mpg.mpiz.koeln.anna.core.AnnaConstants;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
public abstract class AbstractPredict extends AbstractGFF3WrapperStep {
protected final static String TRAIN_PREFIX_KEY = "predict.";
protected volatile File resultFile = null;
protected volatile File trainingFile = null;
// Constructor //
public AbstractPredict() {
super(new File(ConradConstants.WORKING_DIR), new File(
ConradConstants.WORKING_DIR));
}
// Private //
private void createFiles(DataProxy<GFF3DataBean> data) throws Throwable {
resultFile = new File(workingDir, "result.gtf");
trainingFile = (File) data.viewData().getCustom(
ConradConstants.TRAINING_FILE_KEY);
final File file = new File(workingDir, "ref.fasta");
new NewFASTAFileImpl(data.viewData().getInputSequence()).write(file);
logger.debug(StringUtils.getString("got ", trainingFile,
" as training file from data proxy (size=", trainingFile
.length(), ")"));
// copying does not work for some reason.
// take "original" file for now
// try {
// new LazyFileCopier(file2, trainingFile).copy();
// } catch (Throwable t) {
// t.printStackTrace();
// }
// logger.debug(this, "copied files: old=" + file2.length() + ",new="
// + trainingFile.length());
// trainingFile.deleteOnExit();
}
// Override //
@Override
public String toString() {
return this.getClass().getSimpleName();
}
// Implement //
@Override
public void prepare(DataProxy<GFF3DataBean> data) throws Throwable {
// its to late to do that here
//createFiles(data);
}
@Override
public void update(DataProxy<GFF3DataBean> data) throws Throwable {
final GFF3ElementGroup c = GFF3Utils.convertFromGFFFile(resultFile,
true).getElements();
final GFF3ElementGroup result = new GFF3ElementGroupImpl(c.isSorted());
for(GFF3Element e : c){
result.add(new GFF3ElementBuilder(e).setSource(AnnaConstants.IDENT).build());
}
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
logger.debug("setting predicted genes");
v.setPredictedGenesGFF(result);
}
});
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws Throwable {
final boolean predictedGtf = (data.viewData().getPredictedGenesGFF() != null);
final boolean predictedGtfSize = (!data.viewData()
.getPredictedGenesGFF().isEmpty());
logger.debug(StringUtils.getString("need to run: predictedGtf=",
predictedGtf));
logger.debug(StringUtils.getString("need to run: predictedGtfSize=",
predictedGtfSize));
return (predictedGtf && predictedGtfSize);
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws Throwable {
final boolean trainingFileNotNull = (data.viewData().getCustom(ConradConstants.TRAINING_FILE_KEY) != null);
if(trainingFileNotNull){
final File trainingFileFile = (File) data.viewData().getCustom(ConradConstants.TRAINING_FILE_KEY);
if(!FileUtils.fileCheck(trainingFileFile, false)){
logger.info("cannot access training file \"" + trainingFileFile + "\"");
return false;
}
// at this point training file is there and accessible
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (!data.viewData().getInputSequence()
.isEmpty());
logger.debug(StringUtils.getString("requirements: trainingFile=",
trainingFileFile));
logger.debug(StringUtils.getString("requirements: inputSequences=",
inputSequences));
logger.debug(StringUtils.getString("requirements: inputSequencesSize=",
inputSequencesSize));
return (inputSequences && inputSequencesSize);
} else {
logger.debug(StringUtils.getString("requirements: trainingFileNotNull=",
trainingFileNotNull));
return false;
}
}
@Override
public boolean run(DataProxy<GFF3DataBean> data) throws Throwable {
createFiles(data);
addShortCutFile(resultFile.getAbsoluteFile());
addResultFileToWaitFor(resultFile.getAbsoluteFile());
return start();
}
public boolean isCyclic() {
return false;
}
}
| 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.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 {
@Override
public List<String> getCmdList() {
final CommandStringBuilder builder = new CommandStringBuilder(LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStringsFailSave(workingDir));
builder.addFlagCommand(new File(
exeDir, RepeatMaskerConstants.EXE).getAbsolutePath());
builder.addAllFlagCommands(RepeatMaskerConstants.OPTIONS_FLAG);
builder.addAllValueCommands(RepeatMaskerConstants.OPTIONS_VALUE);
// builder.addAllFlagCommands("-s");
// builder.addFlagCommand("-gff");
builder.addFlagCommand(inFile.getAbsolutePath());
return builder.getCommandList();
}
}
| 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.getBsubValueCommandStringsFailSave(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.step.conrad.train.common;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import de.bioutils.fasta.FASTAElementGroup;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff3.element.GFF3ElementGroup;
import de.bioutils.gff3.file.GFF3File;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3WrapperStep;
import de.mpg.mpiz.koeln.anna.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
public abstract class AbstractTrain extends AbstractGFF3WrapperStep {
protected final static File TRAINING_FILE = new File(
ConradConstants.WORKING_DIR, "trainingFile.bin");
public AbstractTrain() {
super(new File(ConradConstants.WORKING_DIR), new File(
ConradConstants.WORKING_DIR));
}
// Override //
@Override
public String toString() {
return this.getClass().getSimpleName();
}
@Override
public List<String> requirementsNeeded(DataProxy<GFF3DataBean> data)
throws Throwable {
final List<String> r = new ArrayList<String>();
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
boolean fastasSize = false;
if (fastas) {
fastasSize = (!data.viewData().getVerifiedGenesFasta().isEmpty());
}
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
boolean gtfSize = false;
if (gtf)
gtfSize = (!data.viewData().getVerifiedGenesGFF().isEmpty());
boolean adapter = false;
if (data.viewData().getCustom(ConradConstants.ADAPTED_KEY) != null) {
adapter = (Boolean) data.viewData().getCustom(
ConradConstants.ADAPTED_KEY);
}
if (!fastas || !fastasSize) {
r.add("verified genes sequences");
}
if (!gtf || !gtfSize) {
r.add("verified genes annotations");
}
if (!adapter)
r.add("data adapted");
return r;
}
@Override
public void prepare(DataProxy<GFF3DataBean> data) throws Throwable {
createFastas(data);
createGFFs(data);
}
@Override
public void update(DataProxy<GFF3DataBean> data) throws Throwable {
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
logger.debug("using custom slot: key=" + TRAINING_FILE
+ ", value=" + TRAINING_FILE.getAbsoluteFile());
v.addCustom(ConradConstants.TRAINING_FILE_KEY, TRAINING_FILE.getAbsoluteFile());
}
});
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws Throwable {
boolean trainingFile = false;
if (getStepProperties().getProperty(ConradConstants.TRAINING_FILE_REFIX) != null) {
trainingFile = FileUtils.fileCheck((File) data.viewData()
.getCustom(ConradConstants.TRAINING_FILE_REFIX), false);
}
logger.debug("need to run: trainingFile=" + trainingFile);
return trainingFile;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws Throwable {
// System.err.println("WENIGSTENS BIS HIER??");
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
boolean fastasSize = false;
if (fastas) {
fastasSize = (!data.viewData().getVerifiedGenesFasta().isEmpty());
}
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
boolean gtfSize = false;
if (gtf)
gtfSize = (!data.viewData().getVerifiedGenesGFF().isEmpty());
boolean adapter = false;
// System.err.println("BIS HIERHER UND NICHT WEITER !!!!!!!!!!");
if (data.viewData().getCustom(ConradConstants.ADAPTED_KEY) != null) {
adapter = (Boolean) data.viewData().getCustom(
ConradConstants.ADAPTED_KEY);
}
logger.debug(this + " requirements: fastas=" + fastas);
logger.debug(this + " requirements: fastasSize=" + fastasSize);
logger.debug(this + " requirements: gtf=" + gtf);
logger.debug(this + " requirements: gtfSize=" + gtfSize);
logger.debug(this + " requirements: data adapted=" + adapter);
return (fastas && fastasSize && gtf && gtfSize && adapter);
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws Throwable {
addShortCutFile(TRAINING_FILE);
return start();
}
public boolean isCyclic() {
return false;
}
// Private //
private void createGFFs(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
final File inGff = new File(ConradConstants.WORKING_DIR, "ref.gtf");
logger.debug("ref.gtf=" + inGff);
logger.debug("getting gtfs for veryfied genes");
final GFF3ElementGroup gtfs = data.viewData().getVerifiedGenesGFF();
final GFF3File gtfFile = new GFF3FileImpl(gtfs);
logger.debug("writing gffs to " + inGff);
gtfFile.write(inGff);
}
private void createFastas(DataProxy<GFF3DataBean> data)
throws DataBeanAccessException, IOException {
final File inFasta = new File(ConradConstants.WORKING_DIR, "ref.fasta");
logger.debug("ref.fasta=" + inFasta);
logger.debug("getting fastas for veryfied genes");
final FASTAElementGroup fastas = data.viewData()
.getVerifiedGenesFasta();
final NewFASTAFile fastaFile = new NewFASTAFileImpl(fastas);
logger.debug("writing fastas to " + inFasta);
fastaFile.write(inFasta);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.annafinishedlistener;
import java.util.Collection;
import de.kerner.commons.logging.Log;
import de.kerner.commons.osgi.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.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 Log logger = new Log(FinishedListener.class);
private final static String PRE_LINE = "!!!!!!!!!!!!!!!!!!!!!!";
private final static String POST_LINE = PRE_LINE;
private volatile boolean error = false;
public synchronized void eventOccoured(AnnaEvent event) {
if(areWeDone(event)){
logger.info(PRE_LINE);
if(error){
logger.info("pipeline finished (with errors)!");
} else {
logger.info("pipeline finished!");
}
logger.info(POST_LINE);
shutdownPipeline();
} else {
// ignore
}
}
private void shutdownPipeline() {
try {
super.getServer().shutdown();
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
}
}
private boolean areWeDone(AnnaEvent event){
final Collection<AnnaStep> eventList = event.getRegisteredSteps();
// boolean done = true;
for(AnnaStep s : eventList){
if(!s.getState().isFinished() || s.getState().isActive())
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 de.bioutils.AbstractSequence;
import de.bioutils.DNABasicAlphabet;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.FASTAElementGroup;
import de.bioutils.fasta.FASTAElementGroupImpl;
import de.bioutils.fasta.FASTAElementImpl;
import de.bioutils.fasta.FastaUtils;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
public class InputSequenceReader extends AbstractGFF3AnnaStep {
private final static String INFILE_KEY = "anna.step.inputsequencereader.infile";
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws Throwable {
logger.debug("no requirements needed");
return true;
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws Throwable {
final boolean inputSequences = (data.viewData().getInputSequence() != null);
final boolean inputSequencesSize = (!data.viewData().getInputSequence()
.isEmpty());
logger.debug("need to run:");
logger.debug("\tinputSequences=" + inputSequences);
logger.debug("\tinputSequencesSize=" + inputSequencesSize);
return (inputSequences && inputSequencesSize);
}
public boolean run(DataProxy<GFF3DataBean> data) throws Throwable {
final File inFile = new File(getStepProperties()
.getProperty(INFILE_KEY));
logger.info("reading file " + inFile);
FASTAElementGroup fastas = NewFASTAFileImpl.parse(inFile)
.getElements();
if (fastas == null || fastas.isEmpty()) {
logger.warn("file " + inFile + " is invalid");
return false;
}
logger.debug("got input sequences:"
+ fastas.iterator().next().getHeader() + " [...]");
fastas = trimmFasta(fastas);
logger.debug("checking for valid alphabet");
final FASTAElementGroup sequencesNew = FastaUtils.adaptToAlphabet(fastas, new DNABasicAlphabet());
//new NewFASTAFileImpl(sequencesNew).write(new File("/home/pcb/kerner/Desktop/input.fasta"));
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setInputSequence(sequencesNew);
}
});
return true;
}
private FASTAElementGroup trimmFasta(FASTAElementGroup fastas) {
final String tmpHeader = fastas.iterator().next()
.getHeader();
logger.debug("trimming fasta headers");
fastas = FastaUtils.trimHeader(fastas);
logger.debug("done trimming fasta headers");
logger.debug("old header: \"" + tmpHeader + "\", new header: \""
+ fastas.iterator().next().getHeader() + "\"");
return fastas;
}
@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;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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";
public final static String OUTSTREAM_FILE_KEY = "anna.step.repeatMasker.outstream.file";
public final static List<String> OPTIONS_FLAG = new ArrayList<String>(){
private static final long serialVersionUID = 1984766436592060144L;
{
add("-gff");
}
};
// TODO: this is c. higginsianum (and path) specific.
public final static Map<String, String> OPTIONS_VALUE = new LinkedHashMap<String, String>(){
private static final long serialVersionUID = 1984766436592060144L;
{
put("-lib", "/opt/share/local/users/kerner/repeatmasker/Libraries/c.higginsianum.lib");
}
};
}
| 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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.kerner.commons.file.AbstractLineByLineReader;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.file.LazyStringWriter;
/**
* <p>
* Try to change line from
* <blockquote>
* contig00001 RepeatMasker similarity 3920 4097 33.7 +Target "Motif:(CGG)n" 3 180
* </blockquote>
* to
* <blockquote>
* contig00001 RepeatMasker similarity 3920 4097 33.7 + Target "Motif:(CGG)n" 3 180
* </blockquote>
* </p>
* @author Alexander Kerner
*
*/
class ResultsPreprocessor {
private final static String PATTERN_PREFIX = ".+";
private final static String PATTERN_POSTFIX = ".+";
private final static Pattern P_PLUS = Pattern.compile(PATTERN_PREFIX
+ "[\\+]Target" + PATTERN_POSTFIX, Pattern.CASE_INSENSITIVE);
private final static Pattern P_MINUS = Pattern.compile(PATTERN_PREFIX
+ "[-]Target" + PATTERN_POSTFIX, Pattern.CASE_INSENSITIVE);
private class Hans extends AbstractLineByLineReader {
private final List<String> lines = new ArrayList<String>();
@Override
public void handleLine(String line) {
final Matcher m_plus = P_PLUS.matcher(line);
final Matcher m_minus = P_MINUS.matcher(line);
if(m_plus.matches()){
lines.add(line.replace("+Target", "+\tTarget\t"));
} else if(m_minus.matches()) {
lines.add(line.replace("-Target", "-\tTarget\t"));
}else {
lines.add(line);
}
}
public void write(File out) throws IOException{
final StringBuilder b = new StringBuilder(lines.size());
for(String s : lines){
b.append(s);
b.append(FileUtils.NEW_LINE);
}
new LazyStringWriter(b.toString()).write(out);
}
}
public void process(File in, File out) throws IOException{
final Hans hans = new Hans();
hans.read(in);
hans.write(out);
}
public static void main(String[] args){
File inFile = new File("/home/pcb/kerner/anna6/repeatMasker/repMask.out.gff.bak");
File outFile = new File("/home/pcb/kerner/anna6/repeatMasker/repMask.out.gff3");
try {
new ResultsPreprocessor().process(inFile, outFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.common;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff3.GFF3Utils;
import de.bioutils.gff3.Type;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.element.GFF3ElementBuilder;
import de.bioutils.gff3.element.GFF3ElementGroup;
import de.bioutils.gff3.element.GFF3ElementGroupImpl;
import de.bioutils.gff3.file.GFF3File;
import de.kerner.commons.file.FileUtils;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3WrapperStep;
import de.mpg.mpiz.koeln.anna.core.AnnaConstants;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
/**
*
* @author Alexander Kerner
*
*/
public abstract class AbstractStepRepeatMasker extends AbstractGFF3WrapperStep {
protected volatile File outFile;
protected volatile File inFile;
protected volatile File outStr;
// Override //
@Override
public void init(BundleContext context) throws StepExecutionException {
super.init(context);
exeDir = new File(getStepProperties().getProperty(
RepeatMaskerConstants.EXE_DIR_KEY));
workingDir = new File(getStepProperties().getProperty(
RepeatMaskerConstants.WORKING_DIR_KEY));
logger.debug("exeDir=" + exeDir.getAbsolutePath());
logger.debug("workingDir=" + workingDir.getAbsolutePath());
inFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME);
outFile = new File(workingDir, RepeatMaskerConstants.TMP_FILENAME
+ RepeatMaskerConstants.OUTFILE_POSTFIX);
outStr = new File(workingDir, getStepProperties().getProperty(
RepeatMaskerConstants.OUTSTREAM_FILE_KEY));
}
@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()
.isEmpty());
if (!sequence || !sequenceSize) {
r.add("input sequences");
}
return r;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
// Implement //
public void prepare(DataProxy<GFF3DataBean> data) throws Throwable {
new NewFASTAFileImpl(data.viewData().getInputSequence()).write(inFile);
// if (!FileUtils.fileCheck(inFile, true))
// throw new StepExecutionException(this, "cannot access file \""
// + inFile + "\"");
// if (!FileUtils.fileCheck(outFile, true))
// throw new StepExecutionException(this, "cannot access file \""
// + outFile + "\"");
// if (!FileUtils.fileCheck(outStr, true))
// throw new StepExecutionException(this, "cannot access file \""
// + outStr + "\"");
}
public void update(DataProxy<GFF3DataBean> data) throws Throwable {
logger.debug("updating data");
final ResultsPreprocessor p = new ResultsPreprocessor();
logger.debug("postprocessing results");
p.process(outFile, outFile);
// TODO really sorted?
GFF3File tmp = GFF3Utils.convertFromGFFFile(outFile, true);
final GFF3ElementGroup result = new GFF3ElementGroupImpl(true);
logger.debug("changing type from \""
+ tmp.getElements().iterator().next().getType() + "\" to \""
+ Type.repeat_region + "\"");
for (GFF3Element e : tmp.getElements()) {
result.add(new GFF3ElementBuilder(e).setType(Type.repeat_region).setSource(AnnaConstants.IDENT)
.build());
}
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
// TODO do we really know elements are sorted??
v.setRepeatMaskerGFF(result);
}
});
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws Throwable {
// must this two actions be atomar?
final boolean repeatGtf = (data.viewData().getRepeatMaskerGFF() != null);
final boolean repeatGtfSize = (!data.viewData().getRepeatMaskerGFF()
.isEmpty());
return (repeatGtf && repeatGtfSize);
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws Throwable {
// must this two actions be atomar?
final boolean sequence = (data.viewData().getInputSequence() != null);
final boolean sequenceSize = (!data.viewData().getInputSequence()
.isEmpty());
return (sequence && sequenceSize);
}
@Override
public boolean run(DataProxy<GFF3DataBean> data) throws Throwable {
logger.debug("running" + FileUtils.NEW_LINE + "\tinFile=" + inFile
+ FileUtils.NEW_LINE + "\toutFile=" + outFile);
boolean success = true;
addResultFileToWaitFor(outFile);
addShortCutFile(outFile);
redirectOutStreamToFile(outStr);
success = start();
return success;
}
public boolean isCyclic() {
return false;
}
}
| 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 |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import de.mpg.mpiz.koeln.anna.server.data.DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
*
*/
interface SerialisationStrategy {
<V extends DataBean> V readDataBean(File file, Class<V> v) throws DataBeanAccessException;
<V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException;
<V extends DataBean> V getNewDataBean();
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy.impl;
import java.io.File;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.server.data.DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.impl.GFF3DataBeanImpl;
/**
*
* @author Alexander Kerner
* @lastVisit 2009-09-21
* @threadSave no need to synchronize (data is volatile), methods from "super"
* already are threadsave.
*
*/
class CachedDiskSerialisation extends GFF3DiskSerialisation {
CachedDiskSerialisation() {
super();
}
CachedDiskSerialisation(LogDispatcher logger) {
super(logger);
}
private volatile boolean dirty = true;
@SuppressWarnings("unchecked")
@Override
public <V extends DataBean> V readDataBean(File file, Class<V> v)
throws DataBeanAccessException {
if (FileUtils.fileCheck(file, true))
;
if (dirty) {
logger.debug(this, "data dirty, reading from disk");
data = super.readDataBean(file, v);
dirty = false;
} else {
logger.debug(this, "reading data from cache");
}
return (V) data;
}
public <V extends DataBean> void writeDataBean(V v, File file)
throws DataBeanAccessException {
try {
super.writeDataBean(v, file);
} finally {
this.dirty = true;
}
}
protected <V extends DataBean> V handleCorruptData(File file, Throwable t) {
dirty = true;
data = new GFF3DataBeanImpl();
return super.handleCorruptData(file, t);
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.server.dataproxy;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
public interface GFF3DataProxy extends DataProxy<GFF3DataBean>{
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.dataadapter.Adapter;
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.DNABasicAlphabet;
import de.bioutils.fasta.FastaUtils;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff3.GFF3FASTAUnion;
import de.bioutils.gff3.GFF3FASTAUnionImpl;
import de.bioutils.gff3.GFF3Statistics;
import de.bioutils.gff3.GFF3Utils;
import de.bioutils.gff3.IntegrityCheckException;
import de.bioutils.gff3.Type;
import de.bioutils.gff3.file.GFF3File;
import de.bioutils.gff3.file.GFF3FileImpl;
import de.bioutils.range.Range;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
public class Adapter extends AbstractGFF3AnnaStep {
private final static String OFFSET_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ "adapter.offset";
private final static String MAX_LENGH_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ "adapter.maxElementLength";
private final static String MAX_NUM_ELEMENTS_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ "adapter.maxElementNumber";
private final static String DO_INTEGRITY_CHECK_KEY = ConradConstants.PROPERTIES_KEY_PREFIX
+ "adapter.integrityCheck";
private final static Log logger = new Log(Adapter.class);
// Constructor //
public Adapter() {
logger.debug(this + " created");
}
// Private //
private void doIntegrityCheck(GFF3FASTAUnion union)
throws IntegrityCheckException {
boolean integrityCheck = true;
if (getStepProperties().getProperty(DO_INTEGRITY_CHECK_KEY) == null) {
// nothing
} else {
integrityCheck = Boolean.parseBoolean(getStepProperties()
.getProperty(DO_INTEGRITY_CHECK_KEY));
}
if (integrityCheck) {
logger.debug("running union integrity test");
union.checkIntegrity();
}
}
private GFF3FASTAUnion trimmFastaElements(GFF3FASTAUnion union)
throws NumberFormatException, IntegrityCheckException {
logger.debug("trimming fasta element length (Offset:"
+ getStepProperties().getProperty(OFFSET_KEY) + ")");
GFF3FASTAUnion unionTrimmed = null;
if (union.containsElementOfType(Type.gene)) {
logger.debug("trimming by type \"" + Type.gene + "\"");
unionTrimmed = union.trimmFastasByType(Integer
.parseInt(getStepProperties().getProperty(OFFSET_KEY)),
Type.gene);
} else {
logger.debug("trimming by attribute");
unionTrimmed = union.trimmFastasByAttribute(Integer
.parseInt(getStepProperties().getProperty(OFFSET_KEY)));
}
return unionTrimmed;
}
// private GFF3FASTAUnion removeNonAlphabetMatching(GFF3FASTAUnion union)
// throws IntegrityCheckException {
// logger.debug("removing fastas that do not match alphabet \""
// + new DNABasicAlphabet() + "\"");
// final GFF3FASTAUnion union2 = union
// .removeNonAlphabetMatching(new DNABasicAlphabet());
// return union2;
// }
private GFF3FASTAUnion removeAllWithRangeGreater(GFF3FASTAUnion union)
throws IntegrityCheckException {
if (getStepProperties().getProperty(MAX_LENGH_KEY) == null) {
return union;
}
logger.debug("discarding all elements with range > "
+ Integer.parseInt(getStepProperties().getProperty(
MAX_LENGH_KEY)));
final GFF3FASTAUnion unionReducedLength = union
.trimmMaxElementLength(Integer.parseInt(getStepProperties()
.getProperty(MAX_LENGH_KEY)));
logger.debug("discarded "
+ (union.getSize() - unionReducedLength.getSize())
+ " elements");
return unionReducedLength;
}
private GFF3FASTAUnion reduceSize(GFF3FASTAUnion union)
throws IntegrityCheckException {
final GFF3FASTAUnion unionReducedSize;
if (getStepProperties().getProperty(MAX_NUM_ELEMENTS_KEY) != null) {
logger.debug("reducing size to "
+ Integer.parseInt(getStepProperties().getProperty(
MAX_NUM_ELEMENTS_KEY)));
unionReducedSize = union.reduceSize(Integer
.parseInt(getStepProperties().getProperty(
MAX_NUM_ELEMENTS_KEY)));
} else {
logger.debug("property \"" + MAX_NUM_ELEMENTS_KEY + "\" not set");
unionReducedSize = union;
}
logger.debug("discarded "
+ (union.getSize() - unionReducedSize.getSize()) + " elements");
logger.debug("length of longest FASTA: "
+ unionReducedSize.getFASTAElements().getLargestElement()
.getSequence().getLength());
logger.debug("length of longest GFF3: "
+ unionReducedSize.getGFF3ElementGroup().getLargestElement()
.getRange().getLength());
return unionReducedSize;
}
// Override //
@Override
public String toString() {
return this.getClass().getSimpleName();
}
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
logger.debug(this + " init");
}
@Override
public List<String> requirementsNeeded(DataProxy<GFF3DataBean> data)
throws Throwable {
final ArrayList<String> result = new ArrayList<String>();
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
final boolean fastasSize = (!data.viewData().getVerifiedGenesFasta()
.isEmpty());
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
final boolean gtfSize = (!data.viewData().getVerifiedGenesGFF()
.isEmpty());
if (!fastas || !fastasSize) {
result.add("verified FASTA");
} else {
logger.debug(this + " requirements fastas satisfied");
}
if (!gtf || !gtfSize) {
result.add("verified GFF");
} else {
logger.debug(this + " requirements gff satisfied");
}
return result;
};
// Implement //
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy) throws Throwable {
logger.debug(this + "checking need to run");
if (proxy.viewData().getCustom(ConradConstants.ADAPTED_KEY) == null) {
return false;
}
final Boolean adapted = (Boolean) proxy.viewData().getCustom(
ConradConstants.ADAPTED_KEY);
return adapted;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data)
throws Throwable {
final boolean fastas = (data.viewData().getVerifiedGenesFasta() != null);
final boolean fastasSize = (!data.viewData().getVerifiedGenesFasta()
.isEmpty());
final boolean gtf = (data.viewData().getVerifiedGenesGFF() != null);
final boolean gtfSize = (!data.viewData().getVerifiedGenesGFF()
.isEmpty());
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);
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws Throwable {
boolean result = false;
NewFASTAFile fastaFile = new NewFASTAFileImpl(proxy.viewData()
.getVerifiedGenesFasta());
//fastaFile = trimmFasta(fastaFile);
final GFF3File gff3File = new GFF3FileImpl(proxy.viewData()
.getVerifiedGenesGFF());
logger.debug("creating Union");
GFF3FASTAUnion union = new GFF3FASTAUnionImpl(gff3File, fastaFile);
logger.debug("cleaning up");
union = union.throwAwayAllOrphans();
//doIntegrityCheck(union);
final Range r = union.getGFF3ElementGroup().getRange();
if(getStepProperties().getProperty(MAX_LENGH_KEY) == null || new Integer(getStepProperties().getProperty(MAX_LENGH_KEY)) > r.getLength()){
logger.debug("no range defined or no elements out of range, wont trimm");
} else {
union = trimmFastaElements(union);
}
// union = removeNonAlphabetMatching(union);
union = removeAllWithRangeGreater(union);
final GFF3FASTAUnion finalUnion = reduceSize(union);
//logger.debug("done with adaptations");
final GFF3Statistics stats = new GFF3Statistics(finalUnion.getMaster());
final int numGenes = stats.getNumberOfGenes();
final double avNumExonsPerGene = stats
.getNumberOfExonsPerGene();
logger.info("adaptaions done, using " + numGenes + " genes, with "
+ String.format("%2.2f", avNumExonsPerGene)
+ " average exons per gene");
doIntegrityCheck(finalUnion);
proxy.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
logger.debug("modifying data");
v.setVerifiedGenesFasta(finalUnion.getFASTAElements());
v.setVerifiedGenesGFF(finalUnion.getGFF3ElementGroup());
v.addCustom(ConradConstants.ADAPTED_KEY, Boolean.TRUE);
}
});
logger.debug("data adaptation sucessfull");
result = true;
return result;
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.core.starter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class Activator implements BundleActivator {
private class BundleStarter implements Callable<Void> {
private final Collection<Bundle> installedBundles;
BundleStarter(Collection<Bundle> installedBundles) {
this.installedBundles = installedBundles;
}
public Void call() throws Exception {
startBundles(installedBundles);
return null;
}
private void startBundles(Collection<Bundle> installedBundles)
throws BundleException {
if (installedBundles.size() == 0) {
System.err.println("no plugins started");
return;
}
for (Bundle b : installedBundles) {
synchronized (Activator.class) {
b.start();
}
}
}
}
private class BundleInstaller implements Callable<Collection<Bundle>> {
private final File path;
private final BundleContext context;
BundleInstaller(final BundleContext context, final File path) {
this.path = path;
this.context = context;
}
public Collection<Bundle> call() throws Exception {
final Collection<String> bundlePathes = getBundlePathes(path);
final Collection<Bundle> installedBundles = installBundles(bundlePathes);
return installedBundles;
}
private Collection<Bundle> installBundles(
Collection<String> bundlePathes) throws BundleException {
if (bundlePathes.size() == 0) {
System.err.println("no plugins installed");
return Collections.emptyList();
}
synchronized (Activator.class) {
final List<Bundle> result = new ArrayList<Bundle>();
for (String p : bundlePathes) {
System.err.println("installing " + p);
synchronized (context) {
final Bundle b = context.installBundle(p);
result.add(b);
}
}
return result;
}
}
private Collection<String> getBundlePathes(File path)
throws NoPluginsFoundException {
final List<String> result = new ArrayList<String>();
final File[] content = path.listFiles();
if (content == null || content.length == 0) {
System.err.println("content of dir =" + content);
// throw new
// NoPluginsFoundException("Could not find any plugins in " +
// path);
return Collections.emptyList();
} else {
for (File f : content) {
if (f.isFile()) {
if (f.canRead()) {
final String s = f.toURI().toString();
if (s.endsWith(".jar")) {
System.err.println("Adding " + f
+ " to known plugins list.");
result.add(s);
}
} else {
System.err.println("Cannot read " + f
+ ". Skipping.");
}
} else {
// ignore dirs
}
}
}
return result;
}
}
private final static String PLUGINS_PATH_1 = System.getProperty("user.dir")
+ "/01-libs/";
private final static String PLUGINS_PATH_2 = System.getProperty("user.dir")
+ "/02-anna-libs/";
private final static String PLUGINS_PATH_3 = System.getProperty("user.dir")
+ "/03-anna-core/";
private final static String PLUGINS_PATH_4 = System.getProperty("user.dir")
+ "/04-anna-dataserver/";
private final static String PLUGINS_PATH_5 = System.getProperty("user.dir")
+ "/05-anna-server/";
private final static String PLUGINS_PATH_6 = System.getProperty("user.dir")
+ "/06-anna-steps/";
private final ExecutorService exe = Executors.newSingleThreadExecutor();
public void start(final BundleContext context) throws Exception {
exe.submit(new Runnable() {
public void run() {
try {
// new BundleStarter(new BundleInstaller(context, new
// File(PLUGINS_PATH_0)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_1)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_2)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_3)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_4)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_5)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_6)).call()).call();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void stop(BundleContext context) throws Exception {
System.err.println(this + " stopping");
}
}
| Java |
package de.mpg.mpiz.koeln.anna.core.starter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class Activator implements BundleActivator {
private class BundleStarter implements Callable<Void> {
private final Collection<Bundle> installedBundles;
BundleStarter(Collection<Bundle> installedBundles) {
this.installedBundles = installedBundles;
}
public Void call() throws Exception {
startBundles(installedBundles);
return null;
}
private void startBundles(Collection<Bundle> installedBundles)
throws BundleException {
if (installedBundles.size() == 0) {
// System.err.println("no plugins started");
return;
}
for (Bundle b : installedBundles) {
synchronized (Activator.class) {
b.start();
}
}
}
}
private class BundleInstaller implements Callable<Collection<Bundle>> {
private final File path;
private final BundleContext context;
BundleInstaller(final BundleContext context, final File path) {
this.path = path;
this.context = context;
}
public Collection<Bundle> call() throws Exception {
final Collection<String> bundlePathes = getBundlePathes(path);
final Collection<Bundle> installedBundles = installBundles(bundlePathes);
return installedBundles;
}
private Collection<Bundle> installBundles(
Collection<String> bundlePathes) throws BundleException {
if (bundlePathes.size() == 0) {
// System.err.println("no plugins installed");
return Collections.emptyList();
}
synchronized (Activator.class) {
final List<Bundle> result = new ArrayList<Bundle>();
for (String p : bundlePathes) {
// System.err.println("installing " + p);
synchronized (context) {
try{
final Bundle b = context.installBundle(p);
result.add(b);
}catch(Exception e){
System.err.println(e.getLocalizedMessage());
System.err.println("... for bundle \"" + p + "\"");
}
}
}
return result;
}
}
private Collection<String> getBundlePathes(File path) {
final List<String> result = new ArrayList<String>();
final File[] content = path.listFiles();
if (content == null || content.length == 0) {
// throw new
// NoPluginsFoundException("Could not find any plugins in " +
// path);
return Collections.emptyList();
} else {
for (File f : content) {
if (f.isFile()) {
if (f.canRead()) {
final String s = f.toURI().toString();
if (s.endsWith(".jar")) {
// System.err.println("Adding " + f
// + " to known plugins list.");
result.add(s);
}
} else {
System.err.println("Cannot read " + f
+ ". Skipping.");
}
} else {
// ignore dirs
}
}
}
return result;
}
}
private final static String PLUGINS_PATH_1 = System.getProperty("user.dir")
+ "/01-libs00/";
private final static String PLUGINS_PATH_2 = System.getProperty("user.dir")
+ "/01-libs01/";
private final static String PLUGINS_PATH_3 = System.getProperty("user.dir")
+ "/02-anna-libs/";
private final static String PLUGINS_PATH_4 = System.getProperty("user.dir")
+ "/03-anna-core/";
private final static String PLUGINS_PATH_5 = System.getProperty("user.dir")
+ "/04-anna-dataserver/";
private final static String PLUGINS_PATH_6 = System.getProperty("user.dir")
+ "/05-anna-server/";
private final static String PLUGINS_PATH_7 = System.getProperty("user.dir")
+ "/06-anna-listeners/";
private final static String PLUGINS_PATH_8 = System.getProperty("user.dir")
+ "/07-anna-steps/";
private final ExecutorService exe = Executors.newSingleThreadExecutor();
public void start(final BundleContext context) throws Exception {
System.err.println("let's get things rolling");
exe.submit(new Runnable() {
public void run() {
try {
// new BundleStarter(new BundleInstaller(context, new
// File(PLUGINS_PATH_0)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_1)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_2)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_3)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_4)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_5)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_6)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_7)).call()).call();
new BundleStarter(new BundleInstaller(context, new File(
PLUGINS_PATH_8)).call()).call();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
exe.shutdown();
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public void stop(BundleContext context) throws Exception {
System.err.println(this + " stopping (nothing to do)");
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.repeatmasker.adapter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.kerner.commons.file.AbstractLineByLineReader;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.file.LazyStringWriter;
/**
* <p>
* Try to change line from
* <blockquote>
* contig00001 RepeatMasker similarity 3920 4097 33.7 +Target "Motif:(CGG)n" 3 180
* </blockquote>
* to
* <blockquote>
* contig00001 RepeatMasker similarity 3920 4097 33.7 + Target "Motif:(CGG)n" 3 180
* </blockquote>
* </p>
* @author Alexander Kerner
*
*/
public class ResultsPreprocessor {
private final static String PATTERN_PREFIX = ".+";
private final static String PATTERN_POSTFIX = ".+";
private final static Pattern P_PLUS = Pattern.compile(PATTERN_PREFIX
+ "[\\+]Target" + PATTERN_POSTFIX, Pattern.CASE_INSENSITIVE);
private final static Pattern P_MINUS = Pattern.compile(PATTERN_PREFIX
+ "[-]Target" + PATTERN_POSTFIX, Pattern.CASE_INSENSITIVE);
private class Hans extends AbstractLineByLineReader {
private final List<String> lines = new ArrayList<String>();
@Override
public void handleLine(String line) {
final Matcher m_plus = P_PLUS.matcher(line);
final Matcher m_minus = P_MINUS.matcher(line);
if(m_plus.matches()){
lines.add(line.replace("+Target", "+\tTarget\t"));
} else if(m_minus.matches()) {
lines.add(line.replace("-Target", "-\tTarget\t"));
}else {
lines.add(line);
}
}
public void write(File out) throws IOException{
final StringBuilder b = new StringBuilder(lines.size());
for(String s : lines){
b.append(s);
b.append(FileUtils.NEW_LINE);
}
new LazyStringWriter(b.toString()).write(out);
}
}
public void process(File in, File out) throws IOException{
final Hans hans = new Hans();
hans.read(in);
hans.write(out);
}
public static void main(String[] args){
File inFile = new File("/home/pcb/kerner/anna6/repeatMasker/repMask.out.gff.bak");
File outFile = new File("/home/pcb/kerner/anna6/repeatMasker/repMask.out.gff3");
try {
new ResultsPreprocessor().process(inFile, outFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.listener.statistics.runtime;
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.kerner.commons.logging.Log;
import de.mpg.mpiz.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 RuntimeStatistics extends AbstractEventListener {
private final static Log logger = new Log(RuntimeStatistics.class);
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());
}
}
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(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.statistics.runtime;
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.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.step.ObservableStep.State;
class StateRuntimes {
private final static Log logger = new Log(StateRuntimes.class);
private volatile State lastState;
private final Map<State, StopWatch> stateToStopWatch = new ConcurrentHashMap<State, StopWatch>();
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("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.SECONDS);
final String s3 = Boolean.toString(e.getValue().isRunning());
sb.append(String.format(
"\tstate\t%-22s\ttime[sec]\t%,10d\trunning\t%6s", s1,
s2, s3).toString());
sb.append(FileUtils.NEW_LINE);
}
return sb.toString();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.core;
public class AnnaConstants {
public static String IDENT = "Anna";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.lsf;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.common.lsf.LSF;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradTrainStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class TrainLSF extends AbstractConradTrainStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir,
LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF
.getBsubValueCommandStrings(workingDir));
builder.addFlagCommand(ConradConstants.CONRAD_EXE);
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(trainingFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
final Process p = new Process(exeDir, workingDir, logger);
// p.addResultFile(true, trainingFile);
return p;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.lsf;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.mpg.mpiz.koeln.anna.step.common.lsf.LSF;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
import de.mpg.mpiz.koeln.anna.step.conrad.train.common.AbstractTrain;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class TrainLSF extends AbstractTrain {
// Implement //
@Override
public List<String> getCmdList() {
final CommandStringBuilder builder = new CommandStringBuilder(
LSF.BSUB_EXE);
builder.addAllFlagCommands(LSF.getBsubFlagCommandStrings());
builder.addAllValueCommands(LSF.getBsubValueCommandStrings(workingDir));
builder.addAllFlagCommands(ConradConstants.getConradCmdString());
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(TRAINING_FILE.getAbsolutePath());
return builder.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.common;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
/**
*
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class ConradConstants {
private ConradConstants(){}
public final static List<String> getConradCmdString(){
return new CommandStringBuilder("java").addFlagCommand("-Xmx10000m").addValueCommand("-jar", "conradCustom.jar").getCommandList();
}
public final static String TRAINING_FILE_KEY = "trainingFile";
public final static String ADAPTED_KEY = "adapted";
public final static String WORKING_DIR = "data/conrad";
public final static String PROPERTIES_KEY_PREFIX = "anna.step.conrad.";
public static final String TRAINING_FILE_REFIX = "conrad.trainingfile";
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradTrainStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 0992-07-28
* @author Alexander Kerner
*
*/
public class TrainLocal extends AbstractConradTrainStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir, LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(
new File(executableDir, ConradConstants.CONRAD_EXE)
.getAbsolutePath());
builder.addFlagCommand("train");
builder.addFlagCommand("models/singleSpecies.xml");
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(trainingFile.getAbsolutePath());
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
final Process p = new Process(exeDir.getAbsoluteFile(), workingDir.getAbsoluteFile(), logger);
// p.addResultFile(true, trainingFile);
return p;
}
} | Java |
package de.mpg.mpiz.koeln.anna.step.conrad.train.local;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
import de.mpg.mpiz.koeln.anna.step.conrad.train.common.AbstractTrain;
public class TrainLocal extends AbstractTrain {
// Implement //
@Override
public List<String> getCmdList() {
return new CommandStringBuilder(ConradConstants.getConradCmdString()).addFlagCommand(
"train").addFlagCommand("models/singleSpecies.xml")
.addFlagCommand(workingDir.getAbsolutePath()).addFlagCommand(
TRAINING_FILE.getAbsolutePath()).getCommandList();
}
} | Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.kerner.osgi.commons.logger.dispatcher.ConsoleLogger;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
public abstract class AbstractAnnaStep<V> implements BundleActivator, AnnaStep {
private final static File PROPERTIES_FILE = new File(FileUtils.WORKING_DIR,
"configuration" + File.separatorChar + "step.properties");
private volatile ServiceTracker tracker;
private volatile Properties properties;
protected volatile LogDispatcher logger = new ConsoleLogger();
private State state = State.LOOSE;
protected void init(BundleContext context) throws StepExecutionException {
this.logger = new LogDispatcherImpl(context);
tracker = new ServiceTracker(context, AnnaServer.class.getName(), null);
tracker.open();
try {
properties = getPropertes();
} catch (Exception e) {
logger.error(this, StringUtils.getString(
"could not load settings from ", PROPERTIES_FILE
.getAbsolutePath(), ", using defaults"));
}
}
public void start(BundleContext context) throws Exception {
logger.debug(this, "starting step " + this);
init(context);
try{
getAnnaServer().registerStep(this);
}catch(Exception e){
final AbstractAnnaStep<?> as = new DummyStep(this.toString());
as.setState(AbstractAnnaStep.State.ERROR);
getAnnaServer().registerStep(as);
}
}
public void stop(BundleContext context) throws Exception {
logger.debug(this, "stopping service");
tracker.close();
tracker = null;
}
public AnnaServer getAnnaServer() throws ServiceNotAvailabeException{
AnnaServer server = (AnnaServer) tracker.getService();
if(server == null)
throw new ServiceNotAvailabeException();
return server;
}
public abstract DataProxy<V> getDataProxy() throws ServiceNotAvailabeException;
public abstract boolean requirementsSatisfied(DataProxy<V> proxy)
throws StepExecutionException;
public abstract boolean canBeSkipped(DataProxy<V> proxy)
throws StepExecutionException;
public abstract boolean run(DataProxy<V> proxy)
throws StepExecutionException;
public boolean requirementsSatisfied() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(e);
}
return requirementsSatisfied(proxy);
}
public boolean canBeSkipped() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(e);
}
return canBeSkipped(proxy);
}
public boolean run() throws StepExecutionException {
DataProxy<V> proxy;
try {
proxy = getDataProxy();
} catch (ServiceNotAvailabeException e) {
logger.error(this, e.getLocalizedMessage(), e);
throw new StepExecutionException(e);
}
return run(proxy);
}
public synchronized Properties getStepProperties() {
return properties;
}
private Properties getPropertes() throws IOException {
final Properties defaultProperties = initDefaults();
final Properties pro = new Properties(defaultProperties);
FileInputStream fi = null;
try {
logger.info(this, StringUtils.getString("loading settings from ",
PROPERTIES_FILE));
fi = new FileInputStream(PROPERTIES_FILE);
pro.load(fi);
} finally {
if (fi != null)
fi.close();
}
return pro;
}
private Properties initDefaults() {
final Properties pro = new Properties();
return pro;
}
public final synchronized State getState() {
return state;
}
public final synchronized void setState(State state) {
this.state = state;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.osgi.commons.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.server.dataproxy.GFF3DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
public abstract class AbstractGFF3AnnaStep extends
AbstractAnnaStep<GFF3DataBean> {
private volatile ServiceTracker tracker;
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
tracker = new ServiceTracker(context, GFF3DataProxy.class.getName(),
null);
tracker.open();
}
@Override
public DataProxy<GFF3DataBean> getDataProxy()
throws ServiceNotAvailabeException {
GFF3DataProxy proxy = (GFF3DataProxy) tracker.getService();
if (proxy == null)
throw new ServiceNotAvailabeException();
return proxy;
}
@Override
protected void finalize() throws Throwable {
this.tracker.close();
tracker = null;
super.finalize();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
class DummyStep extends AbstractGFF3AnnaStep {
private final String name;
DummyStep(String name){
this.name = name;
}
public String toString() {
return "(dummy)"+name;
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws StepExecutionException {
// TODO Auto-generated method stub
return false;
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.commons.StringUtils;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.logging.Log;
import de.kerner.commons.osgi.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.server.AnnaServer;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.AnnaStep;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
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 Log logger = new Log(AbstractAnnaStep.class);
private volatile State state = State.LOOSE;
// fields volatile
protected synchronized void init(BundleContext context)
throws StepExecutionException {
tracker = new ServiceTracker(context, AnnaServer.class.getName(), null);
tracker.open();
try {
properties = getPropertes();
} catch (Exception e) {
logger.error(StringUtils.getString("could not load settings from ",
PROPERTIES_FILE.getAbsolutePath(), ", using defaults"));
}
}
public void start(BundleContext context) throws Exception {
//logger.debug("starting step " + this);
try {
init(context);
getAnnaServer().registerStep(this);
} catch (Throwable e) {
synchronized (this) {
logger.debug("an exception orroured while initiation or registration of step, creating dummy step", e);
final AbstractAnnaStep<?> as = new DummyStep(this.toString());
as.setState(State.ERROR);
getAnnaServer().registerStep(as);
}
}
}
public void stop(BundleContext context) throws Exception {
logger.debug("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 Throwable;
public abstract boolean canBeSkipped(DataProxy<V> proxy) throws Throwable;
public abstract boolean run(DataProxy<V> proxy) throws Throwable;
public boolean requirementsSatisfied() throws StepExecutionException {
try {
final DataProxy<V> proxy = getDataProxy();
return requirementsSatisfied(proxy);
} catch (Throwable t) {
throw new StepExecutionException(this, t);
}
}
public boolean canBeSkipped() throws StepExecutionException {
try {
final DataProxy<V> proxy = getDataProxy();
return canBeSkipped(proxy);
} catch (Throwable t) {
throw new StepExecutionException(this, t);
}
}
public boolean run() throws StepExecutionException {
try {
final DataProxy<V> proxy = getDataProxy();
return run(proxy);
} catch (Throwable t) {
throw new StepExecutionException(this, t);
}
}
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.debug(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 State getState() {
return state;
}
public final void setState(State state) {
this.state = state;
}
public List<String> requirementsNeeded(DataProxy<V> proxy) throws Throwable {
return Collections.emptyList();
}
public List<String> requirementsNeeded() {
try {
final DataProxy<V> proxy = getDataProxy();
return requirementsNeeded(proxy);
} catch (Throwable t) {
logger.error(t.getLocalizedMessage(), t);
return new ArrayList<String>();
}
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.commons.osgi.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataProxy;
import de.mpg.mpiz.koeln.anna.step.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.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
class DummyStep extends AbstractGFF3AnnaStep {
private final String name;
DummyStep(String name){
this.name = name;
}
public String toString() {
return "(dummy)"+name;
}
@Override
public boolean canBeSkipped(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> proxy)
throws StepExecutionException {
return true;
}
@Override
public boolean run(DataProxy<GFF3DataBean> proxy) throws StepExecutionException {
// TODO Auto-generated method stub
return false;
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.logging.Log;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
/**
* <p>
* Helper class to create a WrapperStep for an external programm.
* </p>
*
* @author Alexander Kerner
* @threadSave custom
* @lastVisit 2009-10-02
* @param <T>
* type of {@link de.mpg.mpiz.koeln.anna.server.data.DataBean}
*
*/
public abstract class AbstractWrapperStep<T> extends AbstractAnnaStep<T> {
private class ThreaddedProcess implements Callable<Boolean> {
private final AbstractStepProcessBuilder ps;
private final OutputStream out, err;
ThreaddedProcess(File executableDir, File workingDir, OutputStream out,
OutputStream err, Log logger) {
this.out = out;
this.err = err;
ps = new AbstractStepProcessBuilder(executableDir, workingDir) {
@Override
protected List<String> getCommandList() {
return getCmdList();
}
};
}
public Boolean call() throws Exception {
return ps.createAndStartProcess(out, err);
}
}
private final ExecutorService exe = Executors.newSingleThreadExecutor();
private final static long TIMEOUT = 1000;
protected volatile File exeDir;
protected volatile File workingDir;
private volatile File outFile = null;
private volatile File errFile = null;
private List<File> shortCutFiles = new ArrayList<File>();
private List<File> resultFilesToWaitFor = new ArrayList<File>();
public AbstractWrapperStep(File exeDir, File workingDir) {
this.exeDir = exeDir;
this.workingDir = workingDir;
}
public AbstractWrapperStep() {
}
/**
* <p>
* Finally start this Step.
* </p>
*
* @throws StepExecutionException
*/
public boolean start() throws Throwable {
boolean success = false;
createIfAbsend();
prepare(getDataProxy());
printProperties();
validateProperties();
if (takeShortCut()) {
success = true;
} else {
success = doItFinally();
}
if (success) {
waitForFiles();
update(getDataProxy());
}
return success;
}
protected void createIfAbsend() throws StepExecutionException {
if (!FileUtils.dirCheck(workingDir, true))
throw new StepExecutionException(this,
"cannot access working dir \"" + workingDir + "\"");
if (!FileUtils.dirCheck(exeDir, true))
throw new StepExecutionException(this,
"cannot access executable dir \"" + exeDir + "\"");
}
private void waitForFiles() throws InterruptedException {
if (resultFilesToWaitFor.isEmpty()) {
logger.debug("no files to wait for");
return;
}
for (File f : resultFilesToWaitFor) {
synchronized (f) {
while (!f.exists()) {
logger.debug("waiting for file \"" + f + " \"");
Thread.sleep(TIMEOUT);
}
}
}
}
// fields volatile
private boolean doItFinally() throws Throwable {
boolean success = false;
OutputStream out = System.out;
OutputStream err = System.err;
if (outFile != null) {
out = FileUtils.getBufferedOutputStreamForFile(outFile);
}
if (errFile != null) {
err = FileUtils.getBufferedOutputStreamForFile(errFile);
}
success = exe.submit(
new ThreaddedProcess(exeDir, workingDir, out, err, logger))
.get();
exe.shutdown();
if (outFile != null) {
out.close();
}
if (errFile != null) {
err.close();
}
return success;
}
private synchronized boolean takeShortCut() {
logger.debug("checking for shortcut available");
if (shortCutFiles.isEmpty()) {
logger.debug("no shortcut files defined");
return false;
}
for (File f : shortCutFiles) {
final boolean fileCheck = FileUtils.fileCheck(f, false);
logger.debug("file " + f.getAbsolutePath() + " there=" + fileCheck);
if (!(fileCheck)) {
logger.debug("cannot skip");
return false;
}
}
logger.debug("skip available");
return true;
}
/**
* <p>
* Preparation for running wrapped process. (e.g. creating required files in
* working directory)
* </p>
*
* @throws Throwable
*/
public abstract void prepare(DataProxy<T> data) throws Throwable;
/**
* @return List of command line arguments, that will passed to wrapped step.
*/
public abstract List<String> getCmdList();
public abstract void update(DataProxy<T> data)
throws Throwable;
public synchronized void addShortCutFile(File file) {
shortCutFiles.add(file);
}
public synchronized void addResultFileToWaitFor(File file) {
resultFilesToWaitFor.add(file);
}
public void redirectOutStreamToFile(File file) {
this.outFile = file;
}
public void redirectErrStreamToFile(File file) {
this.errFile = file;
}
// fields volatile
private void printProperties() {
logger.debug("created, properties:" + FileUtils.NEW_LINE
+ "\tstepWorkingDir=" + workingDir + FileUtils.NEW_LINE
+ "\texeDir=" + exeDir);
}
// fields volatile
private void validateProperties() throws Throwable {
if (!FileUtils.dirCheck(exeDir, false))
throw new StepExecutionException(this, "cannot access exe dir");
if (!FileUtils.dirCheck(workingDir, true))
throw new StepExecutionException(this, "cannot access working dir");
}
public void setExeDir(File exeDir){
this.exeDir = exeDir;
}
public void setWorkingDir(File workingDir){
this.workingDir = workingDir;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import de.kerner.commons.file.FileUtils;
import de.kerner.commons.logging.Log;
/**
* @lastVisit 2009-08-12
* @author Alexander Kerner
* @ThreadSave state final, ConcurrentHashMap
* @Exceptions nothing to do, abstract class
* @deprecated use {@code de.kerner.commons.exec.AbstractProcessRunner} instead
*
*/
public abstract class AbstractStepProcessBuilder {
private final static Log logger = new Log(AbstractStepProcessBuilder.class);
protected final File executableDir;
protected final File workingDir;
// TODO: remove this. Let this completely be handled from "WrapperStep"
private final Map<File, Boolean> outFiles = new ConcurrentHashMap<File, Boolean>();
protected AbstractStepProcessBuilder(File executableDir, File workingDir) {
this.executableDir = executableDir;
this.workingDir = workingDir;
}
@Deprecated
public void addResultFile(boolean takeShortCutIfAlreadyThere,
String fileName) {
addResultFile(takeShortCutIfAlreadyThere, new File(fileName));
}
@Deprecated
public void addAllResultFiles(Map<File, Boolean> m) {
if(m.isEmpty())
return;
outFiles.putAll(m);
}
@Deprecated
public void addResultFile(boolean takeShortCutIfAlreadyThere, File file) {
if (file == null)
throw new NullPointerException(
"file must not be null");
outFiles
.put(file, takeShortCutIfAlreadyThere);
}
public boolean createAndStartProcess(final OutputStream out,
final OutputStream err) {
if (takeShortCut()){
logger.info("file(s) there, taking shortcut");
return true;
}
logger.debug("file(s) not there, cannot take shortcut");
final List<String> processCommandList = getCommandList();
final ProcessBuilder processBuilder = new ProcessBuilder(
processCommandList);
logger.debug("creating process " + processBuilder.command());
processBuilder.directory(executableDir);
logger.debug("executable dir of process: " + processBuilder.directory());
processBuilder.redirectErrorStream(true);
try {
Process p = processBuilder.start();
logger.debug("started process " + p);
FileUtils.inputStreamToOutputStream(p.getInputStream(), out);
FileUtils.inputStreamToOutputStream(p.getErrorStream(), err);
final int exit = p.waitFor();
// logger.debug(this, "performing LSF buffer timeout...");
// Thread.sleep(1000);
// logger.debug(this, "continuing");
logger.debug("process " + p + " exited with exit code " + exit);
if (exit != 0)
return false;
return true;
} catch (Exception e){
e.printStackTrace();
logger.error(e.getLocalizedMessage(), e);
return false;
}
}
public boolean createAndStartProcess() {
return createAndStartProcess(System.out, System.err);
}
@Deprecated
private boolean takeShortCut() {
logger.debug("checking for shortcut available");
if(outFiles.isEmpty()){
logger.debug("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("file " + e.getKey().getAbsolutePath() + " there="+fileCheck);
logger.debug("file " + e.getKey() + " skip="+skipIt);
if(!(fileCheck && skipIt)){
logger.debug("cannot skip");
return false;
}
}
logger.debug("skip available");
return true;
}
protected abstract List<String> getCommandList();
}
| Java |
package de.mpg.mpiz.koeln.anna.abstractstep;
import java.io.File;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import de.kerner.commons.osgi.utils.ServiceNotAvailabeException;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
// TODO: class implementation is duplicate to "AbstractGFF3AnnaStep". That is bad!
public abstract class AbstractGFF3WrapperStep extends AbstractWrapperStep<GFF3DataBean>{
public AbstractGFF3WrapperStep(File exeDir, File workingDir) {
super(exeDir, workingDir);
}
public AbstractGFF3WrapperStep() {
super();
}
private volatile ServiceTracker tracker;
// tracker volatile
@Override
protected void init(BundleContext context) throws StepExecutionException {
super.init(context);
tracker = new ServiceTracker(context, GFF3DataProxy.class.getName(),
null);
tracker.open();
}
// tracker volatile
@Override
public DataProxy<GFF3DataBean> getDataProxy()
throws ServiceNotAvailabeException {
GFF3DataProxy proxy = (GFF3DataProxy) tracker.getService();
if (proxy == null)
throw new ServiceNotAvailabeException();
return proxy;
}
@Override
protected void finalize() throws Throwable {
this.tracker.close();
tracker = null;
super.finalize();
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.verifiedgenes.reader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.osgi.framework.BundleContext;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff.element.NewGFFElement;
import de.bioutils.gff.file.NewGFFFile;
import de.bioutils.gff.file.NewGFFFileImpl;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcherImpl;
import de.mpg.mpiz.koeln.anna.abstractstep.AbstractGFF3AnnaStep;
import de.mpg.mpiz.koeln.anna.server.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.server.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataModifier;
import de.mpg.mpiz.koeln.anna.server.dataproxy.DataProxy;
import de.mpg.mpiz.koeln.anna.step.common.StepExecutionException;
import de.mpg.mpiz.koeln.anna.step.common.StepUtils;
public class VerifiedGenesReader extends AbstractGFF3AnnaStep {
private final static String FASTA_KEY = "anna.step.verified.fasta";
private final static String GTF_KEY = "anna.step.verified.gtf";
private File fasta;
private File gtf;
private LogDispatcher logger = null;
public VerifiedGenesReader() {
// use "init()" instead, to make sure "logger" is initiated
}
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
super.init(context);
logger = new LogDispatcherImpl(context);
initFiles();
}
private void initFiles() {
final String fastaPath = super.getStepProperties().getProperty(
FASTA_KEY);
logger.debug(this, "got path for FASTA: " + fastaPath);
final String gtfPath = super.getStepProperties().getProperty(GTF_KEY);
logger.debug(this, "got path for GTF: " + gtfPath);
fasta = new File(fastaPath);
gtf = new File(gtfPath);
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data) {
logger.info(this, "no requirements needed");
return true;
}
public boolean run(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
doFasta(data);
doGtf(data);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
return true;
}
private void doGtf(DataProxy<GFF3DataBean> data) throws IOException,
GFFFormatErrorException, DataBeanAccessException {
logger.info(this, "reading GTF file " + gtf);
final NewGFFFile gtfFile = NewGFFFileImpl.parseFile(gtf);
final Collection<? extends NewGFFElement> elements = gtfFile
.getElements();
logger.info(this, "done reading gtf");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesGFF(new ArrayList<NewGFFElement>(elements));
}
});
}
private void doFasta(DataProxy<GFF3DataBean> data) throws IOException,
DataBeanAccessException, StepExecutionException {
try{
logger.info(this, "reading FASTA file " + fasta);
final NewFASTAFile fastaFile = NewFASTAFileImpl.parse(fasta);
final Collection<? extends FASTAElement> sequences = fastaFile.getElements();
logger.info(this, "done reading fasta");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesFasta(new ArrayList<FASTAElement>(sequences));
}
});
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
}
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws StepExecutionException {
try {
// TODO size == 0 sub-optimal indicator
final Collection<? extends FASTAElement> list1 = data.viewData()
.getVerifiedGenesFasta();
final Collection<? extends NewGFFElement> list2 = data.viewData()
.getVerifiedGenesGFF();
return (list1 != null && list1.size() != 0 && list2 != null && list2
.size() != 0);
} catch (Throwable t) {
StepUtils.handleException(this, t, logger);
// cannot be reached
return false;
}
}
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.verifiedgenes.reader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.osgi.framework.BundleContext;
import de.bioutils.AbstractSequence;
import de.bioutils.DNABasicAlphabet;
import de.bioutils.fasta.FASTAElement;
import de.bioutils.fasta.FASTAElementGroup;
import de.bioutils.fasta.FASTAElementGroupImpl;
import de.bioutils.fasta.FASTAElementImpl;
import de.bioutils.fasta.FastaUtils;
import de.bioutils.fasta.NewFASTAFile;
import de.bioutils.fasta.NewFASTAFileImpl;
import de.bioutils.gff.GFFFormatErrorException;
import de.bioutils.gff3.GFF3Utils;
import de.bioutils.gff3.element.GFF3Element;
import de.bioutils.gff3.element.GFF3ElementGroup;
import de.bioutils.gff3.file.GFF3File;
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.data.DataBeanAccessException;
import de.mpg.mpiz.koeln.anna.data.GFF3DataBean;
import de.mpg.mpiz.koeln.anna.server.data.DataModifier;
import de.mpg.mpiz.koeln.anna.server.data.DataProxy;
import de.mpg.mpiz.koeln.anna.step.StepExecutionException;
public class 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;
public VerifiedGenesReader() {
// use "init()" instead
}
@Override
protected synchronized void init(BundleContext context)
throws StepExecutionException {
super.init(context);
initFiles();
}
private void initFiles() throws StepExecutionException {
final String fastaPath = super.getStepProperties().getProperty(
FASTA_KEY);
logger.debug("got path for FASTA: " + fastaPath);
final String gtfPath = super.getStepProperties().getProperty(GTF_KEY);
logger.debug("got path for GTF: " + gtfPath);
if(fastaPath == null || gtfPath == null)
throw new StepExecutionException(this, "could not determine path to file(s), please check settings");
fasta = new File(fastaPath);
gtf = new File(gtfPath);
if(!FileUtils.fileCheck(fasta, false)){
throw new StepExecutionException(this, "cannot access file \"" + fasta + "\", step settings correct?");
}
if(!FileUtils.fileCheck(gtf, false)){
throw new StepExecutionException(this, "cannot access file \"" + gtf + "\", step settings correct?");
}
}
public boolean requirementsSatisfied(DataProxy<GFF3DataBean> data) {
logger.info("no requirements needed");
return true;
}
public boolean run(DataProxy<GFF3DataBean> data) throws Throwable {
doFasta(data);
doGtf(data);
return true;
}
private void doGtf(DataProxy<GFF3DataBean> data) throws IOException,
GFFFormatErrorException, DataBeanAccessException {
logger.info("reading GFF file " + gtf);
// TODO file may not be sorted.
final GFF3File gtfFile = GFF3Utils.convertFromGFFFile(gtf, true);
final GFF3ElementGroup elements = gtfFile.getElements();
final GFF3ElementGroup elements2 = trimmGFF(elements);
if(elements.getSize() != elements2.getSize()){
logger.warn("size of elements before trimm: " + elements.getSize() + ", size of elements after trimm: " + elements2.getSize());
}
logger.info("done reading GFF");
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
logger.debug("updating verified gff3 (" + elements2.getSize() + " elements)");
v.setVerifiedGenesGFF(elements2);
}
});
}
private GFF3ElementGroup trimmGFF(GFF3ElementGroup elements) {
final String tmpIdent = elements.iterator().next().getSeqID();
logger.debug("trimming gff3 sequence identifiers");
elements = GFF3Utils.trimHeader(elements);
logger.debug("done trimming gff3 sequence identifiers");
logger.debug("old ident: \"" + tmpIdent + "\", new ident: \""
+ elements.iterator().next().getSeqID() + "\"");
return elements;
}
private void doFasta(DataProxy<GFF3DataBean> data) throws IOException,
DataBeanAccessException, StepExecutionException {
logger.info("reading FASTA file " + fasta);
final NewFASTAFile fastaFile = NewFASTAFileImpl.parse(fasta);
FASTAElementGroup sequences = fastaFile.getElements();
logger.info("done reading fasta");
sequences = trimmFasta(sequences);
logger.debug("checking for valid alphabet");
final FASTAElementGroup sequencesNew = FastaUtils.adaptToAlphabet(sequences, new DNABasicAlphabet());
data.modifiyData(new DataModifier<GFF3DataBean>() {
public void modifiyData(GFF3DataBean v) {
v.setVerifiedGenesFasta(sequencesNew);
}
});
}
private FASTAElementGroup trimmFasta(FASTAElementGroup fastas) {
final String tmpHeader = fastas.iterator().next()
.getHeader();
logger.debug("trimming fasta headers");
fastas = FastaUtils.trimHeader(fastas);
logger.debug("done trimming fasta headers");
logger.debug("old header: \"" + tmpHeader + "\", new header: \""
+ fastas.iterator().next().getHeader() + "\"");
return fastas;
}
public boolean canBeSkipped(DataProxy<GFF3DataBean> data) throws Throwable {
// TODO size == 0 sub-optimal indicator
final FASTAElementGroup list1 = data.viewData().getVerifiedGenesFasta();
final GFF3ElementGroup list2 = data.viewData().getVerifiedGenesGFF();
return (list1 != null && !list1.isEmpty() && list2 != null && !list2
.isEmpty());
}
@Override
public List<String> requirementsNeeded(DataProxy<GFF3DataBean> data) throws Throwable {
final ArrayList<String> result = new ArrayList<String>();
final FASTAElementGroup list1 = data.viewData().getVerifiedGenesFasta();
final GFF3ElementGroup list2 = data.viewData().getVerifiedGenesGFF();
if(list1 == null || list1.isEmpty())
result.add("verified genes fasta");
if(list2 == null || list2.isEmpty())
result.add("verified genes GFF");
return result;
}
public String toString() {
return this.getClass().getSimpleName();
}
public boolean isCyclic() {
return false;
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.predict.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.kerner.osgi.commons.logger.dispatcher.LogDispatcher;
import de.mpg.mpiz.koeln.anna.step.common.AbstractStepProcessBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.AbstractConradPredictStep;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
/**
* @cleaned 2009-07-28
* @author Alexander Kerner
*
*/
public class PredictLocal extends AbstractConradPredictStep {
private class Process extends AbstractStepProcessBuilder {
protected Process(File executableDir, File workingDir,
LogDispatcher logger) {
super(executableDir, workingDir, logger);
}
@Override
protected List<String> getCommandList() {
final CommandStringBuilder builder = new CommandStringBuilder(new File(
executableDir, ConradConstants.CONRAD_EXE).getAbsolutePath());
builder.addFlagCommand("predict");
builder.addFlagCommand(trainingFile.getAbsolutePath());
builder.addFlagCommand(workingDir.getAbsolutePath());
builder.addFlagCommand(resultFile.getParentFile().getAbsolutePath() + File.separator + "result");
return builder.getCommandList();
}
}
@Override
protected AbstractStepProcessBuilder getProcess() {
return new Process(exeDir, workingDir, logger);
}
}
| Java |
package de.mpg.mpiz.koeln.anna.step.conrad.predict.local;
import java.io.File;
import java.util.List;
import de.kerner.commons.CommandStringBuilder;
import de.mpg.mpiz.koeln.anna.step.conrad.common.ConradConstants;
import de.mpg.mpiz.koeln.anna.step.conrad.predict.common.AbstractPredict;
/**
* @author Alexander Kerner
*
*/
public class PredictLocal extends AbstractPredict {
@Override
public List<String> getCmdList() {
return new CommandStringBuilder(ConradConstants.getConradCmdString())
.addFlagCommand("predict").addFlagCommand(
trainingFile.getAbsolutePath()).addFlagCommand(
workingDir.getAbsolutePath()).addFlagCommand(
resultFile.getParentFile().getAbsolutePath()
+ File.separator + "result").getCommandList();
}
}
| 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.