Copasi time simulation of SBML model
Created: 2010-03-26 17:23:25
Uses the synchronous Copasi time simulation web service to predict the concentrations of species over a time period. The results from Copasi are provided in SBRML format which is visualised as a graph using an R script.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (3)
Copasi time simulation of SBML model |
Time course simulation of SBML model using CopasiWS |
Perform time simulation of SBML model using Copasi web service |
Descriptions (1)
Uses the synchronous Copasi time simulation web service to predict the concentrations of species over a time period. The results from Copasi are provided in SBRML format which is visualised as a graph using an R script. |
Dependencies (1)
Inputs (1)
Name |
Description |
sbml |
A parameterised SBML model
A parameteried SBML model
|
Processors (7)
Name |
Type |
Description |
stepnumber |
stringconstant |
Value10 |
parseSbrml |
beanshell |
Scriptimport java.util.Iterator;
import java.util.List;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.Document;
import org.apache.xpath.NodeSet;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.apache.xpath.NodeSet;
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = domFactory.newDocumentBuilder();
ByteArrayInputStream bs = new ByteArrayInputStream(sbrml.getBytes());
Document doc = builder.parse(bs);
NamespaceContext ctx = new NamespaceContext()
{
public String getNamespaceURI(String prefix)
{
String uri;
if (prefix.equals("ns1"))
uri = "http://www.sbrml.org/sbrml/level1/version1";
else
uri = null;
return uri;
}
//Dummy implementation - not used!
public Iterator getPrefixes(String val)
{
return null;
}
//Dummy implemenation - not used!
public String getPrefix(String uri)
{
return null;
}
};
//Get all time frames
String xpathStr1 = "/ns1:sbrml/ns1:operations/ns1:operation/ns1:result/ns1:resultComponent/ns1:dimension/ns1:compositeValue/@indexValue";
//Get all species names
String xpathStr2 = "/ns1:sbrml/ns1:operations/ns1:operation/ns1:result/ns1:resultComponent/ns1:dimension/ns1:compositeValue[@indexValue='0']/ns1:compositeValue/@indexValue";
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
xpath.setNamespaceContext(ctx);
Object result = xpath.evaluate(xpathStr1, doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
//Sort out output
StringBuffer sb = new StringBuffer();
//sb.append("Species");
ArrayList timeframes = new ArrayList();
for (int i = 0; i < nodes.getLength(); i++)
{
String time = nodes.item(i).getNodeValue();
timeframes.add(time);
sb.append(time);
if(i == nodes.getLength() - 1)
sb.append("\n");
else
sb.append(",");
}
//Use species names in sbrml
String[] lines = species.split("\n");
Hashtable ht = new Hashtable();
for(int x = 0; x < lines.length; x++)
{
String[] tokens = lines[x].split(";");
String spId = tokens[0];
String name = tokens[1];
if(name.equals("Nicotinamide adenine dinucleotide - reduced"))
name = "NADH";
else if(name.equals("Nicotinamide adenine dinucleotide"))
name = "NAD";
ht.put(spId, name);
}
Object result = xpath.evaluate(xpathStr2, doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++)
{
String species = nodes.item(i).getNodeValue();
String speciesName = ht.get(species);
if(!selectedSpeciesNames.contains(speciesName))
continue;
else
{
sb.append("\"" + speciesName + "\"");
//Iterate
for(int x = 0; x < timeframes.size(); x++)
{
String timeFrame = timeframes.get(x);
//Get concentration values
String xpathStr3 = "/ns1:sbrml/ns1:operations/ns1:operation/ns1:result/ns1:resultComponent/ns1:dimension/ns1:compositeValue[@indexValue='" + timeFrame + "']/ns1:compositeValue[@indexValue='" + species + "']/ns1:tuple/ns1:atomicValue[1]";
String data2 = xpath.evaluate(xpathStr3, doc);
sb.append("," + data2);
}
sb.append("\n");
}
}
//Output
String output = sb.toString();
|
visualiseResults |
rshell |
Script#Initialise output of png image
png(graph_image);
#Read in csv data from previous taverna activity
data <- read.table(file=csv,head=TRUE,sep=",");
#transpose data
tdata <- t(data);
#Plot all species concentrations against time
matplot(tdata,axes=F,frame=T,type="l", col= 1:ncol(tdata), ylab="Concentration", xlab="Time");
#Add title
title("Copasi time course simulation");
# put numerical annotations at the tickmarks in y-axis;
axis(2);
#Remove Xs from row name strings
rnames <- rownames(tdata);
for (i in 1:length(rnames)) #Loop thru rows in x object
{
rnames[i] <- substr(rnames[i], 2, nchar(rnames[i]));
}
#Add ticks and time unit values to x axis
axis(1, 1:length(rnames), rnames);
#Add legend for species
legend("bottomright", colnames(tdata), lty = 1:ncol(tdata), col = 1:ncol(tdata), cex = .6);
#Close stream to png image
dev.off(); R Serverlocalhost:6311 |
duration |
stringconstant |
Value50 |
runTimeCourseSim |
workflow |
|
getSpeciesNames |
beanshell |
Scriptimport org.sbml.libsbml.*;
//Second output
names = new ArrayList();
SBMLReader reader = new SBMLReader();
SBMLDocument doc = reader.readSBMLFromString(sbml);
Model m = doc.getModel();
//To hold data
StringBuffer data = new StringBuffer();
//Get species ids and names
ListOfSpecies spList = m.getListOfSpecies();
for (int i = 0; i < spList.size(); i++)
{
Species sp = (Species) spList.get(i);
String id = sp.getId();
String name = sp.getName();
names.add(name);
data.append(id + ";" + name + "\n");
}
//Output
String species = data.toString();
|
selectworker |
beanshell |
Script/**
* Class representing the selected values of this beanshell processor
*/
class SelectedValues
{
ArrayList selectedValues;
SelectedValues()
{
selectedValues = new ArrayList();
}
synchronized void addToValues(ArrayList values)
{
for(int i = 0; i < values.size(); i ++)
selectedValues.add(values.get(i));
notifyAll();
}
synchronized ArrayList getValues()
{
while (selectedValues.size() == 0)
{
try
{
wait();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
return selectedValues;
}
}
/**
* Class representing the GUI for selecting the values to be
* processed by the remainder of the workflow.
*/
MultipleSelectWorkerGUI(ArrayList input, SelectedValues values)
{
JList list;
DefaultListModel listModel;
final String submitString = "Submit";
JButton submitButton;
int[] accessions;
SelectedValues selectedValues;
ArrayList inputdata;
void init()
{
super.frame = new JFrame("Select data for downstream analysis");
//Place window in centre of the screen
super.frame.setLocationRelativeTo(null);
pane = new JPanel();
super.frame.getContentPane().add(pane);
pane.setLayout(new BorderLayout());
// Set up input data available for selection
listModel = new DefaultListModel();
for (int i = 0; i < input.size(); i++)
listModel.addElement(input.get(i));
selectedValues = values;
//Create the list and put it in a scroll pane
list = new JList(listModel);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setSelectedIndex(0);
list.addListSelectionListener(this);
list.setVisibleRowCount(10);
list.setSize(800,500);
list.setFixedCellHeight(20);
JScrollPane listScrollPane = new JScrollPane(list);
submitButton = new JButton(submitString);
submitButton.setActionCommand(submitString);
submitButton.addActionListener(this);
//Create a panel
JPanel buttonPane = new JPanel();
buttonPane.add(submitButton);
buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
pane.add(listScrollPane, BorderLayout.CENTER);
pane.add(buttonPane, BorderLayout.PAGE_END);
//frame.setSize(800,500);
frame.setVisible(true);
frame.pack();
}
//This method is required by ListSelectionListener.
void valueChanged(ListSelectionEvent e)
{
if (!e.getValueIsAdjusting())
{
if (list.getSelectedIndex() == -1)
{
//No selection so disable fire button
submitButton.setEnabled(false);
}
else
{
//Selection made so enable the fire button.
submitButton.setEnabled(true);
}
}
}
// This method is called only if there is a valid selection
void actionPerformed(ActionEvent e)
{
ArrayList al = new ArrayList();
if (list.getSelectedIndices().length == 0)
{
// Nothing selected so disable firing
submitButton.setEnabled(false);
}
else
{
selectedItems = list.getSelectedIndices();
//System.out.println(selectedItems);
for(int i = 0; i < selectedItems.length; i++)
{
String str = listModel.elementAt(selectedItems[i]);
al.add(str);
}
selectedValues.addToValues(al);
super.frame.dispose();
}
}
init();
return this;
}
/**
* Wrapper for MultipleSelectWorkerGUI
*/
class WorkerWrapper extends Thread
{
SelectedValues selectedValues;
ArrayList inputdata;
WorkerWrapper(ArrayList input, SelectedValues v)
{
inputdata = inputList;
selectedValues = v;
}
void run()
{
msw = MultipleSelectWorkerGUI(inputdata, selectedValues);
}
}
sv = new SelectedValues();
wrapper = new WorkerWrapper(inputList, sv);
wrapper.start();
outputList = sv.getValues(); |
Beanshells (3)
Name |
Description |
Inputs |
Outputs |
parseSbrml |
|
sbrml
species
selectedSpeciesNames
|
output
|
getSpeciesNames |
|
sbml
|
species
names
|
selectworker |
|
inputList
|
outputList
|
Outputs (2)
Name |
Description |
sbrml |
The results of the time course simulation in SBRML format
|
plot |
A png image of the plot of the time simulation results from Copasi
|
Datalinks (11)
Source |
Sink |
runTimeCourseSim:sbrml |
parseSbrml:sbrml |
getSpeciesNames:species |
parseSbrml:species |
selectworker:outputList |
parseSbrml:selectedSpeciesNames |
parseSbrml:output |
visualiseResults:csv |
duration:value |
runTimeCourseSim:duration |
stepnumber:value |
runTimeCourseSim:stepNumber |
sbml |
runTimeCourseSim:sbml |
sbml |
getSpeciesNames:sbml |
getSpeciesNames:names |
selectworker:inputList |
runTimeCourseSim:sbrml |
sbrml |
visualiseResults:graph_image |
plot |
Uploader
License
All versions of this Workflow are
licensed under:
Version 1
(of 1)
Credits (1)
(People/Groups)
Attributions (0)
(Workflows/Files)
None
Shared with Groups (0)
None
Featured In Packs (1)
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment