Skip to content

Commit

Permalink
rampage
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmoho committed Aug 14, 2024
1 parent f294dbf commit 8829f61
Show file tree
Hide file tree
Showing 129 changed files with 2,164 additions and 2,570 deletions.
42 changes: 26 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ repositories {
// snapshot versions of artifacts (i.e. dependency JARs)
// Sonatype is the company behind the Maven Central repository
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
// resolve dependencies from a local directory
flatDir {
dirs "lib/de/zbit/SysBio/1390"
maven {
name "biodata-reposilite"
url "https://biodata.informatik.uni-halle.de/maven/releases"
}

}

/** ==== Dependencies ==== **/
// variables used in dependency definitions
def jacksonVersion = "2.17.1"
def jupiterVersion = "5.10.2"
def testContainersVersion = "1.19.8"
def testContainersVersion = "1.20.1"

/*
- `implementation`: Dependencies required for the main source set.
Expand All @@ -99,28 +100,35 @@ def testContainersVersion = "1.19.8"
- `testRuntimeOnly`: Dependencies required only at test runtime, not at compile time.
*/
dependencies {
// systems biology tools
implementation "de.zbit.SysBio:SysBio:1390"
// reading, writing, and manipulating SBML files
implementation "org.sbml.jsbml:jsbml:1.6.1"
// local dependency for systems biology tools
implementation "de.zbit:SysBio:1390"
// official JDBC driver for PostgreSQL
implementation "org.postgresql:postgresql:42.7.3"
implementation("org.sbml.jsbml:jsbml:1.6.1") {
exclude group: "org.apache.logging.log4j", module: "log4j-core"
exclude group: "org.apache.logging.log4j", module: "log4j-slf4j-impl"
}
// ontology support within BioJava
implementation "org.biojava:biojava-ontology:7.1.1"
// handle Combine Archives (packages of biological models)
implementation "de.uni-rostock.sbi:CombineArchive:1.4.1"
// interacting with MATLAB files
implementation 'us.hebi.matlab.mat:mfl-core:0.5.15'

// JDBC connection pool
implementation "com.zaxxer:HikariCP:5.1.0"
// https://mvnrepository.com/artifact/commons-io/commons-io
implementation group: 'commons-io', name: 'commons-io', version: '2.16.1'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.15.0'
// JSON processor
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
// data binding for Jackson
// data binding for Jackson
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
// Java port of HTML Tidy, for cleaning up malformed HTML
implementation "net.sf.jtidy:jtidy:r938"
// handle Combine Archives (packages of biological models)
implementation "de.uni-rostock.sbi:CombineArchive:1.4.1"
// JDBC connection pool
implementation "com.zaxxer:HikariCP:5.1.0"

implementation 'com.opentable.components:otj-pg-embedded:1.0.1'
// official JDBC driver for PostgreSQL
implementation "org.postgresql:postgresql:42.7.3"

// Test implementation dependencies
// API for writing tests with JUnit 5
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
Expand All @@ -133,6 +141,7 @@ dependencies {
// runtime engine for executing tests with JUnit 5
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.2'
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"

}

/** === Configuration for pre-existing Tasks === **/
Expand Down Expand Up @@ -162,6 +171,7 @@ tasks.withType(JavaCompile).configureEach {

// config for all test tasks
tasks.withType(Test).configureEach {
environment "TESTCONTAINERS_RYUK_DISABLED", "true"
useJUnitPlatform()
testLogging {
showStandardStreams = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.ucsd.sbrg.eco;
package edu.ucsd.sbrg;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -7,14 +7,19 @@
import java.text.ParseException;
import java.util.Set;

import edu.ucsd.sbrg.eco.DAG;
import edu.ucsd.sbrg.eco.Node;
import org.biojava.nbio.ontology.Ontology;
import org.biojava.nbio.ontology.Term;
import org.biojava.nbio.ontology.Triple;
import org.biojava.nbio.ontology.io.OboParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ECOparser {
public class ECOParserCLILauncher {

private static Ontology ontology;
private static final Logger logger = LoggerFactory.getLogger(ECOParserCLILauncher.class);

/**
* @see <a href="https://github.com/draeger-lab/ModelPolisher/issues/5">Issue 5</>
Expand Down Expand Up @@ -57,8 +62,8 @@ public static String getECOTermFromScore(int confidenceScore) {
}


public static void main(String[] args) {
ECOparser.parseECO();
public static void main(String[] args) throws IOException, ParseException {
ECOParserCLILauncher.parseECO();
}


Expand All @@ -82,18 +87,16 @@ public static int getConfidenceScoreForTerm(String query) {
}


public static void parseECO() {
public static void parseECO() throws IOException, ParseException {
String ecoName = "Evidence and Conclusion Ontology";
String ecoDesc = "TODO";
OboParser parser = new OboParser();
try (InputStream inputStream = ECOparser.class.getResourceAsStream("eco.obo");
BufferedReader oboReader = new BufferedReader(new InputStreamReader(inputStream))) {
try (InputStream inputStream = ECOParserCLILauncher.class.getResourceAsStream("eco.obo");
BufferedReader oboReader = new BufferedReader(new InputStreamReader(inputStream))) {
ontology = parser.parseOBO(oboReader, ecoName, ecoDesc);
Term rootTerm = ontology.getTerm("ECO:0000000");
DAG ontologyDAG = new DAG(rootTerm);
traverse(ontologyDAG.getRoot());
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}

Expand Down
127 changes: 65 additions & 62 deletions src/main/java/edu/ucsd/sbrg/ModelPolisherCLILauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.*;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import de.zbit.util.prefs.SBProperties;
import edu.ucsd.sbrg.annotation.AnnotationException;
import edu.ucsd.sbrg.annotation.adb.ADBSBMLAnnotator;
import edu.ucsd.sbrg.annotation.bigg.BiGGSBMLAnnotator;
import edu.ucsd.sbrg.io.*;
import edu.ucsd.sbrg.parameters.CommandLineParameters;
import edu.ucsd.sbrg.db.adb.AnnotateDB;
import edu.ucsd.sbrg.db.bigg.BiGGDB;
import edu.ucsd.sbrg.parameters.ModelPolisherOptions;
import edu.ucsd.sbrg.polishing.SBMLPolisher;
import edu.ucsd.sbrg.reporting.PolisherProgressBar;
import edu.ucsd.sbrg.reporting.ProgressInitialization;
import edu.ucsd.sbrg.reporting.ProgressObserver;
import edu.ucsd.sbrg.resolver.Registry;
import edu.ucsd.sbrg.resolver.identifiersorg.IdentifiersOrg;
import edu.ucsd.sbrg.validation.ModelValidator;
import edu.ucsd.sbrg.validation.ModelValidatorException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;

Expand All @@ -37,11 +40,12 @@
import de.zbit.util.ResourceManager;
import de.zbit.util.logging.LogOptions;
import de.zbit.util.prefs.KeyProvider;
import de.zbit.util.prefs.SBProperties;
import edu.ucsd.sbrg.db.adb.AnnotateDBOptions;
import edu.ucsd.sbrg.db.bigg.BiGGDBOptions;
import org.sbml.jsbml.ext.fbc.FBCConstants;
import org.sbml.jsbml.ext.fbc.FBCModelPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The ModelPolisher class is the entry point of this application.
Expand All @@ -68,7 +72,7 @@ public class ModelPolisherCLILauncher extends Launcher {

private static final ResourceBundle baseBundle = ResourceManager.getBundle("edu.ucsd.sbrg.Messages");
private static final ResourceBundle MESSAGES = ResourceManager.getBundle("edu.ucsd.sbrg.polisher.Messages");
private static final Logger logger = Logger.getLogger(ModelPolisherCLILauncher.class.getName());
private static final Logger logger = LoggerFactory.getLogger(ModelPolisherCLILauncher.class);

private CommandLineParameters parameters;
private Registry registry;
Expand Down Expand Up @@ -117,37 +121,39 @@ public void commandLineMode(AppConf appConf) {
parameters = new CommandLineParameters(args);
registry = new IdentifiersOrg();

if (parameters.annotationParameters().biggAnnotationParameters().annotateWithBiGG()) {
this.bigg = new BiGGDB(parameters.annotationParameters().biggAnnotationParameters().dbParameters());
}

if (parameters.annotationParameters().adbAnnotationParameters().addADBAnnotations()) {
this.adb = new AnnotateDB(parameters.annotationParameters().adbAnnotationParameters().dbParameters());
}

try {
var input = parameters.input();
var output = parameters.output();
validateIOParameters();

// Check if the input exists, throw an exception if it does not
if (!input.exists()) {
throw new IOException(format(MESSAGES.getString("READ_FILE_ERROR"),
input.toString()));
if (parameters.annotationParameters().biggAnnotationParameters().annotateWithBiGG()) {
this.bigg = new BiGGDB(parameters.annotationParameters().biggAnnotationParameters().dbParameters());
}

// If the output is not a directory but the input is, log an error and return
if (!output.isDirectory() && input.isDirectory()) {
throw new IOException(format(MESSAGES.getString("WRITE_DIR_TO_FILE_ERROR"),
input.getAbsolutePath(),
output.getAbsolutePath()));
if (parameters.annotationParameters().adbAnnotationParameters().addADBAnnotations()) {
this.adb = new AnnotateDB(parameters.annotationParameters().adbAnnotationParameters().dbParameters());
}

// Ensure the output directory or file's parent directory exists
SBMLFileUtils.checkCreateOutDir(output);

batchProcess(input, parameters.output());
var inputFiles = FileUtils.listFiles(parameters.input(), new String[]{"xml", "sbml", "json", "mat"}, true);
List<Pair<File, File>> inputOutputPairs = new ArrayList<>();

if (parameters.input().isDirectory()) {
for (var input: inputFiles) {
inputOutputPairs.add(Pair.of(input, SBMLFileUtils.getOutputFileName(input, parameters.output())));
}

// TODO: this is a placeholder for a parallel implementation
for (var pair: inputOutputPairs) {
try {
processFile(pair.getLeft(), pair.getRight());
} catch (ModelReaderException e) {
logger.debug(format("Skipping unreadable file \"{0}\".", pair.getLeft()));
}
}
}
else {
processFile(parameters.input(), parameters.output());
}

} catch (ModelReaderException | ModelValidatorException | ModelWriterException | IOException |
} catch (ModelValidatorException | ModelWriterException | IOException |
AnnotationException e) {
// TODO: produce some user-friendly output and log to a file that can be provided for trouble-shooting
throw new RuntimeException(e);
Expand All @@ -157,52 +163,48 @@ public void commandLineMode(AppConf appConf) {
} catch (SQLException e) {
// TODO: produce some user-friendly output and log to a file that can be provided for trouble-shooting
throw new RuntimeException(e);
} catch (ModelReaderException e) {
throw new RuntimeException(e);
}
}

private void validateIOParameters() throws IOException {
var input = parameters.input();
var output = parameters.output();

/**
* Processes the specified input and output paths. If the input is a directory, it recursively processes each file within.
*
* @param input Path to the input file or directory to be processed. This should correspond to {@link CommandLineParameters#input()}.
* @param output Path to the output file or directory where processed files should be saved. This should correspond to {@link CommandLineParameters#output()}.
*/
private void batchProcess(File input, File output) throws ModelReaderException, ModelWriterException, ModelValidatorException, AnnotationException, SQLException {
// If the input is a directory, process each file within it
if (input.isDirectory()) {
File[] files = input.listFiles();

if (files == null || files.length < 1) {
logger.info(MESSAGES.getString("NO_FILES_ERROR"));
return;
}
// Recursively process each file in the directory
for (File file : files) {
File target = SBMLFileUtils.getOutputFileName(file, output);
batchProcess(file, target);
}
} else {
// NOTE: input is a single file, but output can be a file or a directory
// Adjust output file name if the output is a directory
var newOutput = output.isDirectory() ? SBMLFileUtils.getOutputFileName(input, output) : output;
// Check if the input exists, throw an exception if it does not
if (!input.exists()) {
throw new IOException(format(MESSAGES.getString("READ_FILE_ERROR"),
input.toString()));
}

processFile(input, newOutput);
// If the input is a directory but the output is not, exit with error
if (input.isDirectory() && !output.isDirectory()) {
throw new IOException(format(MESSAGES.getString("WRITE_DIR_TO_FILE_ERROR"),
input.getAbsolutePath(),
output.getAbsolutePath()));
}

// If the output is a directory but the input is not, exit with error
if (output.isDirectory() && !input.isDirectory()) {
throw new IOException(format("Output \"{0}\" is a directory, but Input \"{1}\" is not",
output.getAbsolutePath(),
input.getAbsolutePath()));
}

// Ensure the output directory or file's parent directory exists
SBMLFileUtils.checkCreateOutDir(output);
}


private void processFile(File input, File output) throws ModelReaderException, ModelWriterException, ModelValidatorException, AnnotationException, SQLException {
long startTime = System.currentTimeMillis();

SBMLDocument doc = new ModelReader(parameters.sboParameters(), registry).read(input);
// TODO: we should be doing better sanity checking here; e.g.: just validate the SBML
if (doc == null) return;

// TODO: hier wäre es jetzt angebracht das Ding zu validieren, geht aber nicht, weil es keinen Validator in JSBML gibt

Model model = doc.getModel();
if (model == null) {
logger.severe(MESSAGES.getString("MODEL_MISSING"));
// TODO: handle this better
throw new RuntimeException(MESSAGES.getString("MODEL_MISSING"));
}

List<ProgressObserver> polishingObservers = List.of(new PolisherProgressBar());
int count = getPolishingTaskCount(model);
Expand Down Expand Up @@ -240,6 +242,7 @@ private void processFile(File input, File output) throws ModelReaderException, M

output = new ModelWriter(parameters.outputType()).write(doc, output);

// TODO: das ist keine anständige Validierung!
if (parameters.SBMLValidation()) {
var mv = new ModelValidator();
// use offline validation
Expand Down
Loading

0 comments on commit 8829f61

Please sign in to comment.