Skip to content

Commit

Permalink
Merge pull request #124 from draeger-lab/draeger-lab/ModelPolisher/#121
Browse files Browse the repository at this point in the history
…-polishing-unit-tests

Draeger lab/model polisher/#121 polishing unit tests
  • Loading branch information
Schmoho authored Jun 11, 2024
2 parents 4b7728b + 4f7138c commit 563e2a8
Show file tree
Hide file tree
Showing 34 changed files with 23,430 additions and 502 deletions.
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
id "java"
id "application"
Expand Down Expand Up @@ -49,6 +52,17 @@ test {
}
}

tasks.withType(Test) {
testLogging {
events TestLogEvent.FAILED
exceptionFormat TestExceptionFormat.FULL
showCauses true
showExceptions true
showStackTraces true
showStandardStreams false
}
}

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
Expand All @@ -73,6 +87,8 @@ dependencies {
implementation "de.uni-rostock.sbi:CombineArchive:1.4.1"
implementation "com.zaxxer:HikariCP:5.0.1"
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
testImplementation "org.testcontainers:testcontainers:1.17.3"
testImplementation "org.testcontainers:junit-jupiter:1.17.3"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"
}

Expand Down
22 changes: 22 additions & 0 deletions docker/preloaded_bigg_docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM bigg_db_current:latest AS dumper
# NOTE: this image is curently not available anywhere, but it is nothing more than postgres:14
# with the current DB dump + restore script from mephenors image

RUN ["sed", "-i", "s/exec \"$@\"/echo \"skipping...\"/", "/usr/local/bin/docker-entrypoint.sh"]

RUN mkdir -p /var/lib/postgresql-static/data
ENV PGDATA=/var/lib/postgresql-static/data
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=postgres

RUN ["/usr/local/bin/docker-entrypoint.sh", "postgres"]

FROM postgres:14

COPY --from=dumper /var/lib/postgresql-static/data $PGDATA

# ENTRYPOINT ["/usr/bin/env"]

# USER postgres

# CMD ["postgres"]
53 changes: 41 additions & 12 deletions src/main/java/edu/ucsd/sbrg/bigg/annotation/ReactionAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.ucsd.sbrg.bigg.polishing.PolishingUtils;
import edu.ucsd.sbrg.db.BiGGDB;
import edu.ucsd.sbrg.db.QueryOnce;
import edu.ucsd.sbrg.miriam.Registry;
import edu.ucsd.sbrg.util.GPRParser;
import edu.ucsd.sbrg.util.SBMLUtils;
import org.sbml.jsbml.CVTerm.Qualifier;
Expand All @@ -20,9 +21,6 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static edu.ucsd.sbrg.bigg.annotation.BiGGAnnotation.getBiGGIdFromResources;
import static edu.ucsd.sbrg.db.BiGGDBContract.Constants.TYPE_REACTION;

public class ReactionAnnotation extends CVTermAnnotation {

/**
Expand Down Expand Up @@ -64,7 +62,6 @@ public void annotate() {
});
}


/**
* Checks if {@link Species#getId()} returns a correct {@link BiGGId} and tries to retrieve a corresponding
* {@link BiGGId} based on annotations present.
Expand All @@ -77,20 +74,52 @@ public Optional<BiGGId> checkId() {
String id = reaction.getId();
// extracting BiGGId if not present for species
boolean isBiGGid = id.matches("^(R_)?([a-zA-Z][a-zA-Z0-9_]+)(?:_([a-z][a-z0-9]?))?(?:_([A-Z][A-Z0-9]?))?$")
&& QueryOnce.isReaction(id);
&& QueryOnce.isReaction(id);
if (!isBiGGid) {
// Flatten all resources for all CVTerms into a list
List<String> resources =
reaction.getAnnotation().getListOfCVTerms().stream().filter(cvTerm -> cvTerm.getQualifier() == Qualifier.BQB_IS)
.flatMap(term -> term.getResources().stream()).collect(Collectors.toList());
if (!resources.isEmpty()) {
// update id if we found something
id = getBiGGIdFromResources(resources, TYPE_REACTION).orElse(id);
}
Set<String> ids = reaction.getAnnotation().getListOfCVTerms()
.stream()
.filter(cvTerm -> cvTerm.getQualifier() == Qualifier.BQB_IS)
.flatMap(term -> term.getResources().stream())
.map(Registry::checkResourceUrl)
.flatMap(Optional::stream)
.map(Registry::getPartsFromIdentifiersURI)
.map(parts -> {
String prefix = parts.get(0);
String synonymId = parts.get(1);
return BiGGDB.getBiggIdsForReactionForeignId(prefix, synonymId);
})
.flatMap(Collection::stream)
.filter(this::matchingCompartments)
.map(fr -> fr.reactionId)
.collect(Collectors.toSet());
id = ids.stream()
.findFirst()
.orElse(id);
}
return BiGGId.createReactionId(id);
}

private boolean matchingCompartments(BiGGDB.ForeignReaction foreignReaction) {
if (!reaction.isSetCompartment()
&& null == foreignReaction.compartmentId
&& null == foreignReaction.compartmentName) {
return true;
} else if (!reaction.isSetCompartment()
&& (null != foreignReaction.compartmentId
|| null != foreignReaction.compartmentName)) {
return false;
} else if (reaction.isSetCompartment()) {
return reaction.getCompartment()
.equals(foreignReaction.compartmentId);
} else if (reaction.isSetCompartmentInstance()
&& reaction.getCompartmentInstance().isSetName()) {
return reaction.getCompartmentInstance().getName()
.equals(foreignReaction.compartmentName);
} else
return false;
}


/**
* @param biggId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public void annotate() {
*/
@Override
public Optional<BiGGId> checkId() {
// TODO: compartments are not handled correctly -- is this at all possible to get right?
Optional<BiGGId> metaboliteId = BiGGId.createMetaboliteId(species.getId());
Optional<String> id = metaboliteId.flatMap(biggId -> {
// extracting BiGGId if not present for species
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/edu/ucsd/sbrg/bigg/polishing/ModelPolishing.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.sbml.jsbml.ext.fbc.GeneProduct;
import org.sbml.jsbml.ext.fbc.Objective;

import java.util.Collection;
import java.util.ResourceBundle;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static java.text.MessageFormat.format;

Expand Down Expand Up @@ -91,13 +93,18 @@ public void polishListOfObjectives(FBCModelPlugin modelPlug) {
strict &= SBMLFix.fixObjective(model.getId(), model.getListOfReactions(), modelPlug,
Parameters.get().fluxCoefficients(), Parameters.get().fluxObjectives());
}
if (objective.isSetListOfFluxObjectives()) {
if (objective.isSetListOfFluxObjectives() || objective.getListOfFluxObjectives().size() == 0) {
polishListOfFluxObjectives(objective);
}
}
// removed unused objectives, i.e. those without flux objectives
modelPlug.getListOfObjectives().stream().filter(Predicate.not(Objective::isSetListOfFluxObjectives))
.forEach(modelPlug::removeObjective);
// modelPlug.getListOfObjectives().remove
Collection<Objective> removals = modelPlug.getListOfObjectives()
.stream()
.filter(Predicate.not(Objective::isSetListOfFluxObjectives)
.or(o -> o.getListOfFluxObjectives().size() == 0))
.collect(Collectors.toList());
modelPlug.getListOfObjectives().removeAll(removals);
}
}

Expand Down
Loading

0 comments on commit 563e2a8

Please sign in to comment.