Git Lab CI for docker build enabled! You can enable it using .gitlab-ci.yml in your project. Check file template at https://gitlab.bio.di.uminho.pt/snippets/5

Commit ca93f33c authored by Davide Lagoa's avatar Davide Lagoa
Browse files

correct reversibility and direction method created

parent 8cc73050
...@@ -393,7 +393,13 @@ public class FetchCompoundsByName { ...@@ -393,7 +393,13 @@ public class FetchCompoundsByName {
// } // }
// } // }
} }
if(name.equalsIgnoreCase("Solute"))
System.out.println();
if(Utilities.processBiosynthName(name).equalsIgnoreCase("Solute"))
System.out.println();
compounds.put(Utilities.processBiosynthName(name), references); compounds.put(Utilities.processBiosynthName(name), references);
namesWithoutSigns.put(name, name.replaceAll("[^A-Za-z0-9]", "")); namesWithoutSigns.put(name, name.replaceAll("[^A-Za-z0-9]", ""));
......
...@@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; ...@@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.transyt.service.biosynth.initializeNeo4jdb; import pt.uminho.ceb.biosystems.transyt.service.biosynth.initializeNeo4jdb;
import pt.uminho.ceb.biosystems.transyt.service.containers.BiosynthMetabolites; import pt.uminho.ceb.biosystems.transyt.service.containers.BiosynthMetabolites;
import pt.uminho.ceb.biosystems.transyt.service.reactions.IdentifyReactionsMetabolites;
import pt.uminho.ceb.biosystems.transyt.service.reactions.TransportReactionsBuilder; import pt.uminho.ceb.biosystems.transyt.service.reactions.TransportReactionsBuilder;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.PopulateTransytNeo4jDatabase; import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.PopulateTransytNeo4jDatabase;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.BiosynthMetaboliteProperties; import pt.uminho.ceb.biosystems.transyt.utilities.capsules.BiosynthMetaboliteProperties;
...@@ -42,6 +43,15 @@ public class WriteByMetabolitesID { ...@@ -42,6 +43,15 @@ public class WriteByMetabolitesID {
BiodbGraphDatabaseService service = new BiodbGraphDatabaseService(graphDatabaseService); BiodbGraphDatabaseService service = new BiodbGraphDatabaseService(graphDatabaseService);
// BiosynthMetabolites l = new FetchCompoundsByName(service, false).getResults();
//
//
// dataTx.failure();
// dataTx.close();
// service.shutdown();
// graphDatabaseService.shutdown();
// System.out.println("Shutdown!!!");
// BiodbGraphDatabaseService service = null; // BiodbGraphDatabaseService service = null;
logger.info("Retrieving data from Biosynth database..."); logger.info("Retrieving data from Biosynth database...");
...@@ -60,7 +70,7 @@ public class WriteByMetabolitesID { ...@@ -60,7 +70,7 @@ public class WriteByMetabolitesID {
BiosynthMetabolites namesAndIDsContainer = new FetchCompoundsByName(service, false).getResults(); //168966 names BiosynthMetabolites namesAndIDsContainer = new FetchCompoundsByName(service, false).getResults(); //168966 names
Map<String, Set<TcNumberContainer2>> reactionsData = JSONFilesUtils.readJSONtcdbReactionsFile(); //uncomment Map<String, Set<TcNumberContainer2>> reactionsData = JSONFilesUtils.readJSONtcdbReactionsFile(); //uncomment
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>(); // Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
...@@ -74,29 +84,28 @@ public class WriteByMetabolitesID { ...@@ -74,29 +84,28 @@ public class WriteByMetabolitesID {
// Map<String, String[]> forChildsSearch = metabolitesIdentification.getforChildsSearch(); // Map<String, String[]> forChildsSearch = metabolitesIdentification.getforChildsSearch();
// int n = 1; int n = 1;
//
// while (n != 99) { while (n != 99) {
//
// n = 99;
n = 99;
Map<String, Set<TcNumberContainer2>> newData = test(namesAndIDsContainer, data, service, reactionsData, properties); //uncomment Map<String, Set<TcNumberContainer2>> newData = test(namesAndIDsContainer, data, service, reactionsData, properties); //uncomment
// test2(service, data, namesAndIDsContainer); // test2(service, data, namesAndIDsContainer);
new PopulateTransytNeo4jDatabase(data, newData, properties); //uncomment // new PopulateTransytNeo4jDatabase(data, newData, properties); //uncomment
// System.out.println("Enter a random number to repeat (100 to repeat data retrieval) or 99 to finish: "); System.out.println("Enter a random number to repeat (100 to repeat data retrieval) or 99 to finish: ");
//
// try { try {
// n = reader.nextInt(); n = reader.nextInt();
// } catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); e.printStackTrace();
//
// n = reader.nextInt(); n = reader.nextInt();
// } }
//
// } }
dataTx.failure(); dataTx.failure();
dataTx.close(); dataTx.close();
service.shutdown(); service.shutdown();
...@@ -231,38 +240,38 @@ public class WriteByMetabolitesID { ...@@ -231,38 +240,38 @@ public class WriteByMetabolitesID {
try { try {
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>(); Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
// String[] accessions = new String[] {"P75757", "O85143", "O07084", "P13512", "A0QQH3"}; String[] accessions = new String[] {"O06933"};
//
// for(String acc : accessions) for(String acc : accessions)
// reactionsData2.put(acc, reactionsData.get(acc)); reactionsData2.put(acc, reactionsData.get(acc));
/////TRANSYT /////TRANSYT
Map<String, Set<TcNumberContainer2>> newData = new TransportReactionsBuilder(reactionsData, service, data, namesAndIDsContainer, properties).getResults(); //uncomment Map<String, Set<TcNumberContainer2>> newData = new TransportReactionsBuilder(reactionsData2, service, data, namesAndIDsContainer, properties).getResults(); //uncomment
// for(TcNumberContainer2 container : newData.get("P75757")) { for(TcNumberContainer2 container : newData.get("O06933")) {
//
// System.out.println(container.getTcNumber()); System.out.println(container.getTcNumber());
//
// for( Integer id : container.getAllReactionsIds()) { for( Integer id : container.getAllReactionsIds()) {
// System.out.println(); System.out.println();
//
// System.out.println(container.getReactionContainer(id).getReactionID()); System.out.println(container.getReactionContainer(id).getReactionID());
// System.out.println(container.getReactionContainer(id).getMetaReactionID()); System.out.println(container.getReactionContainer(id).getMetaReactionID());
// System.out.println(container.getReactionContainer(id).getCompartmentalizedReactionID()); System.out.println(container.getReactionContainer(id).getCompartmentalizedReactionID());
// System.out.println(container.getReactionContainer(id).getReaction()); System.out.println(container.getReactionContainer(id).getReaction());
// System.out.println(container.getReactionContainer(id).getReactionBase()); System.out.println(container.getReactionContainer(id).getReactionBase());
// System.out.println(container.getReactionContainer(id).getReactionKEGG()); System.out.println(container.getReactionContainer(id).getReactionKEGG());
// System.out.println(container.getReactionContainer(id).getReactionBiGG()); System.out.println(container.getReactionContainer(id).getReactionBiGG());
// System.out.println(container.getReactionContainer(id).getReactionMetaCyc()); System.out.println(container.getReactionContainer(id).getReactionMetaCyc());
// System.out.println(container.getReactionContainer(id).getReactionModelSEED()); System.out.println(container.getReactionContainer(id).getReactionModelSEED());
// System.out.println(container.getReactionContainer(id).getOriginalReaction()); System.out.println(container.getReactionContainer(id).getOriginalReaction());
// } }
//
//
// System.out.println(); System.out.println();
// } }
......
...@@ -69,12 +69,11 @@ public class IdentifyReactionsMetabolites { ...@@ -69,12 +69,11 @@ public class IdentifyReactionsMetabolites {
// Set<String> forSearch = new HashSet<>(metabolites); // Set<String> forSearch = new HashSet<>(metabolites);
// metabolites = new HashSet<>(standardizationOfNames1(metabolitesFromFile, dictionary)); // metabolites = new HashSet<>(standardizationOfNames1(metabolitesFromFile, dictionary));
this.namesAndIDsContainer = standardizationOfNames2(namesAndIDsContainer);
namesAndIDsContainer = standardizationOfNames2(namesAndIDsContainer); this.allMetabolitesByName = new HashMap<>(this.namesAndIDsContainer.getMetabolitesIDs());
this.allMetabolitesByName = new HashMap<>(namesAndIDsContainer.getMetabolitesIDs());
this.namesAndIDsContainer = namesAndIDsContainer;
// System.out.println("MET>>>>> " + allMetabolitesByName.get("Electron")); // System.out.println("MET>>>>> " + allMetabolitesByName.get("Electron"));
// //
// System.out.println("metabolites >>>" + metabolites.size()); //2078 // System.out.println("metabolites >>>" + metabolites.size()); //2078
...@@ -555,7 +554,7 @@ public class IdentifyReactionsMetabolites { ...@@ -555,7 +554,7 @@ public class IdentifyReactionsMetabolites {
} }
String originalWord = word; String originalWord = word;
if(word.matches("ic acids*")) if(word.matches("ic acids*"))
word = word.replaceAll("ic acids*", "ate"); word = word.replaceAll("ic acids*", "ate");
......
...@@ -13,6 +13,7 @@ import java.util.regex.Pattern; ...@@ -13,6 +13,7 @@ import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.sbml.jsbml.ext.distrib.DistribConstants;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -27,6 +28,7 @@ import pt.uminho.ceb.biosystems.transyt.utilities.dictionary.Synonyms; ...@@ -27,6 +28,7 @@ import pt.uminho.ceb.biosystems.transyt.utilities.dictionary.Synonyms;
import pt.uminho.ceb.biosystems.transyt.utilities.enumerators.Enumerators.TypeOfTransporter; import pt.uminho.ceb.biosystems.transyt.utilities.enumerators.Enumerators.TypeOfTransporter;
import pt.uminho.ceb.biosystems.transyt.utilities.enumerators.MetaboliteReferenceDatabaseEnum; import pt.uminho.ceb.biosystems.transyt.utilities.enumerators.MetaboliteReferenceDatabaseEnum;
import pt.uminho.ceb.biosystems.transyt.utilities.files.FilesUtils; import pt.uminho.ceb.biosystems.transyt.utilities.files.FilesUtils;
import pt.uminho.ceb.biosystems.transyt.utilities.transytUtilities.DistributionsAlgorithm;
import pt.uminho.ceb.biosystems.transyt.utilities.transytUtilities.Properties; import pt.uminho.ceb.biosystems.transyt.utilities.transytUtilities.Properties;
import pt.uminho.ceb.biosystems.transyt.utilities.transytUtilities.Utilities; import pt.uminho.ceb.biosystems.transyt.utilities.transytUtilities.Utilities;
import pt.uminho.sysbio.biosynth.integration.io.dao.neo4j.MetaboliteMajorLabel; import pt.uminho.sysbio.biosynth.integration.io.dao.neo4j.MetaboliteMajorLabel;
...@@ -38,7 +40,7 @@ public class TransportReactionsBuilder { ...@@ -38,7 +40,7 @@ public class TransportReactionsBuilder {
private Map<String, BiosynthMetaboliteProperties> allData; private Map<String, BiosynthMetaboliteProperties> allData;
private Map<String, String> element_map = FormulaParser.getSymbolMap(); private Map<String, String> element_map = FormulaParser.getSymbolMap();
private Map<String, String> allExistingReactions; // = FilesUtils.readMapFromFile(FilesUtils.getReactionsIdentifiersFilePath()); private Map<String, String> allExistingReactions; // = FilesUtils.readMapFromFile(FilesUtils.getReactionsIdentifiersFilePath());
// private Map<String, String> newReactionIDs; // private Map<String, String> newReactionIDs;
private Map<String, Integer> generationsLimit; private Map<String, Integer> generationsLimit;
private Map<String, String> mappingModelSeed; private Map<String, String> mappingModelSeed;
private Map<String, String> mappingBiGG; private Map<String, String> mappingBiGG;
...@@ -66,10 +68,10 @@ public class TransportReactionsBuilder { ...@@ -66,10 +68,10 @@ public class TransportReactionsBuilder {
Map<String, BiosynthMetaboliteProperties> allData, BiosynthMetabolites biosynthMetabolites, Properties properties) { Map<String, BiosynthMetaboliteProperties> allData, BiosynthMetabolites biosynthMetabolites, Properties properties) {
this.allExistingReactions = TransytNeo4jInitializer.getAllReactionsIdentifiersInReferenceDatabase(properties); this.allExistingReactions = TransytNeo4jInitializer.getAllReactionsIdentifiersInReferenceDatabase(properties);
this.allData = allData; this.allData = allData;
this.newData = new HashMap<>(); this.newData = new HashMap<>();
// this.newReactionIDs = new HashMap<>(); // this.newReactionIDs = new HashMap<>();
// this.tcdbMetabolitesIDs = tcdbMetabolitesIDs; // this.tcdbMetabolitesIDs = tcdbMetabolitesIDs;
this.allMetabolitesIDs = biosynthMetabolites.getMetabolitesIDs(); this.allMetabolitesIDs = biosynthMetabolites.getMetabolitesIDs();
...@@ -131,15 +133,15 @@ public class TransportReactionsBuilder { ...@@ -131,15 +133,15 @@ public class TransportReactionsBuilder {
Synonyms dictionary = new Synonyms(); Synonyms dictionary = new Synonyms();
int reactionsCounter = 0; int reactionsCounter = 0;
// int i = 0; // int i = 0;
for(String accession : reactionsData.keySet()) { for(String accession : reactionsData.keySet()) {
// i++; // i++;
// //
// if(i == 1000) // if(i == 1000)
// break; // break;
// System.out.println(); // System.out.println();
// System.out.println(accession); // System.out.println(accession);
...@@ -164,7 +166,7 @@ public class TransportReactionsBuilder { ...@@ -164,7 +166,7 @@ public class TransportReactionsBuilder {
List<Set<String>> sets = new ArrayList<>(); List<Set<String>> sets = new ArrayList<>();
ReactionContainer reactionContainer = tcContainer.getReactionContainer(key); ReactionContainer reactionContainer = tcContainer.getReactionContainer(key);
Map<String, Set<String>> metabolitesForReplacement = IdentifyReactionsMetabolites.getMetabolitesToBeReplaced(reactionContainer.getReaction(), dictionary); Map<String, Set<String>> metabolitesForReplacement = IdentifyReactionsMetabolites.getMetabolitesToBeReplaced(reactionContainer.getReaction(), dictionary);
// System.out.println(metabolitesForReplacement); // System.out.println(metabolitesForReplacement);
...@@ -322,7 +324,7 @@ public class TransportReactionsBuilder { ...@@ -322,7 +324,7 @@ public class TransportReactionsBuilder {
if(allReactions != null) { if(allReactions != null) {
if(commonOntologyMetabolites != null) { if(commonOntologyMetabolites != null) {
List<Set<String>> distributions = getAllDistributions(commonOntologyMetabolites); List<Set<String>> distributions = DistributionsAlgorithm.getAllDistributions(commonOntologyMetabolites);
Map<ReactionContainer, Boolean> reactionsGenerated = generateAllPossibleReactions(distributions, reverseKeys, childNames, metabolites, formulas, Map<ReactionContainer, Boolean> reactionsGenerated = generateAllPossibleReactions(distributions, reverseKeys, childNames, metabolites, formulas,
reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel); reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel);
...@@ -340,7 +342,7 @@ public class TransportReactionsBuilder { ...@@ -340,7 +342,7 @@ public class TransportReactionsBuilder {
} }
} }
List<Set<String>> distributions = getAllDistributions(sets); List<Set<String>> distributions = DistributionsAlgorithm.getAllDistributions(sets);
Map<ReactionContainer, Boolean> reactionsGenerated = generateAllPossibleReactions(distributions, reverseKeys, childNames, metabolites, formulas, Map<ReactionContainer, Boolean> reactionsGenerated = generateAllPossibleReactions(distributions, reverseKeys, childNames, metabolites, formulas,
reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel); reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel);
...@@ -373,7 +375,7 @@ public class TransportReactionsBuilder { ...@@ -373,7 +375,7 @@ public class TransportReactionsBuilder {
newData.put(accession, setTcContainers); newData.put(accession, setTcContainers);
} }
// FilesUtils.addMapToFile(FilesUtils.getReactionsIdentifiersFilePath(), this.newReactionIDs); // FilesUtils.addMapToFile(FilesUtils.getReactionsIdentifiersFilePath(), this.newReactionIDs);
// logger.info(" All TranSyT reactions generated!!!"); //CHECK THESE COUNTERS // logger.info(" All TranSyT reactions generated!!!"); //CHECK THESE COUNTERS
// logger.debug("TOTAl of reactions generated (not filtered): {}", reactionsCounter); // logger.debug("TOTAl of reactions generated (not filtered): {}", reactionsCounter);
...@@ -546,17 +548,20 @@ public class TransportReactionsBuilder { ...@@ -546,17 +548,20 @@ public class TransportReactionsBuilder {
break; break;
} }
} }
if(StringUtils.countMatches(reaction, " + ") >= distribution.size()) String[] res = reaction.replace(ReactionContainer.EXTERIOR_COMPARTMENT_TOKEN, "").replace(ReactionContainer.INTERIOR_COMPARTMENT_TOKEN, "")
go = false; //this means that the same metabolite is twice+ in the reaction .split(reactionContainer.getDirectionRegex());
if(go)
go = areCompoundsRepeated(res[0]) && areCompoundsRepeated(res[1]); //check if the same metabolite is twice+ in the reaction
if(go && formulasReaction != null) { if(go && formulasReaction != null) {
// System.out.println(reaction); // System.out.println(reaction);
// System.out.println(reactionBase); // System.out.println(reactionBase);
// System.out.println(formulasReaction); // System.out.println(formulasReaction);
// //
// System.out.println(); // System.out.println();
String[] reactionSplit = reaction.split(reactionContainer.getDirectionRegex()); String[] reactionSplit = reaction.split(reactionContainer.getDirectionRegex());
...@@ -648,13 +653,13 @@ public class TransportReactionsBuilder { ...@@ -648,13 +653,13 @@ public class TransportReactionsBuilder {
// System.out.println(); // System.out.println();
boolean balanced = isEquationBalanced(formulasReaction, reactionContainer.getDirectionRegex(), print); boolean balanced = isEquationBalanced(formulasReaction, reactionContainer.getDirectionRegex(), print);
// System.out.println("balanced: " + balanced); // System.out.println("balanced: " + balanced);
// System.out.println(reactant + " <<>> " + product); // System.out.println(reactant + " <<>> " + product);
// System.out.println(reactantIDs + " <<>> " + productIDs); // System.out.println(reactantIDs + " <<>> " + productIDs);
// System.out.println(formulasReaction); // System.out.println(formulasReaction);
// System.out.println(reactionKEGG); // System.out.println(reactionKEGG);
// System.out.println(); // System.out.println();
// if(idsReaction.contains("META:BUTYRIC_ACID=MetaCyc (out) + META:CO-A=MetaCyc (in) + META:ATP=MetaCyc (in) $IRREV$ META:BU")) // if(idsReaction.contains("META:BUTYRIC_ACID=MetaCyc (out) + META:CO-A=MetaCyc (in) + META:ATP=MetaCyc (in) $IRREV$ META:BU"))
// System.out.println(balanced); // System.out.println(balanced);
...@@ -711,12 +716,12 @@ public class TransportReactionsBuilder { ...@@ -711,12 +716,12 @@ public class TransportReactionsBuilder {
} }
else if(defaultLabel.equals(MetaboliteMajorLabel.LigandCompound)) else if(defaultLabel.equals(MetaboliteMajorLabel.LigandCompound))
newReactContainer.setReactionKEGG(auxReaction); newReactContainer.setReactionKEGG(auxReaction);
if(reactionBase.contains("cpd00205") && newReactContainer.getMetabolites().size() == 2) // if(reactionBase.contains("cpd00205") && newReactContainer.getMetabolites().size() == 2)
System.out.println(); // System.out.println();
newReactContainer.generateTranSyTID(metabolitesMapById, this.allExistingReactions, tcNumber); newReactContainer.generateTranSyTID(metabolitesMapById, this.allExistingReactions, tcNumber);
String metaId = newReactContainer.getMetaReactionID(); String metaId = newReactContainer.getMetaReactionID();
// if(!reactionsAlreadyGenerated.contains(metaId)) { // if(!reactionsAlreadyGenerated.contains(metaId)) {
...@@ -726,7 +731,7 @@ public class TransportReactionsBuilder { ...@@ -726,7 +731,7 @@ public class TransportReactionsBuilder {
} }
else { else {
this.allExistingReactions.put(metaId, newReactContainer.getReactionID()); this.allExistingReactions.put(metaId, newReactContainer.getReactionID());
// this.newReactionIDs.put(metaId, newReactContainer.getReactionID()); // this.newReactionIDs.put(metaId, newReactContainer.getReactionID());
} }
reactionsGenerated.put(newReactContainer, isChild); reactionsGenerated.put(newReactContainer, isChild);
...@@ -768,6 +773,27 @@ public class TransportReactionsBuilder { ...@@ -768,6 +773,27 @@ public class TransportReactionsBuilder {
// return id; // return id;
// } // }
private boolean areCompoundsRepeated(String string) {
Map<String, Integer> occurrences = new HashMap<String, Integer>();
String[] split = string.split(" \\+ ");
for (String word : split) {
word = word.trim();
Integer oldCount = occurrences.get(word);
if ( oldCount == null ) {
oldCount = 0;
}
occurrences.put(word, oldCount + 1);
if(oldCount > 1)
return false;
}
return true;
}
private boolean checkPEPReactions(String reactant, String product) { private boolean checkPEPReactions(String reactant, String product) {
String sugar = reactant.split(" \\(out\\)")[0].trim(); String sugar = reactant.split(" \\(out\\)")[0].trim();
...@@ -1082,89 +1108,7 @@ public class TransportReactionsBuilder { ...@@ -1082,89 +1108,7 @@ public class TransportReactionsBuilder {
return sortedString; return sortedString;
} }
/**
* @param sets
* @return
*/
private static List<Set<String>> getAllDistributions(List<Set<String>> sets){
List<Set<String>> set1 = new ArrayList<>();
List<Set<String>> set2 = new ArrayList<>();
for(int i = 0; i < sets.size(); i++) {
if(i == 0) {
for(String met : sets.get(i)) {
Set<String> set = new HashSet<>();
set.add(met);
set1.add(set);
}
}
else
set2.add(sets.get(i));
}
return executeDistributions(set1, set2, 0);
}
/**
* Recursive method to find all possible distributions of compounds.
*
* @param set1
* @param set2
* @param cycle
* @return
*/
private static List<Set<String>> executeDistributions(List<Set<String>> set1, List<Set<String>> set2, int cycle){
List<Set<String>> distributions = new ArrayList<>();
if(cycle == 0 && set2.size() == 0) {
for(Set<String> set : set1) {
for(String metabolite : set) {
Set<String> newSet = new HashSet<>();
newSet.add(metabolite);
distributions.add(newSet);
}
}
return distributions;
}
if(cycle == set2.size())
return set1;
Set<String> l2 = set2.get(cycle);