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

pts reaction brute force method created

parent 6b6507a1
......@@ -4,7 +4,7 @@
<groupId>pt.uminho.ceb.biosystems.transyt</groupId>
<artifactId>service</artifactId>
<name>service</name>
<version>0.0.11-SNAPSHOT</version>
<version>0.0.12-SNAPSHOT</version>
<build>
<plugins>
<plugin>
......
......@@ -78,7 +78,7 @@ public class FetchCompoundsByName {
getNamesMethod2();
forReplacement.put("cpd02416", "cpd00122");
// forReplacement.put("cpd20862", "cpd00244");
// forReplacement.put("cpd20862", "cpd00082");
for(String s : compounds.keySet()) {
......
......@@ -8,6 +8,7 @@ import java.util.Set;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -89,9 +90,9 @@ public class WriteByMetabolitesID {
// while (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);
// test2(service, data, namesAndIDsContainer);
// test2(service, data, namesAndIDsContainer);//uncomment
new PopulateTransytNeo4jDatabase(data, newData, properties); //uncomment
......@@ -153,10 +154,18 @@ public class WriteByMetabolitesID {
// }
// }
Node node = service.getNodeByEntryAndLabel("e", MetaboliteMajorLabel.BiGGMetabolite);
Node node = service.getNodeByEntryAndLabel("cpd15496", MetaboliteMajorLabel.ModelSeed);
System.out.println(node.getAllProperties());
Iterable<Relationship> rels = node.getRelationships();
for(Relationship rel : rels) {
Long otherNode = rel.getOtherNodeId(node.getId());
System.out.println(service.getNodeById(otherNode).getAllProperties());
}
} catch (Exception e) {
......@@ -240,8 +249,10 @@ public class WriteByMetabolitesID {
try {
// reactionsData = JSONFilesUtils.readJSONtcdbReactionsFile();
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
// String[] accessions = new String[] {"P31801"};
// String[] accessions = new String[] {"O07084"};
//
// for(String acc : accessions)
// reactionsData2.put(acc, reactionsData.get(acc));
......@@ -250,7 +261,7 @@ public class WriteByMetabolitesID {
Map<String, Set<TcNumberContainer2>> newData = new TransportReactionsBuilder(reactionsData, service, data, namesAndIDsContainer, properties).getResults(); //uncomment
// for(TcNumberContainer2 container : newData.get("P31801")) {
// for(TcNumberContainer2 container : newData.get("O07084")) {
//
// System.out.println(container.getTcNumber());
//
......
......@@ -74,8 +74,6 @@ public class IdentifyReactionsMetabolites {
this.allMetabolitesByName = new HashMap<>(this.namesAndIDsContainer.getMetabolitesIDs());
System.out.println(this.allMetabolitesByName.containsKey("undecaprenyl phosphate-4-amino-4-deoxy-L-arabinose"));
// System.out.println("MET>>>>> " + allMetabolitesByName.get("Electron"));
//
// System.out.println("metabolites >>>" + metabolites.size()); //2078
......
......@@ -177,12 +177,12 @@ public class ProvideTransportReactionsToGenes {
try {
// String path = new File(queryPath).getParent().concat("/");
// String path = new File(queryPath).getParent().concat("/");
resultPath = resultPath.concat("results/");
File resultsFile = new File(resultPath);
if(!resultsFile.exists())
resultsFile.mkdirs();
......@@ -194,13 +194,13 @@ public class ProvideTransportReactionsToGenes {
if(this.modelMetabolites == null) {
logger.info("Searching metabolites.txt file...");
this.modelMetabolites = FilesUtils.readWordsInFile(metabolitesPath);
if(this.modelMetabolites.isEmpty()) { //quick fix to not brake generic method
this.modelMetabolites = null;
logger.warn("Filter by compounds in model disabled!");
}
}
if(this.modelMetabolites != null)
logger.info("Model metabolites size: " + this.modelMetabolites.size());
......@@ -211,11 +211,11 @@ public class ProvideTransportReactionsToGenes {
Set<String> tcNumbers = identifyTcNumbersForSearch();
// this.subunits.setSubunitsDatabase(findSubunitsInDatabase(tcNumbers));
logger.debug("Searching reactions in {} tcNumbers", tcNumbers.size());
logger.info("Searching reactions in {} tcNumbers", tcNumbers.size());
reactionsByTcNumber = getReactionsByTcNumber(tcNumbers);
// System.out.println(reactionsByTcNumber);
if(reactionContainersByID.keySet().size() == 0 && modelMetabolites != null)
......@@ -494,12 +494,12 @@ public class ProvideTransportReactionsToGenes {
String tcNumber = capsule.getTcdbID();
// if(tcNumber.equals("1.B.1.1.1")) {
// System.out.println(key);
// System.out.println(tcNumber);
// System.out.println(capsule.getEvalue() <= properties.geteValueThreshold());
//
// }
// if(tcNumber.equals("1.B.1.1.1")) {
// System.out.println(key);
// System.out.println(tcNumber);
// System.out.println(capsule.getEvalue() <= properties.geteValueThreshold());
//
// }
if(!evaluesEntry.containsKey(tcNumber))
evaluesEntry.put(tcNumber, capsule.getEvalue());
......@@ -551,9 +551,9 @@ public class ProvideTransportReactionsToGenes {
// FilesUtils.readMapFromFile(path.concat("Acc_to_locus.txt"));
for(String queryAccession : resultsByEvalue.keySet()) {
// if(queryAccession.equals("b4087"))
// System.out.println();
if(queryAccession.equals("b0341"))
System.out.println();
Set<String> reactionsAlreadyAssigned = new HashSet<>();
Set<String> accepted = new HashSet<>();
......@@ -572,14 +572,12 @@ public class ProvideTransportReactionsToGenes {
for(String tcNumber : resultsByEvalue.get(queryAccession)) {
// System.out.println(tcNumber + "\t" + reactionsByTcNumberForAnnotation.get(tcNumber));
if(reactionsByTcNumberForAnnotation.containsKey(tcNumber) && tcNumber.contains(tcFamily)){
Set<String> reactions = reactionsByTcNumberForAnnotation.get(tcNumber);
// if(!reactions.isEmpty())
// System.out.println(reactions);
// if(!reactions.isEmpty())
// System.out.println(reactions);
// System.out.println("dddd " + reactions);
......@@ -630,11 +628,11 @@ public class ProvideTransportReactionsToGenes {
if(!reactionsAlreadyAssigned.contains(id)) {
reactionsAlreadyAssigned.add(id);
reactionsAlreadyAssigned.add(id);
toAdd.add(id);
toAdd.add(id);
save = true;
save = true;
}
}
......@@ -1159,8 +1157,8 @@ public class ProvideTransportReactionsToGenes {
for(String tcNumber : identifyTcNumbersForSearch) {
// if(tcNumber.equalsIgnoreCase("1.B.1.1.1"))
// System.out.println(tcNumber);
if(tcNumber.equalsIgnoreCase("2.A.1.17.1"))
System.out.println(tcNumber);
try {
......@@ -1215,9 +1213,11 @@ public class ProvideTransportReactionsToGenes {
reactionsByTcNumberForAnnotation.put(tcNumber, reactionsToSave);
}
else {
tcNumbersNotPresentInTransytDatabase.add(tcNumber);
if(!tcNumbersNotPresentInTransytDatabase.contains(tcNumber)) {
logger.warn("No results found in TranSyT neo4j database for TCnumber {}! Please consider update the database.", tcNumber);
tcNumbersNotPresentInTransytDatabase.add(tcNumber);
logger.warn("No results found in TranSyT neo4j database for TCnumber {}! Please consider update the database.", tcNumber);
}
}
}
......@@ -1609,11 +1609,10 @@ public class ProvideTransportReactionsToGenes {
metabolitesNames.putAll(service.getTemporaryCompoundsNames());
metabolitesFormulas.putAll(service.getTemporaryCompoundsFormulas());
for(String name : metabolitesNames.values())
if(GENERATIONS_EXCEPTION_FILE.containsKey(name)) {
System.out.println("name -> " + name);
return null;
}
// for(String name : metabolitesNames.values())
// if(GENERATIONS_EXCEPTION_FILE.containsKey(name)) {
// return null;
// }
// System.out.println(reactionWithIDs);
// System.out.println(reactionAux);
......@@ -1641,7 +1640,7 @@ public class ProvideTransportReactionsToGenes {
// System.out.println(compounds);
// System.out.println("ToAdd " + reactionIDaux);
if((modelMetabolites == null || modelMetabolites.containsAll(compounds)) && reaction != null) { //null in case no sbml was inserted (accept all)
if((modelMetabolites == null || modelMetabolites.containsAll(compounds)) && reaction != null) { //null in case no sbml was inserted (accept all)
set.add(reactionID);
......
......@@ -17,6 +17,7 @@ import org.sbml.jsbml.ext.distrib.DistribConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.merlin.utilities.io.FileUtils;
import pt.uminho.ceb.biosystems.transyt.service.containers.BiosynthMetabolites;
import pt.uminho.ceb.biosystems.transyt.service.relations.MetabolitesChilds;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.TransytNeo4jInitializer;
......@@ -40,6 +41,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, Set<String>> missingChilds = FilesUtils.readDictionary(FilesUtils.getChildsRelationshipsMissingFilePath(), "\\$");
// private Map<String, String> newReactionIDs;
private Map<String, Integer> generationsLimit;
private Map<String, String> mappingModelSeed;
......@@ -166,7 +168,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);
......@@ -204,7 +206,7 @@ public class TransportReactionsBuilder {
long identifier = MetabolitesChilds.identifyNode(entryID, label, service);
childs.put(originalM, MetabolitesChilds.getMetaboliteChilds(-1, identifier, service)); //no limits here
childs.put(originalM, MetabolitesChilds.getMetaboliteChilds(originalM, -1, identifier, service, this.missingChilds)); //no limits here
mainMetabolitesMap.put(originalM, Long.toString(identifier));
}
}
......@@ -231,7 +233,7 @@ public class TransportReactionsBuilder {
if(allData.containsKey(entryID) && !formulas.containsKey(entryID))
formulas.put(entryID, allData.get(entryID).getFormula());
if(!childs.containsKey(metabolite)) {
if(!label.equals(MetaboliteMajorLabel.MetaCyc) && forChildsSearch.containsKey(metabolite)) {
......@@ -242,7 +244,7 @@ public class TransportReactionsBuilder {
long identifier = MetabolitesChilds.identifyNode(entryID, label, service);
childs.put(metabolite, MetabolitesChilds.getMetaboliteChilds(childGenerationLimit, identifier, service));
childs.put(metabolite, MetabolitesChilds.getMetaboliteChilds(metabolite, childGenerationLimit, identifier, service, this.missingChilds));
mainMetabolitesMap.put(metabolite, Long.toString(identifier));
}
......@@ -458,7 +460,7 @@ public class TransportReactionsBuilder {
boolean go = true;
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))
......@@ -468,24 +470,28 @@ public class TransportReactionsBuilder {
// 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
reaction = reaction.replace(replace + " ", childNames.get(id) + " ");
reactionBase = reactionBase.replace(replace + " ", metabolites.get(id) + " ");
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent)) { //PEP dependent
reaction = reaction.replaceAll(replace + "\\s+\\(", childNames.get(id) + " \\(");
reactionBase = reactionBase.replaceAll(replace + "\\s+\\(", metabolites.get(id) + " \\(");
}
else {
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);
reactionModelSeed = reactionModelSeed.replace(replace, repl);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionModelSeed = reactionModelSeed.replaceAll(replace + "\\s+\\(", repl + " \\(");
else
reactionModelSeed = reactionModelSeed.replace(replace, repl);
}
else {
reactionModelSeed = null;
......@@ -493,7 +499,10 @@ public class TransportReactionsBuilder {
if(mappingBiGG.containsKey(entryID) && reactionBiGG != null) {
repl = mappingBiGG.get(entryID);
reactionBiGG = reactionBiGG.replace(replace, repl);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionBiGG = reactionBiGG.replaceAll(replace + "\\s+\\(", repl + " \\(");
else
reactionBiGG = reactionBiGG.replace(replace, repl);
}
else {
reactionBiGG = null;
......@@ -501,7 +510,10 @@ public class TransportReactionsBuilder {
if(mappingKEGG.containsKey(entryID) && reactionKEGG != null) {
repl = mappingKEGG.get(entryID);
reactionKEGG = reactionKEGG.replace(replace, repl);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionKEGG = reactionKEGG.replaceAll(replace + "\\s+\\(", repl + " \\(");
else
reactionKEGG = reactionKEGG.replace(replace, repl);
}
else {
reactionKEGG = null;
......@@ -509,7 +521,10 @@ public class TransportReactionsBuilder {
if(mappingMetaCyc.containsKey(entryID) && reactionMetaCyc != null) {
repl = mappingMetaCyc.get(entryID);
reactionMetaCyc = reactionMetaCyc.replace(replace, repl);
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
reactionMetaCyc = reactionMetaCyc.replaceAll(replace + "\\s+\\(", repl + " \\(");
else
reactionMetaCyc = reactionMetaCyc.replace(replace, repl);
}
else {
reactionMetaCyc = null;
......@@ -522,19 +537,21 @@ public class TransportReactionsBuilder {
&& !formulas.get(entryID).equals(BiosynthMetaboliteProperties.NONE)) {
String previousFormula = formulasReaction;
formulasReaction = formulasReaction.replace(replace, formulas.get(entryID).concat("@")); //@ is added to control if replacements are really happening
if(reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
formulasReaction = formulasReaction.replaceAll(replace + "\\s+\\(",
formulas.get(entryID).concat("@") + " \\(");
else
formulasReaction = formulasReaction.replaceAll(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)) {
formulasReaction = formulasReaction.replace(replace, "");
}
else if(childNames.get(id).equalsIgnoreCase(ReactionContainer.ELECTRON_NAME)) {
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, "");
}
......@@ -587,7 +604,6 @@ public class TransportReactionsBuilder {
// }
// if(idsReaction.contains("META:BUTYRIC_ACID=MetaCyc (out) + META:CO-A=MetaCyc (in) + META:ATP=MetaCyc (in) $IRREV$ META:BU")) {
// System.out.println(formulasReaction);
// print = true;
......@@ -651,7 +667,7 @@ public class TransportReactionsBuilder {
// System.out.println(formulasReaction);
// System.out.println(reactionContainer.getDirectionRegex());
// System.out.println();
boolean balanced = isEquationBalanced(formulasReaction, reactionContainer.getDirectionRegex(), print);
// System.out.println("balanced: " + balanced);
......@@ -669,13 +685,12 @@ public class TransportReactionsBuilder {
boolean sugarPEPcorrect = true;
if(balanced && reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent))
sugarPEPcorrect = checkPEPReactions(reactant, product);
if(balanced && reactionContainer.getTransportType().equals(TypeOfTransporter.PEPdependent)) {
sugarPEPcorrect = checkPEPReactions(reactant, product, reactionContainer.getDirectionRegex());
}
if(balanced && sugarPEPcorrect) {
// System.out.println(formulasReaction);
reactantIDs = sortReactantsAndProducts(reactantIDs);
productIDs = sortReactantsAndProducts(productIDs);
......@@ -794,13 +809,20 @@ public class TransportReactionsBuilder {
return true;
}
private boolean checkPEPReactions(String reactant, String product) {
private boolean checkPEPReactions(String reactant, String product, String reactionDirection) {
String sugar = reactant.split(" \\(out\\)")[0].trim();
String sugarP = product.split("\\(in\\) \\+")[0].trim();
if(sugarP.contains(sugar) && sugarP.contains("-phosphate"))
if(sugarP.contains(sugar) && (sugarP.matches("(?i).*-phosphate") || sugarP.matches("(?i).*-\\dp")))
return true;
else if(this.reactionMetaCyc != null && reactionDirection != null){
String[] reactantsM = this.reactionMetaCyc.split(reactionDirection);
return checkPEPReactions(reactantsM[0], reactantsM[1], null); //repeat with metacyc IDs
}
// else if((sugar.contains("glucose") || sugar.contains("glucopyranose"))
// && (sugarP.contains("glucose") || sugarP.contains("glucopyranose"))){
//
......
......@@ -9,7 +9,10 @@ import java.util.Set;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.transyt.service.reactions.TransportReactionsBuilder;
import pt.uminho.sysbio.biosynth.integration.io.dao.neo4j.MetaboliteMajorLabel;
import pt.uminho.sysbio.biosynth.integration.io.dao.neo4j.MetaboliteRelationshipType;
import pt.uminho.sysbio.biosynthframework.BiodbGraphDatabaseService;
......@@ -17,6 +20,7 @@ import pt.uminho.sysbio.biosynthframework.BiodbGraphDatabaseService;
public class MetabolitesChilds {
public static final Integer ALL_CODE = -1;
private static final Logger logger = LoggerFactory.getLogger(MetabolitesChilds.class);
/**
* Get all childs of a given metabolite.
......@@ -27,7 +31,8 @@ public class MetabolitesChilds {
* @param service
* @return
*/
public static Set<Long> getMetaboliteChilds(Integer generationLimit, long id, BiodbGraphDatabaseService service) {
public static Set<Long> getMetaboliteChilds(String metabolite, Integer generationLimit, long id,
BiodbGraphDatabaseService service, Map<String, Set<String>> missingChilds) {
Map<Long, Integer> generation = new HashMap<>();
......@@ -36,7 +41,7 @@ public class MetabolitesChilds {
LinkedList<Long> toVisit = new LinkedList<>();
Node node = service.getNodeById(id);
// relation = node.getRelationships(Direction.INCOMING);
// for(Relationship rel : relation) {
......@@ -66,8 +71,6 @@ public class MetabolitesChilds {
node = service.getNodeById(currentNodeID);
// System.out.println(node.getAllProperties());
Iterable<Relationship> relation = node.getRelationships(Direction.INCOMING);
for(Relationship rel : relation) {
......@@ -96,32 +99,32 @@ public class MetabolitesChilds {
visited.add(currentNodeID);
}
// for(Long n : visited) {
//
// Map<String, Object> prop = service.getNodeById(n).getAllProperties();
//
// if(prop.containsKey("name"))
// System.out.println(prop.get("name"));
// else
// System.out.println(prop);
//
// }
//
// System.out.println(visited.size());
// if(entryID.equals("META:ACYL-COA"))
// System.out.println("CHILDSSS: " + visited);
if(missingChilds != null && metabolite != null && missingChilds.containsKey(metabolite)) {
for(String child : missingChilds.get(metabolite)) {
Long missingId = identifyNode("META:"+child, MetaboliteMajorLabel.MetaCyc, service);
if(missingId != null)
visited.add(missingId);
}
}
return visited;
}
public static long identifyNode(String entryID, MetaboliteMajorLabel label, BiodbGraphDatabaseService service) {
Node node = service.getNodeByEntryAndLabel(entryID, label);
return node.getId();
public static Long identifyNode(String entryID, MetaboliteMajorLabel label, BiodbGraphDatabaseService service) {
try {
Node node = service.getNodeByEntryAndLabel(entryID, label);
return node.getId();
}
catch (Exception e) {
logger.error("Missing node " + label.toString() +":" + entryID + " in biosynth database!");
e.printStackTrace();
}
return null;
}
......