From 7ec9cde5c06bbed09bde5ed8da7fe4ab4378ef48 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:35:02 +0100 Subject: [PATCH 01/21] create new class to handle entity type exception --- .../attributes/EntityTypeException.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityTypeException.java diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityTypeException.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityTypeException.java new file mode 100644 index 000000000..47f9544df --- /dev/null +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityTypeException.java @@ -0,0 +1,43 @@ +/* + * Copyright INRAE (2022) + * + * contact-metexplore@inrae.fr + * + * This software is a computer program whose purpose is to [describe + * functionalities and technical features of your software]. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "https://cecill.info/licences/Licence_CeCILL_V2.1-en.html". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ +package fr.inrae.toulouse.metexplore.met4j_io.tabulated.attributes; + +public class EntityTypeException extends RuntimeException { + + public EntityTypeException(String errorMessage) { + super(errorMessage); + } +} -- GitLab From cdf68a1ea1096c6ba811397065781bbeb8ad8113 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:37:02 +0100 Subject: [PATCH 02/21] add new entity type : Compartment --- .../metexplore/met4j_io/tabulated/attributes/EntityType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityType.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityType.java index 8b2ee8d96..ea6f95d1a 100644 --- a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityType.java +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/EntityType.java @@ -36,5 +36,5 @@ package fr.inrae.toulouse.metexplore.met4j_io.tabulated.attributes; public enum EntityType { - REACTION, METABOLITE, GENE, PROTEIN, PATHWAY + REACTION, METABOLITE, GENE, PROTEIN, PATHWAY, COMPARTMENT } -- GitLab From 5a6d8506ce6e74d9d938c62e02d8f7dd1fd5d397 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:37:33 +0100 Subject: [PATCH 03/21] add entity Compartment and EntityTypeException --- .../AbstractSetAttributesFromFile.java | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/AbstractSetAttributesFromFile.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/AbstractSetAttributesFromFile.java index b390b6192..a91f0307a 100644 --- a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/AbstractSetAttributesFromFile.java +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/AbstractSetAttributesFromFile.java @@ -80,13 +80,13 @@ public abstract class AbstractSetAttributesFromFile { * * @param colId a int. * @param colAttr : number of the attribute column - * @param bn : BioNetwork + * @param bn : {@link BioNetwork} * @param fileIn : tabulated file containing the ids and the attributes * @param c : comment character - * @param nSkip a int. + * @param nSkip a int. Number of lines to skip * @param entityType a {@link EntityType} - * @param p a {@link Boolean} object. - * @param s a {@link Boolean} object. + * @param p a {@link Boolean} object : To match the objects in the sbml file, adds the prefix R_ to reactions and M_ to metabolites + * @param s a {@link Boolean} object : To match the objects in the sbml file, adds the suffix _comparmentID to metabolite */ public AbstractSetAttributesFromFile(int colId, int colAttr, BioNetwork bn, String fileIn, String c, int nSkip, EntityType entityType, Boolean p, Boolean s) { @@ -104,24 +104,34 @@ public abstract class AbstractSetAttributesFromFile { this.entityType = entityType; - if (this.entityType.equals(EntityType.REACTION)) { - this.objectIds = bn.getReactionsView().getIds(); - } - - if (this.entityType.equals(EntityType.METABOLITE)) { - this.objectIds = bn.getMetabolitesView().getIds(); - } - - if (this.entityType.equals(EntityType.PROTEIN)) { - this.objectIds = bn.getProteinsView().getIds(); - } - - if (this.entityType.equals(EntityType.GENE)) { - this.objectIds = bn.getGenesView().getIds(); - } - - if (this.entityType.equals(EntityType.PATHWAY)) { - this.objectIds = bn.getPathwaysView().getIds(); + switch (entityType) { + case REACTION: { + this.objectIds = bn.getReactionsView().getIds(); + break; + } + case METABOLITE: { + this.objectIds = bn.getMetabolitesView().getIds(); + break; + } + case PROTEIN: { + this.objectIds = bn.getProteinsView().getIds(); + break; + } + case GENE: { + this.objectIds = bn.getGenesView().getIds(); + break; + } + case COMPARTMENT: { + this.objectIds = bn.getCompartmentsView().getIds(); + break; + } + case PATHWAY: { + this.objectIds = bn.getPathwaysView().getIds(); + break; + } + default: { + throw new EntityTypeException("Entity "+entityType+" not recognized"); + } } if (this.colId < 0) { -- GitLab From 086ae53adfea9583aa1585b9ec6bf5bfbe6d475c Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:39:13 +0100 Subject: [PATCH 04/21] add constructor by copy with new id --- .../met4j_core/biodata/BioCompartment.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioCompartment.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioCompartment.java index 555573328..dd83ee581 100644 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioCompartment.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioCompartment.java @@ -82,6 +82,19 @@ public class BioCompartment extends BioPhysicalEntity { components = new BioCollection<>(); } + /** + * Copy of a compartment with a new id + * Do not copy the list of components + * + * @param compartment the original compartment + * @param id the new id + */ + public BioCompartment(BioCompartment compartment, String id) { + super(compartment, id); + + components = new BioCollection<>(); + } + /** * <p>getComponentsView.</p> * -- GitLab From 35bca210fa8ab2e59daeb359c068750c0bea06ac Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:39:26 +0100 Subject: [PATCH 05/21] add constructor by copy with new id --- .../met4j_core/biodata/BioEntity.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntity.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntity.java index 82248804b..973a7b428 100755 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntity.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntity.java @@ -109,8 +109,22 @@ public abstract class BioEntity { * @param e the original bioentity */ public BioEntity(@NonNull BioEntity e) { - this.id = e.getId(); - this.name = e.getName(); + this(e.getId(), e.getName()); + this.setSynonyms(new ArrayList<>(e.getSynonyms())); + this.setComment(e.getComment()); + this.setRefs(new HashMap<>(e.getRefs())); + this.setAttributes(new HashMap<>(e.getAttributes())); + } + + /** + * Deep copy with a new id + * <p> + * The refs and attributes are not deeply copied + * + * @param e the original bioentity + */ + public BioEntity(@NonNull BioEntity e, String newId) { + this(newId, e.getName()); this.setSynonyms(new ArrayList<>(e.getSynonyms())); this.setComment(e.getComment()); this.setRefs(new HashMap<>(e.getRefs())); -- GitLab From 81ecf10652923e719e6ff87dcab32b0d48484f29 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:39:38 +0100 Subject: [PATCH 06/21] add constructor by copy with new id --- .../met4j_core/biodata/BioPhysicalEntity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPhysicalEntity.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPhysicalEntity.java index 8ccb703ef..ff1ffc5af 100755 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPhysicalEntity.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPhysicalEntity.java @@ -73,4 +73,15 @@ public abstract class BioPhysicalEntity extends BioEntity { super(p); } + /** + * Deep copy with a new Id + * + * @param p the original {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioPhysicalEntity} + * @param id the new id + */ + public BioPhysicalEntity(BioPhysicalEntity p, String id) + { + super(p, id); + } + } -- GitLab From 0493f773586f7ea80c5b34388fab5b4133f89eb6 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:39:50 +0100 Subject: [PATCH 07/21] add constructor by copy with new id --- .../toulouse/metexplore/met4j_core/biodata/BioGene.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioGene.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioGene.java index 834bc8558..32dadae13 100755 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioGene.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioGene.java @@ -71,4 +71,13 @@ public class BioGene extends BioEntity { super(gene); } + /** + * Copy of a gene with a new Id + * + * @param gene the original gene + */ + public BioGene(BioGene gene, String id) { + super(gene, id); + } + } -- GitLab From 8b389a7580ab6b12eb59224d916079d898ced5d1 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:39:56 +0100 Subject: [PATCH 08/21] add constructor by copy with new id --- .../metexplore/met4j_core/biodata/BioMetabolite.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioMetabolite.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioMetabolite.java index 52ecb43b9..a761696cf 100644 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioMetabolite.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioMetabolite.java @@ -98,4 +98,14 @@ public class BioMetabolite extends BioPhysicalEntity { this.setChemicalFormula(metabolite.getChemicalFormula()); } + + public BioMetabolite(@NonNull BioMetabolite metabolite, String newId) { + super(metabolite, newId); + + this.setInchi(metabolite.getInchi()); + this.setSmiles(metabolite.getSmiles()); + this.setCharge(metabolite.getCharge()); + this.setMolecularWeight(metabolite.getMolecularWeight()); + this.setChemicalFormula(metabolite.getChemicalFormula()); + } } -- GitLab From 8a06da91802dfe6780a0147692e79f19c4c3fc71 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:40:00 +0100 Subject: [PATCH 09/21] add constructor by copy with new id --- .../metexplore/met4j_core/biodata/BioPathway.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPathway.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPathway.java index 3de598b16..ca3f1bea8 100755 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPathway.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioPathway.java @@ -82,6 +82,17 @@ public class BioPathway extends BioEntity { reactions = new BioCollection<>(); } + /** + * Copy pathway attributes but not the reactions + * Set new id + * + * @param pathway the original pathway + */ + public BioPathway(@NonNull BioPathway pathway, String id) { + super(pathway, id); + reactions = new BioCollection<>(); + } + /** * Get reactions involved in the pathway * -- GitLab From 4dacc1fbd612b74b466daf719a559fbf6d6947f1 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:40:04 +0100 Subject: [PATCH 10/21] add constructor by copy with new id --- .../met4j_core/biodata/BioReaction.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioReaction.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioReaction.java index 618587de7..80ce4f583 100755 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioReaction.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioReaction.java @@ -106,7 +106,7 @@ public class BioReaction extends BioEntity { } /** - * <p>Constructor for BioReaction.</p> + * <p>Copy of a BioReaction (only atomic attributes, not left nor right).</p> * * @param reaction a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioReaction} object. */ @@ -120,6 +120,22 @@ public class BioReaction extends BioEntity { this.reversible = reaction.reversible; } + /** + * <p>Copy of a BioReaction (only atomic attributes, not left nor right) with new id</p> + * + * @param reaction a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.BioReaction} object. + */ + public BioReaction(@NonNull BioReaction reaction, String id) { + super(reaction, id); + left = new BioCollection<>(); + right = new BioCollection<>(); + enzymes = new BioCollection<>(); + this.spontaneous = reaction.spontaneous; + this.ecNumber = reaction.ecNumber; + this.reversible = reaction.reversible; + } + + /** * <p>Getter for the field <code>ecNumber</code>.</p> * -- GitLab From 96463bb02eee67ce335590dd3bd9c65fe5c295a4 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:40:17 +0100 Subject: [PATCH 11/21] add constructor by copy with new id --- .../met4j_core/biodata/classesForTests/BioEntityFake.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/classesForTests/BioEntityFake.java b/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/classesForTests/BioEntityFake.java index ce64b6073..9a7701991 100644 --- a/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/classesForTests/BioEntityFake.java +++ b/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/classesForTests/BioEntityFake.java @@ -49,4 +49,8 @@ public class BioEntityFake extends BioEntity { super(id); } + public BioEntityFake(BioEntityFake e, String id) { + super(e, id); + } + } -- GitLab From 672887d12524e657f41a26ff378b8b3cf7eb4f31 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:40:30 +0100 Subject: [PATCH 12/21] add test of copy with new id --- .../metexplore/met4j_core/biodata/BioEntityTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntityTest.java b/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntityTest.java index f681a39c9..6d5db6a07 100644 --- a/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntityTest.java +++ b/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioEntityTest.java @@ -59,7 +59,7 @@ import org.junit.Test; public class BioEntityTest { public static BioRef ref; - public static BioEntity bioEntityTest; + public static BioEntityFake bioEntityTest; public static void init() { ref = new BioRef("origin", "dbName", "dbId", 1); @@ -234,4 +234,12 @@ public class BioEntityTest { assertEquals("value", bioEntityTest.getAttribute("test")); } + + @Test + public void copyWithNewId() { + BioEntityFake newEntity = new BioEntityFake(bioEntityTest, "newId"); + + assertEquals("newId", newEntity.getId()); + + } } -- GitLab From f4b07d55a46a54965e5bcff509601a62367b6c30 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:40:55 +0100 Subject: [PATCH 13/21] add removeFromCompartment method --- .../metexplore/met4j_core/biodata/BioNetwork.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetwork.java b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetwork.java index 688ef9c8c..270396600 100755 --- a/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetwork.java +++ b/met4j-core/src/main/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetwork.java @@ -1276,6 +1276,17 @@ public class BioNetwork extends BioEntity { } } + /** + * Remove a component from a compartment + * @param compartment + * @param entities + */ + public void removeFromCompartment(@NonNull BioCompartment compartment, @NonNull BioEntity... entities) { + for(BioEntity ent : entities) { + compartment.getComponents().remove(ent); + } + } + /** * Return true if the entity is in the list of metabolites, reactions, genes, * pathways, proteins, etc... -- GitLab From 599c17b089eef6e648ec1135c28fa3d7b4af6c20 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:41:13 +0100 Subject: [PATCH 14/21] add test for removeFromCompartment --- .../met4j_core/biodata/BioNetworkTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetworkTest.java b/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetworkTest.java index a7769a488..86efe6605 100644 --- a/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetworkTest.java +++ b/met4j-core/src/test/java/fr/inrae/toulouse/metexplore/met4j_core/biodata/BioNetworkTest.java @@ -2338,4 +2338,19 @@ public class BioNetworkTest { public void TestContainsBadEntityWithSameId() { this.network.containsEntityWithSameId(this.network); } + + @Test + public void removeFromCompartment() { + + this.addTestReactionToNetwork(); + + this.network.removeFromCompartment(cpt, s1, p1); + + assertEquals(2, this.network.getCompartment("cpt").getComponents().size()); + + assertNull(this.network.getCompartment("cpt").getComponents().get("s1")); + assertNull(this.network.getCompartment("cpt").getComponents().get("p1")); + + } + } -- GitLab From 0fe3e88775ff14fe87071aabf4892ac9b93d89d7 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:41:48 +0100 Subject: [PATCH 15/21] add compartment entity case --- .../attributes/SetNamesFromFile.java | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFile.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFile.java index 6cad2f176..e0dde0f5a 100644 --- a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFile.java +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFile.java @@ -107,20 +107,36 @@ public class SetNamesFromFile extends AbstractSetAttributesFromFile { String name = this.getIdAttributeMap().get(id); - if(this.entityType.equals(EntityType.METABOLITE)) { - object = this.bn.getMetabolite(id); - } - else if(this.entityType.equals(EntityType.GENE)) { - object = this.bn.getGene(id); - } - else if(this.entityType.equals(EntityType.PROTEIN)) { - object = this.bn.getProtein(id); - } - else if(this.entityType.equals(EntityType.PATHWAY)) { - object = this.bn.getPathway(id); - } - else { - object = this.bn.getReaction(id); + switch (this.entityType) { + case METABOLITE: + { + object = this.bn.getMetabolite(id); + break; + } + case GENE: { + object = this.bn.getGene(id); + break; + } + case PROTEIN: { + object = this.bn.getProtein(id); + break; + } + case PATHWAY: { + object = this.bn.getPathway(id); + break; + } + case REACTION: { + object = this.bn.getReaction(id); + break; + } + case COMPARTMENT: { + object = this.bn.getCompartment(id); + break; + } + default: { + throw new EntityTypeException("Entity type "+this.entityType+" is not recognized"); + } + } object.setName(name); -- GitLab From c9d72c1cff63c4aaef0c2d2364c4f2b866155347 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:41:57 +0100 Subject: [PATCH 16/21] add compartment entity case --- .../tabulated/attributes/SetRefsFromFile.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFile.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFile.java index b692e5bf8..6f6bd05bf 100644 --- a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFile.java +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFile.java @@ -111,20 +111,34 @@ public class SetRefsFromFile extends AbstractSetAttributesFromFile { BioEntity object; n++; - if(this.entityType.equals(EntityType.METABOLITE)) { - object = this.bn.getMetabolite(id); - } - else if(this.entityType.equals(EntityType.GENE)) { - object = this.bn.getGene(id); - } - else if(this.entityType.equals(EntityType.PROTEIN)) { - object = this.bn.getProtein(id); - } - else if(this.entityType.equals(EntityType.PATHWAY)) { - object = this.bn.getPathway(id); - } - else { - object = this.bn.getReaction(id); + switch (this.entityType) { + case METABOLITE: { + object = this.bn.getMetabolite(id); + break; + } + case GENE: { + object = this.bn.getGene(id); + break; + } + case PROTEIN: { + object = this.bn.getProtein(id); + break; + } + case PATHWAY: { + object = this.bn.getPathway(id); + break; + } + case REACTION: { + object = this.bn.getReaction(id); + break; + } + case COMPARTMENT: { + object = this.bn.getCompartment(id); + break; + } + default: { + throw new EntityTypeException("Entity type " + this.entityType + " is not recognized"); + } } object.addRef(new BioRef("attributesTable", this.ref, this.getIdAttributeMap().get(id), 1)); -- GitLab From 74ad5606c9a001d8b5376220b50f72167af1b5c7 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:46:42 +0100 Subject: [PATCH 17/21] add test for compartments --- .../attributes/SetNamesFromFileTest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFileTest.java b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFileTest.java index 2dbb97acb..f5843f828 100644 --- a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFileTest.java +++ b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetNamesFromFileTest.java @@ -54,6 +54,8 @@ public class SetNamesFromFileTest { private BioGene gene; private BioPathway pathway; + private BioCompartment compartment; + @Before public void init() { network = new BioNetwork(); @@ -62,8 +64,9 @@ public class SetNamesFromFileTest { protein = new BioProtein("p"); gene = new BioGene("g"); pathway = new BioPathway("pathway"); + compartment = new BioCompartment("cpt"); - network.add(reaction, metabolite, protein, gene, pathway); + network.add(reaction, metabolite, protein, gene, pathway, compartment); } @@ -166,6 +169,24 @@ public class SetNamesFromFileTest { } + @Test + public void setAttributesCompartment() throws IOException { + + SetNamesFromFile setNamesFromFile = Mockito.spy(new SetNamesFromFile(0, 1, network, "", "", 0, false, false, EntityType.COMPARTMENT)); + Mockito.doReturn(true).when(setNamesFromFile).parseAttributeFile(); + + String line = "cpt\tcompartment\n"; + + Boolean flag = setNamesFromFile.parseLine(line, 1); + + assertTrue(flag); + + setNamesFromFile.setAttributes(); + + assertEquals("compartment", compartment.getName()); + + } + } \ No newline at end of file -- GitLab From 0d9980f68f004010cbd5e698a5c9f9943672b3f7 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 07:48:32 +0100 Subject: [PATCH 18/21] add test for compartments --- .../attributes/SetRefsFromFileTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFileTest.java b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFileTest.java index 179d33846..6ffbbc186 100644 --- a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFileTest.java +++ b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetRefsFromFileTest.java @@ -54,6 +54,7 @@ public class SetRefsFromFileTest { private BioProtein protein; private BioPathway pathway; private BioGene gene; + private BioCompartment compartment; @Before public void init() { @@ -63,8 +64,9 @@ public class SetRefsFromFileTest { protein = new BioProtein("p"); pathway = new BioPathway("pathway"); gene = new BioGene("g"); + compartment = new BioCompartment("cpt"); - network.add(reaction, metabolite, protein, pathway, gene); + network.add(reaction, metabolite, protein, pathway, gene, compartment); } @Test @@ -156,4 +158,20 @@ public class SetRefsFromFileTest { assertTrue(pathway.getRefs().get("refTest").contains(refRef)); } + @Test + public void setAttributesCompartment() throws IOException { + SetRefsFromFile setRefsFromFile = Mockito.spy(new SetRefsFromFile(0, 1, network, "", "", 0, false, false, "refTest", EntityType.COMPARTMENT)); + Mockito.doReturn(true).when(setRefsFromFile).parseAttributeFile(); + + String line = "cpt\trefValue"; + Boolean flag = setRefsFromFile.parseLine(line, 1); + + assertTrue(flag); + + setRefsFromFile.setAttributes(); + assertTrue(compartment.getRefs().containsKey("refTest")); + BioRef refRef = new BioRef("attributeTable", "refTest", "refValue", 1); + assertTrue(compartment.getRefs().get("refTest").contains(refRef)); + } + } \ No newline at end of file -- GitLab From 2e5822955b93a6a13ef9012b0fa0828b2db9326c Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 09:58:41 +0100 Subject: [PATCH 19/21] met4j-io : add class SetIdsFromFile --- .../tabulated/attributes/SetIdsFromFile.java | 286 ++++++++++++++++++ .../attributes/SetIdsFromFileTest.java | 260 ++++++++++++++++ 2 files changed, 546 insertions(+) create mode 100644 met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFile.java create mode 100644 met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFileTest.java diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFile.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFile.java new file mode 100644 index 000000000..f32a689cb --- /dev/null +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFile.java @@ -0,0 +1,286 @@ +/* + * Copyright INRAE (2022) + * + * contact-metexplore@inrae.fr + * + * This software is a computer program whose purpose is to [describe + * functionalities and technical features of your software]. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "https://cecill.info/licences/Licence_CeCILL_V2.1-en.html". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ +package fr.inrae.toulouse.metexplore.met4j_io.tabulated.attributes; + +import fr.inrae.toulouse.metexplore.met4j_core.biodata.*; +import fr.inrae.toulouse.metexplore.met4j_core.utils.StringUtils; + +import java.io.IOException; + +public class SetIdsFromFile extends AbstractSetAttributesFromFile { + + + /** + * <p>Constructor for AbstractSetAttributesFromFile.</p> + * + * @param colId a int. + * @param colAttr : number of the attribute column + * @param bn : {@link BioNetwork} + * @param fileIn : tabulated file containing the ids and the attributes + * @param c : comment character + * @param nSkip a int. Number of lines to skip + * @param entityType a {@link EntityType} + * @param p a {@link Boolean} object : To match the objects in the sbml file, adds the prefix R_ to reactions and M_ to metabolites + * @param s a {@link Boolean} object : To match the objects in the sbml file, adds the suffix _comparmentID to metabolite + */ + public SetIdsFromFile(int colId, int colAttr, BioNetwork bn, String fileIn, String c, int nSkip, EntityType entityType, Boolean p, Boolean s) { + super(colId, colAttr, bn, fileIn, c, nSkip, entityType, p, s); + } + + @Override + public Boolean testAttribute(String attribute) { + return !StringUtils.isVoid(attribute); + } + + @Override + public Boolean setAttributes() throws IOException { + Boolean flag; + + try { + flag = this.parseAttributeFile(); + } catch (IOException e) { + return false; + } + + if (!flag) { + return false; + } + + int n = 0; + + for (String id : this.getIdAttributeMap().keySet()) { + + String newId = this.getIdAttributeMap().get(id); + + if (!id.equals(newId)) { + + n++; + + switch (entityType) { + case GENE: { + this.setGeneId(id, newId); + break; + } + case PATHWAY: { + this.setPathwayId(id, newId); + break; + } + case METABOLITE: { + this.setMetaboliteId(id, newId); + break; + } + case REACTION: { + this.setReactionId(id, newId); + break; + } + case COMPARTMENT: { + this.setCompartmentId(id, newId); + break; + } + default: { + throw new EntityTypeException("Entity type "+this.entityType+" not recognized"); + } + } + } + } + + System.err.println(n + " entities processed"); + + return flag; + } + + /** + * Replace a compartment with the same compartment with another id + * + * @param id : the original id + * @param newId : the new id + */ + private void setCompartmentId(String id, String newId) { + BioCompartment compartment = this.bn.getCompartment(id); + + if (compartment != null) { + BioCompartment newCompartment = new BioCompartment(compartment, newId); + this.bn.add(newCompartment); + + // Add metabolites + this.bn.affectToCompartment(newCompartment, compartment.getComponentsView()); + + // Change compartment in each left reactant + this.bn.getReactionsView().forEach(r -> { + r.getLeftReactantsView().forEach(reactant -> { + if (reactant.getLocation().equals(compartment)) { + BioMetabolite metabolite = reactant.getMetabolite(); + Double sto = reactant.getQuantity(); + this.bn.affectLeft(r, sto, newCompartment, metabolite); + this.bn.removeLeft(metabolite, compartment, r); + } + }); + }); + + // Change compartment in each right reactant + this.bn.getReactionsView().forEach(r -> { + r.getRightReactantsView().forEach(reactant -> { + if (reactant.getLocation().equals(compartment)) { + BioMetabolite metabolite = reactant.getMetabolite(); + Double sto = reactant.getQuantity(); + this.bn.affectRight(r, sto, newCompartment, metabolite); + this.bn.removeRight(metabolite, compartment, r); + } + }); + }); + + this.bn.removeOnCascade(compartment); + + } + } + + /** + * Replace a reaction with the same reaction with another id + * + * @param id : the original id + * @param newId : the new id + */ + private void setReactionId(String id, String newId) { + BioReaction reaction = this.bn.getReaction(id); + + if (reaction != null) { + BioReaction newReaction = new BioReaction(reaction, newId); + this.bn.add(newReaction); + + // Add enzymes + this.bn.affectEnzyme(newReaction, reaction.getEnzymesView()); + + // Change reaction in the pathways + this.bn.getPathwaysFromReaction(reaction).forEach(p -> { + this.bn.affectToPathway(p, newReaction); + }); + + // Add lefts and rights + this.bn.affectLeft(newReaction, reaction.getLeftReactantsView()); + this.bn.affectRight(newReaction, reaction.getRightReactantsView()); + + this.bn.removeOnCascade(reaction); + } + } + + /** + * Replace a metabolite with the same metabolite with another id + * + * @param id : the original id + * @param newId : the new id + */ + private void setMetaboliteId(String id, String newId) { + BioMetabolite metabolite = this.bn.getMetabolite(id); + + if (metabolite != null) { + BioMetabolite newMetabolite = new BioMetabolite(metabolite, newId); + this.bn.add(newMetabolite); + + // Change the metabolite in the compartments + this.bn.getCompartmentsView().stream().filter(c -> c.getComponentsView().contains(metabolite)).forEach(c -> { + this.bn.removeFromCompartment(c, metabolite); + this.bn.affectToCompartment(c, newMetabolite); + }); + + // Change the metabolite in the left reactants + this.bn.getReactionsView().forEach(r -> { + r.getLeftReactantsView().stream().filter(reactant -> reactant.getMetabolite().equals(metabolite)) + .forEach(reactant -> { + Double sto = reactant.getQuantity(); + BioCompartment cpt = reactant.getLocation(); + this.bn.affectLeft(r, sto, cpt, newMetabolite); + }); + }); + + // Change the metabolite in the right reactants + this.bn.getReactionsView().forEach(r -> + r.getRightReactantsView() + .stream().filter(reactant -> reactant.getMetabolite().equals(metabolite)) + .forEach(reactant -> { + Double sto = reactant.getQuantity(); + BioCompartment cpt = reactant.getLocation(); + this.bn.affectRight(r, sto, cpt, newMetabolite); + })); + + // Change the metabolite in the enzymes + this.bn.getEnzymesView(). + forEach(e -> e.getParticipantsView() + .stream().filter(p -> p.getPhysicalEntity().equals(metabolite)) + .forEach(partcipant -> { + Double sto = partcipant.getQuantity(); + this.bn.affectSubUnit(e, sto, newMetabolite); + })); + + this.bn.removeOnCascade(metabolite); + } + } + + /** + * Replace a pathway with the same pathway with another id + * + * @param id : the original id + * @param newId : the new id + */ + private void setPathwayId(String id, String newId) { + BioPathway originalPathway = this.bn.getPathway(id); + + if (originalPathway != null) { + BioPathway newPathway = new BioPathway(originalPathway, newId); + this.bn.add(newPathway); + this.bn.affectToPathway(newPathway, this.bn.getReactionsFromPathways(originalPathway)); + this.bn.removeOnCascade(originalPathway); + } + } + + /** + * Replace a gene with the same gene with another id + * + * @param id : the origina id + * @param newId : the new id + */ + private void setGeneId(String id, String newId) { + BioGene originalGene = this.bn.getGene(id); + + if (originalGene != null) { + BioGene newGene = new BioGene(originalGene, newId); + this.bn.add(newGene); + this.bn.getProteinsView().stream().filter(p -> p.getGene().equals(originalGene)).forEach(p -> { + this.bn.affectGeneProduct(p, newGene); + }); + this.bn.removeOnCascade(originalGene); + } + } +} diff --git a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFileTest.java b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFileTest.java new file mode 100644 index 000000000..579b835b8 --- /dev/null +++ b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/tabulated/attributes/SetIdsFromFileTest.java @@ -0,0 +1,260 @@ +/* + * Copyright INRAE (2022) + * + * contact-metexplore@inrae.fr + * + * This software is a computer program whose purpose is to [describe + * functionalities and technical features of your software]. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "https://cecill.info/licences/Licence_CeCILL_V2.1-en.html". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +package fr.inrae.toulouse.metexplore.met4j_io.tabulated.attributes; + +import fr.inrae.toulouse.metexplore.met4j_core.biodata.*; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.IOException; + +import static org.junit.Assert.*; + +public class SetIdsFromFileTest { + + + private BioNetwork network; + + private SetIdsFromFile setIdsFromFile; + + @Before + public void init() { + network = new BioNetwork(); + } + + @Test + public void setGeneIds() throws IOException { + BioGene gene = new BioGene("g1"); + BioProtein protein = new BioProtein("p1"); + + network.add(gene, protein); + + network.affectGeneProduct(protein, gene); + + setIdsFromFile = Mockito.spy(new SetIdsFromFile(0, 1, network, "", "", 0, EntityType.GENE,false, false)); + + Mockito.doReturn(true).when(setIdsFromFile).parseAttributeFile(); + + String line = "g1\tgene1\n"; + + Boolean flag = setIdsFromFile.parseLine(line, 1); + + assertTrue(flag); + + setIdsFromFile.setAttributes(); + + assertEquals(1, network.getGenesView().size()); + assertNotNull(network.getGene("gene1")); + + assertEquals(1, network.getProteinsView().size()); + + } + + @Test + public void setMetaboliteIds() throws IOException { + BioMetabolite metabolite = new BioMetabolite("m1"); + BioCompartment cpt = new BioCompartment("cpt"); + BioReaction r1 = new BioReaction("r1"); + BioReaction r2 = new BioReaction("r2"); + BioEnzyme e = new BioEnzyme("e"); + + network.add(metabolite, cpt, r1, r2, e); + + network.affectToCompartment(cpt, metabolite); + network.affectLeft(r1, 1.0, cpt, metabolite); + network.affectRight(r2, 1.0, cpt, metabolite); + network.affectSubUnit(e, 1.0, metabolite); + + setIdsFromFile = Mockito.spy(new SetIdsFromFile(0, 1, network, "", "", 0, EntityType.METABOLITE,false, false)); + + Mockito.doReturn(true).when(setIdsFromFile).parseAttributeFile(); + + String line = "m1\tmetabolite1\n"; + + Boolean flag = setIdsFromFile.parseLine(line, 1); + + assertTrue(flag); + + setIdsFromFile.setAttributes(); + + assertEquals(1, network.getMetabolitesView().size()); + + BioMetabolite newMetabolite = network.getMetabolite("metabolite1"); + + assertNotNull(newMetabolite); + + BioCompartment newCpt = network.getCompartment("cpt"); + + assertNotNull(newCpt); + + assertNotNull(newCpt.getComponentsView().get("metabolite1")); + + assertEquals(2, network.getReactionsView().size()); + + assertEquals(1, r1.getLeftsView().size()); + assertTrue(r1.getLeftsView().contains(newMetabolite)); + + assertEquals(1, r2.getRightsView().size()); + assertTrue(r2.getRightsView().contains(newMetabolite)); + + assertEquals(1, network.getEnzymesView().size()); + assertTrue(e.getParticipantsView().stream().anyMatch(p -> p.getPhysicalEntity().equals(newMetabolite))); + assertFalse(e.getParticipantsView().stream().anyMatch(p -> p.getPhysicalEntity().equals(metabolite))); + + } + + @Test + public void setPathwayIds() throws IOException { + BioPathway pathway = new BioPathway("p1"); + BioReaction r1 = new BioReaction("r1"); + BioReaction r2 = new BioReaction("r2"); + + network.add(pathway, r1, r2); + network.affectToPathway(pathway, r1, r2); + + setIdsFromFile = Mockito.spy(new SetIdsFromFile(0, 1, network, "", "", 0, EntityType.PATHWAY,false, false)); + + Mockito.doReturn(true).when(setIdsFromFile).parseAttributeFile(); + + String line = "p1\tpathway1\n"; + + Boolean flag = setIdsFromFile.parseLine(line, 1); + + assertTrue(flag); + + setIdsFromFile.setAttributes(); + + assertEquals(1, network.getPathwaysView().size()); + + BioPathway newPathway = network.getPathway("pathway1"); + assertNotNull(newPathway); + assertEquals(2, network.getReactionsFromPathways(newPathway).size()); + + } + + @Test + public void setReactionIds() throws IOException { + BioPathway pathway = new BioPathway("p1"); + BioReaction r1 = new BioReaction("r1"); + BioMetabolite metabolite = new BioMetabolite("m1"); + BioMetabolite metabolite2 = new BioMetabolite("m2"); + BioCompartment cpt = new BioCompartment("cpt"); + BioEnzyme e = new BioEnzyme("e"); + + this.network.add(pathway, r1, metabolite, metabolite2, cpt, e); + + this.network.affectToPathway(pathway, r1); + this.network.affectToCompartment(cpt, metabolite2, metabolite); + this.network.affectLeft(r1, 1.0, cpt, metabolite); + this.network.affectRight(r1, 1.0, cpt, metabolite2); + this.network.affectEnzyme(r1, e); + + setIdsFromFile = Mockito.spy(new SetIdsFromFile(0, 1, network, "", "", 0, EntityType.REACTION,false, false)); + + Mockito.doReturn(true).when(setIdsFromFile).parseAttributeFile(); + + String line = "r1\treaction1\n"; + + Boolean flag = setIdsFromFile.parseLine(line, 1); + + assertTrue(flag); + + setIdsFromFile.setAttributes(); + + assertEquals(1, network.getReactionsView().size()); + + BioReaction newReaction = network.getReaction("reaction1"); + + assertNotNull(newReaction); + + assertEquals(1, network.getPathwaysView().size()); + + assertEquals(1, network.getReactionsFromPathways(pathway).size()); + + assertTrue(network.getReactionsFromPathways(pathway).contains(newReaction)); + + assertTrue(r1.getEnzymesView().contains(e)); + + assertEquals(1, newReaction.getLeftsView().size()); + assertEquals(1, newReaction.getRightsView().size()); + } + + @Test + public void setCompartmentIds() throws IOException { + + BioReaction r1 = new BioReaction("r1"); + BioMetabolite metabolite = new BioMetabolite("m1"); + BioMetabolite metabolite2 = new BioMetabolite("m2"); + BioCompartment cpt = new BioCompartment("cpt"); + + this.network.add(r1, metabolite, metabolite2, cpt); + + this.network.affectToCompartment(cpt, metabolite2, metabolite); + this.network.affectLeft(r1, 1.0, cpt, metabolite); + this.network.affectRight(r1, 1.0, cpt, metabolite2); + + setIdsFromFile = Mockito.spy(new SetIdsFromFile(0, 1, network, "", "", 0, EntityType.COMPARTMENT,false, false)); + + Mockito.doReturn(true).when(setIdsFromFile).parseAttributeFile(); + + String line = "cpt\tcompartment\n"; + + Boolean flag = setIdsFromFile.parseLine(line, 1); + + assertTrue(flag); + + setIdsFromFile.setAttributes(); + + assertEquals(1, this.network.getCompartmentsView().size()); + + BioCompartment newCpt = this.network.getCompartment("compartment"); + + assertNotNull(newCpt); + + assertEquals(2, newCpt.getComponentsView().size()); + + assertEquals(1, this.network.getReactionsView().size()); + + assertEquals(1, r1.getLeftsView().size()); + assertEquals(1, r1.getRightsView().size()); + + assertTrue(r1.getLeftReactantsView().stream().allMatch(reactant -> reactant.getLocation().equals(newCpt))); + assertTrue(r1.getRightReactantsView().stream().allMatch(reactant -> reactant.getLocation().equals(newCpt))); + + } +} \ No newline at end of file -- GitLab From ff5428be183f86df7f4f4b8b53b25ca96d9eb9f0 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 10:50:13 +0100 Subject: [PATCH 20/21] met4j-toolbox: add SbmlSetIdsFromFile --- .../attributes/SbmlSetIdsFromFile.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 met4j-toolbox/src/main/java/fr/inrae/toulouse/metexplore/met4j_toolbox/attributes/SbmlSetIdsFromFile.java diff --git a/met4j-toolbox/src/main/java/fr/inrae/toulouse/metexplore/met4j_toolbox/attributes/SbmlSetIdsFromFile.java b/met4j-toolbox/src/main/java/fr/inrae/toulouse/metexplore/met4j_toolbox/attributes/SbmlSetIdsFromFile.java new file mode 100644 index 000000000..12def855d --- /dev/null +++ b/met4j-toolbox/src/main/java/fr/inrae/toulouse/metexplore/met4j_toolbox/attributes/SbmlSetIdsFromFile.java @@ -0,0 +1,112 @@ +/* + * Copyright INRAE (2022) + * + * contact-metexplore@inrae.fr + * + * This software is a computer program whose purpose is to [describe + * functionalities and technical features of your software]. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "https://cecill.info/licences/Licence_CeCILL_V2.1-en.html". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ +package fr.inrae.toulouse.metexplore.met4j_toolbox.attributes; + +import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioNetwork; +import fr.inrae.toulouse.metexplore.met4j_io.tabulated.attributes.SetIdsFromFile; +import fr.inrae.toulouse.metexplore.met4j_io.tabulated.attributes.SetNamesFromFile; +import fr.inrae.toulouse.metexplore.met4j_toolbox.generic.annotations.EnumParameterTypes; +import fr.inrae.toulouse.metexplore.met4j_toolbox.generic.annotations.ParameterType; +import org.kohsuke.args4j.Option; + +public class SbmlSetIdsFromFile extends AbstractSbmlSetAny { + + @ParameterType(name= EnumParameterTypes.Integer) + @Option(name="-cnew", usage="[2] number of the column where are the new ids") + public int colname=2; + + /** {@inheritDoc} */ + @Override + public String getLabel() { + return this.getClass().getSimpleName(); + } + + /** {@inheritDoc} */ + @Override + public String getLongDescription() { + return this.getShortDescription()+"\n" + + this.setDescription+"\n"; + } + + /** {@inheritDoc} */ + @Override + public String getShortDescription() { + return "Set new ids to network objects from a tabulated file containing the old ids and the new ids"; + } + + /** + * <p>main.</p> + * + * @param args an array of {@link java.lang.String} objects. + */ + public static void main(String[] args) { + + SbmlSetIdsFromFile app = new SbmlSetIdsFromFile(); + + app.parseArguments(args); + + app.run(); + + } + + private void run() { + + BioNetwork bn = this.readSbml(); + + SetIdsFromFile setter = new SetIdsFromFile(this.colid-1, this.colname-1, + bn, this.tab, this.c, this.nSkip, this.o, this.p, this.s); + + Boolean flag = true; + + try { + flag = setter.setAttributes(); + } catch (Exception e) { + flag=false; + } + + if(!flag) { + System.err.println("Error in "+this.getLabel()); + System.exit(1); + } + + this.writeSbml(bn); + + System.exit(0); + + + } + +} -- GitLab From 86837cfe0e9ebbe979ba7a0959d13b2435e8262c Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Tue, 15 Nov 2022 12:36:30 +0100 Subject: [PATCH 21/21] replace / by _ in the name of the branches Otherwise, the name of the branch is understood as a path in the singularity or docker registry --- .gitlab-ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 826bb9d63..b7eed923f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,8 +19,8 @@ stages: # version in lower case - if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" -a "$VERSION" != "$LOWER_CASE_VERSION" ]; then docker build -t "$DOCKER_IMAGE:$LOWER_CASE_VERSION" .; fi - if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" -a "$VERSION" != "$LOWER_CASE_VERSION" ]; then docker push "$DOCKER_IMAGE:$LOWER_CASE_VERSION"; fi - - docker build -t "$DOCKER_IMAGE:$CI_COMMIT_BRANCH" . - - docker push "$DOCKER_IMAGE:$CI_COMMIT_BRANCH" + - docker build -t "$DOCKER_IMAGE:$FORMATTED_COMMIT_BRANCH" . + - docker push "$DOCKER_IMAGE:$FORMATTED_COMMIT_BRANCH" # branch in lower case - docker build -t "$DOCKER_IMAGE:$LOWER_CASE_COMMIT_BRANCH" . - docker push "$DOCKER_IMAGE:$LOWER_CASE_COMMIT_BRANCH" @@ -56,9 +56,12 @@ build: - VERSION=$TRUEVERSION - if [ "$CI_COMMIT_BRANCH" = "master" ]; then VERSION=${VERSION%"-SNAPSHOT"}; fi - LOWER_CASE_VERSION=${VERSION,,} - - LOWER_CASE_COMMIT_BRANCH=${CI_COMMIT_BRANCH,,} + # Replace / by _ in the name of the commit + - FORMATTED_COMMIT_BRANCH=${CI_COMMIT_BRANCH//\//_} + - LOWER_CASE_COMMIT_BRANCH=${FORMATTED_COMMIT_BRANCH,,} - echo "VERSION=$VERSION" >> build.env - echo "TRUEVERSION=$TRUEVERSION" >> build.env + - echo "FORMATTED_COMMIT_BRANCH=$FORMATTED_COMMIT_BRANCH" >> build.env - echo "LOWER_CASE_VERSION=$LOWER_CASE_VERSION" >> build.env - echo "LOWER_CASE_COMMIT_BRANCH=$LOWER_CASE_COMMIT_BRANCH" >> build.env artifacts: @@ -162,7 +165,7 @@ buildSingularity: - if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" ]; then singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$VERSION"; fi # version in lower case - if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" -a "$VERSION" != "$LOWER_CASE_VERSION"]; then singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$LOWER_CASE_VERSION"; fi - - singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$CI_COMMIT_BRANCH" + - singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$FORMATTED_COMMIT_BRANCH" # branch in lower case - singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$LOWER_CASE_COMMIT_BRANCH" rules: -- GitLab