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 76dd80f2 authored by dlagoa's avatar dlagoa
Browse files

duplicated entries fixed

parent cdccb9ce
......@@ -44,13 +44,14 @@ public class Blast implements Observer{
private static final Logger logger = LoggerFactory.getLogger(Blast.class);
private ConcurrentLinkedQueue<AlignmentCapsule> results;
private String blastDirectory;
// private String blastDirectory;
private String workFolderID;
private Integer queryFileSize = 0;
private Properties properties;
private String queryFilePath;
private boolean forceBlast;
public Blast(boolean forceBlast, String queryFilePath, Properties properties) {
public Blast(boolean forceBlast, String workFolderID, String queryFilePath, Properties properties) {
try {
......@@ -62,7 +63,9 @@ public class Blast implements Observer{
this.queryFilePath = queryFilePath;
blastDirectory = FilesUtils.getBlastDirectory();
this.workFolderID = workFolderID;
// blastDirectory = FilesUtils.getBlastDirectory();
results = performBlast();
......@@ -127,7 +130,7 @@ public class Blast implements Observer{
run_similaritySearch.setSubjectFastaFilePath(tcdbFastaFile);
run_similaritySearch.addObserver(this);
run_similaritySearch.setWorkspaceTaxonomyFolderPath(blastDirectory);
run_similaritySearch.setWorkspaceTaxonomyFolderPath(workFolderID);
ConcurrentLinkedQueue<AlignmentCapsule> results = null;
if(sequences.keySet().size()>0)
......
......@@ -142,18 +142,15 @@ public class BlastAlignmentTransyt extends Observable implements ModelAlignments
try {
File tcdbfile = new File(subjectFasta);
String outputFileName = queryFasta.substring(queryFasta.lastIndexOf("/")).replace(".faa", "").concat("_blastReport.xml");
if(isTransportersSearch)
outputFileName = outputFileName.replace(".xml", "_transporters.xml");
File outputFile;
if(this.blastOutputFolderPath!=null && !this.blastOutputFolderPath.isEmpty())
outputFile = new File(this.blastOutputFolderPath.concat(outputFileName));
else
outputFile = new File(tcdbfile.getParent().concat("\\..\\").concat("reports").concat(outputFileName));
this.blastOutputFolderPath = new File(queryFasta).getParent().concat("reports");
outputFile = new File(blastOutputFolderPath.concat(outputFileName));
outputFile.getParentFile().mkdirs();
......
......@@ -12,7 +12,6 @@ import org.neo4j.graphdb.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.transyt.scraper.tcdb.tcdbTransportTypesRetriever.Retriever;
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;
......@@ -80,13 +79,13 @@ public class WriteByMetabolitesID {
// while (n != 99) {
//
// n = 99;
//
test(namesAndIDsContainer, data, service, null, reactionsData, null, properties); //uncomment
// test2(service);
// System.out.println("Enter a random number to repeat (100 to repeat data retrieval) or 99 to finish: ");
////
////// test2(service);
////
//// 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) {
......@@ -170,10 +169,11 @@ public class WriteByMetabolitesID {
try {
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
//
// String[] accessions = new String[] {"P28570"};
////
// reactionsData2.put("P25185", reactionsData.get("P25185"));
// reactionsData2.put("Q8SKU2", reactionsData.get("Q8SKU2"));
// reactionsData2.put("P23200", reactionsData.get("P23200"));
// for(String acc : accessions)
// reactionsData2.put(acc, reactionsData.get(acc));
IdentifyReactionsMetabolites metabolitesIdentification = new IdentifyReactionsMetabolites(reactionsData, namesAndIDsContainer, service);
......@@ -192,7 +192,7 @@ public class WriteByMetabolitesID {
// System.out.println(service.getNodeById(Long.valueOf(65729)).getAllProperties());
//
// for(TcNumberContainer2 container : newData.get("P25185")) {
// for(TcNumberContainer2 container : newData.get("P28570")) {
//
// System.out.println(container.getTcNumber());
//
......@@ -200,6 +200,7 @@ public class WriteByMetabolitesID {
// System.out.println();
//
// System.out.println(container.getReactionContainer(id).getReactionID());
// 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());
......@@ -211,7 +212,7 @@ public class WriteByMetabolitesID {
//
// System.out.println();
// }
//
// System.out.println(data.containsKey("D07664"));
// test2(service);
......
......@@ -38,7 +38,7 @@ public class Tools {
* @param path
* @return
*/
public static Map<String, String> readModelMetabolitesFromSBML(String path) {
public static Set<String> readModelMetabolitesFromSBML(String path) {
if(path == null)
return null;
......@@ -99,11 +99,11 @@ public class Tools {
}
catch (Exception e) {
e.printStackTrace();
System.out.println("MODEL NOT PROVIDED!!!!!");
return null;
}
return metabolites;
return metabolites.keySet();
}
}
......@@ -17,7 +17,6 @@ import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -74,7 +73,7 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
}
public void restartDriver() { //the program executes faster when the driver is closed
public void restartDriver() {
driver = GraphDatabase.driver( uri, AuthTokens.basic( username, password ) );
......@@ -841,7 +840,7 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
* @param tcNumber
* @return
*/
public String getReactionEquation(boolean reversible, Set<TransytRelationship> reactants, Set<TransytRelationship> products) {
public String getReactionEquation(String reactionID, boolean reversible, Set<TransytRelationship> reactants, Set<TransytRelationship> products) {
temporaryCompounds = new HashSet<>();
temporaryCompoundsNames = new HashMap<>();
......@@ -857,10 +856,22 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
// Set<TransytRelationship> reactants = getDownstreamRelationships(reactionNodeID, reactantRel);
// Set<TransytRelationship> products = getDownstreamRelationships(reactionNodeID, productRel);
try {
String reactant = buildEquationAux(reactants);
String product = buildEquationAux(products);
if(reactant == null || product == null)
return null;
reaction = reactant.concat(reversibility).concat(product);
}
catch (Exception e) {
logger.error("An error occurred while building the equation for reaction {}", reactionID);
logger.trace("StackTrace: {}", e);
return null;
}
return reaction;
}
......@@ -888,6 +899,9 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
// System.out.println(rel.getEndNode().getAllProperties());
metaboliteID = node.getProperty(TransytGeneralProperties.MetaboliteID);
if(metaboliteID == null)
return null;
temporaryCompounds.add(metaboliteID);
String name = node.getProperty(TransytGeneralProperties.Name);
......@@ -977,10 +991,16 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
try {
if(!property.isEmpty() && property.contains("=")) {
String[] aux = property.split("=");
properties.put(aux[0], aux[1]);
if(aux.length > 1) {
properties.put(aux[0], aux[1]);
previousKey = aux[0];
}
else
previousKey = "";
}
else if(!property.isEmpty()){
properties.put(previousKey, properties.get(previousKey).concat(", ").concat(property));
......@@ -989,7 +1009,6 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
}
catch (Exception e) {
logger.warn("An error occurred while mapping the node properties for the following sentence: {}", text);
logger.trace("StackTrace: {}", e);
}
}
}
......
package pt.uminho.ceb.biosystems.transyt.service.reactions;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
//FONT : https://gist.github.com/atomictom/7797647
......@@ -20,7 +18,7 @@ import java.util.HashMap;
public class FormulaParser {
public static String symbols_map =
public static String symbols_map = //save this in one file
"H Hydrogen\n" +
"He Helium\n" +
"Li Lithium\n" +
......@@ -138,7 +136,9 @@ public class FormulaParser {
"Uup Ununpentium\n" +
"Lv Livermorium\n" +
"Uus Ununseptium\n" +
"Uuo Ununoctium";
"Uuo Ununoctium\n"+
"R R\n"
;
public static Map<String,String> getSymbolMap(){
Map<String, String> element_map = new HashMap<>();
......@@ -151,6 +151,7 @@ public class FormulaParser {
element_map.put(shortform, longform);
element_map.put(longform.toUpperCase(), longform);
}
return element_map;
}
......@@ -158,6 +159,7 @@ public class FormulaParser {
private static Map<String,Integer> parseFormulaString(String formula, Map<String,String> element_map){
Map<String,Integer> element_counts = new HashMap<>();
/* formula = formula.toUpperCase(); */
int len = formula.length();
for(int i = 0; i < len;){
boolean is_group = false;
......@@ -172,42 +174,73 @@ public class FormulaParser {
int restore_i = 0;
String element = null;
String restore_element = null;
while(formula.charAt(i) == '('){
while(i < len && formula.charAt(i) != ')'){
i++;
}
if(i++ < len && Character.isDigit(formula.charAt(i))) {
while(i < len && Character.isDigit(formula.charAt(i))){
i++;
}
}
atoms_in_group.putAll(parseFormulaString(formula.substring(start, i), element_map));
start = i;
}
while(i < len && Character.isLetter(formula.charAt(i))){
i++;
element = formula.substring(start, i);
/* System.out.println( element); */
String element_from_map = element_map.get(element);
if(element_from_map == null)
element_from_map = element_map.get(element.toUpperCase());
if(element_from_map != null){
/* System.out.println("element from map: " + element_from_map); */
// System.out.println("element from map: " + element_from_map);
restore_i = i;
restore_element = element_from_map;
}
}
// System.out.println(restore_element);
if(restore_element != null){
i = restore_i;
element = restore_element;
}
if(element == null || element == ""){
// if(element == null || element == ""){
// System.out.println("Parse error: could not detect an element where one was expected in formula string.");
// System.out.println("Remaining formula to parse: " + formula.substring(i));
// System.exit(0);
}
// throw new Exception("Parse error: could not detect an element where one was expected in formula string for element"+element+".");
// }
start = i;
while(i < len && Character.isDigit(formula.charAt(i))){
i++;
}
int count;
try{
count = Integer.parseInt(formula.substring(start, i));
}catch(NumberFormatException e){
count = 1;
}
/* System.out.println("element: "+element); */
if(element != null && element.equalsIgnoreCase("R")) {
element = element.concat(count+"");
count = 1;
}
if(element != null)
atoms_in_group.put(element, count);
if(i < len && formula.charAt(i) == ')'){
if(!is_group)
System.out.println("Parse error: unmatched parenthesis detected...");
......@@ -242,14 +275,20 @@ public class FormulaParser {
/**
* @param formula
* @return
* @throws Exception
*/
public static Map<String,Integer> parse(String formula, Map<String,String> element_map) {
public static Map<String,Integer> parse(String formula, Map<String,String> element_map){
if(element_map == null)
element_map = getSymbolMap();
// System.out.println(element_map);
// System.out.println(formula);
formula = formula.replaceAll("[^a-zA-Z0-9()]", "");
// System.out.println(formula);
Map<String,Integer> element_counts = parseFormulaString(formula, element_map);
return element_counts;
......
......@@ -143,6 +143,7 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
try {
if(metabolite.matches("^(D*L*-+).+")){
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("^(D*L*-+)", ""))) {
......@@ -168,6 +169,10 @@ public class IdentifyReactionsMetabolites {
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
......@@ -178,6 +183,7 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
try {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("[^A-Za-z0-9]", "").toLowerCase())) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("[^A-Za-z0-9]", "").toLowerCase());
......@@ -193,6 +199,10 @@ public class IdentifyReactionsMetabolites {
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
/**
......@@ -202,6 +212,7 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
try {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("[^A-Za-z0-9]", ""))) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("[^A-Za-z0-9]", ""));
......@@ -217,6 +228,10 @@ public class IdentifyReactionsMetabolites {
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
/**
......@@ -226,6 +241,7 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
try {
if(namesAndIDsContainer.getNamesLowerCase().containsKey(metabolite.toLowerCase())) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.toLowerCase());
......@@ -242,6 +258,10 @@ public class IdentifyReactionsMetabolites {
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
/**
......@@ -251,6 +271,7 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
try {
identificationDeletingStoichiometryAux(metabolite, false);
if(metabolites.contains(metabolite)) {
......@@ -262,6 +283,10 @@ public class IdentifyReactionsMetabolites {
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
/**
......@@ -443,6 +468,7 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : metabolites) {
try {
if(metabolite.matches("(?i).+(-P)$"))
metabolite = metabolite.replaceAll("(?i)(-P)$", "\\sphosphate");
......@@ -455,6 +481,10 @@ public class IdentifyReactionsMetabolites {
else
standardNames.add(metabolite);
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
return standardNames;
}
......
......@@ -2,6 +2,7 @@ package pt.uminho.ceb.biosystems.transyt.service.reactions;
import java.io.File;
import java.io.FileOutputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
......@@ -16,14 +17,11 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pt.uminho.ceb.biosystems.merlin.utilities.containers.capsules.AlignmentCapsule;
import pt.uminho.ceb.biosystems.merlin.utilities.io.FileUtils;
import pt.uminho.ceb.biosystems.mew.biocomponents.container.Container;
import pt.uminho.ceb.biosystems.mew.biocomponents.container.components.MetaboliteCI;
import pt.uminho.ceb.biosystems.mew.biocomponents.container.components.ReactionCI;
......@@ -40,7 +38,6 @@ import pt.uminho.ceb.biosystems.transyt.service.kbase.Tools;
import pt.uminho.ceb.biosystems.transyt.service.neo4jRest.RestNeo4jGraphDatabase;
import pt.uminho.ceb.biosystems.transyt.service.relations.GPRAssociations;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.TransytGeneralProperties;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.TransytGraphDatabaseService;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.TransytNeo4jInitializer;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.TransytNode;
import pt.uminho.ceb.biosystems.transyt.service.transytDatabase.TransytNodeLabel;
......@@ -75,7 +72,7 @@ public class ProvideTransportReactionsToGenes {
private Map<String, Set<String>> resultsByEvalue;
private Map<String, List<String>> mainReactions;
private Map<String, Set<String>> reactionsByTcNumber;
private Map<String, Set<String>> reactionsByTcNumberForAnnotation;
private Map<String, Set<String>> reactionsByTcNumberForAnnotation; //1
private Set<String> hitsWithoutReactions;
private Map<String, Map<String, Set<String>>> finalResults;
private Map<String, ReactionContainer> reactionContainersByID;
......@@ -83,7 +80,7 @@ public class ProvideTransportReactionsToGenes {
private Set<String> reactionsToIgnore;
private Set<String> tcNumbersNotPresentInTransytDatabase; //tcNumbers present in this set are not yet in the
private Map<String, String> modelMetabolites; //neo4j database (solution: update the database)
private Set<String> modelMetabolites; //neo4j database (solution: update the database)
private TransytRelationshipType defaultRelationshipReactants;
private TransytRelationshipType defaultRelationshipProducts;
......@@ -98,8 +95,8 @@ public class ProvideTransportReactionsToGenes {
private static final Logger logger = LoggerFactory.getLogger(WriteByMetabolitesID.class);
public ProvideTransportReactionsToGenes(Organism organismProperties, String queryPath, String modelPath,
String resultPath, Properties properties) {
public ProvideTransportReactionsToGenes(String workFolderID, Organism organismProperties, String queryPath, String modelPath,
String metabolitesPath, String resultPath, Properties properties, boolean forceBlast) {
logger.info("TranSyT initialized!");
......@@ -127,7 +124,7 @@ public class ProvideTransportReactionsToGenes {
// findTaxonomyByTaxonomyID(taxID);
try {
Blast blast = new Blast(false, queryPath, properties);
Blast blast = new Blast(forceBlast, workFolderID, queryPath, properties);
blastResults = blast.getAlignmentsByQuery();
service = TransytNeo4jInitializer.getDatabaseService(true, properties);
......@@ -147,7 +144,7 @@ public class ProvideTransportReactionsToGenes {
// while (n != 99) {
start(queryPath, resultPath);
start(metabolitesPath, queryPath, resultPath);
// System.out.println("Insert a number to repeat or 99 to finish");
//
......@@ -177,7 +174,7 @@ public class ProvideTransportReactionsToGenes {
}
}