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 {
......@@ -61,8 +62,10 @@ public class Blast implements Observer{
this.properties = properties;
this.queryFilePath = queryFilePath;
this.workFolderID = workFolderID;
blastDirectory = FilesUtils.getBlastDirectory();
// 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)
......
......@@ -98,7 +98,7 @@ public class BlastAlignmentTransyt extends Observable implements ModelAlignments
this.alignmentContainerSet = alignmentContainerSet;
this.cancel = cancel;
this.jc = jc;
}
......@@ -141,19 +141,16 @@ public class BlastAlignmentTransyt extends Observable implements ModelAlignments
if(!this.cancel.get()) {
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) {
......@@ -169,11 +168,12 @@ public class WriteByMetabolitesID {
try {
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
////
// reactionsData2.put("P25185", reactionsData.get("P25185"));
// reactionsData2.put("Q8SKU2", reactionsData.get("Q8SKU2"));
// reactionsData2.put("P23200", reactionsData.get("P23200"));
// Map<String, Set<TcNumberContainer2>> reactionsData2 = new HashMap<>();
//
// String[] accessions = new String[] {"P28570"};
////
// for(String acc : accessions)
// reactionsData2.put(acc, reactionsData.get(acc));
IdentifyReactionsMetabolites metabolitesIdentification = new IdentifyReactionsMetabolites(reactionsData, namesAndIDsContainer, service);
......@@ -189,10 +189,10 @@ public class WriteByMetabolitesID {
/////TRIAGE
Map<String, Set<TcNumberContainer2>> newData = new TransportReactionsBuilder(tcdbMetabolitesIDs, reactionsData, forChildsSearch, service, data, namesAndIDsContainer.getMetabolitesIDs(), properties).getResults(); //uncomment
// 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);
String reactant = buildEquationAux(reactants);
String product = buildEquationAux(products);
try {
String reactant = buildEquationAux(reactants);
String product = buildEquationAux(products);
reaction = reactant.concat(reversibility).concat(product);
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;
}
......@@ -887,6 +898,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);
......@@ -977,9 +991,15 @@ public class RestNeo4jGraphDatabase implements AutoCloseable{
try {
if(!property.isEmpty() && property.contains("=")) {
String[] aux = property.split("=");
properties.put(aux[0], aux[1]);
previousKey = aux[0];
if(aux.length > 1) {
properties.put(aux[0], aux[1]);
previousKey = aux[0];
}
else
previousKey = "";
}
else if(!property.isEmpty()){
......@@ -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); */
atoms_in_group.put(element, count);
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,29 +143,34 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
if(metabolite.matches("^(D*L*-+).+")){
try {
if(metabolite.matches("^(D*L*-+).+")){
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("^(D*L*-+)", ""))) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("^(D*L*-+)", ""))) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("^(D*L*-+)", ""));
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("^(D*L*-+)", ""));
saveMetabolite(metabolite, ids);
saveMetabolite(metabolite, ids);
}
}
}
else {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey("D-"+metabolite)) {
else {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey("D-"+metabolite)) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get("D-"+metabolite);
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get("D-"+metabolite);
saveMetabolite(metabolite, ids);
}
saveMetabolite(metabolite, ids);
}
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey("L-"+metabolite)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey("L-"+metabolite)) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get("L-"+metabolite);
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get("L-"+metabolite);
saveMetabolite(metabolite, ids);
saveMetabolite(metabolite, ids);
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
......@@ -178,19 +183,24 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("[^A-Za-z0-9]", "").toLowerCase())) {
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());
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("[^A-Za-z0-9]", "").toLowerCase());
saveMetabolite(metabolite, ids);
}
else if(String.valueOf(metabolite.charAt(metabolite.length()-1)).equals(s)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""))) {
saveMetabolite(metabolite, ids);
}
else if(String.valueOf(metabolite.charAt(metabolite.length()-1)).equals(s)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""))) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""));
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""));
saveMetabolite(metabolite, ids);
saveMetabolite(metabolite, ids);
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
......@@ -202,19 +212,24 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("[^A-Za-z0-9]", ""))) {
try {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.replaceAll("[^A-Za-z0-9]", ""))) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("[^A-Za-z0-9]", ""));
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.replaceAll("[^A-Za-z0-9]", ""));
saveMetabolite(metabolite, ids);
}
else if(String.valueOf(metabolite.charAt(metabolite.length()-1)).equals(s)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""))) {
saveMetabolite(metabolite, ids);
}
else if(String.valueOf(metabolite.charAt(metabolite.length()-1)).equals(s)) {
if(namesAndIDsContainer.getNamesWithoutSigns().containsKey(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""))) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""));
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.substring(0, metabolite.length()-1).replaceAll("[^A-Za-z0-9]", ""));
saveMetabolite(metabolite, ids);
saveMetabolite(metabolite, ids);
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
......@@ -226,20 +241,25 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
if(namesAndIDsContainer.getNamesLowerCase().containsKey(metabolite.toLowerCase())) {
try {
if(namesAndIDsContainer.getNamesLowerCase().containsKey(metabolite.toLowerCase())) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.toLowerCase());
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.toLowerCase());
saveMetabolite(metabolite, ids);
}
else if(String.valueOf(metabolite.charAt(metabolite.length()-1)).equals(s)) {
saveMetabolite(metabolite, ids);
}
else if(String.valueOf(metabolite.charAt(metabolite.length()-1)).equals(s)) {
if(namesAndIDsContainer.getNamesLowerCase().containsKey(metabolite.substring(0, metabolite.length()-1).toLowerCase())) {
if(namesAndIDsContainer.getNamesLowerCase().containsKey(metabolite.substring(0, metabolite.length()-1).toLowerCase())) {
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.substring(0, metabolite.length()-1).toLowerCase());
Map<MetaboliteMajorLabel, String> ids = allMetabolitesByName.get(metabolite.substring(0, metabolite.length()-1).toLowerCase());
saveMetabolite(metabolite, ids);
saveMetabolite(metabolite, ids);
}
}
}
catch (Exception e) {
logger.trace("StackTrace: {}", e);
}
}
}
......@@ -251,15 +271,20 @@ public class IdentifyReactionsMetabolites {
for(String metabolite : new HashSet<>(metabolites)) {
identificationDeletingStoichiometryAux(metabolite, false);