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

changes to generate gene reaction rules

parent 12a9c0f8
......@@ -52,8 +52,8 @@ public class BiggMain {
break;
}
new ProvideBiggReactionsToGenes(workFolderID, filePath, properties, option, items);
//GET WORKSPACE NAME AND SEND IT
new ProvideBiggReactionsToGenes(workFolderID, filePath, properties, option, items,"workspaceName");
File unzippedResults = new File(workFolderID+"Bigg_Files/Results/");
......
......@@ -18,15 +18,14 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import pt.uminho.ceb.biosystems.merlin.bigg.data.BiggDataCenter;
import pt.uminho.ceb.biosystems.merlin.core.datatypes.WorkspaceInitialData;
import pt.uminho.ceb.biosystems.merlin.services.WorkspaceInitialDataServices;
public class ProvideBiggReactionsToGenes {
private Map<String,Set<String>> blastResults;
......@@ -36,19 +35,21 @@ public class ProvideBiggReactionsToGenes {
private Map<String, String> gprsMap = new HashMap<String,String>();
private String workFolderID;
private Map<String,Set<String>> queryGeneBiggGeneMap;
private String workspaceName;
public ProvideBiggReactionsToGenes(String workFolderID, String queryPathParameters, Properties properties, int option, String items) {
public ProvideBiggReactionsToGenes(String workFolderID, String queryPathParameters, Properties properties, int option, String items, String workspaceName) {
this.queryPath = queryPathParameters;
this.workFolderID = workFolderID;
this.workspaceName = workspaceName;
try {
Blast blast = new Blast(workFolderID, queryPath, properties, option, items);
blastResults = blast.getResults();
getReactionIds(properties, option, workFolderID);
gprsMap = createGPRs(workFolderID);
getReactionIds(properties, option);
gprsMap = createGPRs();
updateDatabase();
......@@ -62,7 +63,7 @@ public class ProvideBiggReactionsToGenes {
}
}
private void getReactionIds(Properties properties, int option, String workFolderID) throws IOException {
private void getReactionIds(Properties properties, int option) throws IOException {
try {
......@@ -83,7 +84,7 @@ public class ProvideBiggReactionsToGenes {
}
createGPRs(workFolderID);
createGPRs();
}
catch(Exception ex) {
......@@ -156,9 +157,9 @@ public class ProvideBiggReactionsToGenes {
// }
// }
private Map<String,String> createGPRs(String workFolderID) throws Exception {
private Map<String,String> createGPRs() throws Exception {
queryGeneBiggGeneMap = queryGeneBiggGeneRetriever(); //get bigg genes associated with the query gene
queryGeneBiggGeneMap = BiggDataCenter.biggGeneToQueryGeneRetriever(sequenceIdsGenesRelation,workFolderID,blastResults); //get bigg genes associated with the query gene
Map<String,String> parsedRules = booleanRulesParser(BiggDataCenter.readGenesReactionsRuleFile(workFolderID));
Map<String,Set<String>> finalRules = new HashMap<String,Set<String>>();
......@@ -227,11 +228,12 @@ public class ProvideBiggReactionsToGenes {
String rule = "";
List<String> genesList = new ArrayList<>(entry.getValue());
rule = genesList.get(0); //adds the first item
for(int i=1;i<genesList.size();i++) { //for the other ones, adds the item preceded by an "OR"
rule += " or " + genesList.get(i);
for(String gene : genesList) {
if(rule.equals(""))
rule = gene;
else
rule += " or " + gene;
}
finalRulesParsed.put(entry.getKey(), rule);
......@@ -272,10 +274,11 @@ public class ProvideBiggReactionsToGenes {
List<String> queryGenesList = new ArrayList<>(queryGenes);
subRuleAnd = queryGenesList.get(0); //adds the first item
for(int i=1;i<queryGenesList.size();i++) { //for the other ones, adds the item preceeded by an "AND"
subRuleAnd += " and " + queryGenesList.get(i);
for(String gene : queryGenesList) {
if(subRuleAnd.equals(""))
subRuleAnd = gene;
else
subRuleAnd += " and " + gene;
}
Set<String> queryGenesRule = finalRules.get(reaction); //gets the current results for the reaction
......@@ -307,46 +310,6 @@ public class ProvideBiggReactionsToGenes {
return listQueryGenes;
}
private Map<String, Set<String>> queryGeneBiggGeneRetriever() throws IOException{
Map<String,String> seqIDGenesMap = BiggDataCenter.readSeqIDGenesRelationFile(sequenceIdsGenesRelation, workFolderID);
Map<String,Set<String>> map = new HashMap<String,Set<String>>();
for (Entry<String,Set<String>> result : blastResults.entrySet()) {
for(String gene : result.getValue()) {
String biggGenes = seqIDGenesMap.get(gene);
List<String> biggGenesList = new ArrayList<String>();
biggGenesList = Arrays.asList(biggGenes.split(";"));
for(String geneListElement : biggGenesList) {
String geneFinal = geneListElement.trim();
if(map.containsKey(geneFinal)) {
Set<String> set = map.get(geneFinal);
set.add(result.getKey());
map.put(geneFinal, set);
}else {
Set<String> set = new HashSet<String>();
set.add(result.getKey());
map.put(geneFinal, set);
}
}
}
}
return map;
}
/**
* @param reactionsRules
* @return
......@@ -486,5 +449,25 @@ public class ProvideBiggReactionsToGenes {
return executeDistributions(set1, set2, cycle);
}
private void updateDatabase() {
try {
WorkspaceInitialData databaseInitialData = WorkspaceInitialDataServices.retrieveAllData(workspaceName);
//for cada reaction, adicionar os genes, e meter a reaction in model
}catch(Exception ex) {
ex.printStackTrace();
}
}
}
......@@ -14,19 +14,11 @@ import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import com.bpodgursky.jbool_expressions.*;
import com.bpodgursky.jbool_expressions.parsers.ExprParser;
import com.bpodgursky.jbool_expressions.rules.Rule;
import com.bpodgursky.jbool_expressions.rules.RuleSet;
import com.wolfram.*;
import com.wolfram.alpha.WAEngine;
import com.wolfram.alpha.WAQuery;
import com.wolfram.alpha.WAQueryResult;
import com.wolfram.alpha.net.*;
import com.wolfram.alpha.visitor.*;
import pt.uminho.ceb.biosystems.merlin.bigg.blast.Properties;
import pt.uminho.ceb.biosystems.merlin.bigg.data.BiggUtils;
......@@ -1055,100 +1047,7 @@ public class BiggDataCenter {
}
public static Map<String,String> genesReactionsRuleFile(String path) throws Exception {
Map<String,String> geneReactionRuleMap = new HashMap<String, String>();
Map<String,List<String>> geneReactionRuleMapList = new HashMap<String,List<String>>();
try {
List<String> modelFiles = new ArrayList<String>();
File folder = new File(path+"Bigg_Files/BiggData/");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
modelFiles.add(listOfFiles[i].getName().replace(".txt", ""));
}
for (String model : modelFiles) {
File f = new File(path+"Bigg_Files/BiggData/"+model+".txt");
if(!f.exists())
continue;
String file = BiggUtils.readFile(path+"Bigg_Files/BiggData/"+model+".txt", StandardCharsets.UTF_8);
System.out.println(model);
JSONObject modelDetails = new JSONObject(file);
modelDetails = modelDetails.getJSONObject(model);
BiggModels biggModel = new BiggModels();
//model genes
biggModel.setReactions(readModelReactions(modelDetails.getJSONObject("reaction"))); //Get all the reaction
for(BiggReactions reaction : biggModel.getReactions()) {
List<String> reactions = new ArrayList<String>();
List<BiggReactionResult> results = reaction.getResults();
for(BiggReactionResult result: results) {
if(result.getGeneReactionRule().equals(null) || result.getGeneReactionRule().equals(""))
continue;
if(!geneReactionRuleMap.containsKey(reaction.getBiggId())) {//If the key (Gene ID) doesn't exist already
if(reactions.isEmpty()) {//If it's the first result, just uses the value
reactions.add(result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), result.getGeneReactionRule());
}
else { //Else, checks if the value is different and updates
if(reactions.contains(result.getGeneReactionRule()))
continue;
else {
reactions.add(result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), geneReactionRuleMap.get(reaction.getBiggId()) + " or " + result.getGeneReactionRule());
}
}
geneReactionRuleMapList.put(reaction.getBiggId(), reactions);
}
else {//If already exists
reactions = geneReactionRuleMapList.get(reaction.getBiggId());
if(reactions.contains(result.getGeneReactionRule()))
continue;
else {
reactions.add(result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), geneReactionRuleMap.get(reaction.getBiggId()) + " or " + result.getGeneReactionRule());
}
geneReactionRuleMapList.put(reaction.getBiggId(), reactions);
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PrintWriter geneReactionRuleWriter = new PrintWriter(path+"Bigg_Files/Results/"+"geneReactionRuleFile.txt");
for (Entry<String,String> entry : geneReactionRuleMap.entrySet())
geneReactionRuleWriter.println(entry.getKey() + " - " + entry.getValue());
geneReactionRuleWriter.close();
return geneReactionRuleMap;
}
public static Map<String,String> readGenesReactionsRuleFile(String dockerPath) throws IOException{
Map<String,String> map = new HashMap<String, String>();
......@@ -1258,4 +1157,44 @@ public class BiggDataCenter {
return map;
}
public static Map<String, Set<String>> biggGeneToQueryGeneRetriever(String sequenceIdsGenesRelation, String workFolderID, Map<String,Set<String>> blastResults) throws IOException{
Map<String,String> seqIDGenesMap = BiggDataCenter.readSeqIDGenesRelationFile(sequenceIdsGenesRelation, workFolderID);
Map<String,Set<String>> map = new HashMap<String,Set<String>>();
for (Entry<String,Set<String>> result : blastResults.entrySet()) {
for(String gene : result.getValue()) {
String biggGenes = seqIDGenesMap.get(gene);
List<String> biggGenesList = new ArrayList<String>();
biggGenesList = Arrays.asList(biggGenes.split(";"));
for(String geneListElement : biggGenesList) {
String geneFinal = geneListElement.trim();
if(map.containsKey(geneFinal)) {
Set<String> set = map.get(geneFinal);
set.add(result.getKey());
map.put(geneFinal, set);
}else {
Set<String> set = new HashSet<String>();
set.add(result.getKey());
map.put(geneFinal, set);
}
}
}
}
return map;
}
}
......@@ -56,7 +56,8 @@ public class UpdateBiggFiles {
System.out.println("----creating fasta file-----");
createFastaFile(resultModel);
System.out.println("----Seq Id reaction relation-----");
writeSeqIDReactionRelationFile();
writeSeqIDReactionRelationFile();
System.out.println("----Genes reactions rule file-----");
genesReactionsRuleFile();
zipResultsFolder();
......@@ -935,7 +936,7 @@ public class UpdateBiggFiles {
public static Map<String,String> genesReactionsRuleFile() throws Exception {
Map<String,String> geneReactionRuleMap = new HashMap<String, String>();
Map<String,List<String>> geneReactionRuleMapList = new HashMap<String,List<String>>();
Map<String,List<String>> geneReactionRuleMapList = new HashMap<String,List<String>>();
try {
......@@ -975,7 +976,7 @@ public class UpdateBiggFiles {
continue;
else {
reactions.add(result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), geneReactionRuleMap.get(reaction.getBiggId()) + " OR " + result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), geneReactionRuleMap.get(reaction.getBiggId()) + " or " + result.getGeneReactionRule());
}
}
......@@ -989,7 +990,7 @@ public class UpdateBiggFiles {
continue;
else {
reactions.add(result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), geneReactionRuleMap.get(reaction.getBiggId()) + " OR " + result.getGeneReactionRule());
geneReactionRuleMap.put(reaction.getBiggId(), geneReactionRuleMap.get(reaction.getBiggId()) + " or " + result.getGeneReactionRule());
}
geneReactionRuleMapList.put(reaction.getBiggId(), reactions);
......
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