VisualiseNodeClasses.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 » VisualiseNodeClasses.py
'''
Colin Gillespie (c.gillespie@ncl.ac.uk)
Last modified: 1/4/05

If want change the shape/colour/etc of a node or arrow
make your changes here
'''
'''
Small changes to format/style and stoichiometry marked as # brett 20050702
Brett G. Olivier (bgoli@users.sourceforge.net)
'''


class EdgeLines:
  '''
  If we want differnt arrow types for the different reaction types
  For example, square 'arrows' for a product
  Just now all the arrows are the same
  '''
  
  def __init__(self, edge_attribute):
    self.edge_attribute = edge_attribute
  
  def reactant(self):
    '''See class doc'''
    if self.edge_attribute['arrowtail'] != 'none':
      self.edge_attribute['arrowtail'] = 'normal'
    self.edge_attribute['arrowhead'] = 'none' # brett 20050702
    self.edge_attribute['arrowsize'] = '0.8'  # brett 20050702
    return self.edge_attribute
  
  def product(self):
    '''See class doc'''
    #if self.edge_attribute['arrowtail'] != 'none':  # brett 20050702
    #  self.edge_attribute['arrowtail'] = 'normal' # brett 20050702
    self.edge_attribute['arrowhead'] = 'normal'

    self.edge_attribute['arrowtail'] = 'none' # brett 20050702
    self.edge_attribute['arrowsize'] = '0.8'  # brett 20050702
    return self.edge_attribute
  
  def modifier(self):
    '''See class doc'''
    #if self.edge_attribute['arrowtail'] != 'none': # brett 20050702
    #  self.edge_attribute['arrowtail'] = 'normal' # brett 20050702
    self.edge_attribute['arrowhead'] = 'normal'
    self.edge_attribute['arrowtail'] = 'none'               # brett 20050702
    self.edge_attribute['weight'] = 0             # brett 20050702
    self.edge_attribute['style'] = 'dotted, setlinewidth(2)'# brett 20050702
    self.edge_attribute['arrowsize'] = '0.8'        # brett 20050702
    self.edge_attribute['color'] = 'mediumblue'       # brett 20050702
    return self.edge_attribute

class DotNodes:
  '''A class used to define the node shapes, colours, fonts, etc.
  So you can change what a species node looks like here.
  For edges, see the EdgeLines class'''
  
  def  __init__(self, model):
    self.general_node = {'style':'filled', 'fontsize':10, 'fontname':'Arial'}
    self.m = model
  
  def edgeNode(self, reaction, stoic=0):
    '''See class doc'''
    edge_attribute = {'arrowtail':'none', 'arrowhead':'normal',
      'color':'black', 'fontsize':10, 'fontname':'Arial'}
    
    if reaction.getReversible() == 1:
      edge_attribute['arrowtail'] = 'normal'
    
    if reaction.getFast() == 1: 
      edge_attribute['color'] = 'red'
    
    # if stoic != 1:        # brett 20050702
    if stoic > 0.0 and stoic != 1: # brett 20050702: only show non-int, non-unitary stoich.  
      edge_attribute['label'] = str(stoic) # brett 20050702
    
    return EdgeLines(edge_attribute)

  def specieNode(self, i, other_attributes=None):
    '''See class doc'''
    if not other_attributes:
      other_attributes = {}
    
    label = get_label(self.m.getSpecies(i-1))

    node_attribute = self.general_node
    node_attribute['color'] = 'orange'
    node_attribute['shape'] = 'ellipse'
    node_attribute['label'] = label
    node_attribute['URL'] = "Javascript:species('//sbml:species[%s]')" % str(i)
    
    #if boundary condition
    if self.m.getSpecies(i-1).getBoundaryCondition():
      node_attribute['color'] = "coral"
    
    for key, value in other_attributes.items():
      node_attribute[key] = value
    return node_attribute
  
  def reactionNode(self, i, other_attributes=None):
    '''See class doc'''
    if not other_attributes:
      other_attributes = {}
    
    label = get_label(self.m.getReaction(i-1))
    
    node_attribute = self.general_node
    node_attribute['color'] = 'moccasin'
    node_attribute['shape'] = 'rectangle'
    node_attribute['label'] = label
    node_attribute['URL'] = "Javascript:reaction('//sbml:reaction[%s]')" % str(i)
    
    for key, value in other_attributes.items():
      node_attribute[key] = value
    return node_attribute
    
  def compartmentNode(self, i, other_attributes=None):  
    '''See class doc'''
    if not other_attributes:
      other_attributes = {}
    
    label = get_label(self.m.getCompartment(i-1))
    
    node_attribute = self.general_node
    node_attribute['graph_name'] = self.m.getCompartment(i-1).getId()
    node_attribute['label'] = label
    node_attribute['URL'] = "Javascript:compartment(\'//sbml:compartment[%s]\')" \
      % str(i)
    
    for key, value in other_attributes.items():
      node_attribute[key] = value
    return node_attribute
    
def get_label(obj):
  '''Just now the visualiser displays id's not names
  Uncomment the lines below to display names'''
#  if len(obj.getName()):
#    return obj.getName()
#  else:
#    return obj.getId()
  return obj.getId()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.