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 b2e5cf95 authored by Davide Lagoa's avatar Davide Lagoa
Browse files

coa reactions fixed

parent 82d3fd82
......@@ -155,11 +155,14 @@ public class WriteByMetabolitesID {
Map<String, Set<TcNumberContainer2>> reactionsData, Properties properties) {
try {
Boolean generate = true;
String accession = "P77211";
String accession = "Q56582";
Retriever.runRetriever(true, true, accession);
// Retriever.runRetriever(true, true, accession);
// reactionsData = JSONFilesUtils.readJSONtcdbReactionsFile();
if(generate) {
reactionsData = JSONFilesUtils.readJSONtcdbReactionsFile();
Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
String[] accessions = new String[] {accession};
......@@ -193,12 +196,13 @@ public class WriteByMetabolitesID {
System.out.println();
}
}
// JSONFilesUtils.writeJSONTriageReactions(newData);
System.out.println("Done!!!");
return newData;
return null;
}
catch (Exception e) {
e.printStackTrace();
......@@ -232,7 +236,7 @@ public class WriteByMetabolitesID {
String entryID = node.getEntry();
if(!entryID.isEmpty()) {
Map<String, Object> nodeProperties = node.getAllProperties();
BiosynthMetaboliteProperties bioSynMetab;
......@@ -265,6 +269,11 @@ public class WriteByMetabolitesID {
if(node.hasProperty("formula"))
bioSynMetab.setFormula((String) nodeProperties.get("formula"));
if(entryID.equalsIgnoreCase("cpd03805"))
bioSynMetab.setFormula("C6H11O8P"); //there's an error in the database, it needs to be updated
else if(entryID.equalsIgnoreCase("cpd15391"))
bioSynMetab.setFormula("C11H17NO11P"); //there's an error in the database, it needs to be updated
if(node.hasProperty("remark"))
bioSynMetab.setRemark((String) nodeProperties.get("remark"));
......
......@@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.transyt.service.containers.BiosynthMetabolites;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.ReactionContainer;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.TcNumberContainer2;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.TcdbMetabolitesContainer;
import pt.uminho.ceb.biosystems.transyt.utilities.dictionary.Synonyms;
import pt.uminho.sysbio.biosynth.integration.io.dao.neo4j.MetaboliteMajorLabel;
import pt.uminho.sysbio.biosynthframework.BiodbGraphDatabaseService;
......@@ -423,7 +424,8 @@ public class IdentifyReactionsMetabolites {
reactionContainer.getOriginalReaction()};
for(String reaction : reactions) {
for(Entry<String, Set<String>> entry : getMetabolitesToBeReplaced(reaction, dictionary).entrySet()) {
for(Entry<String, Set<String>> entry : getMetabolitesToBeReplaced(reaction,
dictionary, reactionContainer.isCombineSameMetabolite()).entrySet()) {
if(metabolites.containsKey(entry.getKey()))
metabolites.get(entry.getKey()).addAll(entry.getValue());
else
......@@ -443,7 +445,7 @@ public class IdentifyReactionsMetabolites {
* @param dictionary
* @return
*/
public static Set<String> getMetabolitesFromReaction(String reaction, Synonyms dictionary){
public static Set<String> getMetabolitesFromReaction(String reaction, Synonyms dictionary, boolean combineWithItself){
Set<String> metabolites = new HashSet<>();
......@@ -453,15 +455,22 @@ public class IdentifyReactionsMetabolites {
String[] metabs = reaction.split(" \\+ ");
for(String metab : metabs) {
if(!metab.matches("^(\\d+-).+")) {
metab = metab.replaceAll("^(\\d+)", "");
}
metab = metab.replaceAll("^(\\+\\s)", "").trim();
if(!metab.isEmpty())
metabolites.add(metab);
if(!metab.isEmpty()) {
if(combineWithItself) {
if(!metab.endsWith(TcdbMetabolitesContainer.SAME_METABOLITE_COMBINATION_SUFFIX))
metabolites.add(metab);
}
else {
metabolites.add(metab);
}
}
}
return metabolites;
......@@ -473,9 +482,9 @@ public class IdentifyReactionsMetabolites {
* @param reaction
* @return
*/
public static Map<String, Set<String>> getMetabolitesToBeReplaced(String reaction, Synonyms dictionary){
public static Map<String, Set<String>> getMetabolitesToBeReplaced(String reaction, Synonyms dictionary, boolean combineWithItself){
Set<String> metabolites = getMetabolitesFromReaction(reaction, dictionary);
Set<String> metabolites = getMetabolitesFromReaction(reaction, dictionary, combineWithItself);
// System.out.println(metabolites);
......
......@@ -25,6 +25,7 @@ import pt.uminho.ceb.biosystems.transyt.service.utilities.MappingMetabolites;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.BiosynthMetaboliteProperties;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.ReactionContainer;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.TcNumberContainer2;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.TcdbMetabolitesContainer;
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.MetaboliteReferenceDatabaseEnum;
......@@ -51,13 +52,18 @@ public class TransportReactionsBuilder {
private Map<String, Map<MetaboliteMajorLabel, String>> allMetabolitesIDs;
private MetaboliteMajorLabel defaultLabel;
private String reaction;
private String reactionBase;
private String reactionMetaCyc;
private String reactionModelSeed;
private String reactionBiGG;
private String reactionKEGG;
private String formulasReaction;
private Properties properties;
private boolean go;
private boolean isChild;
public static final List<String> ELEMENTS_EXCEPTIONS = List.of("Ac", "Ar", "As", "Au", "Ba", "Be",
"Ca", "Cd", "Ce", "Cm", "Cu", "Db", "Es", "Eu", "He", "Hg", "Fe", "Fm",
......@@ -169,14 +175,15 @@ public class TransportReactionsBuilder {
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, reactionContainer.isCombineSameMetabolite());
// System.out.println(metabolitesForReplacement);
Set<String> originalMetabolites = new HashSet<>();
if(originalMetabolites.isEmpty())
originalMetabolites =IdentifyReactionsMetabolites.getMetabolitesFromReaction(reactionContainer.getOriginalReaction(), dictionary);
originalMetabolites =IdentifyReactionsMetabolites.getMetabolitesFromReaction(reactionContainer.getOriginalReaction(), dictionary, false);
if(!originalMetabolites.isEmpty() && !(originalMetabolites.size() == 1 && originalMetabolites.contains(BiosynthMetaboliteProperties.NONE))) {
for(String originalM : new HashSet<>(originalMetabolites)) {
......@@ -326,7 +333,7 @@ public class TransportReactionsBuilder {
if(allReactions != null) {
if(commonOntologyMetabolites != null) {
List<Set<String>> distributions = DistributionsAlgorithm.getAllDistributions(commonOntologyMetabolites);
List<Set<String>> distributions = DistributionsAlgorithm.getAllDistributions(commonOntologyMetabolites, reactionContainer.isCombineSameMetabolite());
Map<ReactionContainer, Boolean> reactionsGenerated = generateAllPossibleReactions(distributions, reverseKeys, childNames, metabolites, formulas,
reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel);
......@@ -344,7 +351,7 @@ public class TransportReactionsBuilder {
}
}
List<Set<String>> distributions = DistributionsAlgorithm.getAllDistributions(sets);
List<Set<String>> distributions = DistributionsAlgorithm.getAllDistributions(sets, reactionContainer.isCombineSameMetabolite());
Map<ReactionContainer, Boolean> reactionsGenerated = generateAllPossibleReactions(distributions, reverseKeys, childNames, metabolites, formulas,
reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel);
......@@ -446,137 +453,39 @@ public class TransportReactionsBuilder {
for(Set<String> distribution : distributions) {
boolean isChild = false;
this.isChild = false;
String reaction = reactionContainer.getReaction() + " "; //important for correct following replacements
reaction = reactionContainer.getReaction() + " "; //important for correct following replacements
reactionBase = reaction;
reactionMetaCyc = reaction;
reactionModelSeed = reaction;
reactionBiGG = reaction;
reactionKEGG = reaction;
String formulasReaction = reaction;
boolean go = true;
formulasReaction = reaction;
this.go = true;
Set<String> metabolitesToReplace = new HashSet<>();
for(String id : distribution) {
if(metabolites.get(id).contains("=") && MetaboliteMajorLabel.valueOf(metabolites.get(id).split("=")[1]).equals(defaultLabel) && metabolitesForReplacement.size() == distribution.size()) {
if(!mainMetabolites.contains(id))
isChild = true;
// System.out.println(metabolitesForReplacement);
// System.out.println("reverse" + metabolitesForReplacement.get(reverseKeys.get(id)));
for(String replace : metabolitesForReplacement.get(reverseKeys.get(id))) {
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent)) { //PEP dependent
replace = replace + "\\s+\\(";
reaction = reaction.replaceAll(replace, childNames.get(id) + " \\(");
reactionBase = reactionBase.replaceAll(replace, metabolites.get(id) + " \\(");
}
else {
replace = replace + " ";
reaction = reaction.replace(replace, childNames.get(id) + " ");
reactionBase = reactionBase.replace(replace, metabolites.get(id) + " ");
}
String repl = "";
String entryID = metabolites.get(id).split("=")[0];
if(mappingModelSeed.containsKey(entryID) && reactionModelSeed != null) {
repl = mappingModelSeed.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionModelSeed = reactionModelSeed.replaceAll(replace, repl + " \\(");
else
reactionModelSeed = reactionModelSeed.replace(replace, repl + " ");
}
else {
reactionModelSeed = null;
}
if(mappingBiGG.containsKey(entryID) && reactionBiGG != null) {
repl = mappingBiGG.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionBiGG = reactionBiGG.replaceAll(replace, repl + " \\(");
else
reactionBiGG = reactionBiGG.replace(replace, repl+ " ");
}
else {
reactionBiGG = null;
}
if(mappingKEGG.containsKey(entryID) && reactionKEGG != null) {
repl = mappingKEGG.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionKEGG = reactionKEGG.replaceAll(replace, repl + " \\(");
else
reactionKEGG = reactionKEGG.replace(replace, repl+ " ");
}
else {
reactionKEGG = null;
}
if(mappingMetaCyc.containsKey(entryID) && reactionMetaCyc != null) {
repl = mappingMetaCyc.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionMetaCyc = reactionMetaCyc.replaceAll(replace, repl + " \\(");
else
reactionMetaCyc = reactionMetaCyc.replace(replace, repl + " ");
}
else {
reactionMetaCyc = null;
}
metabolitesMapByName.put(childNames.get(id), metabolites.get(id));
metabolitesMapById.put(metabolites.get(id).split("=")[0], childNames.get(id));
if(formulasReaction != null && formulas.containsKey(entryID) && formulas.get(entryID) != null
&& !formulas.get(entryID).equals(BiosynthMetaboliteProperties.NONE)) {
String previousFormula = formulasReaction;
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
formulasReaction = formulasReaction.replaceAll(replace,
formulas.get(entryID).concat("@") + " \\(");
else
formulasReaction = formulasReaction.replace(replace,
formulas.get(entryID).concat("@") + " "); //@ is added to control if replacements are really happening bacause some names might be like the formula
if(formulasReaction.equals(previousFormula))
formulasReaction = null;
}
else if((reactionContainer.getTransportType().equals(TypeOfTransporter.Light) &&
childNames.get(id).equalsIgnoreCase(ReactionContainer.LIGHT_NAME)) ||
childNames.get(id).equalsIgnoreCase(ReactionContainer.ELECTRON_NAME)) {
formulasReaction = formulasReaction.replace(replace, " ");
}
else {
formulasReaction = null;
}
}
}
else {
go = false;
break;
}
if(reactionContainer.isCombineSameMetabolite() && distribution.size() < 2)
this.go = false;
else if(go)
executeSubstitutions(id, metabolitesToReplace, reactionContainer, distribution,
childNames, metabolites, metabolitesForReplacement, metabolitesMapById,
metabolitesMapByName, reverseKeys, mainMetabolites, formulas);
}
String[] res = reaction.replace(ReactionContainer.EXTERIOR_COMPARTMENT_TOKEN, "").replace(ReactionContainer.INTERIOR_COMPARTMENT_TOKEN, "")
.split(reactionContainer.getDirectionRegex());
if(this.go)
this.go = areCompoundsNotRepeated(res[0]) && areCompoundsNotRepeated(res[1]); //check if the same metabolite is twice+ in the reaction
if(go)
go = areCompoundsRepeated(res[0]) && areCompoundsRepeated(res[1]); //check if the same metabolite is twice+ in the reaction
if(go && formulasReaction != null) {
if(this.go && formulasReaction != null) {
// System.out.println(reaction);
// System.out.println(reactionBase);
......@@ -617,10 +526,6 @@ public class TransportReactionsBuilder {
// System.out.println(formulasReaction);
System.out.println(reactant + " <<>> " + product);
System.out.println(reactantIDs + " <<>> " + productIDs);
System.out.println(formulasReaction);
if((reactant.contains("ATP") && product.contains("ADP")) || (reactant.contains("GTP") && product.contains("GDP"))) {
newTransportType = TypeOfTransporter.BiochemicalATP;
......@@ -670,7 +575,13 @@ public class TransportReactionsBuilder {
// System.out.println(reactionContainer.getDirectionRegex());
// System.out.println();
boolean print = false;
boolean print = true;
if(print) {
System.out.println(reactant + " <<>> " + product);
System.out.println(reactantIDs + " <<>> " + productIDs);
System.out.println(formulasReaction);
}
boolean balanced = isEquationBalanced(formulasReaction, reactionContainer.getDirectionRegex(), print);
......@@ -756,6 +667,138 @@ public class TransportReactionsBuilder {
return reactionsGenerated;
}
public void executeSubstitutions(String id, Set<String> metabolitesToReplace, ReactionContainer reactionContainer, Set<String> distribution,
Map<String, String> childNames, Map<String, String> metabolites, Map<String, Set<String>> metabolitesForReplacement,
Map<String, String> metabolitesMapById, Map<String, String> metabolitesMapByName, Map<String, String> reverseKeys,
Set<String> mainMetabolites, Map<String, String> formulas) {
if(metabolites.get(id).contains("=") && MetaboliteMajorLabel.valueOf(metabolites.get(id).split("=")[1]).equals(defaultLabel)
&& (metabolitesForReplacement.size() == distribution.size() || reactionContainer.isCombineSameMetabolite())) {
if(!mainMetabolites.contains(id))
isChild = true;
// System.out.println(metabolitesForReplacement);
// System.out.println("reverse" + metabolitesForReplacement.get(reverseKeys.get(id)));
if(metabolitesToReplace.isEmpty()) {
for(String s : metabolitesForReplacement.get(reverseKeys.get(id))) {
metabolitesToReplace.add(s); //deep copy
if(reactionContainer.isCombineSameMetabolite())
metabolitesToReplace.add(s.concat(TcdbMetabolitesContainer.SAME_METABOLITE_COMBINATION_SUFFIX));
}
}
String replace = metabolitesToReplace.iterator().next();
metabolitesToReplace.remove(replace);
// for(String replace : metabolitesToReplace) {
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent)) { //PEP dependent
replace = replace + "\\s+\\(";
reaction = reaction.replaceAll(replace, childNames.get(id) + " \\(");
reactionBase = reactionBase.replaceAll(replace, metabolites.get(id) + " \\(");
}
else {
replace = replace + " ";
reaction = reaction.replace(replace, childNames.get(id) + " ");
reactionBase = reactionBase.replace(replace, metabolites.get(id) + " ");
}
String repl = "";
String entryID = metabolites.get(id).split("=")[0];
if(mappingModelSeed.containsKey(entryID) && reactionModelSeed != null) {
repl = mappingModelSeed.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionModelSeed = reactionModelSeed.replaceAll(replace, repl + " \\(");
else
reactionModelSeed = reactionModelSeed.replace(replace, repl + " ");
}
else {
reactionModelSeed = null;
}
if(mappingBiGG.containsKey(entryID) && reactionBiGG != null) {
repl = mappingBiGG.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionBiGG = reactionBiGG.replaceAll(replace, repl + " \\(");
else
reactionBiGG = reactionBiGG.replace(replace, repl+ " ");
}
else {
reactionBiGG = null;
}
if(mappingKEGG.containsKey(entryID) && reactionKEGG != null) {
repl = mappingKEGG.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionKEGG = reactionKEGG.replaceAll(replace, repl + " \\(");
else
reactionKEGG = reactionKEGG.replace(replace, repl+ " ");
}
else {
reactionKEGG = null;
}
if(mappingMetaCyc.containsKey(entryID) && reactionMetaCyc != null) {
repl = mappingMetaCyc.get(entryID);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionMetaCyc = reactionMetaCyc.replaceAll(replace, repl + " \\(");
else
reactionMetaCyc = reactionMetaCyc.replace(replace, repl + " ");
}
else {
reactionMetaCyc = null;
}
metabolitesMapByName.put(childNames.get(id), metabolites.get(id));
metabolitesMapById.put(metabolites.get(id).split("=")[0], childNames.get(id));
if(formulasReaction != null && formulas.containsKey(entryID) && formulas.get(entryID) != null
&& !formulas.get(entryID).equals(BiosynthMetaboliteProperties.NONE)) {
String previousFormula = formulasReaction;
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
formulasReaction = formulasReaction.replaceAll(replace,
formulas.get(entryID).concat("@") + " \\(");
else
formulasReaction = formulasReaction.replace(replace,
formulas.get(entryID).concat("@") + " "); //@ is added to control if replacements are really happening bacause some names might be like the formula
if(formulasReaction.equals(previousFormula))
formulasReaction = null;
}
else if((reactionContainer.getTransportType().equals(TypeOfTransporter.Light) &&
childNames.get(id).equalsIgnoreCase(ReactionContainer.LIGHT_NAME)) ||
childNames.get(id).equalsIgnoreCase(ReactionContainer.ELECTRON_NAME)) {
formulasReaction = formulasReaction.replace(replace, " ");
}
else {
formulasReaction = null;
}
// }
}
else {
go = false;
}
if(go && !reactionContainer.isCombineSameMetabolite() && !metabolitesToReplace.isEmpty())
executeSubstitutions(id, metabolitesToReplace, reactionContainer, distribution,
childNames, metabolites, metabolitesForReplacement, metabolitesMapById,
metabolitesMapByName, reverseKeys, mainMetabolites, formulas);
}
// /**
// * @param newReactContainer
......@@ -786,9 +829,13 @@ public class TransportReactionsBuilder {
// return id;
// }
private boolean areCompoundsRepeated(String string) {
private boolean areCompoundsNotRepeated(String string) {
Map<String, Integer> occurrences = new HashMap<String, Integer>();
if(string.matches("(?i).*Phosphate.*\\+.*ADP.*\\+.*Phosphate.*")) { //exception
return true;
}
String[] split = string.split(" \\+ ");
for (String word : split) {
......@@ -800,8 +847,9 @@ public class TransportReactionsBuilder {
}
occurrences.put(word, oldCount + 1);
if(oldCount > 1)
if(oldCount > 0) {
return false;
}
}
return true;
......@@ -812,7 +860,7 @@ public class TransportReactionsBuilder {
String sugar = reactant.split(" \\(out\\)")[0].trim();
String sugarP = product.split("\\(in\\) \\+")[0].trim();
if(sugarP.contains(sugar) && (sugarP.matches("(?i).*-phosphate") || sugarP.matches("(?i).*-\\dp")))
if(sugarP.toLowerCase().contains(sugar.toLowerCase()) && (sugarP.matches("(?i).*-phosphate") || sugarP.matches("(?i).*-\\d-*p")))
return true;
else if(this.reactionMetaCyc != null && reactionDirection != null){
......@@ -830,6 +878,11 @@ public class TransportReactionsBuilder {
return false;
}
private void correctPhosphateATPReaction(){
}
/**
* Corrects the reversability of the reaction.
......
......@@ -36,8 +36,9 @@ public class TransyTestMain {
// coiso.add("2.A.1");
// FindTransporters.saveAllTCFamiliesInformation(coiso);
ReadFastaTcdb.buildFastaFileForAlignments();
// ReadFastaTcdb.buildFastaFileForAlignments();
//
// Retriever.runRetriever(true, true, "P31552");
// System.exit(0);
Properties properties = new Properties();
......