Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Nexus.Nexus.StepMatrix Class Reference

List of all members.

Public Member Functions

def __init__
def set
def add
def sum
def transformation
def weighting
def smprint

Public Attributes

 data
 symbols

Detailed Description

Calculate a stepmatrix for weighted parsimony.

See Wheeler (1990), Cladistics 6:269-275.

Definition at line 133 of file Nexus.py.


Constructor & Destructor Documentation

def Bio.Nexus.Nexus.StepMatrix.__init__ (   self,
  symbols,
  gap 
)

Definition at line 139 of file Nexus.py.

00139 
00140     def __init__(self,symbols,gap):
00141         self.data={}
00142         self.symbols=[s for s in symbols]
00143         self.symbols.sort()
00144         if gap:
00145             self.symbols.append(gap)
00146         for x in self.symbols:
00147             for y in [s for s in self.symbols if s!=x]:
00148                 self.set(x,y,0)

Here is the caller graph for this function:


Member Function Documentation

def Bio.Nexus.Nexus.StepMatrix.add (   self,
  x,
  y,
  value 
)

Definition at line 154 of file Nexus.py.

00154 
00155     def add(self,x,y,value):
00156         if x>y:
00157             x,y=y,x
00158         self.data[x+y]+=value

Here is the caller graph for this function:

def Bio.Nexus.Nexus.StepMatrix.set (   self,
  x,
  y,
  value 
)

Definition at line 149 of file Nexus.py.

00149 
00150     def set(self,x,y,value):
00151         if x>y:
00152             x,y=y,x
00153         self.data[x+y]=value

def Bio.Nexus.Nexus.StepMatrix.smprint (   self,
  name = 'your_name_here' 
)

Definition at line 175 of file Nexus.py.

00175 
00176     def smprint(self,name='your_name_here'):
00177         matrix='usertype %s stepmatrix=%d\n' % (name,len(self.symbols))
00178         matrix+='        %s\n' % '        '.join(self.symbols)
00179         for x in self.symbols:
00180             matrix+='[%s]'.ljust(8) % x
00181             for y in self.symbols:
00182                 if x==y:
00183                     matrix+=' .       '
00184                 else:
00185                     if x>y:
00186                         x1,y1=y,x
00187                     else:
00188                         x1,y1=x,y
00189                     if self.data[x1+y1]==0:
00190                         matrix+='inf.     '
00191                     else:
00192                         matrix+='%2.2f'.ljust(10) % (self.data[x1+y1])
00193             matrix+='\n'
00194         matrix+=';\n'
        return matrix

Definition at line 159 of file Nexus.py.

00159 
00160     def sum(self):
00161         return reduce(lambda x,y:x+y,self.data.values()) 

Here is the caller graph for this function:

Definition at line 162 of file Nexus.py.

00162 
00163     def transformation(self):
00164         total=self.sum()
00165         if total!=0:
00166             for k in self.data:
00167                 self.data[k]=self.data[k]/float(total)
00168         return self
    

Here is the call graph for this function:

Definition at line 169 of file Nexus.py.

00169 
00170     def weighting(self):
00171         for k in self.data:
00172             if self.data[k]!=0:
00173                 self.data[k]=-math.log(self.data[k])
00174         return self


Member Data Documentation

Definition at line 140 of file Nexus.py.

Definition at line 141 of file Nexus.py.


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