From 2c2a94e0e89bd11a7ffe14a182bb412945636ba2 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 8 Nov 2023 19:43:18 -0500 Subject: [PATCH] Add maven to repository, remove UI Processing and implement FBA draft --- .gitignore | 5 +- .project | 17 - pom.xml | 46 ++ src/main/java/metapenta/MetaPeNTA.java | 6 + .../commands/ConnectedComponents.java | 0 .../commands/DescribeMetabolicNetwork.java | 0 src/main/java/metapenta/commands/FBA.java | 6 + .../java}/metapenta/commands/GapFindGams.java | 0 .../java}/metapenta/commands/GetAllPaths.java | 0 .../commands/GetCommonMetabolites.java | 0 .../commands/GetCommonReactions.java | 0 .../commands/GetReactionsCatalyzedBy.java | 0 .../commands/MetabolicNetworkCSVWriter.java | 0 .../commands/ReactionsOfMetabolite.java | 0 .../ShortestPathByMetabolitesNumber.java | 0 .../java}/metapenta/commands/SinksFinder.java | 0 .../metapenta/commands/SourcesFinder.java | 0 .../metapenta/model/FluxBalanceAnalysis.java | 285 ++++++++++++ .../java}/metapenta/model/GeneProduct.java | 0 .../java}/metapenta/model/IMetaPenta.java | 3 +- .../java}/metapenta/model/MetaPenta.java | 9 +- .../metapenta/model/MetabolicNetwork.java | 2 +- .../model/MetabolicNetworkXMLLoader.java | 0 .../metapenta/model/MetabolicPetriNet.java | 0 .../java}/metapenta/model/Metabolite.java | 0 .../java}/metapenta/model/MetabolitesP.java | 0 .../java}/metapenta/model/Reaction.java | 0 .../metapenta/model/ReactionComponent.java | 0 .../java}/metapenta/petrinet/Edge.java | 0 .../java}/metapenta/petrinet/Place.java | 0 .../java}/metapenta/petrinet/Transition.java | 0 .../java}/metapenta/petrinet2/Attributes.java | 0 .../java}/metapenta/petrinet2/Edge.java | 0 .../java}/metapenta/petrinet2/IPetriNet.java | 0 .../java}/metapenta/petrinet2/PetriNet.java | 2 +- .../java}/metapenta/petrinet2/Place.java | 0 .../java}/metapenta/petrinet2/Transition.java | 0 .../metapenta/tools/CommandsDescriptor.java | 7 + .../metapenta/tools/CommandsDescriptor.xml | 7 + .../tools/io}/DescribeNetworkWriter.java | 2 +- .../java/metapenta/tools/io}/StringUtils.java | 4 +- src/metapenta/gui/Controller.java | 417 ----------------- src/metapenta/gui/Main.java | 8 - src/metapenta/gui/MetaPenta.java | 33 -- src/metapenta/gui/mainGUI.fxml | 319 ------------- .../processing/petrinet/Constants.java | 45 -- .../processing/petrinet/MySketch.java | 422 ------------------ .../processing/petrinet/NodeProcessing.java | 104 ----- .../processing/petrinet/PlaceProcessing.java | 7 - .../processing/petrinet/RGBTuple.java | 12 - .../petrinet/TransitionProcessing.java | 9 - .../processing/petrinet/Translator.java | 247 ---------- src/metapenta/tools/JsonWriter.java | 16 - 53 files changed, 375 insertions(+), 1665 deletions(-) delete mode 100644 .project create mode 100644 pom.xml create mode 100644 src/main/java/metapenta/MetaPeNTA.java rename src/{ => main/java}/metapenta/commands/ConnectedComponents.java (100%) rename src/{ => main/java}/metapenta/commands/DescribeMetabolicNetwork.java (100%) create mode 100644 src/main/java/metapenta/commands/FBA.java rename src/{ => main/java}/metapenta/commands/GapFindGams.java (100%) rename src/{ => main/java}/metapenta/commands/GetAllPaths.java (100%) rename src/{ => main/java}/metapenta/commands/GetCommonMetabolites.java (100%) rename src/{ => main/java}/metapenta/commands/GetCommonReactions.java (100%) rename src/{ => main/java}/metapenta/commands/GetReactionsCatalyzedBy.java (100%) rename src/{ => main/java}/metapenta/commands/MetabolicNetworkCSVWriter.java (100%) rename src/{ => main/java}/metapenta/commands/ReactionsOfMetabolite.java (100%) rename src/{ => main/java}/metapenta/commands/ShortestPathByMetabolitesNumber.java (100%) rename src/{ => main/java}/metapenta/commands/SinksFinder.java (100%) rename src/{ => main/java}/metapenta/commands/SourcesFinder.java (100%) create mode 100644 src/main/java/metapenta/model/FluxBalanceAnalysis.java rename src/{ => main/java}/metapenta/model/GeneProduct.java (100%) rename src/{ => main/java}/metapenta/model/IMetaPenta.java (68%) rename src/{ => main/java}/metapenta/model/MetaPenta.java (93%) rename src/{ => main/java}/metapenta/model/MetabolicNetwork.java (99%) rename src/{ => main/java}/metapenta/model/MetabolicNetworkXMLLoader.java (100%) rename src/{ => main/java}/metapenta/model/MetabolicPetriNet.java (100%) rename src/{ => main/java}/metapenta/model/Metabolite.java (100%) rename src/{ => main/java}/metapenta/model/MetabolitesP.java (100%) rename src/{ => main/java}/metapenta/model/Reaction.java (100%) rename src/{ => main/java}/metapenta/model/ReactionComponent.java (100%) rename src/{ => main/java}/metapenta/petrinet/Edge.java (100%) rename src/{ => main/java}/metapenta/petrinet/Place.java (100%) rename src/{ => main/java}/metapenta/petrinet/Transition.java (100%) rename src/{ => main/java}/metapenta/petrinet2/Attributes.java (100%) rename src/{ => main/java}/metapenta/petrinet2/Edge.java (100%) rename src/{ => main/java}/metapenta/petrinet2/IPetriNet.java (100%) rename src/{ => main/java}/metapenta/petrinet2/PetriNet.java (99%) rename src/{ => main/java}/metapenta/petrinet2/Place.java (100%) rename src/{ => main/java}/metapenta/petrinet2/Transition.java (100%) create mode 100644 src/main/java/metapenta/tools/CommandsDescriptor.java create mode 100644 src/main/java/metapenta/tools/CommandsDescriptor.xml rename src/{metapenta/tools => main/java/metapenta/tools/io}/DescribeNetworkWriter.java (99%) rename src/{metapenta/tools => main/java/metapenta/tools/io}/StringUtils.java (93%) delete mode 100644 src/metapenta/gui/Controller.java delete mode 100644 src/metapenta/gui/Main.java delete mode 100644 src/metapenta/gui/MetaPenta.java delete mode 100644 src/metapenta/gui/mainGUI.fxml delete mode 100644 src/metapenta/processing/petrinet/Constants.java delete mode 100644 src/metapenta/processing/petrinet/MySketch.java delete mode 100644 src/metapenta/processing/petrinet/NodeProcessing.java delete mode 100644 src/metapenta/processing/petrinet/PlaceProcessing.java delete mode 100644 src/metapenta/processing/petrinet/RGBTuple.java delete mode 100644 src/metapenta/processing/petrinet/TransitionProcessing.java delete mode 100644 src/metapenta/processing/petrinet/Translator.java delete mode 100644 src/metapenta/tools/JsonWriter.java diff --git a/.gitignore b/.gitignore index 19294a1..fcb5c98 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ /bin/ .idea MetaPeNTA.iml -/classes \ No newline at end of file +/classes +*.class +/target/* + diff --git a/.project b/.project deleted file mode 100644 index 34ddfa1..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - MetaPeNTA - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b89f289 --- /dev/null +++ b/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + metapenta + MetaPeNTA + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + 19 + 0.0.8 + + + + + + org.openjfx + javafx-controls + ${javafx.version} + + + org.apache.commons + commons-math3 + 3.6.1 + + + + + + + org.openjfx + javafx-maven-plugin + ${javafx.maven.plugin.version} + + metapenta.commands.ConnectedComponents + + + + + + \ No newline at end of file diff --git a/src/main/java/metapenta/MetaPeNTA.java b/src/main/java/metapenta/MetaPeNTA.java new file mode 100644 index 0000000..87d6ec4 --- /dev/null +++ b/src/main/java/metapenta/MetaPeNTA.java @@ -0,0 +1,6 @@ +package metapenta; + +public class MetaPeNTA { + + +} diff --git a/src/metapenta/commands/ConnectedComponents.java b/src/main/java/metapenta/commands/ConnectedComponents.java similarity index 100% rename from src/metapenta/commands/ConnectedComponents.java rename to src/main/java/metapenta/commands/ConnectedComponents.java diff --git a/src/metapenta/commands/DescribeMetabolicNetwork.java b/src/main/java/metapenta/commands/DescribeMetabolicNetwork.java similarity index 100% rename from src/metapenta/commands/DescribeMetabolicNetwork.java rename to src/main/java/metapenta/commands/DescribeMetabolicNetwork.java diff --git a/src/main/java/metapenta/commands/FBA.java b/src/main/java/metapenta/commands/FBA.java new file mode 100644 index 0000000..f3021c6 --- /dev/null +++ b/src/main/java/metapenta/commands/FBA.java @@ -0,0 +1,6 @@ +package metapenta.commands; + +public class FBA { + + +} diff --git a/src/metapenta/commands/GapFindGams.java b/src/main/java/metapenta/commands/GapFindGams.java similarity index 100% rename from src/metapenta/commands/GapFindGams.java rename to src/main/java/metapenta/commands/GapFindGams.java diff --git a/src/metapenta/commands/GetAllPaths.java b/src/main/java/metapenta/commands/GetAllPaths.java similarity index 100% rename from src/metapenta/commands/GetAllPaths.java rename to src/main/java/metapenta/commands/GetAllPaths.java diff --git a/src/metapenta/commands/GetCommonMetabolites.java b/src/main/java/metapenta/commands/GetCommonMetabolites.java similarity index 100% rename from src/metapenta/commands/GetCommonMetabolites.java rename to src/main/java/metapenta/commands/GetCommonMetabolites.java diff --git a/src/metapenta/commands/GetCommonReactions.java b/src/main/java/metapenta/commands/GetCommonReactions.java similarity index 100% rename from src/metapenta/commands/GetCommonReactions.java rename to src/main/java/metapenta/commands/GetCommonReactions.java diff --git a/src/metapenta/commands/GetReactionsCatalyzedBy.java b/src/main/java/metapenta/commands/GetReactionsCatalyzedBy.java similarity index 100% rename from src/metapenta/commands/GetReactionsCatalyzedBy.java rename to src/main/java/metapenta/commands/GetReactionsCatalyzedBy.java diff --git a/src/metapenta/commands/MetabolicNetworkCSVWriter.java b/src/main/java/metapenta/commands/MetabolicNetworkCSVWriter.java similarity index 100% rename from src/metapenta/commands/MetabolicNetworkCSVWriter.java rename to src/main/java/metapenta/commands/MetabolicNetworkCSVWriter.java diff --git a/src/metapenta/commands/ReactionsOfMetabolite.java b/src/main/java/metapenta/commands/ReactionsOfMetabolite.java similarity index 100% rename from src/metapenta/commands/ReactionsOfMetabolite.java rename to src/main/java/metapenta/commands/ReactionsOfMetabolite.java diff --git a/src/metapenta/commands/ShortestPathByMetabolitesNumber.java b/src/main/java/metapenta/commands/ShortestPathByMetabolitesNumber.java similarity index 100% rename from src/metapenta/commands/ShortestPathByMetabolitesNumber.java rename to src/main/java/metapenta/commands/ShortestPathByMetabolitesNumber.java diff --git a/src/metapenta/commands/SinksFinder.java b/src/main/java/metapenta/commands/SinksFinder.java similarity index 100% rename from src/metapenta/commands/SinksFinder.java rename to src/main/java/metapenta/commands/SinksFinder.java diff --git a/src/metapenta/commands/SourcesFinder.java b/src/main/java/metapenta/commands/SourcesFinder.java similarity index 100% rename from src/metapenta/commands/SourcesFinder.java rename to src/main/java/metapenta/commands/SourcesFinder.java diff --git a/src/main/java/metapenta/model/FluxBalanceAnalysis.java b/src/main/java/metapenta/model/FluxBalanceAnalysis.java new file mode 100644 index 0000000..8bc600f --- /dev/null +++ b/src/main/java/metapenta/model/FluxBalanceAnalysis.java @@ -0,0 +1,285 @@ +package metapenta.model; + +import metapenta.petrinet2.Edge; +import metapenta.petrinet2.Transition; +import metapenta.petrinet2.PetriNet; +import metapenta.petrinet2.Place; +import org.apache.commons.math3.linear.MatrixUtils; +import org.apache.commons.math3.linear.RealMatrix; +import org.apache.commons.math3.optim.*; +import org.apache.commons.math3.optim.linear.*; +import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; +import org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer; + +import java.util.*; + +public class FluxBalanceAnalysis { + private RealMatrix stequiometryMatrix; + private Map rowsMetabolites = new HashMap<>(); + private Map columnReactions = new HashMap<>(); + private ArrayList reactionsBounds = new ArrayList(); + private PetriNet petriNet; + + private int growthReactionIndex; + private static final double LOWER_LIMIT_NO_REVERSIBLE_RXN = 0; + private static final double UPPER_LIMIT_RXN = 1000; + private static final double LOWER_LIMIT_REVERSIBLE_RXN = -1000; + + FluxBalanceAnalysis(PetriNet petriNet, String growthReactionID) { + int actualColum = 0; + Set reactionsKeySet = petriNet.getTransitions().keySet(); + for (String reaction : reactionsKeySet) { + Reaction r = (Reaction) petriNet.getTransition(reaction).getObject(); + columnReactions.put(r.getId(), actualColum); + + if (r.getId().equals(growthReactionID)) { + growthReactionIndex = actualColum; + } + + actualColum++; + } + + int actualRow = 0; + Set metabolitesKeySet = petriNet.getPlaces().keySet(); + for (String metabolite : metabolitesKeySet) { + rowsMetabolites.put(petriNet.getPlace(metabolite).getID(), actualRow); + actualRow++; + } + + this.petriNet = petriNet; + loadStequiometryMatrix(); + } + + private void loadStequiometryMatrix() { + double[][] data = new double[petriNet.getPlaces().size()][petriNet.getTransitions().size()]; + + Set reactionsKeys = columnReactions.keySet(); + + for (String reaction : reactionsKeys) { + Integer columnReaction = columnReactions.get(reaction); + Reaction r = (Reaction) petriNet.getTransition(reaction).getObject(); + + double[] bounds = getReactionsBounds(r); + reactionsBounds.add(bounds); + + List reactants = r.getReactants(); + + for (ReactionComponent reactant : reactants) { + String metaboliteId = reactant.getMetabolite().getId(); + Integer rowMetabolite = rowsMetabolites.get(metaboliteId); + data[rowMetabolite][columnReaction] = -reactant.getStoichiometry(); + } + + List products = r.getProducts(); + + for (ReactionComponent product : products) { + String metaboliteId = product.getMetabolite().getId(); + int rowMetabolite = rowsMetabolites.get(metaboliteId); + data[rowMetabolite][columnReaction] = product.getStoichiometry(); + } + } + + stequiometryMatrix = MatrixUtils.createRealMatrix(data); + } + + private LinearObjectiveFunction getObjectiveFunction() { + double[] reactionVector = new double[columnReactions.size()]; + reactionVector[growthReactionIndex] = 1; + + return new LinearObjectiveFunction(reactionVector, 0); + } + + private LinearConstraintSet getConstraints() { + Collection constraints = new ArrayList(); + for (int i = 0; i < rowsMetabolites.size(); i++) { + double[] dmdt = stequiometryMatrix.getRow(i); + + LinearConstraint steadyStateConstraint = new LinearConstraint(dmdt, Relationship.EQ, 0); + Collection boundsConstraints = getLinearConstraintForBounds(reactionsBounds.get(i), i); + + constraints.add(steadyStateConstraint); + constraints.addAll(boundsConstraints); + + } + + return new LinearConstraintSet(constraints); + } + + private Collection getLinearConstraintForBounds(double[] bounds, int reactionNumber){ + double[] reactionVector = new double[columnReactions.size()]; + reactionVector[reactionNumber] = 1; + + LinearConstraint lowerBoundConstraint = new LinearConstraint(reactionVector, Relationship.GEQ, bounds[0]); + LinearConstraint upperBoundConstraint = new LinearConstraint(reactionVector, Relationship.LEQ, bounds[1]); + + Collection boundsConstraints = new ArrayList(); + boundsConstraints.add(lowerBoundConstraint); + boundsConstraints.add(upperBoundConstraint); + + + // Rea x Metabolito , [flujos], optimizar flujo [i - Indice donde esta la funcion de crecimiento] y las condiciones S*v = 0 <--- SS + + return boundsConstraints; + } + + private double[] getReactionsBounds(Reaction r) { + if (r.isReversible()) { + return new double[]{LOWER_LIMIT_REVERSIBLE_RXN, UPPER_LIMIT_RXN}; + } + + return new double[]{LOWER_LIMIT_NO_REVERSIBLE_RXN, UPPER_LIMIT_RXN}; + } + + public void Optimize() { + + LinearObjectiveFunction lof = getObjectiveFunction(); + LinearConstraintSet linearConstraints = getConstraints(); + + + double[] initialB = {1, 1, 1, 1, 1, 1}; + + MultivariateOptimizer optimizer = new SimplexSolver(); + + PointValuePair solution = optimizer.optimize( + new MaxIter(2000), + lof, + linearConstraints, + GoalType.MAXIMIZE); + + + double[] optimalB = solution.getPoint(); + System.out.println(Arrays.toString(optimalB)); + } + + + public static void main(String[] args) { + Metabolite a = new Metabolite("a", "a", "e"); + Metabolite b = new Metabolite("b", "b", "e"); + Metabolite c = new Metabolite("c", "c", "e"); + Metabolite d = new Metabolite("d", "d", "e"); + Metabolite e = new Metabolite("e", "e", "e"); + + List reactions = new ArrayList<>(); + + + //R1 Reaction + ReactionComponent r1a = new ReactionComponent(a,1); + ReactionComponent r1d = new ReactionComponent(d,1); + List reactantsR1 = new ArrayList(); + reactantsR1.add(r1a); + reactantsR1.add(r1d); + + ReactionComponent r1b = new ReactionComponent(b, 1); + List productsR1 = new ArrayList(); + productsR1.add(r1b); + + Reaction r1 = new Reaction("r1", "r1", reactantsR1, productsR1); + + //R2 Reaction + ReactionComponent r2b = new ReactionComponent(b,2); + List reactantsR2 = new ArrayList(); + reactantsR2.add(r2b); + + ReactionComponent r2e = new ReactionComponent(e,2); + List productsR2 = new ArrayList(); + productsR2.add(r2e); + + Reaction r2 = new Reaction("r2", "r2", reactantsR2, productsR2); + + //R3 Reaction + ReactionComponent r3e = new ReactionComponent(e,1); + List reactantsR3 = new ArrayList(); + reactantsR3.add(r3e); + + ReactionComponent r3a = new ReactionComponent(a,1); + List productsR3 = new ArrayList(); + productsR3.add(r3a); + + Reaction r3 = new Reaction("r3", "r3", reactantsR3, productsR3); + + //R4 Reaction + ReactionComponent r4b = new ReactionComponent(b,1); + ReactionComponent r4e = new ReactionComponent(e,1); + List reactantsR4 = new ArrayList(); + reactantsR4.add(r4b); + reactantsR4.add(r4e); + + ReactionComponent r4c = new ReactionComponent(c,2); + List productsR4 = new ArrayList(); + productsR4.add(r4c); + + Reaction r4 = new Reaction("r4", "r4", reactantsR4, productsR4); + + + //R5 Reaction + ReactionComponent r5a = new ReactionComponent(a,1); + List productsR5 = new ArrayList(); + productsR5.add(r5a); + + Reaction r5 = new Reaction("r5", "r5", new ArrayList<>(), productsR5); + r5.setReversible(true); + + + //R6 Reaction + ReactionComponent r6d = new ReactionComponent(d,1); + List productsR6 = new ArrayList(); + productsR6.add(r6d); + + Reaction r6 = new Reaction("r6", "r6", new ArrayList<>(), productsR6); + r6.setReversible(true); + + //R7 Reaction + ReactionComponent r7e = new ReactionComponent(e,1); + List productsR7 = new ArrayList(); + productsR6.add(r7e); + + Reaction r7 = new Reaction("r7", "r7", new ArrayList<>(), productsR7); + r7.setReversible(true); + + // Create and load PetriNet + PetriNet pn = new PetriNet(); + + pn.addPlace("a", new Place("a", "a", a)); + pn.addPlace("b", new Place("b", "b", b)); + pn.addPlace("c", new Place("c", "a", c)); + pn.addPlace("d", new Place("d", "d", d)); + pn.addPlace("e", new Place("e", "e", e)); + + reactions.add(r1); + reactions.add(r2); + reactions.add(r3); + reactions.add(r4); + reactions.add(r5); + reactions.add(r6); + reactions.add(r7); + + for (Reaction r: reactions) { + Transition t = new Transition(r.getId(), r.getName(), r); + + for (ReactionComponent reactant: r.getReactants()) { + Metabolite metabolite = reactant.getMetabolite(); + + Place place = pn.getPlace(metabolite.getId()); + Edge edge = new Edge<>(place, reactant.getStoichiometry()); + + t.AddEdgeIn(edge); + } + + for (ReactionComponent reactant: r.getProducts()) { + Metabolite metabolite = reactant.getMetabolite(); + + Place place = pn.getPlace(metabolite.getId()); + Edge edge = new Edge<>(place, reactant.getStoichiometry()); + + t.AddEdgeOut(edge); + } + + pn.AddTransition(t.getID(), t); + } + + FluxBalanceAnalysis fba = new FluxBalanceAnalysis(pn, "r4"); + fba.Optimize(); + + } + +} \ No newline at end of file diff --git a/src/metapenta/model/GeneProduct.java b/src/main/java/metapenta/model/GeneProduct.java similarity index 100% rename from src/metapenta/model/GeneProduct.java rename to src/main/java/metapenta/model/GeneProduct.java diff --git a/src/metapenta/model/IMetaPenta.java b/src/main/java/metapenta/model/IMetaPenta.java similarity index 68% rename from src/metapenta/model/IMetaPenta.java rename to src/main/java/metapenta/model/IMetaPenta.java index 3960117..eadc97e 100644 --- a/src/metapenta/model/IMetaPenta.java +++ b/src/main/java/metapenta/model/IMetaPenta.java @@ -1,9 +1,10 @@ package metapenta.model; import java.io.IOException; +import java.util.ArrayList; public interface IMetaPenta { void describeMetabolicNetwork(String outFilePrefix) throws Exception; void getSinks(String outFilePrefix) throws Exception; - + ArrayList fluxVector(String outFilePrefix) throws Exception; } diff --git a/src/metapenta/model/MetaPenta.java b/src/main/java/metapenta/model/MetaPenta.java similarity index 93% rename from src/metapenta/model/MetaPenta.java rename to src/main/java/metapenta/model/MetaPenta.java index 6848197..9d2eca8 100644 --- a/src/metapenta/model/MetaPenta.java +++ b/src/main/java/metapenta/model/MetaPenta.java @@ -33,6 +33,13 @@ public void getSinks(String outFilePrefix) throws Exception { petriNet.getSinks(); } + @Override + public ArrayList fluxVector(String outFilePrefix) throws Exception { + + return null; + } + + private void loadPetriNet(MetabolicNetwork network){ List keysReaction = network.getReactionIds(); for (String key : keysReaction) { @@ -71,7 +78,7 @@ private List loadMetabolitesAndCreateEdgeList(List reac place = createAndAddPlaceToNet(metabolite); } - Edge edge = new Edge<>(place, reactionComponent.getStoichiometry()); + Edge edge = new Edge(place, reactionComponent.getStoichiometry()); edges.add(edge); } diff --git a/src/metapenta/model/MetabolicNetwork.java b/src/main/java/metapenta/model/MetabolicNetwork.java similarity index 99% rename from src/metapenta/model/MetabolicNetwork.java rename to src/main/java/metapenta/model/MetabolicNetwork.java index f18bb4b..df326c1 100644 --- a/src/metapenta/model/MetabolicNetwork.java +++ b/src/main/java/metapenta/model/MetabolicNetwork.java @@ -17,7 +17,7 @@ import metapenta.petrinet.Edge; import metapenta.petrinet.Place; import metapenta.petrinet.Transition; -import metapenta.tools.DescribeNetworkWriter; +import metapenta.tools.io.DescribeNetworkWriter; /** * Represents a metabolic network of reactions on metabolites diff --git a/src/metapenta/model/MetabolicNetworkXMLLoader.java b/src/main/java/metapenta/model/MetabolicNetworkXMLLoader.java similarity index 100% rename from src/metapenta/model/MetabolicNetworkXMLLoader.java rename to src/main/java/metapenta/model/MetabolicNetworkXMLLoader.java diff --git a/src/metapenta/model/MetabolicPetriNet.java b/src/main/java/metapenta/model/MetabolicPetriNet.java similarity index 100% rename from src/metapenta/model/MetabolicPetriNet.java rename to src/main/java/metapenta/model/MetabolicPetriNet.java diff --git a/src/metapenta/model/Metabolite.java b/src/main/java/metapenta/model/Metabolite.java similarity index 100% rename from src/metapenta/model/Metabolite.java rename to src/main/java/metapenta/model/Metabolite.java diff --git a/src/metapenta/model/MetabolitesP.java b/src/main/java/metapenta/model/MetabolitesP.java similarity index 100% rename from src/metapenta/model/MetabolitesP.java rename to src/main/java/metapenta/model/MetabolitesP.java diff --git a/src/metapenta/model/Reaction.java b/src/main/java/metapenta/model/Reaction.java similarity index 100% rename from src/metapenta/model/Reaction.java rename to src/main/java/metapenta/model/Reaction.java diff --git a/src/metapenta/model/ReactionComponent.java b/src/main/java/metapenta/model/ReactionComponent.java similarity index 100% rename from src/metapenta/model/ReactionComponent.java rename to src/main/java/metapenta/model/ReactionComponent.java diff --git a/src/metapenta/petrinet/Edge.java b/src/main/java/metapenta/petrinet/Edge.java similarity index 100% rename from src/metapenta/petrinet/Edge.java rename to src/main/java/metapenta/petrinet/Edge.java diff --git a/src/metapenta/petrinet/Place.java b/src/main/java/metapenta/petrinet/Place.java similarity index 100% rename from src/metapenta/petrinet/Place.java rename to src/main/java/metapenta/petrinet/Place.java diff --git a/src/metapenta/petrinet/Transition.java b/src/main/java/metapenta/petrinet/Transition.java similarity index 100% rename from src/metapenta/petrinet/Transition.java rename to src/main/java/metapenta/petrinet/Transition.java diff --git a/src/metapenta/petrinet2/Attributes.java b/src/main/java/metapenta/petrinet2/Attributes.java similarity index 100% rename from src/metapenta/petrinet2/Attributes.java rename to src/main/java/metapenta/petrinet2/Attributes.java diff --git a/src/metapenta/petrinet2/Edge.java b/src/main/java/metapenta/petrinet2/Edge.java similarity index 100% rename from src/metapenta/petrinet2/Edge.java rename to src/main/java/metapenta/petrinet2/Edge.java diff --git a/src/metapenta/petrinet2/IPetriNet.java b/src/main/java/metapenta/petrinet2/IPetriNet.java similarity index 100% rename from src/metapenta/petrinet2/IPetriNet.java rename to src/main/java/metapenta/petrinet2/IPetriNet.java diff --git a/src/metapenta/petrinet2/PetriNet.java b/src/main/java/metapenta/petrinet2/PetriNet.java similarity index 99% rename from src/metapenta/petrinet2/PetriNet.java rename to src/main/java/metapenta/petrinet2/PetriNet.java index 70aeb43..d5a88ea 100644 --- a/src/metapenta/petrinet2/PetriNet.java +++ b/src/main/java/metapenta/petrinet2/PetriNet.java @@ -3,7 +3,7 @@ import metapenta.model.Metabolite; import metapenta.model.Reaction; import metapenta.model.ReactionComponent; -import metapenta.tools.DescribeNetworkWriter; +import metapenta.tools.io.DescribeNetworkWriter; import java.util.*; diff --git a/src/metapenta/petrinet2/Place.java b/src/main/java/metapenta/petrinet2/Place.java similarity index 100% rename from src/metapenta/petrinet2/Place.java rename to src/main/java/metapenta/petrinet2/Place.java diff --git a/src/metapenta/petrinet2/Transition.java b/src/main/java/metapenta/petrinet2/Transition.java similarity index 100% rename from src/metapenta/petrinet2/Transition.java rename to src/main/java/metapenta/petrinet2/Transition.java diff --git a/src/main/java/metapenta/tools/CommandsDescriptor.java b/src/main/java/metapenta/tools/CommandsDescriptor.java new file mode 100644 index 0000000..c371373 --- /dev/null +++ b/src/main/java/metapenta/tools/CommandsDescriptor.java @@ -0,0 +1,7 @@ +package metapenta.tools; + +public class CommandsDescriptor { + public static CommandsDescriptor instance = new CommandsDescriptor(); + + +} diff --git a/src/main/java/metapenta/tools/CommandsDescriptor.xml b/src/main/java/metapenta/tools/CommandsDescriptor.xml new file mode 100644 index 0000000..3b6c0b5 --- /dev/null +++ b/src/main/java/metapenta/tools/CommandsDescriptor.xml @@ -0,0 +1,7 @@ + + Metabolic Petri Nets + + + De-novo and reference guided reads processing + + \ No newline at end of file diff --git a/src/metapenta/tools/DescribeNetworkWriter.java b/src/main/java/metapenta/tools/io/DescribeNetworkWriter.java similarity index 99% rename from src/metapenta/tools/DescribeNetworkWriter.java rename to src/main/java/metapenta/tools/io/DescribeNetworkWriter.java index 9b32575..5753acb 100644 --- a/src/metapenta/tools/DescribeNetworkWriter.java +++ b/src/main/java/metapenta/tools/io/DescribeNetworkWriter.java @@ -1,4 +1,4 @@ -package metapenta.tools; +package metapenta.tools.io; import java.nio.file.Files; import java.nio.file.Paths; diff --git a/src/metapenta/tools/StringUtils.java b/src/main/java/metapenta/tools/io/StringUtils.java similarity index 93% rename from src/metapenta/tools/StringUtils.java rename to src/main/java/metapenta/tools/io/StringUtils.java index 28117c5..c773598 100644 --- a/src/metapenta/tools/StringUtils.java +++ b/src/main/java/metapenta/tools/io/StringUtils.java @@ -1,6 +1,4 @@ -package metapenta.tools; - -import java.util.SplittableRandom; +package metapenta.tools.io; public class StringUtils { diff --git a/src/metapenta/gui/Controller.java b/src/metapenta/gui/Controller.java deleted file mode 100644 index f398102..0000000 --- a/src/metapenta/gui/Controller.java +++ /dev/null @@ -1,417 +0,0 @@ -package metapenta.gui; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.ResourceBundle; -import java.util.Set; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.canvas.Canvas; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextInputDialog; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.HBox; -import javafx.scene.text.Text; -import javafx.stage.FileChooser; -import javafx.stage.Stage; -import metapenta.model.MetabolicNetwork; -import metapenta.model.MetabolicNetworkXMLLoader; -import metapenta.processing.petrinet.MySketch; -import metapenta.processing.petrinet.Translator; -import processing.javafx.PSurfaceFX; -/** - * JavaFX MVC model controller class - * @author Valerie Parra Cortés - */ -public class Controller implements Initializable { - /** - * Main class of world - */ - public MetabolicNetwork metabolicNetwork; - /** - * Surface that allows us to communicate with the main class of processing - */ - public static PSurfaceFX surface; - /** - * Reference to processing main class - */ - public static MySketch metabolicNetworkProcessing; - /** - * Stage that will be used to display processing - */ - protected static Stage stage; - /** - * Class that translates the model used in the world so that it can be painted in the interface - */ - private Translator translator; - - @FXML - Text details_title; - - @FXML - AnchorPane processing; - - @FXML - HBox options_bar; - - @FXML - ChoiceBox metabolite_list; - - @FXML - TextArea initialMetabolites; - - @FXML - TextArea targetMetabolite; - - @FXML - Button findPathButton; - - @FXML - Button downloadPathButton; - - @FXML - TextArea entryMetabolite; - - @FXML - Button findReactionMetaboliteButton; - - @FXML - Button downloadReactionsMetaboliteButton; - - @FXML - CheckBox sinksSourcesCheckBox; - - @FXML - CheckBox connectedComponentsCheckbox; - - @FXML - Button downloadFilesButton; - - @FXML - CheckBox isSubstrateCheckBox; - - @FXML - CheckBox isProductCheckBox; - - @FXML - CheckBox gapFindFilesCheckBox; - - List lista; - - List initialMetabolitesString; - String targetStringMetabolite; - String metaboliteName; - - @Override - public void initialize(URL arg0, ResourceBundle arg1) { - // These lines allow you to tell processing in which panel the entire JavaFX scene will be drawn - Canvas canvas = (Canvas) surface.getNative(); - surface.fx.context = canvas.getGraphicsContext2D(); - processing.getChildren().add(canvas); - canvas.widthProperty().bind(processing.widthProperty()); - canvas.heightProperty().bind(processing.heightProperty()); - } - - - /** - * Method that load a metabolic network enter by parameters - * @param event of button action (not used) - */ - @FXML - public void loadButtonAction(ActionEvent event){ - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Select the metabolic network file"); - File file = fileChooser.showOpenDialog(null); - if(file!=null) { - MetabolicNetworkXMLLoader loader = new MetabolicNetworkXMLLoader(); - try { - this.metabolicNetwork = loader.loadNetwork(file.getCanonicalPath()); - this.metabolicNetwork.makeNet(); - translator = new Translator(metabolicNetwork); - enableComponets(); - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle("Sucess"); - alert.setHeaderText("Successfully uploaded"); - alert.setContentText("The information of the network was updated successfully"); - alert.showAndWait(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - - /** - * Method that calculates and show the metabolic path - */ - @FXML - public void findMetabolicPath() { - boolean notNull = true; - translator.resetSubnet(); - assignAttributesToMetabolicNetwork(); - downloadPathButton.setDisable(true); - - String[] initialMetabolitesString = initialMetabolites.getText().split(","); - targetStringMetabolite = targetMetabolite.getText(); - - if(initialMetabolitesString.length==0||targetStringMetabolite.equals("")) { - notNull=false; - - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("Please fill in all the fields in order to calculate your route"); - alert.showAndWait(); - - } - - - if(notNull) { - boolean correctInput = true; - List im= new ArrayList(); - if(metabolicNetwork.getMetabolite(targetStringMetabolite)==null) { - correctInput = false; - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("The final metabolite is not in the network. Please check the IDs and try again."); - alert.showAndWait(); - } - - for (int i = 0; i < initialMetabolitesString.length && correctInput; i++) { - im.add(initialMetabolitesString[i]); - if(metabolicNetwork.getMetabolite(initialMetabolitesString[i])==null) { - correctInput = false; - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("One of the input metabolites is not defined. Please check the id."); - alert.showAndWait(); - break; - } - } - - lista = im; - - if(correctInput) { - Set reactions = translator.shortestPathByMetabolitesNumber(im, targetStringMetabolite); - if(reactions.isEmpty()) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("It is not possible with these initial metabolites to reach the final metabolite"); - alert.showAndWait(); - } - downloadPathButton.setDisable(false); - assignAttributesToMetabolicNetwork(); - } - - } - } - - - - /** - * Method to init the petri net of processing class - */ - public void assignAttributesToMetabolicNetwork() { - metabolicNetworkProcessing.positionTransitions = translator.positionTransitions; - metabolicNetworkProcessing.positionsPlaces = translator.positionsPlaces; - metabolicNetworkProcessing.adjacencyMatrix = translator.adjacencyMatrix; - metabolicNetworkProcessing.adjacencyMatrixWeightsTP = translator.adjacencyMatrixWeightsTP; - metabolicNetworkProcessing.adjacencyMatrixWeightsPT = translator.adjacencyMatrixWeightsPT; - metabolicNetworkProcessing.translator = translator; - } - - @FXML - public void downloadButtonAction(ActionEvent event) { - - } - - - /** - * Method to enable the components of UI where a network was upload - */ - private void enableComponets(){ - initialMetabolites.setEditable(true); - targetMetabolite.setEditable(true); - findPathButton.setDisable(false); - entryMetabolite.setEditable(true); - findReactionMetaboliteButton.setDisable(false); - sinksSourcesCheckBox.setDisable(false); - connectedComponentsCheckbox.setDisable(false); - downloadFilesButton.setDisable(false); - isSubstrateCheckBox.setDisable(false); - isProductCheckBox.setDisable(false); - downloadFilesButton.setDisable(false); - sinksSourcesCheckBox.setDisable(false); - connectedComponentsCheckbox.setDisable(false); - gapFindFilesCheckBox.setDisable(false); - - } - - /** - * Method that allows to the user download the information of path calculated - * @param event of button action (not used) - */ - - @FXML - public void pathButtonAction(ActionEvent event) { - TextInputDialog td = new TextInputDialog("metabolicNetworkFileName"); - td.setHeaderText("Enter the suffix of the files"); - Optional result =td.showAndWait(); - result.ifPresent(name -> { - try { - String file1 = name+"_metabolicNetwork.txt"; - String file2 = name+"_reactions.txt"; - String file3 = name+"_catalysts.txt"; - metabolicNetwork.printShortestPath(file1, file2, file3, lista, targetStringMetabolite); - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle("Success"); - alert.setHeaderText("Success creating files"); - alert.setContentText("The files were generated successfully"); - alert.showAndWait(); - } catch (FileNotFoundException e) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("An error occurred, please try again"); - alert.showAndWait(); - } - }); - } - - - /** - * Method to download the reaction of the current metabolite - */ - @FXML - public void downloadReactionsMetabolites() { - TextInputDialog td = new TextInputDialog("metabolicNetworkFileName"); - td.setHeaderText("Enter the name of file"); - Optional result =td.showAndWait(); - result.ifPresent(name -> { - try { - String file1 = name; - metabolicNetwork.printInAFileReactionsOfMetabolite(metaboliteName, file1); - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle("Success"); - alert.setHeaderText("Success creating files"); - alert.setContentText("The files were generated successfully"); - alert.showAndWait(); - } catch (FileNotFoundException e) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("An error occurred, please try again"); - alert.showAndWait(); - } - }); - } - - - /** - * Method to download the files of sink, sources and connected components - */ - - public void downloadFiles() { - if(!sinksSourcesCheckBox.isSelected()&&!connectedComponentsCheckbox.isSelected()) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error downloading the files"); - alert.setContentText("Please select a type of analysis"); - alert.showAndWait(); - } - else { - TextInputDialog td = new TextInputDialog("metabolicNetworkFileName"); - td.setHeaderText("Enter the suffix of the files"); - Optional result =td.showAndWait(); - result.ifPresent(name -> { - - try { - if(sinksSourcesCheckBox.isSelected()) { - metabolicNetwork.printsSinksInAFile(name+"_sinks.txt"); - metabolicNetwork.printsSourcesInAFile(name+"_sources.txt"); - } - if(connectedComponentsCheckbox.isSelected()) { - metabolicNetwork.printConnectedComponents(name+"_cc.txt"); - } - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle("Success"); - alert.setHeaderText("Success creating files"); - alert.setContentText("The files were generated successfully"); - alert.showAndWait(); - } catch (FileNotFoundException e) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("An error occurred, please try again"); - alert.showAndWait(); - } catch (IOException e) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the path"); - alert.setContentText("An error occurred, please try again"); - alert.showAndWait(); - } - - }); - } - } - - - /** - * Method that resets the metabolic network network - * @param event - */ - - @FXML - public void cleanButtonAction(ActionEvent event) { - translator.resetSubnet(); - assignAttributesToMetabolicNetwork(); - } - /** - * Method to shows the reaction of currect selected metabolite - * @param event of button (not used) - */ - - @FXML - public void reactionsButtonAction(ActionEvent event) { - translator.resetSubnet(); - assignAttributesToMetabolicNetwork(); - boolean productsb = isProductCheckBox.isSelected(); - boolean substrateb = isSubstrateCheckBox.isSelected(); - String metabolite = entryMetabolite.getText(); - if(metabolite.equals("")) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the reactions"); - alert.setContentText("You must indicate the id of the metabolite to which you want to visualize the reactions."); - alert.showAndWait(); - } - else if(metabolicNetwork.getMetabolite(metabolite)==null) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Error calculating the reactions"); - alert.setContentText("The id entered is invalid"); - alert.showAndWait(); - } - else { - metaboliteName = metabolite; - translator.getReactionsOfMetabolite(metabolite, productsb, substrateb); - assignAttributesToMetabolicNetwork(); - downloadReactionsMetaboliteButton.setDisable(false); - } - } -} diff --git a/src/metapenta/gui/Main.java b/src/metapenta/gui/Main.java deleted file mode 100644 index a91295c..0000000 --- a/src/metapenta/gui/Main.java +++ /dev/null @@ -1,8 +0,0 @@ - package metapenta.gui; -import metapenta.processing.petrinet.MySketch; -import processing.core.PApplet; -public class Main { - public static void main(String[] args) { - PApplet.main(MySketch.class.getName()); - } -} \ No newline at end of file diff --git a/src/metapenta/gui/MetaPenta.java b/src/metapenta/gui/MetaPenta.java deleted file mode 100644 index dcc8b7e..0000000 --- a/src/metapenta/gui/MetaPenta.java +++ /dev/null @@ -1,33 +0,0 @@ -package metapenta.gui; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; -import processing.javafx.PSurfaceFX; -/** - * Class to init the Stage of JavaFX processing scenes - * @author vparrac - * - */ -public class MetaPenta extends Application { - /** - * Surface of Processing - */ - public static PSurfaceFX surface; - @Override - public void start(Stage primaryStage) throws Exception { - FXMLLoader loader = new FXMLLoader(getClass().getResource("mainGUI.fxml")); - Parent root = loader.load(); - Controller.stage = primaryStage; - Scene scene = new Scene(root, 1280, 720); - primaryStage.setTitle("MetaPenta"); - primaryStage.setScene(scene); - primaryStage.show(); - surface.stage = primaryStage; - Controller.stage = primaryStage; - } - - -} diff --git a/src/metapenta/gui/mainGUI.fxml b/src/metapenta/gui/mainGUI.fxml deleted file mode 100644 index 5c0b029..0000000 --- a/src/metapenta/gui/mainGUI.fxml +++ /dev/null @@ -1,319 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -