[Calibayesr-commits] r8 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 25 15:47:11 CET 2010


Author: csgillespie
Date: 2010-03-25 15:47:11 +0100 (Thu, 25 Mar 2010)
New Revision: 8

Added:
   pkg/man/createDistribution.Rd
   pkg/man/createExperiment.Rd
Removed:
   pkg/man/createCalibayes.Rd
   pkg/man/isCaliBayesFinished.Rd
Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
   pkg/R/basisWS.R
   pkg/R/caliBayesObject.R
   pkg/R/caliBayesWebservices.R
   pkg/R/checkExperiments.R
   pkg/R/checkSettings.R
   pkg/R/getDistribution.R
   pkg/R/makeDistribution.R
   pkg/R/makeExperiments.R
   pkg/R/makeSettings.R
   pkg/man/calibayes-package.Rd
   pkg/man/calibrate.Rd
   pkg/man/createSettings.Rd
   pkg/man/getPredictiveDistribution.Rd
   pkg/man/listSimulatorMethods.Rd
Log:
Version: 0.1-8.0
 * Major changes. 
 * XML now generated using paste - it's faster
 * New makeCaliBayesExperiments
 * Made functions more consistent


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/DESCRIPTION	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,11 +1,11 @@
 Package: calibayesR
 Type: Package
 Title: CaliBayes: Parameter estimation for stochastic kinetic models
-Version: 0.1-7.1
-Date: 2010-03-16
+Version: 0.1-8.0
+Date: 2010-03-23
 Author: Colin Gillespie
 Maintainer: Colin Gillespie <c.gillespie at ncl.ac.uk>
 Description: The CaliBayes project is concerned with the problem of estimating the kinetic parameters of dynamic biological simulation models (either deterministic or stochastic) encoded in SBML, by using time course experimental data. This package provides tools to generate the calibayes XML file format. The package also provides a web-serivce interface to the CaliBayes system. See http://www.calibayes.ncl.ac.uk for more details.
 License: LGPL-3
-Depends: R (>= 2.9.0), XML, RCurl (>= 1.2-1), SSOAP(>= 0.5-2), XMLSchema(>= 0.1-2)
-Imports: basisR, XML
+Depends: R (>= 2.9.0), XML (>= 2.8-1), RCurl (>= 1.3-1), SSOAP(>= 0.5-2), XMLSchema(>= 0.1-4), basisR, Rcompression (>= 0.92-0)
+

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/NAMESPACE	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,7 +1,8 @@
 export(listSimulatorMethods,getPosterior,isCaliBayesReady,calibrate, isCaliBayesFinished,
-    createCalibayes, saveCalibayes, loadCalibayes,  
-    createSettings, saveSettings, 
-    mean.CaliBayes, summary.CaliBayes, plot.CaliBayes, compareDistributions,
+    createCaliBayesExperiment, saveCaliBayesExperiment,
+    createCaliBayesDistribution, saveCaliBayesDistribution, loadCaliBayesDistribution,
+    createCaliBayesSettings, saveCaliBayesSettings, 
+    mean.CaliBayes.Distribution, summary.CaliBayes.Distribution, plot.CaliBayes.Distribution, compareDistributions,
     getPredictiveDistribution,updatePredictiveResults)
 
 #getUpdate,

Modified: pkg/R/basisWS.R
===================================================================
--- pkg/R/basisWS.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/basisWS.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,3 +1,4 @@
+
 ######################################
 #Private functions
 ######################################

Modified: pkg/R/caliBayesObject.R
===================================================================
--- pkg/R/caliBayesObject.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/caliBayesObject.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -2,36 +2,35 @@
 #Private functions
 ################################################
 
-
-createCalibayesObject = function(iters, par_df, sp_df, dist, err_df, exp_df)
+pri_createCaliBayesDistribution = function(iters, parameters, species, distributions, errors)
 {
     y = list()
-    y$iters = iters    
-    y$parameters = par_df
-    y$species = sp_df
-    y$errors = err_df
-    y$dist = dist
-    y$experiments = exp_df
-    class(y) = "CaliBayes"
+    y$iters = iters
+    y$parameters = parameters
+    y$species = species
+    y$errors = errors
+    y$dist = distributions
+    class(y) = "CaliBayes.Distribution"
     return(y)
 }
+
  
     
-mean.CaliBayes = function(x,...)
+mean.CaliBayes.Distribution = function(x,...)
 {
     x = cbind(x$parameters,  x$species, x$errors)
     mean(x)
     
 }
 
-summary.CaliBayes = function(object,...)
+summary.CaliBayes.Distribution = function(object,...)
 {
     object = cbind(object$parameters, object$species, object$errors)
     summary(object)
 }
 
 
-plot.CaliBayes = function(x, lm=400, rows=4, burnin=1, thin=1, ...)
+plot.CaliBayes.Distribution = function(x, lm=400, rows=4, burnin=1, thin=1, ...)
 {	
     d = cbind(x$parameters, x$species, x$errors)
     names = attr(d, "names")
@@ -97,46 +96,63 @@
 #Public Calibayes functions
 ################################################
 
+createCaliBayesSettings = function(wsdl, burn=500, thin=50, block=1, simulator="copasi-deterministic", wsdl.simulator="internal", check=TRUE)
+{
+    if(check)
+        checkSettings(burn, thin, block)
+    
+    y = list()
+    y$burn = burn
+    y$thin = thin
+    y$block = block
+    y$simulator = simulator
+    y$wsdl.simulator = wsdl.simulator
+    class(y) = "CaliBayes.Settings"
+    return(y)
+}
 
-createCalibayes = function(parameters, species, distributions, errors, experiments)
+createCaliBayesExperiment = function(experiments, species, check=TRUE)
 {
     mf = match.call(expand.dots = FALSE)
-    m = match(c("parameters", "experiments"), names(mf), 0L)
+    m = match(c("species"), names(mf), 0L)
     mf = mf[c(1L, m)]
-    if(!is.element("parameters",names(mf)))
-        parameters = FALSE
+    if(!is.element("species",names(mf)))
+        species = FALSE
 
-    if(is.element("experiments",names(mf))){
-        if(is.data.frame(experiments)){
-            experiments = list(experiments)
-        }
+
+    if(is.data.frame(experiments)){
+        experiments = list(experiments)
+    }
+    
+    if(check)
         checkExperiments(experiments, species)
-    }else{
-        experiments = NULL
-    }    
-    checkDistribution(parameters, species, distributions, errors)
-    y = createCalibayesObject(seq(0, (dim(species)[1]-1)), parameters, species, distributions, errors, experiments)
+      
+    y = experiments
+    class(y) = "CaliBayes.Experiment"
     return(y)
 }
+ 
+createCaliBayesDistribution = function(parameters, species, distributions, errors, check=TRUE)
+{
+    mf = match.call(expand.dots = FALSE)
+    m = match(c("parameters"), names(mf), 0L)
+    mf = mf[c(1L, m)]
+    if(!is.element("parameters",names(mf)))
+        parameters = FALSE
 
-saveCalibayes = function(filename, calibayes)
-{
-    data = calibayes     
-    if(is.data.frame(data$species))
-    {
-        dis_filename = paste(filename, '_distributions.xml', sep='')
-        makeDistribution(dis_filename, data$parameters, data$species, data$dist, data$errors, FALSE)
-    }
-    if(is.list(data$experiments))
-    {
-        exp_filename = paste(filename, '_experiments.xml', sep='')
-        makeExperiments(exp_filename, data$experiments, check=FALSE)
-    }
-  
-    return(TRUE)
+    if(check)
+        checkDistribution(parameters, species, distributions, errors)
+        
+    iters = seq(0, (dim(species)[1]-1))
+    y = pri_createCaliBayesDistribution(iters, parameters, species, distributions, errors)
+    
+    return(y)
+
 }
 
-loadCalibayes = function(filename)
+
+
+loadCaliBayesDistribution = function(filename)
 {
     calibayes = getDistribution(filename, asText=FALSE)
     return(calibayes)
@@ -158,26 +174,33 @@
 
 
 ############################################################################################################
-#Public Settings functions
+#Public Save Functions
 ############################################################################################################
-createSettings = function(wsdl, burn=500, thin=50, block=1, simulator="copasi-deterministic", wsdl.simulator="internal")
+
+
+saveCaliBayesExperiment = function(filename, CaliBayes.Experiment)
 {
-    checkSettings(burn, thin, block)
-    
-    y = list()
-    y$burn = burn
-    y$thin = thin
-    y$block = block
-    y$simulator = simulator
-    y$wsdl.simulator = wsdl.simulator
-    class(y) = "settings"
-    return(y)
+    makeExperiments(filename, CaliBayes.Experiment)       
+    return(TRUE)
 }
 
-saveSettings = function(filename, settings)
+saveCaliBayesDistribution = function(filename, CaliBayes.Distribution)
 {
+    data = CaliBayes.Distribution     
+    if(is.data.frame(data$species))
+    {
+        makeDistribution(filename, data$parameters, data$species, data$dist, data$errors, FALSE)
+    }
+  
+    return(TRUE)
+}
+
+saveCaliBayesSettings = function(filename, CaliBayes.Settings)
+{
+    settings = CaliBayes.Settings
     makeSettings(filename, settings$burn, settings$thin, settings$block, 
                     settings$simulator, settings$wsdl, FALSE)
+    return(TRUE)
 }
     
 

Modified: pkg/R/caliBayesWebservices.R
===================================================================
--- pkg/R/caliBayesWebservices.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/caliBayesWebservices.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -70,25 +70,42 @@
 #Public methods
 ########################################################
 
-calibrate = function(wsdl, sbml, settings, calibayes, asText=FALSE) 
+calibrate = function(wsdl, sbml, CaliBayes.Settings, CaliBayes.Experiment, CaliBayes.Distribution, asText=FALSE) 
 {
+    
+    
     if(!asText)
         sbml = toString.XMLNode(xmlInternalTreeParse(sbml))
     
     #Remove the XML heading
     sbml = strsplit(sbml,'\\?>')[[1]][[2]]
     
+    message("Making SOAP interface...")
     cali.def = getCaliDef(wsdl, FALSE)
+    message("Finished SOAP interface\n\n")
     
-    expDataXml = makeExperiments(FALSE, calibayes$experiments, calibayes$species, FALSE)
-    distributionXml  = makeDistribution(FALSE, calibayes$parameters, calibayes$species, calibayes$dist, calibayes$errors, FALSE)
-    tuningXml = makeSettings(FALSE, settings$burn, settings$thin, settings$block, settings$simulator, settings$wsdl, FALSE)
+    message("Making Settings XML...")
+    settings = CaliBayes.Settings
+    tuningXML = makeSettings(FALSE, settings$burn, settings$thin, settings$block, settings$simulator, settings$wsdl, FALSE)
+
+    message("Making Experiment XML...")
+    expDataXML = makeExperiments(FALSE, CaliBayes.Experiment)    
+
+    message("Making Distribution XML...")
+    distributionXML  = makeDistribution(FALSE, 
+                                        CaliBayes.Distribution$parameters, 
+                                        CaliBayes.Distribution$species, 
+                                        CaliBayes.Distribution$dist, 
+                                        CaliBayes.Distribution$errors, 
+                                        FALSE)
     
     
-    req = paste("<doc>", sbml, expDataXml, tuningXml, distributionXml, "</doc>", sep="")
+    req = paste("<doc>", sbml, expDataXML, tuningXML, distributionXML, "</doc>", sep="")
     req = gsub('\n','',req)
     
     setAs("character", "rSubmit", RSubmit,  where=globalenv())
+    message("Sending SOAP message to CaliBayes...")
+
     rst = cali.def at functions$rSubmit(req)
     return(rst at sessionId)
 }
@@ -124,7 +141,9 @@
     }
     cali.def = getCaliDef(wsdl, FALSE)   
     setAs("character", "getResult", getResult,  where=globalenv())
+    message("Sending request to CaliBayes...")
     rst = cali.def at functions$getResult(sid)
+    message("Converting to CaliBayes Objects...")
     xmlString = rst at result
     result = getDistribution(xmlString)
     

Modified: pkg/R/checkExperiments.R
===================================================================
--- pkg/R/checkExperiments.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/checkExperiments.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -5,7 +5,10 @@
 {
     
     checkExperimentHeaders(experiments)
-    checkExperimentSpecies(experiments, species)
+    if(!is.logical(species))
+        checkExperimentSpecies(experiments, species)
+    else
+        message("Skipping check 2. Need species argument")
     checkExperimentTime(experiments)
     return(TRUE)
 }

Modified: pkg/R/checkSettings.R
===================================================================
--- pkg/R/checkSettings.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/checkSettings.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -7,7 +7,7 @@
     checkThin(thin)
     checkBlock(block)
     simulator = 'XXX'
-    checkSimulator(simulator)
+#    checkSimulator(simulator)
     
     message("All tests passed")
     return(TRUE)

Modified: pkg/R/getDistribution.R
===================================================================
--- pkg/R/getDistribution.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/getDistribution.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -31,7 +31,7 @@
 
     iterations = environment(s1$Iteration)$iterations
     errors = environment(s1$Error)$errors
-    
+
     if(length(pa_ids))
     {
         l = length(pa_values)/length(pa_ids)
@@ -58,7 +58,7 @@
         sp_df = data.frame()
         err_df = data.frame()
     }
-    y = createCalibayesObject(iterations, par_df, sp_df, dist, err_df, NULL)
+    y = pri_createCaliBayesDistribution(iterations, par_df, sp_df, dist, err_df)
     return(y)
 }
 
@@ -66,29 +66,31 @@
 
     id = attrs["id"]
     if(!is.na(id))
-        assign("sp_ids", append(sp_ids, id), envir = cali)
+        cali[["sp_ids"]] = append(cali[["sp_ids"]], id)
         
     value = attrs["value"]
     if(!is.na(value))
-        assign("sp_values", append(sp_values, as.double(value)), envir = cali)
+        cali[["sp_values"]] = append(cali[["sp_values"]], as.double(value))
 
 }
 
 getParameters = function(name, attrs, ...){
     id = attrs["id"]
     if(!is.na(id))
-        assign("pa_ids", append(pa_ids, id), envir = cali)
+        cali[["pa_ids"]] = append(cali[["pa_ids"]], id)
         
     value = attrs["value"]
     if(!is.na(value))
-        assign("pa_values", append(pa_values, as.double(value)), envir = cali)
+        cali[["pa_values"]] = append(cali[["pa_values"]], as.double(value))
+
 }
 
 
 getIterations = function(name, attrs, ...){
     iteration = attrs["number"]
     if(!is.na(iteration))
-        assign("iterations", append(iterations, as.integer(iteration)), envir = cali)
+        cali[["iterations"]] = append(cali[["iterations"]], as.double(iteration))
+#        assign("iterations", append(iterations, as.integer(iteration)), envir = cali)
 }
 
 
