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 {
// }
// }
}
if(name.equalsIgnoreCase("Solute"))
System.out.println();
if(Utilities.processBiosynthName(name).equalsIgnoreCase("Solute"))
System.out.println();
compounds.put(Utilities.processBiosynthName(name), references);
namesWithoutSigns.put(name, name.replaceAll("[^A-Za-z0-9]", ""));
......
......@@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory;
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.reactions.IdentifyReactionsMetabolites;
import pt.uminho.ceb.biosystems.transyt.service.reactions.TransportReactionsBuilder;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.PopulateTransytNeo4jDatabase;
import pt.uminho.ceb.biosystems.transyt.utilities.capsules.BiosynthMetaboliteProperties;
......@@ -42,6 +43,15 @@ public class WriteByMetabolitesID {
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;
logger.info("Retrieving data from Biosynth database...");
......@@ -60,7 +70,7 @@ public class WriteByMetabolitesID {
BiosynthMetabolites namesAndIDsContainer = new FetchCompoundsByName(service, false).getResults(); //168966 names
Map<String, Set<TcNumberContainer2>> reactionsData = JSONFilesUtils.readJSONtcdbReactionsFile(); //uncomment
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
......@@ -74,29 +84,28 @@ public class WriteByMetabolitesID {
// Map<String, String[]> forChildsSearch = metabolitesIdentification.getforChildsSearch();
// int n = 1;
//
// while (n != 99) {
//
// n = 99;
int n = 1;
while (n != 99) {
n = 99;
Map<String, Set<TcNumberContainer2>> newData = test(namesAndIDsContainer, data, service, reactionsData, properties); //uncomment
// 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: ");
//
// try {
// n = reader.nextInt();
// } catch (Exception e) {
// e.printStackTrace();
//
// n = reader.nextInt();
// }
//
// }
System.out.println("Enter a random number to repeat (100 to repeat data retrieval) or 99 to finish: ");
try {
n = reader.nextInt();
} catch (Exception e) {
e.printStackTrace();
n = reader.nextInt();
}
}
dataTx.failure();
dataTx.close();
service.shutdown();
......@@ -231,38 +240,38 @@ public class WriteByMetabolitesID {
try {
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
// String[] accessions = new String[] {"P75757", "O85143", "O07084", "P13512", "A0QQH3"};
//
// for(String acc : accessions)
// reactionsData2.put(acc, reactionsData.get(acc));
Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
String[] accessions = new String[] {"O06933"};
for(String acc : accessions)
reactionsData2.put(acc, reactionsData.get(acc));
/////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")) {
//
// System.out.println(container.getTcNumber());
//
// for( Integer id : container.getAllReactionsIds()) {
// System.out.println();
//
// System.out.println(container.getReactionContainer(id).getReactionID());
// System.out.println(container.getReactionContainer(id).getMetaReactionID());
// System.out.println(container.getReactionContainer(id).getCompartmentalizedReactionID());
// System.out.println(container.getReactionContainer(id).getReaction());
// System.out.println(container.getReactionContainer(id).getReactionBase());
// System.out.println(container.getReactionContainer(id).getReactionKEGG());
// System.out.println(container.getReactionContainer(id).getReactionBiGG());
// System.out.println(container.getReactionContainer(id).getReactionMetaCyc());
// System.out.println(container.getReactionContainer(id).getReactionModelSEED());
// System.out.println(container.getReactionContainer(id).getOriginalReaction());
// }
//
//
// System.out.println();
// }
for(TcNumberContainer2 container : newData.get("O06933")) {
System.out.println(container.getTcNumber());
for( Integer id : container.getAllReactionsIds()) {
System.out.println();
System.out.println(container.getReactionContainer(id).getReactionID());
System.out.println(container.getReactionContainer(id).getMetaReactionID());
System.out.println(container.getReactionContainer(id).getCompartmentalizedReactionID());
System.out.println(container.getReactionContainer(id).getReaction());
System.out.println(container.getReactionContainer(id).getReactionBase());
System.out.println(container.getReactionContainer(id).getReactionKEGG());
System.out.println(container.getReactionContainer(id).getReactionBiGG());
System.out.println(container.getReactionContainer(id).getReactionMetaCyc());
System.out.println(container.getReactionContainer(id).getReactionModelSEED());
System.out.println(container.getReactionContainer(id).getOriginalReaction());
}
System.out.println();
}
......
......@@ -69,12 +69,11 @@ public class IdentifyReactionsMetabolites {
// Set<String> forSearch = new HashSet<>(metabolites);
// metabolites = new HashSet<>(standardizationOfNames1(metabolitesFromFile, dictionary));
this.namesAndIDsContainer = standardizationOfNames2(namesAndIDsContainer);
namesAndIDsContainer = standardizationOfNames2(namesAndIDsContainer);
this.allMetabolitesByName = new HashMap<>(namesAndIDsContainer.getMetabolitesIDs());
this.namesAndIDsContainer = namesAndIDsContainer;
this.allMetabolitesByName = new HashMap<>(this.namesAndIDsContainer.getMetabolitesIDs());
// System.out.println("MET>>>>> " + allMetabolitesByName.get("Electron"));
//
// System.out.println("metabolites >>>" + metabolites.size()); //2078
......@@ -555,7 +554,7 @@ public class IdentifyReactionsMetabolites {
}
String originalWord = word;
if(word.matches("ic acids*"))
word = word.replaceAll("ic acids*", "ate");
......
......@@ -13,6 +13,7 @@ import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.neo4j.graphdb.Node;
import org.sbml.jsbml.ext.distrib.DistribConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -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.MetaboliteReferenceDatabaseEnum;
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.Utilities;
import pt.uminho.sysbio.biosynth.integration.io.dao.neo4j.MetaboliteMajorLabel;
......@@ -38,7 +40,7 @@ public class TransportReactionsBuilder {
private Map<String, BiosynthMetaboliteProperties> allData;
private Map<String, String> element_map = FormulaParser.getSymbolMap();
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, String> mappingModelSeed;
private Map<String, String> mappingBiGG;
......@@ -66,10 +68,10 @@ public class TransportReactionsBuilder {
Map<String, BiosynthMetaboliteProperties> allData, BiosynthMetabolites biosynthMetabolites, Properties properties) {
this.allExistingReactions = TransytNeo4jInitializer.getAllReactionsIdentifiersInReferenceDatabase(properties);
this.allData = allData;
this.newData = new HashMap<>();
// this.newReactionIDs = new HashMap<>();
// this.newReactionIDs = new HashMap<>();
// this.tcdbMetabolitesIDs = tcdbMetabolitesIDs;
this.allMetabolitesIDs = biosynthMetabolites.getMetabolitesIDs();
......@@ -131,15 +133,15 @@ public class TransportReactionsBuilder {
Synonyms dictionary = new Synonyms();
int reactionsCounter = 0;
// int i = 0;
// int i = 0;
for(String accession : reactionsData.keySet()) {
// i++;
//
// if(i == 1000)
// break;
// i++;
//
// if(i == 1000)
// break;
// System.out.println();
// System.out.println(accession);
......@@ -164,7 +166,7 @@ public class TransportReactionsBuilder {
List<Set<String>> sets = new ArrayList<>();
ReactionContainer reactionContainer = tcContainer.getReactionContainer(key);
Map<String, Set<String>> metabolitesForReplacement = IdentifyReactionsMetabolites.getMetabolitesToBeReplaced(reactionContainer.getReaction(), dictionary);
// System.out.println(metabolitesForReplacement);
......@@ -322,7 +324,7 @@ public class TransportReactionsBuilder {
if(allReactions != 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,
reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel);
......@@ -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,
reactionContainer, tcContainer.getTcNumber(), metabolitesForReplacement, mainMetabolites, defaultLabel);
......@@ -373,7 +375,7 @@ public class TransportReactionsBuilder {
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.debug("TOTAl of reactions generated (not filtered): {}", reactionsCounter);
......@@ -546,17 +548,20 @@ public class TransportReactionsBuilder {
break;
}
}
if(StringUtils.countMatches(reaction, " + ") >= distribution.size())
go = false; //this means that the same metabolite is twice+ in the reaction
String[] res = reaction.replace(ReactionContainer.EXTERIOR_COMPARTMENT_TOKEN, "").replace(ReactionContainer.INTERIOR_COMPARTMENT_TOKEN, "")
.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) {
// System.out.println(reaction);
// System.out.println(reactionBase);
// System.out.println(formulasReaction);
//
// System.out.println();
// System.out.println(reaction);
// System.out.println(reactionBase);
// System.out.println(formulasReaction);
//
// System.out.println();
String[] reactionSplit = reaction.split(reactionContainer.getDirectionRegex());
......@@ -648,13 +653,13 @@ public class TransportReactionsBuilder {
// System.out.println();
boolean balanced = isEquationBalanced(formulasReaction, reactionContainer.getDirectionRegex(), print);
// System.out.println("balanced: " + balanced);
// System.out.println(reactant + " <<>> " + product);
// System.out.println(reactantIDs + " <<>> " + productIDs);
// System.out.println(formulasReaction);
// System.out.println(reactionKEGG);
// System.out.println();
// System.out.println("balanced: " + balanced);
// System.out.println(reactant + " <<>> " + product);
// System.out.println(reactantIDs + " <<>> " + productIDs);
// System.out.println(formulasReaction);
// System.out.println(reactionKEGG);
// System.out.println();
// if(idsReaction.contains("META:BUTYRIC_ACID=MetaCyc (out) + META:CO-A=MetaCyc (in) + META:ATP=MetaCyc (in) $IRREV$ META:BU"))
// System.out.println(balanced);
......@@ -711,12 +716,12 @@ public class TransportReactionsBuilder {
}
else if(defaultLabel.equals(MetaboliteMajorLabel.LigandCompound))
newReactContainer.setReactionKEGG(auxReaction);
if(reactionBase.contains("cpd00205") && newReactContainer.getMetabolites().size() == 2)
System.out.println();
// if(reactionBase.contains("cpd00205") && newReactContainer.getMetabolites().size() == 2)
// System.out.println();
newReactContainer.generateTranSyTID(metabolitesMapById, this.allExistingReactions, tcNumber);
String metaId = newReactContainer.getMetaReactionID();
// if(!reactionsAlreadyGenerated.contains(metaId)) {
......@@ -726,7 +731,7 @@ public class TransportReactionsBuilder {
}
else {
this.allExistingReactions.put(metaId, newReactContainer.getReactionID());
// this.newReactionIDs.put(metaId, newReactContainer.getReactionID());
// this.newReactionIDs.put(metaId, newReactContainer.getReactionID());
}
reactionsGenerated.put(newReactContainer, isChild);
......@@ -768,6 +773,27 @@ public class TransportReactionsBuilder {
// 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) {
String sugar = reactant.split(" \\(out\\)")[0].trim();
......@@ -1082,89 +1108,7 @@ public class TransportReactionsBuilder {
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);
for(Set<String> er : set1) {
for(String el: l2) {
Set<String> erClone = new HashSet<>(er);
erClone.add(el);
distributions.add(erClone);
}
}
set1.clear();
set1.addAll(distributions);
cycle++;
return executeDistributions(set1, set2, cycle);
}
private String[] getMetaboliteProperties(String id, MetaboliteMajorLabel metaboliteReferenceDatabaseEnum, BiodbGraphDatabaseService service) {
......
package pt.uminho.ceb.biosystems.transyt.service.transyt;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.transyt.scraper.tcdb.tcdbTransportTypesRetriever.FindTransporters;
import pt.uminho.ceb.biosystems.transyt.scraper.tcdb.tcdbTransportTypesRetriever.Retriever;
import pt.uminho.ceb.biosystems.transyt.service.internalDB.WriteByMetabolitesID;
import pt.uminho.ceb.biosystems.transyt.service.reactions.ProvideTransportReactionsToGenes;
......@@ -27,6 +31,14 @@ public class TransyTestMain {
// JSONFilesUtils.readJSONtcdbReactionsFile();
// Set<String> coiso = new HashSet<>();
// coiso.add("2.A.1");
// FindTransporters.saveAllTCFamiliesInformation(coiso);
// ReadFastaTcdb.buildFastaFileForAlignments();
//
// System.exit(0);
Properties properties = new Properties();
String path = "/Users/davidelagoa/Desktop/ecoli/ecoli_iML1515/";
......@@ -35,7 +47,7 @@ public class TransyTestMain {
String modelPath = path + "model.xml";
String command = "3";
String command = "1";
String resultPath = path + "results_e#1/";
......
......@@ -23,7 +23,7 @@ public class TransytMain {
// Integer taxID = Integer.valueOf(args[0]);
logger.info("############################################ TranSyT - v0.0.11.1-SNAPSHOT ############################################");
logger.info("############################################ TranSyT - v0.0.11.4-SNAPSHOT ############################################");
String command = args[0];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment