Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Properties | Private Member Functions
Bio.Graphics.GenomeDiagram._Graph.GraphData Class Reference

List of all members.

Public Member Functions

def __init__
def set_data
def get_data
def add_point
def quartiles
def range
def mean
def stdev
def __len__
def __getitem__
def __str__

Public Attributes

 id
 data
 name
 style
 poscolor
 negcolor
 linewidth
 center

Properties

 centre

Private Member Functions

def _set_centre

Detailed Description

GraphData

    Provides:

    Methods:

    o __init__(self, id=None, data=None, name=None, style='bar',
             color=colors.lightgreen, altcolor=colors.darkseagreen)
             Called on instantiation

    o set_data(self, data)  Load the object with data to be plotted

    o get_data(self)    Returns the data to be plotted as a list of
                        (position, value) tuples

    o add_point(self, point)    Add a single point to the data set

    o quartiles(self)   Returns a tuple of the data quartiles

    o range(self)   Returns a tuple of the base range covered by the graph
                    data

    o mean(self)    Returns a float of the mean data point value

    o stdev(self)   Returns the sample standard deviation of the data values

    o __len__(self) Returns the length of sequence covered by the data

    o __getitem__(self, index)  Returns the value at the base specified,
                                or graph data in the base range

    o __str__(self) Returns a formatted string describing the graph data

    Attributes:

    o id    Unique identifier for the data

    o data  Dictionary of describing the data, keyed by position

    o name  String describing the data

    o style String ('bar', 'heat', 'line') describing how to draw the data

    o poscolor     colors.Color for drawing high (some styles) or all
                    values

    o negcolor     colors.Color for drawing low values (some styles)

    o linewidth     Int, thickness to draw the line in 'line' styles

Definition at line 35 of file _Graph.py.


Constructor & Destructor Documentation

def Bio.Graphics.GenomeDiagram._Graph.GraphData.__init__ (   self,
  id = None,
  data = None,
  name = None,
  style = 'bar',
  color = colors.lightgreen,
  altcolor = colors.darkseagreen,
  center = None,
  colour = None,
  altcolour = None,
  centre = None 
)
__init__(self, id=None, data=None, name=None, style='bar',
 color=colors.lightgreen, altcolor=colors.darkseagreen)

    o id    Unique ID for the graph

    o data  List of (position, value) tuples

    o name  String describing the graph

    o style String describing the presentation style ('bar', 'line',
    'heat')

    o color   colors.Color describing the color to draw all or the
      'high' (some styles) values (overridden by backwards
      compatible argument with UK spelling, colour).

    o altcolor colors.Color describing the color to draw the 'low'
       values (some styles only) (overridden by backwards
       compatible argument with UK spelling, colour).

    o center Value at which x-axis crosses y-axis (overridden by
     backwards comparible argument with UK spelling, centre).

Definition at line 88 of file _Graph.py.

00088 
00089                  center=None, colour=None, altcolour=None, centre=None):
00090         """__init__(self, id=None, data=None, name=None, style='bar',
00091                  color=colors.lightgreen, altcolor=colors.darkseagreen)
00092 
00093             o id    Unique ID for the graph
00094 
00095             o data  List of (position, value) tuples
00096 
00097             o name  String describing the graph
00098 
00099             o style String describing the presentation style ('bar', 'line',
00100                     'heat')
00101 
00102             o color   colors.Color describing the color to draw all or the
00103                       'high' (some styles) values (overridden by backwards
00104                       compatible argument with UK spelling, colour).
00105 
00106             o altcolor colors.Color describing the color to draw the 'low'
00107                        values (some styles only) (overridden by backwards
00108                        compatible argument with UK spelling, colour).
00109 
00110             o center Value at which x-axis crosses y-axis (overridden by
00111                      backwards comparible argument with UK spelling, centre).
00112 
00113         """
00114 
00115         #Let the UK spelling (colour) override the USA spelling (color)
00116         if colour is not None:
00117             color = colour
00118         if altcolour is not None:
00119             altcolor = altcolour
00120         if centre is not None:
00121             center = centre
00122 
00123         self.id = id            # Unique identifier for the graph
00124         self.data = {}          # holds values, keyed by sequence position
00125         if data is not None:    
00126             self.set_data(data)
00127         self.name = name        # Descriptive string
00128 
00129         # Attributes describing how the graph will be drawn
00130         self.style = style          # One of 'bar', 'heat' or 'line'
00131         self.poscolor = color     # Color to draw all, or 'high' values
00132         self.negcolor = altcolor  # Color to draw 'low' values
00133         self.linewidth = 2          # linewidth to use in line graphs
00134         self.center = center        # value at which x-axis crosses y-axis

Here is the caller graph for this function:


Member Function Documentation

__getitem__(self, index) -> Float or list of tuples

    Given an integer representing position on the sequence
    returns a float - the data value at the passed position.

    If a slice, returns graph data from the region as a list or
    (position, value) tuples. Slices with step are not supported.

    Returns the data value at the passed position

Definition at line 240 of file _Graph.py.

00240 
00241     def __getitem__(self, index):
00242         """ __getitem__(self, index) -> Float or list of tuples
00243 
00244             Given an integer representing position on the sequence
00245             returns a float - the data value at the passed position.
00246 
00247             If a slice, returns graph data from the region as a list or
00248             (position, value) tuples. Slices with step are not supported.
00249 
00250             Returns the data value at the passed position
00251         """
00252         if isinstance(index, int):
00253             return self.data[index]
00254         elif isinstance(index, slice):
00255             #TODO - Why does it treat the end points both as inclusive?
00256             #This doesn't match Python norms does it?
00257             low = index.start
00258             high = index.stop
00259             if index.step is not None and index.step != 1:
00260                 raise ValueError
00261             positions = self.data.keys()
00262             positions.sort()
00263             outlist = []
00264             for pos in positions:
00265                 if pos >= low and pos <=high:
00266                     outlist.append((pos, self.data[pos]))
00267             return outlist
00268         else:
00269             raise TypeError("Need an integer or a slice")
00270 

Here is the caller graph for this function:

__len__(self) -> Int

    Returns the number of points in the data set

Definition at line 232 of file _Graph.py.

00232 
00233     def __len__(self):
00234         """ __len__(self) -> Int
00235 
00236             Returns the number of points in the data set
00237         """
00238         return len(self.data)
00239 

__str__(self) -> ""

    Returns a string describing the graph data

Definition at line 271 of file _Graph.py.

00271 
00272     def __str__(self):
00273         """ __str__(self) -> ""
00274 
00275             Returns a string describing the graph data
00276         """
00277         outstr = ["\nGraphData: %s, ID: %s" % (self.name, self.id)]
00278         outstr.append("Number of points: %d" % len(self.data))
00279         outstr.append("Mean data value: %s" % self.mean())
00280         outstr.append("Sample SD: %.3f" % self.stdev())
00281         outstr.append("Minimum: %s\n1Q: %s\n2Q: %s\n3Q: %s\nMaximum: %s" % self.quartiles())
00282         outstr.append("Sequence Range: %s..%s" % self.range())
00283         return "\n".join(outstr)
00284 
00285 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._Graph.GraphData._set_centre (   self,
  value 
) [private]

Definition at line 135 of file _Graph.py.

00135 
00136     def _set_centre(self, value):
00137         import warnings
00138         import Bio
00139         warnings.warn("The _set_centre method and .centre attribute are deprecated; please use the .center attribute instead", Bio.BiopythonDeprecationWarning)
        self.center = value
add_point(self, point)

    o point     (position, value) tuple

    Add a single point to the set of data

Definition at line 168 of file _Graph.py.

00168 
00169     def add_point(self, point):
00170         """ add_point(self, point)
00171 
00172             o point     (position, value) tuple
00173 
00174             Add a single point to the set of data
00175         """
00176         pos, val = point
00177         self.data[pos] = val
00178 

get_data(self) -> [(int, float), (int, float), ...]

    Return data as a list of sorted (position, value) tuples

Definition at line 155 of file _Graph.py.

00155 
00156     def get_data(self):
00157         """ get_data(self) -> [(int, float), (int, float), ...]
00158 
00159             Return data as a list of sorted (position, value) tuples
00160         """
00161         data = []
00162         for xval in self.data.keys():
00163             yval = self.data[xval]            
00164             data.append((xval, yval))
00165         data.sort()
00166         return data
00167 

mean(self) -> Float

    Returns the mean value for the data points

Definition at line 205 of file _Graph.py.

00205 
00206     def mean(self):
00207         """ mean(self) -> Float
00208 
00209             Returns the mean value for the data points
00210         """
00211         data = self.data.values()
00212         sum = 0.
00213         for item in data:
00214             sum += float(item)
00215         return sum/len(data)
00216 

Here is the caller graph for this function:

quartiles(self) -> (float, float, float, float, float)

    Returns the (minimum, lowerQ, medianQ, upperQ, maximum) values as
    a tuple

Definition at line 179 of file _Graph.py.

00179 
00180     def quartiles(self):
00181         """ quartiles(self) -> (float, float, float, float, float)
00182 
00183             Returns the (minimum, lowerQ, medianQ, upperQ, maximum) values as
00184             a tuple
00185         """
00186         data = self.data.values()
00187         data.sort()
00188         datalen = len(data)
00189         return(data[0], data[datalen//4], data[datalen//2],
00190                data[3*datalen//4], data[-1])
00191 

Here is the caller graph for this function:

range(self) -> (int, int)

    Returns the range of the data, i.e. its start and end points on
    the genome as a (start, end) tuple

Definition at line 192 of file _Graph.py.

00192 
00193     def range(self):
00194         """ range(self) -> (int, int)
00195 
00196             Returns the range of the data, i.e. its start and end points on
00197             the genome as a (start, end) tuple
00198         """
00199         positions = self.data.keys()
00200         positions.sort()
00201         # Return first and last positions in graph
00202         #print len(self.data)
00203         return (positions[0], positions[-1])    
00204 

Here is the caller graph for this function:

set_data(self, data)

    o data      List of (position, value) tuples

    Add data with a list of (position, value) tuples

Definition at line 144 of file _Graph.py.

00144 
00145     def set_data(self, data):
00146         """ set_data(self, data)
00147 
00148             o data      List of (position, value) tuples
00149 
00150             Add data with a list of (position, value) tuples
00151         """
00152         for (pos, val) in data:     # Fill data dictionary
00153             self.data[pos] = val
00154 

stdev(self) -> Float

    Returns the sample standard deviation for the data

Definition at line 217 of file _Graph.py.

00217 
00218     def stdev(self):
00219         """ stdev(self) -> Float
00220 
00221             Returns the sample standard deviation for the data
00222         """
00223         data = self.data.values()
00224         m = self.mean()
00225         runtotal = 0.
00226         for entry in data:
00227             runtotal += float((entry - m)**2)
00228         # This is sample standard deviation; population stdev would involve
00229         # division by len(data), rather than len(data)-1
00230         return sqrt(runtotal/(len(data)-1))
00231         

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 133 of file _Graph.py.

Definition at line 123 of file _Graph.py.

Definition at line 122 of file _Graph.py.

Definition at line 132 of file _Graph.py.

Definition at line 126 of file _Graph.py.

Definition at line 131 of file _Graph.py.

Definition at line 130 of file _Graph.py.

Definition at line 129 of file _Graph.py.


Property Documentation

Initial value:
property(fget = lambda self : self.center,
                       fset = _set_centre,
                       doc="Backwards compatible alias for center (DEPRECATED)")

Definition at line 140 of file _Graph.py.


The documentation for this class was generated from the following file: