Commit d925056a authored by lcottret's avatar lcottret
Browse files

Finish 0.9.1

parents 3b2a546b 817b9fbd
......@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 0.9.1
### Fixed
[met4j-io] Great speed improvements to read gene reaction associations
## 0.9.0
### Features
......
......@@ -44,7 +44,7 @@
<parent>
<groupId>fr.inrae.toulouse.metexplore</groupId>
<artifactId>met4j</artifactId>
<version>0.9.0-SNAPSHOT</version>
<version>0.9.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>fr.inrae.toulouse.metexplore</groupId>
<artifactId>met4j</artifactId>
<version>0.9.0-SNAPSHOT</version>
<version>0.9.1-SNAPSHOT</version>
</parent>
<properties>
......@@ -35,7 +35,7 @@
<dependency>
<groupId>fr.inrae.toulouse.metexplore</groupId>
<artifactId>met4j-core</artifactId>
<version>0.9.0-SNAPSHOT</version>
<version>0.9.1-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>fr.inrae.toulouse.metexplore</groupId>
<artifactId>met4j</artifactId>
<version>0.9.0-SNAPSHOT</version>
<version>0.9.1-SNAPSHOT</version>
</parent>
<scm>
......
......@@ -90,6 +90,144 @@ public class BioNetwork extends BioEntity {
super("NA");
}
/**
* Get a reaction by its id
*
* @param id a String
* @return a {@link BioReaction}
*/
public BioReaction getReaction(@NonNull String id) {
return this.reactions.get(id);
}
/**
* Check if a reaction with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioReaction} with this id exists in the BioNetwork
*/
public boolean containsReaction(@NonNull String id) {
return this.reactions.containsId(id);
}
/**
* Get a metabolite by its id
* @param id a String
* @return a {@link BioMetabolite}
*/
public BioMetabolite getMetabolite(@NonNull String id) {
return this.metabolites.get(id);
}
/**
* Check if a metabolite with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioMetabolite} with this id exists in the BioNetwork
*/
public boolean containsMetabolite(@NonNull String id) {
return this.metabolites.containsId(id);
}
/**
* Get a pathway by its id
* @param id a String
* @return a {@link BioPathway}
*/
public BioPathway getPathway(@NonNull String id) {
return this.pathways.get(id);
}
/**
* Check if a pathway with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioPathway} with this id exists in the BioNetwork
*/
public boolean containsPathway(@NonNull String id) {
return this.pathways.containsId(id);
}
/**
* Get a protein by its id
* @param id a String
* @return a {@link BioProtein}
*/
public BioProtein getProtein(@NonNull String id) {
return this.proteins.get(id);
}
/**
* Check if a pathway with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioPathway} with this id exists in the BioNetwork
*/
public boolean containsProtein(@NonNull String id) {
return this.proteins.containsId(id);
}
/**
* Get a gene by its id
* @param id a String
* @return a {@link BioGene}
*/
public BioGene getGene(String id) {
return this.genes.get(id);
}
/**
* Check if a gene with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioGene} with this id exists in the BioNetwork
*/
public boolean containsGene(String id) {
return this.genes.containsId(id);
}
/**
* Get a compartment by its id
* @param id a String
* @return a {@link BioCompartment}
*/
public BioCompartment getCompartment(String id) {
return this.compartments.get(id);
}
/**
* Check if a compartment with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioCompartment} with this id exists in the BioNetwork
*/
public boolean containsCompartment(String id) {
return this.compartments.containsId(id);
}
/**
* Get an enzyme by its id
* @param id a String
* @return a {@link BioEnzyme}
*/
public BioEnzyme getEnzyme(String id) {
return this.enzymes.get(id);
}
/**
* Check if an enzyme with a specific id already exists in the network
*
* @param id a String
* @return true if there is a {@link BioEnzyme} with this id exists in the BioNetwork
*/
public boolean containsEnzyme(String id) {
return this.enzymes.containsId(id);
}
/**
* Add several entities
*
......@@ -134,8 +272,7 @@ public class BioNetwork extends BioEntity {
this.addCompartment((BioCompartment) e);
} else if (e instanceof BioEnzyme) {
this.addEnzyme((BioEnzyme) e);
}
else {
} else {
throw new IllegalArgumentException(
"BioEntity \"" + e.getClass().getSimpleName() + "\" not supported by BioNetwork");
}
......@@ -583,7 +720,7 @@ public class BioNetwork extends BioEntity {
* @param localisation a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioCompartment}
* @param products a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.collection.BioCollection} of {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioMetabolite} to add to the right side of the reaction
*/
public void affectRight(@NonNull BioReaction reaction, @NonNull Double stoichiometry, @NonNull BioCompartment localisation, @NonNull BioCollection<BioMetabolite> products) {
public void affectRight(@NonNull BioReaction reaction, @NonNull Double stoichiometry, @NonNull BioCompartment localisation, @NonNull BioCollection<BioMetabolite> products) {
for (BioMetabolite product : products)
affectSideReaction(reaction, stoichiometry, localisation, BioReaction.Side.RIGHT, product);
}
......@@ -632,9 +769,9 @@ public class BioNetwork extends BioEntity {
/**
* get a reactant with the same metabolite, stoichiometry and compartment
*
* @param metabolite a {@link BioMetabolite}
* @param metabolite a {@link BioMetabolite}
* @param stoichiometry a {@link Double}
* @param compartment a {@link BioCompartment}
* @param compartment a {@link BioCompartment}
* @return a {@link BioReactant}
*/
protected BioReactant getReactant(@NonNull BioMetabolite metabolite, @NonNull Double stoichiometry, @NonNull BioCompartment compartment) {
......@@ -646,12 +783,11 @@ public class BioNetwork extends BioEntity {
}
/**
*
* @param reaction a {@link BioReaction}
* @param reaction a {@link BioReaction}
* @param stoichiometry a {@link Double}
* @param localisation a {@link BioCompartment}
* @param side a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioReaction.Side}
* @param metabolite a {@link BioMetabolite}
* @param localisation a {@link BioCompartment}
* @param side a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioReaction.Side}
* @param metabolite a {@link BioMetabolite}
*/
private void affectSideReaction(@NonNull BioReaction reaction, @NonNull Double stoichiometry, @NonNull BioCompartment localisation, @NonNull BioReaction.Side side, @NonNull BioMetabolite metabolite) {
......@@ -672,10 +808,11 @@ public class BioNetwork extends BioEntity {
/**
* Add reactants in the list of reactants
*
* @param reactants a list of {@link BioReactant}
*/
protected void addReactants(@NonNull BioReactant ...reactants) {
for(BioReactant r : reactants) {
protected void addReactants(@NonNull BioReactant... reactants) {
for (BioReactant r : reactants) {
this.addReactant(r);
}
}
......@@ -685,7 +822,7 @@ public class BioNetwork extends BioEntity {
BioCompartment localisation = reactant.getLocation();
if (! this.reactants.contains(reactant)) {
if (!this.reactants.contains(reactant)) {
throw new IllegalArgumentException("Reactant " + reactant.getId() + " not in the network");
}
......@@ -820,7 +957,7 @@ public class BioNetwork extends BioEntity {
* Get enzyme participant with the same quantity and the same entity
*
* @param quantity a {@link Double}
* @param unit a {@link BioPhysicalEntity}
* @param unit a {@link BioPhysicalEntity}
* @return a {@link BioEnzymeParticipant}
*/
protected BioEnzymeParticipant getEnzymeParticipant(@NonNull BioPhysicalEntity unit, @NonNull Double quantity) {
......@@ -841,7 +978,7 @@ public class BioNetwork extends BioEntity {
*/
private void affectSubUnit(@NonNull BioEnzyme enzyme, @NonNull Double quantity, @NonNull BioPhysicalEntity unit) {
if(! (unit instanceof BioMetabolite) && ! (unit instanceof BioProtein) ) {
if (!(unit instanceof BioMetabolite) && !(unit instanceof BioProtein)) {
throw new IllegalArgumentException("A subunit of a BioEnzyme must be a BioProtein or a BioMetabolite");
}
BioEnzymeParticipant p = this.getEnzymeParticipant(unit, quantity);
......@@ -864,7 +1001,7 @@ public class BioNetwork extends BioEntity {
*/
private void affectSubUnit(@NonNull BioEnzyme enzyme, @NonNull BioEnzymeParticipant unit) {
if(! this.enzymeParticipants.contains(unit)) {
if (!this.enzymeParticipants.contains(unit)) {
throw new IllegalArgumentException("Enzyme participant " + unit.getId() + " not present in the network");
}
......@@ -876,7 +1013,7 @@ public class BioNetwork extends BioEntity {
throw new IllegalArgumentException("Physical entity " + unit.getPhysicalEntity().getId() + " not present in the network");
}
if(! enzyme.getParticipants().containsId(unit.getId())) {
if (!enzyme.getParticipants().containsId(unit.getId())) {
enzyme.addParticipant(unit);
}
......@@ -1202,7 +1339,7 @@ public class BioNetwork extends BioEntity {
}
}
HashSet<BioReaction> reactionSet = this.getReactionsView().stream().filter(r -> {
HashSet<BioReaction> reactionSet = this.reactions.stream().filter(r -> {
if (!r.isReversible()) {
......@@ -1230,7 +1367,7 @@ public class BioNetwork extends BioEntity {
BioCollection<BioReaction> reactions = new BioCollection<>();
this.getReactionsView().forEach(r -> {
this.reactions.forEach(r -> {
boolean flag;
BioCollection<BioMetabolite> lefts = r.getLeftsView();
......@@ -1314,7 +1451,7 @@ public class BioNetwork extends BioEntity {
}
}
HashSet<BioReaction> reactionSet = this.getReactionsView().stream().
HashSet<BioReaction> reactionSet = this.reactions.stream().
filter(o -> all ? o.getGenes().containsAll(genes) : !Collections.disjoint(o.getGenes(), genes))
.collect(Collectors.toCollection(HashSet::new));
......@@ -1334,7 +1471,7 @@ public class BioNetwork extends BioEntity {
throw new IllegalArgumentException("Gene " + gene + " not present in the network");
}
HashSet<BioReaction> reactionSet = this.getReactionsView().stream().
HashSet<BioReaction> reactionSet = this.reactions.stream().
filter(o -> o.getGenes().contains(gene))
.collect(Collectors.toCollection(HashSet::new));
......@@ -1678,8 +1815,8 @@ public class BioNetwork extends BioEntity {
BioCollection<BioMetabolite> allMetabolites = new BioCollection<>();
for (BioReaction reaction : reactions) {
if(! this.contains(reaction)) {
throw new IllegalArgumentException("Reaction "+reaction+" not present in the network");
if (!this.contains(reaction)) {
throw new IllegalArgumentException("Reaction " + reaction + " not present in the network");
}
if (this.contains(reaction)) {
allMetabolites.addAll(this.getLefts(reaction));
......@@ -1721,7 +1858,7 @@ public class BioNetwork extends BioEntity {
throw new IllegalArgumentException("Entity " + e + " not present in the network");
}
for (BioCompartment c : this.getCompartmentsView()) {
for (BioCompartment c : this.compartments) {
if (c.getComponents().contains(e)) {
cpts.add(c);
}
......@@ -1829,17 +1966,17 @@ public class BioNetwork extends BioEntity {
/**
* Adds enzymes participants in the network
*
* @param enzymeParticipants a list of {@link BioEnzymeParticipant}
*/
protected void addEnzymeParticipants(@NonNull BioEnzymeParticipant ...enzymeParticipants) {
for(BioEnzymeParticipant ep : enzymeParticipants) {
protected void addEnzymeParticipants(@NonNull BioEnzymeParticipant... enzymeParticipants) {
for (BioEnzymeParticipant ep : enzymeParticipants) {
this.addEnzymeParticipant(ep);
}
}
/**
*
* @param ep a {@link BioEnzymeParticipant}
*/
private void addEnzymeParticipant(@NonNull BioEnzymeParticipant ep) {
......
......@@ -63,7 +63,9 @@ public class BioNetworkUtils {
BioCollection<BioReaction> chokeReactions = new BioCollection<>();
for (BioReaction r : network.getReactionsView()) {
BioCollection<BioReaction> reactions = network.getReactionsView();
for (BioReaction r : reactions) {
BioCollection<BioMetabolite> metabolites = network.getLefts(r);
metabolites.addAll(network.getRights(r));
......@@ -117,7 +119,8 @@ public class BioNetworkUtils {
* - add metabolites to a compartment
* - add components to an enzyme
* - add reactions to a pathway
* - add enzymes or reactants to a reaction
* - add enzymes to a reaction
* But, it does not change the reactants of a reaction, ie the formula of the reaction.
*/
public static void deepCopy(@NonNull BioNetwork networkIn, @NonNull BioNetwork networkOut, Boolean keepGPR, Boolean keepPrevious) {
......@@ -155,7 +158,7 @@ public class BioNetworkUtils {
newCpt = new BioCompartment(cpt);
networkOut.add(newCpt);
} else {
newCpt = networkOut.getCompartmentsView().get(cpt.getId());
newCpt = networkOut.getCompartment(cpt.getId());
}
// Copy metabolites in the compartments
......@@ -163,7 +166,7 @@ public class BioNetworkUtils {
filter((c) -> c.getClass().equals(BioMetabolite.class)).
map(BioEntity::getId).
forEach((id) -> {
BioMetabolite newMetabolite = networkOut.getMetabolitesView().get(id);
BioMetabolite newMetabolite = networkOut.getMetabolite(id);
networkOut.affectToCompartment(newCpt, newMetabolite);
});
}
......@@ -197,12 +200,12 @@ public class BioNetworkUtils {
newProtein = new BioProtein(protein);
networkOut.add(newProtein);
} else {
newProtein = networkOut.getProteinsView().get(protein.getId());
newProtein = networkOut.getProtein(protein.getId());
}
if (protein.getGene() != null) {
String geneId = protein.getGene().getId();
BioGene newGene = networkOut.getGenesView().get(geneId);
BioGene newGene = networkOut.getGene(geneId);
networkOut.affectGeneProduct(newProtein, newGene);
}
}
......@@ -224,7 +227,7 @@ public class BioNetworkUtils {
newEnzyme = new BioEnzyme(enzyme);
networkOut.add(newEnzyme);
} else {
newEnzyme = networkOut.getEnzymesView().get(enzyme.getId());
newEnzyme = networkOut.getEnzyme(enzyme.getId());
}
BioCollection<BioEnzymeParticipant> participants = enzyme.getParticipantsView();
......@@ -234,11 +237,11 @@ public class BioNetworkUtils {
if (participant.getPhysicalEntity().getClass().equals(BioMetabolite.class)) {
BioMetabolite metabolite = (BioMetabolite) participant.getPhysicalEntity();
BioMetabolite newMetabolite = networkOut.getMetabolitesView().get(metabolite.getId());
BioMetabolite newMetabolite = networkOut.getMetabolite(metabolite.getId());
networkOut.affectSubUnit(newEnzyme, quantity, newMetabolite);
} else if (participant.getPhysicalEntity().getClass().equals(BioProtein.class)) {
BioProtein protein = (BioProtein) participant.getPhysicalEntity();
BioProtein newProtein = networkOut.getProteinsView().get(protein.getId());
BioProtein newProtein = networkOut.getProtein(protein.getId());
networkOut.affectSubUnit(newEnzyme, quantity, newProtein);
}
}
......@@ -246,16 +249,19 @@ public class BioNetworkUtils {
}
// Copy reactions
BioCollection<BioReaction> reactionsIn = networkIn.getReactionsView();
BioCollection<BioReaction> reactionsOut = networkOut.getReactionsView();
BioCollection<BioReaction> reactionsToCopy = networkIn.getReactionsView();
if (keepPrevious) {
reactionsToCopy.removeAll(networkOut.getReactionsView());
reactionsToCopy.removeAll(reactionsOut);
}
for (BioReaction r : networkIn.getReactionsView()) {
for (BioReaction r : reactionsIn) {
BioReaction newReaction;
if (reactionsToCopy.contains(r) && !networkOut.containsEntityWithSameId(r)) {
if (reactionsToCopy.contains(r) && !networkOut.containsReaction(r.getId())) {
newReaction = new BioReaction(r);
newReaction.setSpontaneous(r.isSpontaneous());
......@@ -263,30 +269,30 @@ public class BioNetworkUtils {
newReaction.setEcNumber(r.getEcNumber());
networkOut.add(newReaction);
} else {
newReaction = networkOut.getReactionsView().get(r.getId());
}
// Copy lefts
for (BioReactant reactant : r.getLeftReactantsView()) {
BioMetabolite newMetabolite = networkOut.getMetabolitesView().get(reactant.getMetabolite().getId());
BioCompartment newCpt = networkOut.getCompartmentsView().get(reactant.getLocation().getId());
Double sto = reactant.getQuantity();
networkOut.affectLeft(newReaction, sto, newCpt, newMetabolite);
}
// Copy lefts
for (BioReactant reactant : r.getLeftReactantsView()) {
BioMetabolite newMetabolite = networkOut.getMetabolite(reactant.getMetabolite().getId());
BioCompartment newCpt = networkOut.getCompartment(reactant.getLocation().getId());
Double sto = reactant.getQuantity();
networkOut.affectLeft(newReaction, sto, newCpt, newMetabolite);
}
// Copy rights
for (BioReactant reactant : r.getRightReactantsView()) {
BioMetabolite newMetabolite = networkOut.getMetabolitesView().get(reactant.getMetabolite().getId());
BioCompartment newCpt = networkOut.getCompartmentsView().get(reactant.getLocation().getId());
Double sto = reactant.getQuantity();
networkOut.affectRight(newReaction, sto, newCpt, newMetabolite);
// Copy rights
for (BioReactant reactant : r.getRightReactantsView()) {
BioMetabolite newMetabolite = networkOut.getMetabolite(reactant.getMetabolite().getId());
BioCompartment newCpt = networkOut.getCompartment(reactant.getLocation().getId());
Double sto = reactant.getQuantity();
networkOut.affectRight(newReaction, sto, newCpt, newMetabolite);
}
} else {
newReaction = networkOut.getReaction(r.getId());
}
// Copy enzymes
if (keepGPR) {
for (BioEnzyme enzyme : r.getEnzymesView()) {
BioEnzyme newEnzyme = networkOut.getEnzymesView().get(enzyme.getId());
BioEnzyme newEnzyme = networkOut.getEnzyme(enzyme.getId());
networkOut.affectEnzyme(newReaction, newEnzyme);
}
}
......@@ -305,12 +311,12 @@ public class BioNetworkUtils {
networkOut.add(newPathway);
}
BioPathway newPathway = networkOut.getPathwaysView().get(pathway.getId());
BioPathway newPathway = networkOut.getPathway(pathway.getId());
// Add reactions into pathway
BioCollection<BioReaction> reactions = networkIn.getReactionsFromPathways(pathway);
for (BioReaction reaction : reactions) {
BioReaction newReaction = networkOut.getReactionsView().get(reaction.getId());
BioReaction newReaction = networkOut.getReaction(reaction.getId());
networkOut.affectToPathway(newPathway, newReaction);
}
}
......
......@@ -1893,7 +1893,7 @@ public class BioNetworkTest {
assertEquals("Bad number of pathways with these genes", 1, pathways.size());
assertTrue("Bad pathway with these genes",
pathways.contains(network.getPathwaysView().get("pathway1")));
pathways.contains(network.getPathway("pathway1")));
pathways = network.getPathwaysFromGenes(genes, true);
......@@ -1989,7 +1989,7 @@ public class BioNetworkTest {
BioReaction r3 = new BioReaction("r3");
network.add(r3);
BioPathway pathway1 = network.getPathwaysView().get("pathway1");
BioPathway pathway1 = network.getPathway("pathway1");
network.affectToPathway(pathway1, r2);
......
......@@ -184,38 +184,38 @@ public class BioNetworkUtilsTest {
assertEquals(1, newNetwork.getGenesView().size());
r1.setName("newName");
assertNotEquals(r1.getName(), newNetwork.getReactionsView().get("R1").getName());
assertNotEquals(r1.getName(), newNetwork.getReaction("R1").getName());
m1.setName("newName");
assertNotEquals(m1.getName(), newNetwork.getMetabolitesView().get("M1").getName());
assertNotEquals(m1.getName(), newNetwork.getMetabolite("M1").getName());
c1.setName("newName");
assertNotEquals(c1.getName(), newNetwork.getCompartmentsView().get("c1").getName());
assertNotEquals(c1.getName(), newNetwork.getCompartment("c1").getName());
pathway1.setName("newName");
assertNotEquals(pathway1.getName(), newNetwork.getPathwaysView().get("pathway1").getName());
assertNotEquals(pathway1.getName(), newNetwork.getPathway("pathway1").getName());