Allows to run GeneNet java with user values and added option to save

sbml file.
This commit is contained in:
leandrohw 2018-01-09 18:56:40 -07:00
parent b705b54819
commit 541d5d9de3
4 changed files with 138 additions and 13 deletions

View file

@ -32,10 +32,12 @@ import org.sbml.jsbml.Parameter;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLReader;
import org.sbml.jsbml.SBMLWriter;
import org.sbml.jsbml.Species;
import org.sbml.jsbml.SpeciesReference;
import edu.utah.ece.async.ibiosim.dataModels.biomodel.parser.BioModel;
import edu.utah.ece.async.ibiosim.dataModels.biomodel.parser.GCM2SBML;
import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.SBMLutilities;
import edu.utah.ece.async.ibiosim.dataModels.util.Message;
import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.BioSimException;
@ -60,6 +62,7 @@ import edu.utah.ece.async.ibiosim.learn.parameterestimator.ParameterEstimator;
* <li>-e: when specified, the program will run parameter estimation.</li>
* <li>-l: when specified, parameter estimation will use the estimate the value of the parameters in the list.</li>
* <li>--cpp: runs the C++ GeneNet. Default is the Java version. </li>
* <li>--sbml [name]: outputs an sbml file with the specified name (e.g. learn.xml). </li>
* <li>-ta [num]: Sets the activation threshold. Default 1.15</li>
* <li>-tr [num]: Sets the repression threshold. Default 0.75</li>
* <li>-ti [num]: Sets how high a score must be to be considered a parent. Default 0.5</li>
@ -100,6 +103,7 @@ public class Learn implements BioObserver
noSUCC, PRED, basicFBP;
private String directory;
private String filename;
private String sbmlOut;
private List<String> listOfParameters;
private Learn()
@ -193,6 +197,17 @@ public class Learn implements BioObserver
usage();
}
break;
case "--sbml":
if(i+1 < end)
{
learn.sbmlOut = args[i+1];
i=i+1;
}
else
{
usage();
}
break;
case "-ta":
if(i+1 < end)
{
@ -393,6 +408,7 @@ public class Learn implements BioObserver
SBMLDocument newDocument = ParameterEstimator.estimate(filename, directory, listOfParameters, E, S);
if (newDocument != null)
{
saveSBML(null);
Model model = newDocument.getModel();
for (String parameterId : listOfParameters)
{
@ -407,6 +423,10 @@ public class Learn implements BioObserver
}
}
}
else
{
System.out.println("Could not run parameter estimation.");
}
}
private void runGeneNet() throws BioSimException, IOException, XMLStreamException, InterruptedException
@ -429,10 +449,41 @@ public class Learn implements BioObserver
else
{
System.out.println("Running GeneNet (Java)");
Run.run(filename, directory);
Run.run(ta, tr, ti, tt, nb, filename, directory);
}
saveSBML(null);
}
private void saveSBML(SBMLDocument doc) throws XMLStreamException, IOException
{
if(sbmlOut != null)
{
String newFileName = directory + File.separator + sbmlOut;
System.out.println("Saving " + newFileName);
if(runParameterEstimation)
{
SBMLWriter.write(doc, new File(newFileName), ' ', (short) 4);
}
else
{
String learnFile = directory + File.separator + "method.gcm";
if(new File(learnFile).exists())
{
BioModel biomodel = new BioModel(directory);
biomodel.load(learnFile);
GCM2SBML gcm2sbml = new GCM2SBML(biomodel);
gcm2sbml.load(learnFile);
gcm2sbml.convertGCM2SBML(directory, "method.gcm");
biomodel.save(newFileName);
}
}
}
}
private String[] getProcessArguments()
{
ArrayList<String> args = new ArrayList<String>();

View file

@ -415,11 +415,11 @@ public class Learn
{
score = scoreParents(s, S, new HashSet<String>(Arrays.asList(p)), new HashSet<String>(Arrays.asList(s)), E, T, L);
if (score >= T.getTv())
if (score >= T.getTi())
{
C.addConnection(s, "activator", score, p);
}
else if (score <= -T.getTv())
else if (score <= -T.getTi())
{
C.addConnection(s, "repressor", score, p);
}

View file

@ -30,7 +30,7 @@ import org.sbml.jsbml.Species;
import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.BioSimException;
/**
*
* This class is used for running the Java version of the GeneNet learning algorithm.
*
* @author Leandro Watanabe
* @author Chris Myers
@ -42,6 +42,50 @@ public class Run
private static int experiment;
/**
* Runs GeneNet with custom values.
*
* @param Ta - activation threshold
* @param Tr - repression threshold
* @param Ti - influence threshold
* @param Tt - relaxing of activation repression threshold.
* @param bins - number of bins
* @param filename - the input sbml file
* @param directory - the directory of the project.
* @return true if learn was completed. False otherwise.
* @throws BioSimException - if something wrong happens with the learn procedure.
*/
public static boolean run(double Ta, double Tr, double Ti, double Tt, int bins, String filename, String directory) throws BioSimException
{
SpeciesCollection S = new SpeciesCollection();
Experiments E = new Experiments();
Encodings L = new Encodings();
Thresholds T = new Thresholds(Ta, Tr, Ti, Tt);
NetCon C = new NetCon();
init(filename, S);
loadExperiments(directory, S, E);
if(experiment < 1)
{
return false;
}
Learn learn = new Learn(bins);
learn.learnNetwork(S, E, C, T, L);
learn.getDotFile("method.gcm", directory, S, C);
learn.getDotFile("method.dot", directory, S, C);
return true;
}
/**
* Runs GeneNet with default values.
*
* @param filename - the input sbml file
* @param directory - the directory of the project.
* @return true if learn was completed. False otherwise.
* @throws BioSimException - if something wrong happens with the learn procedure.
*/
public static boolean run(String filename, String directory) throws BioSimException
{
@ -64,6 +108,14 @@ public class Run
return true;
}
/**
* Reads in time-series data to an {@link Experiments} object.
*
* @param directory - where the experiments are located.
* @param S - the interesting species.
* @param E - where the data is stored.
* @throws BioSimException - if there is a problem reading the data.
*/
public static void loadExperiments(String directory, SpeciesCollection S, Experiments E) throws BioSimException
{
File path = new File(directory);
@ -84,6 +136,12 @@ public class Run
}
}
/**
* Retrieves the interesting species of a model.
*
* @param filename - an SBML model.
* @param S - where the interesting species are stored.
*/
public static void init(String filename, SpeciesCollection S)
{
try

View file

@ -24,7 +24,7 @@ package edu.utah.ece.async.ibiosim.learn.genenet;
public class Thresholds
{
private double Ta, Tr, Tv, Tt;
private double Ta, Tr, Ti, Tt;
/**
* Creates a Thresholds object using default values.
@ -33,7 +33,7 @@ public class Thresholds
{
Ta = 1.15;
Tr = 0.75;
Tv = 0.5;
Ti = 0.5;
Tt = 0.025;
}
@ -42,15 +42,31 @@ public class Thresholds
*
* @param Ta - activation threshold.
* @param Tr - repression threshold.
* @param Tv - no influence threshold.
* @param Ti - no influence threshold.
*/
public Thresholds(double Ta, double Tr, double Tv)
public Thresholds(double Ta, double Tr, double Ti)
{
this.Ta = Ta;
this.Tr = Tr;
this.Tv = Tv;
this.Ti = Ti;
this.Tt = 0.025;
}
/**
* Creates a Thresholds object using custom values.
*
* @param Ta - activation threshold.
* @param Tr - repression threshold.
* @param Ti - no influence threshold.
* @param Tt - how relaxed the activation and repression thresholds are.
*/
public Thresholds(double Ta, double Tr, double Ti, double Tt)
{
this.Ta = Ta;
this.Tr = Tr;
this.Ti = Ti;
this.Tt = Tt;
}
/**
* Returns the threshold value of activation.
@ -77,9 +93,9 @@ public class Thresholds
*
* @return threshold for no influence.
*/
public double getTv()
public double getTi()
{
return Tv;
return Ti;
}
/**
@ -107,9 +123,9 @@ public class Thresholds
*
* @param Tv - value of threshold.
*/
public void setTv(double Tv)
public void setTi(double Ti)
{
this.Tv = Tv;
this.Ti = Ti;
}
/**