CaliBayes tutorial
Preliminaries
Before starting this tutorial, you need
- Java.
The Calibayes Java API
The Calibayes calibration framework implements MCMC Calibration algorithms. Users can invoke its Java APIs to start calibration tasks with the Fern and Roadrunner Simulator Web Services deployed at Newcastle University.
Method Summary
The Calibayes Java APIs comprises three functions:
- String calibrate(String algorithm, String simulatorName, String sbmlModel, String expDataXml, String tuningXml, String distributionXml)
- String convertDocumentToString(Document doc)
- Document readStringCreateDocument(java.lang.String str)
calibration() function takes four String parameters for starting off a calibration task.
- sbmlModel: the SBML model to be calibrated
- expDataXml: the experiment data in XML format
- tuingXml: tuning parameters in XML format
- distributionXml: prior distribution data in XML format
- return: a calibrated distribution data in XML format
convertDocumentToString() function converts a XML document into String
readStringCreateDocument() function converts a XML formatted String in to a XML document
Demo script
Adds the following line at the top of a Java class to import calibayes Java APIs:
1 import uk.ac.ncl.calibayes.calibration.*;
Creates a function to start a calibration job:
1 public static void main(String[] args) {
2 XMLParser xmlparser = new XMLParser();
3 Calibration calibration = new Calibration();
4
5 Document doc = null;
6
7 String sbmlModel = "death.xml";
8 String expDataXml = "experiment.xml";
9 String tuningXml = "tuning.xml";
10 String distributionXml = "distribution.xml";
11
12 doc = xmlparser.readFileCreateDocument(sbmlModel);
13 sbmlModel = xmlparser.readDocumentCreateString(doc);
14
15 doc = xmlparser.readFileCreateDocument(expDataXml);
16 expDataXml = xmlparser.readDocumentCreateString(doc);
17
18 doc = xmlparser.readFileCreateDocument(tuningXml);
19 tuningXml = xmlparser.readDocumentCreateString(doc);
20
21 doc = xmlparser.readFileCreateDocument(distributionXml);
22 distributionXml = xmlparser.readDocumentCreateString(doc);
23
24
25 String rst = calibration.calibrate(sbmlModel, expDataXml, tuningXml, distributionXml);
26
27 String filename = "CalibayesOutput.xml";
28 BufferedWriter out = new BufferedWriter(new FileWriter(filename));
29 out.write(rst); //Write out a file
30 out.flush();
31 out.close(); //flushes and closes the stream
32 }
The above Java script reads RGW SBML model, experiment data, tuning parameters and distribution data from files and starts a calibration job. Once the job has completed, the result (distribution data) is written into a output file.
Newcastle University !CaliBayes Web Services
Here at Newcastle University we have deployed CaliBayes Web Services based upon the CaliBayes Java APIs. Please read CaliBayes_web-services for more details.
Demo script
The example listed below were written upon CaliBayes Web Service Java Client Library that can be downloaded at Documentation/installation. It is also desirable to invoke the web services via static proxies/stubs generated by using toolkits such as JAXWS, etc. Users can put the proxy class into the working directory and invoke the web services as local Java APIs.
CaliBayes Web Services expose calibration functionality over the Internet, and allows public access. Although the Web Services were developed using Java, users can write the client code in other programming languages that supporting Web Services, e.g. Python, PHP, C++, Visual Basic, etc. Here we only show a client code written in Java to illustrate the business logic for consuming the Web Services.
Or, if you are using CaliBayes Web Services Java Library:
1 import calibayesclient.*;
1 public static void main(String[] args) {
2
3 CalibayesService calibayes;
4 Calibayes calibration;
5 XMLParser xmlparser = new XMLParser();
6 Calibration calibration = new Calibration();
7
8 Document doc = null;
9
10 String sbmlModel = "death.xml";
11 String expDataXml = "experiment.xml";
12 String tuningXml = "tuning.xml";
13 String distributionXml = "distribution.xml";
14
15 doc = xmlparser.readFileCreateDocument(sbmlModel);
16 sbmlModel = xmlparser.readDocumentCreateString(doc);
17
18 doc = xmlparser.readFileCreateDocument(expDataXml);
19 expDataXml = xmlparser.readDocumentCreateString(doc);
20
21 doc = xmlparser.readFileCreateDocument(tuningXml);
22 tuningXml = xmlparser.readDocumentCreateString(doc);
23
24 doc = xmlparser.readFileCreateDocument(distributionXml);
25 distributionXml = xmlparser.readDocumentCreateString(doc);
26
27 String sessionId = calibration.submit(sbmlModel, expDataXml, tuningXml, distributionXml);
28
29 while (!calibration.isReady(sessionId)){
30 //checks every hour
31 Thread.sleep(60*60*1000);
32 }
33
34 // retrives result
35 String rst = calibration.getResult(sessionId);
36 doc = xmlparser.readStringCreateDocument(rst);
37
38 String filename = "CalibayesOutput.xml";
39 xmlparser.writeDocumentToFile(doc, filename);
40 }
For further information about the CaliBayes web services and their use, please consult the Documentation.