@@ -96,8 +98,8 @@
 {
     error = attrs["value"]
     if(!is.na(error))
-        assign("errors", append(errors, as.double(error)), envir = cali)
-    
+        cali[["errors"]] = append(cali[["errors"]], as.double(error))
+
 }
 
 

Modified: pkg/R/makeDistribution.R
===================================================================
--- pkg/R/makeDistribution.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/makeDistribution.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,8 +1,7 @@
 #$Date$
 #$Author$
 
-
-makeDistribution = function(filename=FALSE, parameters, species, distributions, errors, check=TRUE)
+makeDistribution = function(filename=FALSE, parameters, species, distributions, errors, check=FALSE)
 {
     #Only parameters are optional
     #Next few lines are over kill, but can be easily expanded.
@@ -11,49 +10,93 @@
     mf = mf[c(1L, m)]
     if(!is.element("parameters",names(mf)))
         parameters = FALSE
+
+#    if(!is.element("species",names(mf)))
+#        species = FALSE
     
     if(check)
         checkDistribution(parameters, species, distributions, errors)
     
-    top=newXMLNode("Distribution")
-    var=newXMLNode("ListOfVariables",parent=top)
-    seq=newXMLNode("sequence",parent=var)
-    
+    message("\tAdding in the ListOfVariables...")
+    n = dim(species)[1]
     if(is.data.frame(parameters))
     {
         df_pars = fixParameters(parameters)
-        pars = as.character(unique(df_pars$id))
-        lapply(pars, makeDistributionParameters, seq)
+        xml_str_vars = makeParametersAtListOfVariables(parameters)
+        iter_pars = tapply(df_pars$value, df_pars$iters, pastePars)
+
+    } else {#Create an empty strings for below.
+        xml_str_vars = ""
+        iter_pars = rep("", n)
     }
+        
+    xml_str_vars = paste(xml_str_vars,makeSpeciesAtListOfVariables(species, distributions))
+    xml_str_vars = addXMLTag(xml_str_vars, "sequence")
+    xml_str_vars = addXMLTag(xml_str_vars, "ListOfVariables")
 
-    df_sp = fixSpecies(species)
-    apply(data.frame(colnames(species), distributions, c(species[1,],recursive=T)),  1, makeDistributionSpecies, seq)
-    n = dim(species)[1]
+    message("\tAdding in the ListOfIterations...may take a while")
+
+    #Now create ListOfIterations
+    df_sp = fixSpecies(species)    
+    iter_sps = tapply(df_sp$value, paste(df_sp$iters, df_sp$id), pasteSpecies)
+
     df_er = fixErrors(errors)
-    
-    lOfIters=newXMLNode("ListOfIterations",parent=top)
-    listofnodes = c()
-    for(i in 1:n){
-        node=newXMLNode("Iteration",attrs=c(number=as.numeric(i)),parent=lOfIters)
-        seq1=newXMLNode("sequence",parent=node)
-        listofnodes = c(listofnodes, seq1)
-    }
-    
-    if(is.data.frame(parameters))
-        apply(df_pars, 1, makeparamnode, listofnodes)
- 
-    apply(df_sp, 1, makespecnode,listofnodes, df_er)
+    iter_errs = tapply(paste("<Error value='", df_er$value, "'/>", sep=""), paste(df_er$iters,df_er$species) , paste, collapse="")
 
+    xml_str_iters = paste(iter_sps,"<sequence>", iter_errs, "</sequence></Species>", sep="")
+
+    xml_str_iters[df_sp$id==df_sp$id[1]] = paste("<Iteration number='",seq(1, n), "'><sequence>", iter_pars, xml_str_iters[df_sp$id==df_sp$id[1]], sep="")
+    xml_str_iters[df_sp$id==df_sp$id[length(df_sp$id)]] = paste(xml_str_iters[df_sp$id==df_sp$id[length(df_sp$id)]], "</sequence></Iteration>", sep="")
+    xml_str_iters = paste(xml_str_iters, collapse="")
+    xml_str_iters = addXMLTag(xml_str_iters, "ListOfIterations")
+
+
+    #Combine Iterations and variables
+    xml_str = paste(xml_str_vars, xml_str_iters, sep="")
+    rt_values = addXMLTag(xml_str, "Distribution")
+
+
     if(is.character(filename)){
-        saveXML(top, filename)
-        rt_value = TRUE
-    }else{
-        rt_value = saveXML(top)
+        message("Writing to file...")
+        write(rt_values, filename)
+        rt_values = TRUE
     }
-    return(rt_value)
+
+
+    return(rt_values)
 }
 
