Back to index

python-biopython  1.60
Classes | Functions
Bio.PopGen.GenePop.Controller Namespace Reference

Classes

class  _FileIterator
class  _GenePopCommandline
class  GenePopController

Functions

def _gp_float
def _gp_int
def _read_allele_freq_table
def _read_table
def _read_triangle_matrix
def _read_headed_triangle_matrix
def _hw_func

Function Documentation

def Bio.PopGen.GenePop.Controller._gp_float (   tok) [private]
Gets a float from a token, if it fails, returns the string.

Definition at line 22 of file Controller.py.

00022 
00023 def _gp_float(tok):
00024     """Gets a float from a token, if it fails, returns the string.
00025     """
00026     try:
00027         return float(tok)
00028     except ValueError:
00029         return str(tok)

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller._gp_int (   tok) [private]
Gets a int from a token, if it fails, returns the string.

Definition at line 30 of file Controller.py.

00030 
00031 def _gp_int(tok):
00032     """Gets a int from a token, if it fails, returns the string.
00033     """
00034     try:
00035         return int(tok)
00036     except ValueError:
00037         return str(tok)
00038     
    

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller._hw_func (   stream,
  is_locus,
  has_fisher = False 
) [private]

Definition at line 113 of file Controller.py.

00113 
00114 def _hw_func(stream, is_locus, has_fisher = False): 
00115     l = stream.readline()
00116     if is_locus:
00117         hook = "Locus "
00118     else:
00119         hook = " Pop : "
00120     while l != "":
00121         if l.startswith(hook):
00122             stream.readline()
00123             stream.readline()
00124             stream.readline()
00125             table = _read_table(stream,[str,_gp_float,_gp_float,_gp_float,_gp_float,_gp_int,str])
00126             #loci might mean pop if hook="Locus "
00127             loci = {}
00128             for entry in table:
00129                 if len(entry) < 3:
00130                     loci[entry[0]] = None
00131                 else:
00132                     locus, p, se, fis_wc, fis_rh, steps = entry[:-1]
00133                     if se == "-": se = None
00134                     loci[locus] = p, se, fis_wc, fis_rh, steps
00135             return loci
00136         l = stream.readline()
00137     #self.done = True
00138     raise StopIteration

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 39 of file Controller.py.

00039 
00040 def _read_allele_freq_table(f):
00041     l = f.readline()
00042     while l.find(" --")==-1:
00043         if l == "":
00044             raise StopIteration
00045         if l.find("No data")>-1:
00046             return None, None
00047         l = f.readline()
00048     alleles = filter(lambda x: x != '', f.readline().rstrip().split(" "))
00049     alleles = map(lambda x: _gp_int(x), alleles)
00050     l = f.readline().rstrip()
00051     table = []
00052     while l != "":
00053         line = filter(lambda x: x != '', l.split(" "))
00054         try:
00055             table.append(
00056                 (line[0],
00057                 map(lambda x: _gp_float(x), line[1:-1]),
00058                 _gp_int(line[-1])))
00059         except ValueError:
00060             table.append(
00061                 (line[0],
00062                 [None] * len(alleles),
00063                 0))
00064         l = f.readline().rstrip()
00065     return alleles, table

Here is the call graph for this function:

Definition at line 94 of file Controller.py.

00094 
00095 def _read_headed_triangle_matrix(f):
00096     matrix = {}
00097     header = f.readline().rstrip()
00098     if header.find("---")>-1 or header.find("===")>-1:
00099         header = f.readline().rstrip()
00100     nlines = len(filter(lambda x:x != '', header.split(' '))) - 1
00101     for line_pop in range(nlines):
00102         l = f.readline().rstrip()
00103         vals = filter(lambda x:x != '', l.split(' ')[1:])
00104         clean_vals = []
00105         for val in vals:
00106             try:
00107                 clean_vals.append(_gp_float(val))
00108             except ValueError:
00109                 clean_vals.append(None)
00110         for col_pop in range(len(clean_vals)):
00111             matrix[(line_pop+1, col_pop)] = clean_vals[col_pop]
00112     return matrix

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller._read_table (   f,
  funs 
) [private]

Definition at line 66 of file Controller.py.

00066 
00067 def _read_table(f, funs):
00068     table = []
00069     l = f.readline().rstrip()
00070     while l.find("---")==-1:
00071         l = f.readline().rstrip()
00072     l = f.readline().rstrip()
00073     while l.find("===")==-1 and l.find("---")==-1 and l != "":
00074         toks = filter(lambda x: x != "", l.split(" ")) 
00075         line = []
00076         for i in range(len(toks)):
00077             try:
00078                 line.append(funs[i](toks[i]))
00079             except ValueError:
00080                 line.append(toks[i])  # Could not cast
00081         table.append(tuple(line))
00082         l = f.readline().rstrip()
00083     return table

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 84 of file Controller.py.

00084 
00085 def _read_triangle_matrix(f):
00086     matrix = []
00087     l = f.readline().rstrip()
00088     while l != "":
00089         matrix.append(
00090             map(lambda x: _gp_float(x),
00091                 filter(lambda y: y != "", l.split(" "))))
00092         l = f.readline().rstrip()
00093     return matrix

Here is the call graph for this function:

Here is the caller graph for this function: