VisualiseSBML.py :  » Mobile » Pysces » pysces-0.7.2-(test) » pysces » contrib » visualise » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Pysces 
Pysces » pysces 0.7.2 test  » pysces » contrib » visualise » VisualiseSBML.py
'''
Colin Gillespie (c.gillespie@ncl.ac.uk)
Last modified: 4/4/05

The access point to the visualisation stuff
'''

from VisualiseClasses import VisualiseSpecies,VisualiseReaction,VisualiseModel

class VisualiseFormat:
  '''Static returns a single value
    web returns a piccy with an image map
  '''
  
  formats = ['ps', 'ps2', 'hpgl', 'pcl', 'mif', 'pic', 'gd', 'gd2', 'gif',
    'jpg', 'jpeg', 'png', 'wbmp', 'ismap', 'imap', 'cmap', 'vrml', 'vtx', 
    'mp','fig', 'svg', 'svgz', 'dia', 'dot', 'canon', 'plain', 'plain-ext',
    'xdot']
  
  def __init__(self, py_dot_graph):
    self.pyGraph = py_dot_graph
  
  def web(self, frmt='gif'):
    '''Returns a base64 encoded graph and an image map'''
    if frmt not in self.formats:
      raise 'Format not recognised.'
    graph = self.pyGraph.create(format=frmt)
    cmap = self.pyGraph.create(format='cmap')
    return graph, cmap
  
  def static(self, frmt='dot'):
    '''returns just one value'''
    if frmt not in self.formats:
      raise 'Format not recognised.'
    return self.pyGraph.create(format=frmt)
    
class VisualiseSBML:
  """The main visualisation class"""
  
  def  __init__(self, m):
    self.m = m
    
  def visualiseModel(self):
    '''Visualise the entire SBML model'''
    py_dot_graph = VisualiseModel(self.m).getPyDot()
    return VisualiseFormat(py_dot_graph)
    
  def visualiseReaction(self, rea_num):
    '''
    Visualise a single reaction
    rea_num is the number of the reaction you want to visualise
    Numbering starts at 1
    '''
    py_dot_graph = VisualiseReaction(self.m, rea_num).getPyDot()
    return VisualiseFormat(py_dot_graph)

  def visualiseSpecies(self, sp_num):
    '''
    Visualise a single species
    sp_num is the number of the species you want to visualise
    Numbering starts at 1
    '''
    py_dot_graph = VisualiseSpecies(self.m, sp_num).getPyDot()
    return VisualiseFormat(py_dot_graph)

if __name__ == "__main__":
  sbml_file = open('../chapmodel1.xml','r').read()
  from BasisTools import BasisTools
  sbml1 = BasisTools(sbml = sbml_file)
  sbml =  sbml1.m

  print 'model visualise'
  print VisualiseSBML(sbml).visualiseModel().static('dot')

  print 'Specie visualise'
  print VisualiseSBML(sbml).visualiseSpecies(1).static('dot')

  print 'Reaction visualise'
  print VisualiseSBML(sbml).visualiseReaction(2).static('dot')
  
  print 'Empty Model'
  sbml1 = BasisTools()
  sbml = sbml1.m
  print VisualiseSBML(sbml).visualiseModel().static('dot')
  
  print 'One Compartment 1 Species'
  sbml1 = BasisTools()
  sbml1.add(Compartments={'Id':'Cell'})
  sbml1.add(Species={'Id':'sp1', 'Compartment':'Cell'})
  sbml = sbml1.m
  print VisualiseSBML(sbml).visualiseModel().static('dot')
  
  sbml =  sbml1.m
  print 'EOF'
  
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.