+makeSpeciesAtListOfVariables = function(species, distributions)
+{
+    xml_str = ""
+    if(is.data.frame(species)){
+        sps = colnames(species)
+        xml_str = paste("<Species id='", sps, "' error='", distributions, "' hasValue='True'/>", sep="", collapse="")
+    }
+    return(xml_str)
+}
 
+makeParametersAtListOfVariables  = function(parameters)
+{    
+    xml_str = ""
+    if(is.data.frame(parameters)){
+        pars = colnames(parameters)
+        xml_str = paste("<Parameter id='", pars, "'/>", sep="", collapse="")
+    }
+    return(xml_str)
+}
+
+pastePars = function(parameters)
+{
+    paste("<Parameter value='", parameters, "'/>", collapse="" ,sep="")
+}
+
+
+pasteSpecies = function(species)
+{
+    paste("<Species value='", species, "'>", collapse="" ,sep="")
+}
+
 fixParameters = function(parameters)
 {
     values = as.vector(c(parameters, recursive=TRUE))
@@ -94,68 +137,21 @@
     return(df_er)
 }
 
-makeDistributionParameters = function(id, seq)
-{
-    newXMLNode("Parameter", parent=seq, attrs=c(id=id))
-}
-
-makeDistributionSpecies = function(row, seq)
-{
-    if(is.na(row[[3]]))
-        newXMLNode("Species", parent=seq,attrs=c(id=row[[1]], error=row[[2]], hasValue='False'))
-    else
-        newXMLNode("Species", parent=seq,attrs=c(id=row[[1]], error=row[[2]], hasValue='True'))
-}
-
-makeparamnode = function(row, listofnodes)
-{
-    par = listofnodes[[as.numeric(row[1])]]
-    newXMLNode("Parameter", attrs=c(value=as.numeric(row[2])), parent=par)
-    return()
-}
-
-makespecnode = function(row, listofnodes, df_er)
-{
-    par = listofnodes[[as.numeric(row[1])]]
-    if(is.na(row[2]))
-    {
-        node = newXMLNode("Species", parent=par)
-    }else{
-        node = newXMLNode("Species", attrs=c(value=as.numeric(row[2])), parent=par)
-    }
-    errors = df_er[df_er$species == row[3] & df_er$iters == as.numeric(row[1]) ,]
-    if(dim(errors)[1] > 0){
-        seq=newXMLNode("sequence",parent=node)
-        apply(errors, 1, makeerrornode, seq)
-    }
-}
-
-
-makeerrornode = function(row, node)
-{
-    newXMLNode("Error",attrs=c(value=as.numeric(row[2])), parent=node)
-}
-    
-
-
 ############################################
 #Example usage
 ############################################
 
-#n=10
+#n=2
 #parameters=data.frame(mu=runif(n,0.01,0.1),alpha=runif(n,0.1,1))
 #species=data.frame(X=rnorm(n,50,1), Y=rnorm(n, 100, 10), Z=rnorm(n, 150, 10))
 #distributions = c('Gaussian', 'Gaussian', "Gaussian")
 #errors = data.frame(X.tau=rnorm(n,10), X.tau1=rnorm(n,10),Y.p2=rnorm(n, 100))
 #
+#makeDistribution1(stdout() , parameters, species, distributions, errors)
+#n=2
+#parameters=data.frame(mu=runif(n,0.01,0.1),alpha=runif(n,0.1,1))
+#species=data.frame(X=rnorm(n,50,1), Y=rnorm(n, 100, 10))
+#distributions = c('Gaussian', 'Gaussian')
+#errors = data.frame(X.tau=rnorm(n,10), X.tau1=rnorm(n,10),Y.p2=rnorm(n, 100))#
 #makeDistribution(stdout() , parameters, species, distributions, errors)
 
-
-
-
-
-
-
-
-
-

Modified: pkg/R/makeExperiments.R
===================================================================
--- pkg/R/makeExperiments.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/makeExperiments.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,43 +1,41 @@
 #$Date$
 #$Author$
 
+addXMLTag = function(value, tag)
+{
+    return(paste("<", tag, ">", value, "</", tag, ">", sep=""))
+    
+}
 
-makeExperiments = function(filename=FALSE, experiments, species, check=TRUE)
+makeExperiments = function(filename=FALSE, experiments, species, check=FALSE)
 { 
     if(check)
     {
         checkExperiments(experiments, species)
     }
 
-    top = newXMLNode("listOfExperiments")
-    seq = newXMLNode("sequence", parent=top)
-    lapply(experiments, makeExperiment, seq)
+    rt_values = paste(unlist(lapply(experiments, makeExperiment)), collapse="\n")
+    rt_values = addXMLTag(rt_values, "sequence")
+    rt_values = addXMLTag(rt_values, "listOfExperiments")
+
+
     if(is.character(filename)){
-        saveXML(top, filename)
-        rt_value = TRUE
-    }else{
-        rt_value = saveXML(top)
+        write(rt_values, filename)
+        rt_values = TRUE
     }
-    return(rt_value)
+
+    return(rt_values)
 }
 
-makeExperiment = function(exp_df, par)
+
+makeExperiment = function(exp_df)
 {
-    exper = newXMLNode("Experiment", parent=par)
-    listof = newXMLNode("listOfObservations", parent=exper)
-    
-    #Make sure columns are in the correct order!
-    switch_cols = data.frame(species = exp_df$species, time = exp_df$time, value = exp_df$value)
-    
     #Order by time
-    switch_cols = switch_cols[order(switch_cols$time), ]
-    apply(switch_cols, 1, makeObservation, listof)
+    exp_df = exp_df[order(exp_df$time), ]
+    exp_xml = paste("<Observation species='", exp_df$species, "' time='", exp_df$time, "' value='", exp_df$value, "'/>", sep="", collapse="")
+    return(paste("<Experiment>", exp_xml, "</Experiment>", sep=""))
 }
 
-makeObservation = function(row, par)
-{
-    newXMLNode("Observation", parent=par, attrs=c(species=row[[1]], time=as.numeric(row[[2]]), value=as.numeric(row[[3]])))
-}
 
 
 ############################################
@@ -46,5 +44,4 @@
 
 #exp1 = data.frame(time = seq(10), species = rep(c('X'), each=10), value=runif(10))
 #exp2 = data.frame(time = seq(5), species = rep(c('X','Y'), each=5), value=rep(c(runif(5, 0, 1), runif(5, 10, 12))))
-#makeExperiments(stdout(), list(exp1, exp2))
-
+#makeExperiments(FALSE, list(exp1, exp2))

Modified: pkg/R/makeSettings.R
===================================================================
--- pkg/R/makeSettings.R	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/R/makeSettings.R	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,12 +1,12 @@
 #$Date$
 #$Author$
-makeSettings = function(filename=FALSE, 
+makeSettings1 = function(filename=FALSE, 
                         burn=500, 
                         thin=50, 
                         block=1, 
                         simulator="copasi-stochastic",
                         wsdl="internal",
-                        check=TRUE)
+                        check=FALSE)
 {
 
     if(check)
@@ -32,6 +32,30 @@
 ############################################
 #Example usage
 ############################################
+#makeSettings(FALSE, burn=100, thin=10, block = 3)
+makeSettings = function(filename=FALSE, 
+                        burn=500, 
+                        thin=50, 
+                        block=1, 
+                        simulator="copasi-stochastic",
+                        wsdl="internal",
+                        check=FALSE)
+{
 
+    if(check)
+        check = checkSettings(burn, thin, block)
 
-#makeParameterTuning('/tmp/tuning.xml', iters=100000, burn=100, thin=10, block = 3)
+    df = data.frame(nodes = c("burn","thin", "block", "simulationMethod","simulatorWSDLLocation"))
+    df$values = c(burn, thin, block, simulator, wsdl)
+    
+    rt_values = paste("<", df$nodes, " value='", df$values, "'/>", sep="", collapse="")
+    rt_values = addXMLTag(rt_values, "parameterTuning")
+
+    if(is.character(filename)){
+        write(rt_values, filename)
+        rt_values = TRUE
+    }
+
+    return(rt_values)
+}
+    

Modified: pkg/man/calibayes-package.Rd
===================================================================
--- pkg/man/calibayes-package.Rd	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/man/calibayes-package.Rd	2010-03-25 14:47:11 UTC (rev 8)
@@ -60,6 +60,11 @@
 \keyword{package}
 \keyword{distribution}
 
-\seealso{\code{\link{createCalibayes}}, \code{link{calibrate}}}
+\seealso{
+\code{\link{createCaliBayesSettings}}, 
+\code{\link{createCaliBayesExperiment}},
+\code{\link{createCaliBayesDistribution}},
+\code{\link{calibrate}}
+}
 
 

Modified: pkg/man/calibrate.Rd
===================================================================
--- pkg/man/calibrate.Rd	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/man/calibrate.Rd	2010-03-25 14:47:11 UTC (rev 8)
@@ -4,15 +4,22 @@
 \alias{calibrate}
 \alias{getPosterior}
 \alias{isCaliBayesReady}
+\alias{isCaliBayesFinished}
 
 \title{The core calibayes webservices}
 
-\description{These functions access CaliBayes through a web-service interface. \code{calibrate} sets off a job, \code{isFinished} determines if a job is finished, and \code{getPosterior} downloads the result.}
+\description{These functions access CaliBayes through a web-service interface. \code{calibrate} sets off a job, \code{isCaliBayesReady} determines if a job is finished, and \code{getPosterior} downloads the result.}
 
 \usage{
-    calibrate(wsdl, sbml, settings, calibayes, asText=FALSE)
+    calibrate(wsdl,
+                sbml, 
+                CaliBayes.Settings, 
+                CaliBayes.Experiment, 
+                CaliBayes.Distribution, 
+                asText=FALSE) 
     isCaliBayesReady(wsdl, sid)
     getPosterior(wsdl, sid)
+    isCaliBayesFinished(wsdl, sid, no_of_checks, maxtime)
 }
 
 
@@ -20,29 +27,37 @@
   \item{wsdl}{A valid url that points to the CaliBayes wsdl file. The inference engine of CaliBayes can (and should) be downloaded and installed on your local infrastructure. The wsdl url given in the example is only for illustration purposes.}
   \item{sbml}{A valid SBML model.}
   \item{asText}{A logical value indicating that the first argument, \code{sbmlModel}, should be treated as a string to parse, and not the name of a file.}
-  \item{settings}{A settings object, created by the \code{\link{createSettings}} function.}  
-  \item{calibayes}{A calibayes object, created by the \code{\link{createCalibayes}} function.}
-  \item{sid}{A valid calibayes session id.}
+  \item{CaliBayes.Settings}{A settings object, created by the \code{\link{createCaliBayesSettings}} function.}  
+  \item{CaliBayes.Experiment}{An experiment object, created by the \code{\link{createCaliBayesExperiment}} function.}  
+  \item{CaliBayes.Distribution}{A CaliBayes Distribution object, created by the \code{\link{createCaliBayesDistribution}} function.}
+  \item{sid}{A valid CaliBayes session id.}
+  \item{no_of_checks}{The number of times the \code{isCaliBayesReady} function will be called}.
+  \item{maxtime}{The maximum number of minutes to check CaliBayes.}
+
 }
 
 \value{
-    \code{calibrate}: Returns a session id (sid). This session id is valid for any web-service interface to the calibayes system.
+    \code{calibrate}: Returns a session id (sid). This session id is valid for any web-service interface to the CaliBayes system.
     
     \code{isCaliBayesReady}: Checks if the calibration has finished. Returns \code{TRUE} or \code{FALSE}.
+       
+    \code{isCaliBayesFinished}: Returns a either \code{TRUE} or \code{FALSE} to indicate if calibration is complete. This function also prints times when the last check was carred out.
     
-    \code{getPosterior}: Downloads the results from the CaliBayes installation described by the wsdl file and returns a CaliBayes object.
+    \code{getPosterior}: Downloads the results from the CaliBayes installation described by the wsdl file and returns a CaliBayes Distribution object.   
+
+
 }
 
 \author{Colin Gillespie}
 
-\seealso{See also \code{\link{createCalibayes}}, \code{\link{createSettings}}  and \code{\link{listSimulatorMethods}}.}
+\seealso{See also \code{\link{createCaliBayesDistribution}}, \code{\link{createCaliBayesSettings}}  and \code{\link{listSimulatorMethods}}.}
 \examples{
     \dontrun{
     library(SBMLModels)
     data(LogisticModel)
 
-    #Just use the first experiment
-    yeast_data = YeastGrowth[[1]]
+    #Just use the first experiment and the first few time points
+    yeast_data = YeastGrowth[[1]][1:3,]
     
     #Plot of the experiment data for the simple decay model
     plot(yeast_data$time, yeast_data$value, xlab="Time", ylab="Population level")
@@ -66,16 +81,26 @@
 	                r=rlnorm(n,1,0.6)
                 )
 
-    #Create a prior object
-    prior = createCalibayes(parameters, species, distributions, errors, yeast_data)
+    #Create an Experiment object
+    experiments = createCaliBayesExperiment(yeast_data, species)
+    #Create a Distribution object
+    prior = createCaliBayesDistribution(parameters, species, distributions, errors, FALSE)
 
     #Create settings file
     wsdl = "http://calibayes1.ncl.ac.uk:81/CaliBayesService_v2.wsdl"
-    settings = createSettings(wsdl, burn=10, thin=2)
+    settings = createCaliBayesSettings(wsdl, burn=10, thin=2)
     sbml = LogisticModel
     
-    sid = calibrate(wsdl, sbml, settings, prior, asText=TRUE)
+    sid = calibrate(wsdl, sbml, settings, experiments, prior, asText=TRUE)
+    
+    #A one off check of CaliBayes
     isCaliBayesReady(wsdl, sid)
+
+    #Now check every 100 seconds    
+    maxtime = 10 # 10*60 seconds
+    no_of_checks = 6 # Check calibayes every 100 seconds, i.e. every (60*10)/6 seconds
+    isCaliBayesFinished(wsdl, sid, no_of_checks, maxtime)
+   
     
     posterior = getPosterior(wsdl, sid)
     

Deleted: pkg/man/createCalibayes.Rd
===================================================================
--- pkg/man/createCalibayes.Rd	2010-03-19 10:42:44 UTC (rev 7)
+++ pkg/man/createCalibayes.Rd	2010-03-25 14:47:11 UTC (rev 8)
@@ -1,90 +0,0 @@
-%$Date$
-%$Author$
-\name{createCalibayes}
-\alias{createCalibayes}
-\alias{saveCalibayes}
-\alias{loadCalibayes}
-\alias{mean.CaliBayes}
-\alias{summary.CaliBayes}
-\alias{plot.CaliBayes}
-\alias{compareDistributions}
-
-
-\title{Creates a CaliBayes object.}
-
-\description{These functions enable the creation of the calibayes object that is used by the R web-services. The \code{saveCaliBayes} function constructs XML files for other web-service tools to use.}
-
-\usage{
-createCalibayes(parameters, species, distributions, errors, experiments)
-saveCalibayes(filename, calibayes)
-loadCalibayes(filename)
-compareDistributions(prior, posterior)
-}
-
-
-\arguments{
-    \item{parameters}{Optional argument. A data frame containing the prior specification of the estimated parameters. This is technically optional, but in almost all cases, will be needed. If a parameter is not entered in this data frame, but is present in the model, then CaliBayes will use the model value.}
-    \item{species}{A data frame containing the prior distribution of the species at time t=0. If a species is not entered in this data frame, but is present in your model, then CaliBayes will use the initial conditions specified in the SBML file and assume no uncertainty exists in the initial conditions.}
-    \item{distributions}{A vector specifying the error distribution of the species. Currently the distribution supported by CaliBayes are \code{Gaussian}.}
-    \item{errors}{A data frame containing the prior specification of the errors. The numbers of columns must be equal to the number of columns in the species data frame. Each column in the error data frame has the format: species\_id.error\_parameter . At present we only support Gaussian error structures, so error\_parameter = tau.}
-    \item{experiments}{A list of data frames containing the experiments. Each data frame have three columns: time, species and value.}
-    \item{filename}{The filename where the XML string will be written. If filename=stdout(), the XML string is printed to the screen.}
-    \item{calibayes}{A calibayes object, created by the \code{createCalibayes} function.}
-    \item{prior}{A calibayes object, created by the \code{createCalibayes} or \code{loadCalibayes} function.}
-    \item{posterior}{A calibayes object, created by the \code{createCalibayes} or \code{loadCalibayes} function.}
-}
-
-\value{
-    \code{createCalibayes}: Returns a calibayes object. This object is used by the \code{calibrate} web-service.
-    
-    \code{saveCalibayes}: This function may create two files: filename_distributions.xml containing your prior specifications and filename_experiments.xml containing your experimental data. You should use this function if you want to store your results or if you want to create the CaliBayes XML files.
-    
-    \code{loadCalibayes}: Returns a calibayes object. This function will not load experimental data.
-    }
-
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/calibayesr -r 8


More information about the Calibayesr-commits mailing list