Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.PopGen.GenePop.Controller.GenePopController Class Reference

List of all members.

Public Member Functions

def __init__
def test_pop_hz_deficiency
def test_pop_hz_excess
def test_pop_hz_prob
def test_global_hz_deficiency
def test_global_hz_excess
def test_ld
def create_contingency_tables
def test_genic_diff_all
def test_genic_diff_pair
def test_genotypic_diff_all
def test_genotypic_diff_pair
def estimate_nm
def calc_allele_genotype_freqs
def calc_diversities_fis_with_identity
def calc_diversities_fis_with_size
def calc_fst_all
def calc_fst_pair
def calc_rho_all
def calc_rho_pair
def calc_ibd_diplo
def calc_ibd_haplo

Public Attributes

 controller
 done
 first_locus
 old_line
 curr_pop
 last_line

Private Member Functions

def _remove_garbage
def _get_opts
def _run_genepop
def _test_pop_hz_both
def _test_global_hz_both
def _calc_diversities_fis
def _calc_ibd

Detailed Description

Definition at line 213 of file Controller.py.


Constructor & Destructor Documentation

def Bio.PopGen.GenePop.Controller.GenePopController.__init__ (   self,
  genepop_dir = None 
)
Initializes the controller.

genepop_dir is the directory where GenePop is.

The binary should be called Genepop (capital G)

Definition at line 214 of file Controller.py.

00214 
00215     def __init__(self, genepop_dir = None):
00216         """Initializes the controller.
00217         
00218         genepop_dir is the directory where GenePop is.
00219 
00220         The binary should be called Genepop (capital G)
00221         
00222         """
00223         self.controller = _GenePopCommandline(genepop_dir)


Member Function Documentation

def Bio.PopGen.GenePop.Controller.GenePopController._calc_diversities_fis (   self,
  fname,
  ext 
) [private]

Definition at line 664 of file Controller.py.

00664 
00665     def _calc_diversities_fis(self, fname, ext):
00666         self._run_genepop([ext], [5,2], fname)
00667         f = open(fname + ext)
00668         l = f.readline()
00669         while l != "":
00670             l = l.rstrip()
00671             if l.startswith("Statistics per sample over all loci with at least two individuals typed"):
00672                 avg_fis = _read_table(f, [str, _gp_float, _gp_float, _gp_float])
00673                 avg_Qintra = _read_table(f, [str, _gp_float])
00674             l = f.readline()
00675         f.close()
00676         def fis_func(self): 
00677             l = self.stream.readline()
00678             while l != "":
00679                 l = l.rstrip()
00680                 m = re.search("Locus: (.+)", l)
00681                 if m != None:
00682                     locus = m.group(1)
00683                     self.stream.readline()
00684                     if self.stream.readline().find("No complete")>-1: return locus, None
00685                     self.stream.readline()
00686                     fis_table = _read_table(self.stream, [str, _gp_float, _gp_float, _gp_float])
00687                     self.stream.readline()
00688                     avg_qinter, avg_fis = tuple(map (lambda x: _gp_float(x),
00689                         filter(lambda y:y != "", self.stream.readline().split(" "))))
00690                     return locus, fis_table, avg_qinter, avg_fis
00691                 l = self.stream.readline()
00692             self.done = True
00693             raise StopIteration
00694         dvf = open(fname + ext)
00695         return _FileIterator(fis_func, dvf, fname + ext), avg_fis, avg_Qintra

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController._calc_ibd (   self,
  fname,
  sub,
  stat = "a",
  scale = "Log",
  min_dist = 0.00001 
) [private]
Calculates isolation by distance statistics

Definition at line 816 of file Controller.py.

00816 
00817     def _calc_ibd(self, fname, sub, stat="a", scale="Log", min_dist=0.00001):
00818         """Calculates isolation by distance statistics
00819         """
00820         self._run_genepop([".GRA", ".MIG", ".ISO"], [6,sub],
00821             fname, opts = {
00822             "MinimalDistance" : min_dist,
00823             "GeographicScale" : scale,
00824             "IsolBDstatistic" : stat,
00825             })
00826         f = open(fname + ".ISO")
00827         f.readline()
00828         f.readline()
00829         f.readline()
00830         f.readline()
00831         estimate = _read_triangle_matrix(f)
00832         f.readline()
00833         f.readline()
00834         distance = _read_triangle_matrix(f)
00835         f.readline()
00836         match = re.match("a = (.+), b = (.+)", f.readline().rstrip())
00837         a = _gp_float(match.group(1))
00838         b = _gp_float(match.group(2))
00839         f.readline()
00840         f.readline()
00841         match = re.match(" b=(.+)", f.readline().rstrip())
00842         bb = _gp_float(match.group(1))
00843         match = re.match(".*\[(.+)  ;  (.+)\]", f.readline().rstrip())
00844         bblow = _gp_float(match.group(1))
00845         bbhigh = _gp_float(match.group(2))
00846         f.close()
00847         os.remove(fname + ".MIG")
00848         os.remove(fname + ".GRA")
00849         os.remove(fname + ".ISO")
00850         return estimate, distance, (a, b), (bb, bblow, bbhigh)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController._get_opts (   self,
  dememorization,
  batches,
  iterations,
  enum_test = None 
) [private]

Definition at line 242 of file Controller.py.

00242 
00243     def _get_opts(self, dememorization, batches, iterations, enum_test=None):
00244         opts = {}
00245         opts["Dememorization"]=dememorization
00246         opts["BatchNumber"]=batches
00247         opts["BatchLength"]=iterations
00248         if enum_test != None:
00249             if enum_test == True:
00250                 opts["HWtests"]="Enumeration"
00251             else:
00252                 opts["HWtests"]="MCMC"
00253         return opts

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController._remove_garbage (   self,
  fname_out 
) [private]

Definition at line 224 of file Controller.py.

00224 
00225     def _remove_garbage(self, fname_out):
00226         try:
00227             if fname_out != None: os.remove(fname_out)
00228         except OSError:
00229             pass # safe
00230         try:
00231             os.remove("genepop.txt")
00232         except OSError:
00233             pass # safe
00234         try:
00235             os.remove("fichier.in")
00236         except OSError:
00237             pass # safe
00238         try:
00239             os.remove("cmdline.txt")
00240         except OSError:
00241             pass # safe

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController._run_genepop (   self,
  extensions,
  option,
  fname,
  opts = {} 
) [private]

Definition at line 254 of file Controller.py.

00254 
00255     def _run_genepop(self, extensions, option, fname, opts={}):
00256         for extension in extensions:
00257             self._remove_garbage(fname + extension)
00258         self.controller.set_menu(option)
00259         self.controller.set_input(fname)
00260         for opt in opts:
00261             self.controller.set_parameter(opt, opt+"="+str(opts[opt]))
00262         self.controller() #checks error level is zero
00263         self._remove_garbage(None)
00264         return
00265 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController._test_global_hz_both (   self,
  fname,
  type,
  ext,
  enum_test = True,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
) [private]
Global Hardy-Weinberg test for heterozygote deficiency/excess.

   Returns a triple with:
     A list per population containg
       (pop_name, P-val, SE, switches)
 Some pops have a None if the info is not available
 SE might be none (for enumerations)
     A list per loci containg
       (locus_name, P-val, SE, switches)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)
     Overall results (P-val, SE, switches)

Definition at line 283 of file Controller.py.

00283 
00284         dememorization = 10000, batches = 20, iterations = 5000):
00285         """Global Hardy-Weinberg test for heterozygote deficiency/excess.
00286 
00287            Returns a triple with:
00288              A list per population containg
00289                (pop_name, P-val, SE, switches)
00290                  Some pops have a None if the info is not available
00291                  SE might be none (for enumerations)
00292              A list per loci containg
00293                (locus_name, P-val, SE, switches)
00294                  Some loci have a None if the info is not available
00295                  SE might be none (for enumerations)
00296              Overall results (P-val, SE, switches)
00297 
00298         """
00299         opts = self._get_opts(dememorization, batches, iterations, enum_test)
00300         self._run_genepop([ext], [1, type], fname, opts)
00301         def hw_pop_func(self):
00302             return _read_table(self.stream, [str, _gp_float, _gp_float, _gp_float])
00303         f1 = open(fname + ext)
00304         l = f1.readline()
00305         while l.find("by population") == -1:
00306             l = f1.readline()
00307         pop_p = _read_table(f1, [str, _gp_float, _gp_float, _gp_float])
00308         f2 = open(fname + ext)
00309         l = f2.readline()
00310         while l.find("by locus") == -1:
00311             l = f2.readline()
00312         loc_p = _read_table(f2, [str, _gp_float, _gp_float, _gp_float])
00313         f = open(fname + ext)
00314         l = f.readline()
00315         while l.find("all locus") == -1:
00316             l = f.readline()
00317         f.readline()
00318         f.readline()
00319         f.readline()
00320         f.readline()
00321         l = f.readline().rstrip()
00322         p, se, switches = tuple(map(lambda x: _gp_float(x),
00323             filter(lambda y: y != "",l.split(" "))))
00324         f.close()
00325         return pop_p, loc_p, (p, se, switches)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController._test_pop_hz_both (   self,
  fname,
  type,
  ext,
  enum_test = True,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
) [private]
Hardy-Weinberg test for heterozygote deficiency/excess.

   Returns a population iterator containg
       A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)

Definition at line 267 of file Controller.py.

00267 
00268         dememorization = 10000, batches = 20, iterations = 5000):
00269         """Hardy-Weinberg test for heterozygote deficiency/excess.
00270 
00271            Returns a population iterator containg
00272                A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
00273                  Some loci have a None if the info is not available
00274                  SE might be none (for enumerations)
00275         """
00276         opts = self._get_opts(dememorization, batches, iterations, enum_test)
00277         self._run_genepop([ext], [1, type], fname, opts)
00278         f = open(fname + ext)
00279         def hw_func(self):
00280             return _hw_func(self.stream, False)
00281         return _FileIterator(hw_func, f, fname + ext)

Here is the call graph for this function:

Here is the caller graph for this function:

Calculates allele and genotype frequencies per locus and per sample.

Parameters:
fname - file name

Returns tuple with 2 elements:
Population iterator with
    population name
    Locus dictionary with key = locus name and content tuple as
      Genotype List with
(Allele1, Allele2, observed, expected)
      (expected homozygotes, observed hm, 
      expected heterozygotes, observed ht)
      Allele frequency/Fis dictionary with allele as key and
(count, frequency, Fis Weir & Cockerham)
      Totals as a pair
count
Fis Weir & Cockerham,
Fis Robertson & Hill
Locus iterator with
    Locus name
    allele list
    Population list with a triple
       population name
       list of allele frequencies in the same order as allele list above
       number of genes


Will create a file called fname.INF

Definition at line 521 of file Controller.py.

00521 
00522     def calc_allele_genotype_freqs(self, fname):
00523         """Calculates allele and genotype frequencies per locus and per sample.
00524         
00525         Parameters:
00526         fname - file name
00527 
00528         Returns tuple with 2 elements:
00529         Population iterator with
00530             population name
00531             Locus dictionary with key = locus name and content tuple as
00532               Genotype List with
00533                 (Allele1, Allele2, observed, expected)
00534               (expected homozygotes, observed hm, 
00535               expected heterozygotes, observed ht)
00536               Allele frequency/Fis dictionary with allele as key and
00537                 (count, frequency, Fis Weir & Cockerham)
00538               Totals as a pair
00539                 count
00540                 Fis Weir & Cockerham,
00541                 Fis Robertson & Hill
00542         Locus iterator with
00543             Locus name
00544             allele list
00545             Population list with a triple
00546                population name
00547                list of allele frequencies in the same order as allele list above
00548                number of genes
00549 
00550         
00551         Will create a file called fname.INF
00552         """
00553         self._run_genepop(["INF"], [5,1], fname)
00554         #First pass, general information
00555         #num_loci = None
00556         #num_pops = None
00557         #f = open(fname + ".INF")
00558         #l = f.readline()
00559         #while (num_loci == None or num_pops == None) and l != '':
00560         #    m = re.search("Number of populations detected : ([0-9+])", l)
00561         #    if m != None:
00562         #        num_pops = _gp_int(m.group(1))
00563         #    m = re.search("Number of loci detected        : ([0-9+])", l)
00564         #    if m != None:
00565         #        num_loci = _gp_int(m.group(1))
00566         #    l = f.readline()
00567         #f.close()
00568         def pop_parser(self):
00569             if hasattr(self, "old_line"):
00570                 l = self.old_line
00571                 del self.old_line
00572             else:
00573                 l = self.stream.readline()
00574             loci_content = {}
00575             while l != '':
00576                 l = l.rstrip()
00577                 if l.find("Tables of allelic frequencies for each locus")>-1:
00578                     return self.curr_pop, loci_content
00579                 match = re.match(".*Pop: (.+) Locus: (.+)", l)
00580                 if match != None:
00581                     pop = match.group(1)
00582                     locus = match.group(2)
00583                     if not hasattr(self, "first_locus"):
00584                         self.first_locus = locus
00585                     if hasattr(self, "curr_pop"):
00586                         if self.first_locus == locus:
00587                             old_pop = self.curr_pop
00588                             #self.curr_pop = pop
00589                             self.old_line = l
00590                             del self.first_locus
00591                             del self.curr_pop
00592                             return old_pop, loci_content
00593                     self.curr_pop = pop
00594                 else:
00595                     l = self.stream.readline()
00596                     continue
00597                 geno_list = []
00598                 l = self.stream.readline()
00599                 if l.find("No data")>-1: continue
00600 
00601                 while l.find("Genotypes  Obs.")==-1:
00602                     l = self.stream.readline()
00603 
00604                 while l != "\n":
00605                     m2 = re.match(" +([0-9]+) , ([0-9]+) *([0-9]+) *(.+)",l)
00606                     if m2 != None:
00607                         geno_list.append((_gp_int(m2.group(1)), _gp_int(m2.group(2)),
00608                             _gp_int(m2.group(3)), _gp_float(m2.group(4))))
00609                     else:
00610                         l = self.stream.readline()
00611                         continue
00612                     l = self.stream.readline()
00613 
00614                 while l.find("Expected number of ho")==-1:
00615                     l = self.stream.readline()
00616                 expHo =  _gp_float(l[38:])
00617                 l = self.stream.readline()
00618                 obsHo =  _gp_int(l[38:])
00619                 l = self.stream.readline()
00620                 expHe =  _gp_float(l[38:])
00621                 l = self.stream.readline()
00622                 obsHe =  _gp_int(l[38:])
00623                 l = self.stream.readline()
00624 
00625                 while l.find("Sample count")==-1:
00626                     l = self.stream.readline()
00627                 l = self.stream.readline()
00628                 freq_fis={}
00629                 overall_fis = None
00630                 while l.find("----")==-1:
00631                     vals = filter(lambda x: x!='',
00632                             l.rstrip().split(' '))
00633                     if vals[0]=="Tot":
00634                         overall_fis = _gp_int(vals[1]), \
00635                                 _gp_float(vals[2]), _gp_float(vals[3])
00636                     else:
00637                         freq_fis[_gp_int(vals[0])] = _gp_int(vals[1]), \
00638                                 _gp_float(vals[2]), _gp_float(vals[3])
00639                     l = self.stream.readline()
00640                 loci_content[locus] = geno_list, \
00641                         (expHo, obsHo, expHe, obsHe), \
00642                         freq_fis, overall_fis
00643             self.done = True
00644             raise StopIteration
00645         def locus_parser(self):
00646             l = self.stream.readline()
00647             while l != "":
00648                 l = l.rstrip()
00649                 match = re.match(" Locus: (.+)", l)
00650                 if match != None:
00651                     locus = match.group(1)
00652                     alleles, table = _read_allele_freq_table(self.stream)
00653                     return locus, alleles, table
00654                 l = self.stream.readline()
00655             self.done = True
00656             raise StopIteration
00657 
00658         popf = open(fname + ".INF")
00659         shutil.copyfile(fname + ".INF", fname + ".IN2")
00660         locf = open(fname + ".IN2")
00661         pop_iter = _FileIterator(pop_parser, popf, fname + ".INF")
00662         locus_iter = _FileIterator(locus_parser, locf, fname + ".IN2")
00663         return (pop_iter, locus_iter)

Here is the call graph for this function:

Definition at line 697 of file Controller.py.

00697 
00698     def calc_diversities_fis_with_identity(self, fname):
00699         return self._calc_diversities_fis(fname, ".DIV")

Here is the call graph for this function:

Definition at line 701 of file Controller.py.

00701 
00702     def calc_diversities_fis_with_size(self, fname):
00703         raise NotImplementedError

Executes GenePop and gets Fst/Fis/Fit (all populations)

Parameters:
fname - file name

Returns:
(multiLocusFis, multiLocusFst, multiLocus Fit),
Iterator of tuples
  (Locus name, Fis, Fst, Fit, Qintra, Qinter)

Will create a file called fname.FST .

This does not return the genotype frequencies.

Definition at line 705 of file Controller.py.

00705 
00706     def calc_fst_all(self, fname):
00707         """Executes GenePop and gets Fst/Fis/Fit (all populations)
00708         
00709         Parameters:
00710         fname - file name
00711 
00712         Returns:
00713         (multiLocusFis, multiLocusFst, multiLocus Fit),
00714         Iterator of tuples
00715           (Locus name, Fis, Fst, Fit, Qintra, Qinter)
00716 
00717         Will create a file called fname.FST .
00718 
00719         This does not return the genotype frequencies.
00720         
00721         """
00722         self._run_genepop([".FST"], [6,1], fname)
00723         f = open(fname + ".FST")
00724         l = f.readline()
00725         while l != '':
00726             if l.startswith('           All:'):
00727                 toks=filter(lambda x:x!="", l.rstrip().split(' '))
00728                 try:
00729                     allFis = _gp_float(toks[1])
00730                 except ValueError:
00731                     allFis = None
00732                 try:
00733                     allFst = _gp_float(toks[2])
00734                 except ValueError:
00735                     allFst = None
00736                 try:
00737                     allFit = _gp_float(toks[3])
00738                 except ValueError:
00739                     allFit = None
00740             l = f.readline()
00741         f.close()
00742         f = open(fname + ".FST")
00743         def proc(self): 
00744             if hasattr(self, "last_line"):
00745                 l = self.last_line
00746                 del self.last_line
00747             else:
00748                 l = self.stream.readline()
00749             locus = None
00750             fis = None
00751             fst = None
00752             fit = None
00753             qintra = None
00754             qinter = None
00755             while l != '':
00756                 l = l.rstrip()
00757                 if l.startswith('  Locus:'):
00758                     if locus != None:
00759                         self.last_line = l
00760                         return locus, fis, fst, fit, qintra, qinter
00761                     else:
00762                         locus = l.split(':')[1].lstrip()
00763                 elif l.startswith('Fis^='):
00764                     fis = _gp_float(l.split(' ')[1])
00765                 elif l.startswith('Fst^='):
00766                     fst = _gp_float(l.split(' ')[1])
00767                 elif l.startswith('Fit^='):
00768                     fit = _gp_float(l.split(' ')[1])
00769                 elif l.startswith('1-Qintra^='):
00770                     qintra = _gp_float(l.split(' ')[1])
00771                 elif l.startswith('1-Qinter^='):
00772                     qinter = _gp_float(l.split(' ')[1])
00773                     return locus, fis, fst, fit, qintra, qinter
00774                 l = self.stream.readline()
00775             if locus != None:
00776                 return locus, fis, fst, fit, qintra, qinter
00777             self.stream.close()
00778             self.done = True
00779             raise StopIteration
00780         return (allFis, allFst, allFit), _FileIterator(proc , f, fname + ".FST")

Here is the call graph for this function:

Definition at line 782 of file Controller.py.

00782 
00783     def calc_fst_pair(self, fname):
00784         self._run_genepop([".ST2", ".MIG"], [6,2], fname)
00785         f = open(fname + ".ST2")
00786         l = f.readline()
00787         while l != "":
00788             l = l.rstrip()
00789             if l.startswith("Estimates for all loci"):
00790                 avg_fst = _read_headed_triangle_matrix(f)
00791             l = f.readline()
00792         f.close()
00793         def loci_func(self): 
00794             l = self.stream.readline()
00795             while l != "":
00796                 l = l.rstrip()
00797                 m = re.search(" Locus: (.+)", l)
00798                 if m != None:
00799                     locus = m.group(1)
00800                     matrix = _read_headed_triangle_matrix(self.stream)
00801                     return locus, matrix
00802                 l = self.stream.readline()
00803             self.done = True
00804             raise StopIteration
00805         stf = open(fname + ".ST2")
00806         os.remove(fname + ".MIG")
00807         return _FileIterator(loci_func, stf, fname + ".ST2"), avg_fst

Here is the call graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.calc_ibd_diplo (   self,
  fname,
  stat = "a",
  scale = "Log",
  min_dist = 0.00001 
)
Calculates isolation by distance statistics for diploid data.

   See _calc_ibd for parameter details.
   Note that each pop can only have a single individual and
   the individual name has to be the sample coordinates.

Definition at line 852 of file Controller.py.

00852 
00853     def calc_ibd_diplo(self, fname, stat="a", scale="Log", min_dist=0.00001):
00854         """Calculates isolation by distance statistics for diploid data.
00855 
00856            See _calc_ibd for parameter details.
00857            Note that each pop can only have a single individual and
00858            the individual name has to be the sample coordinates.
00859         """
00860         return self._calc_ibd(fname, 5, stat, scale, min_dist)

Here is the call graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.calc_ibd_haplo (   self,
  fname,
  stat = "a",
  scale = "Log",
  min_dist = 0.00001 
)
Calculates isolation by distance statistics for haploid data.

   See _calc_ibd for parameter details.
   Note that each pop can only have a single individual and
   the individual name has to be the sample coordinates.

Definition at line 862 of file Controller.py.

00862 
00863     def calc_ibd_haplo(self, fname, stat="a", scale="Log", min_dist=0.00001):
00864         """Calculates isolation by distance statistics for haploid data.
00865 
00866            See _calc_ibd for parameter details.
00867            Note that each pop can only have a single individual and
00868            the individual name has to be the sample coordinates.
00869         """
00870         return self._calc_ibd(fname, 6, stat, scale, min_dist)
00871 
00872 

Here is the call graph for this function:

Definition at line 809 of file Controller.py.

00809 
00810     def calc_rho_all(self, fname):
00811         raise NotImplementedError

Definition at line 813 of file Controller.py.

00813 
00814     def calc_rho_pair(self, fname):
00815         raise NotImplementedError

Definition at line 469 of file Controller.py.

00469 
00470     def create_contingency_tables(self, fname):
00471         raise NotImplementedError

Here is the call graph for this function:

Definition at line 493 of file Controller.py.

00493 
00494     def estimate_nm(self, fname):
00495         self._run_genepop(["PRI"], [4], fname)
00496         f = open(fname + ".PRI")
00497         lines = f.readlines() # Small file, it is ok
00498         f.close()
00499         for line in lines:
00500             m = re.search("Mean sample size: ([.0-9]+)", line)
00501             if m != None:
00502                 mean_sample_size = _gp_float(m.group(1))
00503             m = re.search("Mean frequency of private alleles p\(1\)= ([.0-9]+)", line)
00504             if m != None:
00505                 mean_priv_alleles = _gp_float(m.group(1))
00506             m = re.search("N=10: ([.0-9]+)", line)
00507             if m != None:
00508                 mig10 = _gp_float(m.group(1))
00509             m = re.search("N=25: ([.0-9]+)", line)
00510             if m != None:
00511                  mig25 = _gp_float(m.group(1))
00512             m = re.search("N=50: ([.0-9]+)", line)
00513             if m != None:
00514                  mig50 = _gp_float(m.group(1))
00515             m = re.search("for size= ([.0-9]+)", line)
00516             if m != None:
00517                  mig_corrected = _gp_float(m.group(1))
00518         os.remove(fname + ".PRI")
00519         return mean_sample_size, mean_priv_alleles, mig10, mig25, mig50, mig_corrected

Here is the call graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_genic_diff_all (   self,
  fname,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)

Definition at line 474 of file Controller.py.

00474 
00475         dememorization = 10000, batches = 20, iterations = 5000):
00476         raise NotImplementedError

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_genic_diff_pair (   self,
  fname,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)

Definition at line 479 of file Controller.py.

00479 
00480         dememorization = 10000, batches = 20, iterations = 5000):
00481         raise NotImplementedError

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_genotypic_diff_all (   self,
  fname,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)

Definition at line 484 of file Controller.py.

00484 
00485         dememorization = 10000, batches = 20, iterations = 5000):
00486         raise NotImplementedError

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_genotypic_diff_pair (   self,
  fname,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)

Definition at line 489 of file Controller.py.

00489 
00490         dememorization = 10000, batches = 20, iterations = 5000):
00491         raise NotImplementedError

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_global_hz_deficiency (   self,
  fname,
  enum_test = True,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)
Global Hardy-Weinberg test for heterozygote deficiency.

   Returns a triple with:
     An list per population containg
       (pop_name, P-val, SE, switches)
 Some pops have a None if the info is not available
 SE might be none (for enumerations)
     An list per loci containg
       (locus_name, P-val, SE, switches)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)
     Overall results (P-val, SE, switches)

Definition at line 384 of file Controller.py.

00384 
00385         dememorization = 10000, batches = 20, iterations = 5000):
00386         """Global Hardy-Weinberg test for heterozygote deficiency.
00387 
00388            Returns a triple with:
00389              An list per population containg
00390                (pop_name, P-val, SE, switches)
00391                  Some pops have a None if the info is not available
00392                  SE might be none (for enumerations)
00393              An list per loci containg
00394                (locus_name, P-val, SE, switches)
00395                  Some loci have a None if the info is not available
00396                  SE might be none (for enumerations)
00397              Overall results (P-val, SE, switches)
00398         """
00399         return self._test_global_hz_both(fname, 4, ".DG", enum_test,
00400             dememorization, batches, iterations)
00401 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_global_hz_excess (   self,
  fname,
  enum_test = True,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)
Global Hardy-Weinberg test for heterozygote excess.

   Returns a triple with:
     An list per population containg
       (pop_name, P-val, SE, switches)
 Some pops have a None if the info is not available
 SE might be none (for enumerations)
     An list per loci containg
       (locus_name, P-val, SE, switches)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)
     Overall results (P-val, SE, switches)

Definition at line 404 of file Controller.py.

00404 
00405         dememorization = 10000, batches = 20, iterations = 5000):
00406         """Global Hardy-Weinberg test for heterozygote excess.
00407 
00408            Returns a triple with:
00409              An list per population containg
00410                (pop_name, P-val, SE, switches)
00411                  Some pops have a None if the info is not available
00412                  SE might be none (for enumerations)
00413              An list per loci containg
00414                (locus_name, P-val, SE, switches)
00415                  Some loci have a None if the info is not available
00416                  SE might be none (for enumerations)
00417              Overall results (P-val, SE, switches)
00418         """
00419         return self._test_global_hz_both(fname, 5, ".EG", enum_test,
00420             dememorization, batches, iterations)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_ld (   self,
  fname,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)

Definition at line 423 of file Controller.py.

00423 
00424         dememorization = 10000, batches = 20, iterations = 5000):
00425         opts = self._get_opts(dememorization, batches, iterations)
00426         self._run_genepop([".DIS"], [2, 1], fname, opts)
00427         def ld_pop_func(self):
00428             current_pop = None
00429             l = self.stream.readline().rstrip()
00430             if l == "":
00431                 self.done = True
00432                 raise StopIteration
00433             toks = filter(lambda x: x != "", l.split(" "))
00434             pop, locus1, locus2 = toks[0], toks[1], toks[2]
00435             if not hasattr(self, "start_locus1"):
00436                 start_locus1, start_locus2 = locus1, locus2
00437                 current_pop = -1
00438             if locus1 == start_locus1 and locus2 == start_locus2:
00439                 current_pop += 1
00440             if toks[3] == "No":
00441                 return current_pop, pop, (locus1, locus2), None
00442             p, se, switches = _gp_float(toks[3]), _gp_float(toks[4]), _gp_int(toks[5])
00443             return current_pop, pop, (locus1, locus2), (p, se, switches)
00444         def ld_func(self):
00445             l = self.stream.readline().rstrip()
00446             if l == "":
00447                 self.done = True
00448                 raise StopIteration
00449             toks = filter(lambda x: x != "", l.split(" "))
00450             locus1, locus2 = toks[0], toks[2]
00451             try:
00452                 chi2, df, p = _gp_float(toks[3]), _gp_int(toks[4]), _gp_float(toks[5])
00453             except ValueError:
00454                 return (locus1, locus2), None
00455             return (locus1, locus2), (chi2, df, p)
00456         f1 = open(fname + ".DIS")
00457         l = f1.readline()
00458         while l.find("----")==-1:
00459             l = f1.readline()
00460         shutil.copyfile(fname + ".DIS", fname + ".DI2")
00461         f2 = open(fname + ".DI2")
00462         l = f2.readline()
00463         while l.find("Locus pair")==-1:
00464             l = f2.readline()
00465         while l.find("----")==-1:
00466             l = f2.readline()
00467         return _FileIterator(ld_pop_func, f1, fname+".DIS"), _FileIterator(ld_func, f2, fname + ".DI2")

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_pop_hz_deficiency (   self,
  fname,
  enum_test = True,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)
Hardy-Weinberg test for heterozygote deficiency.

   Returns a population iterator containg
       A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)

Definition at line 328 of file Controller.py.

00328 
00329         dememorization = 10000, batches = 20, iterations = 5000):
00330         """Hardy-Weinberg test for heterozygote deficiency.
00331 
00332            Returns a population iterator containg
00333                A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
00334                  Some loci have a None if the info is not available
00335                  SE might be none (for enumerations)
00336         """
00337         return self._test_pop_hz_both(fname, 1, ".D", enum_test,
00338             dememorization, batches, iterations)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_pop_hz_excess (   self,
  fname,
  enum_test = True,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)
Hardy-Weinberg test for heterozygote deficiency.

   Returns a population iterator containg
       A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)

Definition at line 341 of file Controller.py.

00341 
00342         dememorization = 10000, batches = 20, iterations = 5000):
00343         """Hardy-Weinberg test for heterozygote deficiency.
00344 
00345            Returns a population iterator containg
00346                A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
00347                  Some loci have a None if the info is not available
00348                  SE might be none (for enumerations)
00349         """
00350         return self._test_pop_hz_both(fname, 2, ".E", enum_test,
00351             dememorization, batches, iterations)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PopGen.GenePop.Controller.GenePopController.test_pop_hz_prob (   self,
  fname,
  ext,
  enum_test = False,
  dememorization = 10000,
  batches = 20,
  iterations = 5000 
)
Hardy-Weinberg test based on probability.

   Returns 2 iterators and a final tuple:

  1. Returns a loci iterator containing
       b. A dictionary[pop_pos]=(P-val, SE, Fis-WC, Fis-RH, steps)
 Some pops have a None if the info is not available
 SE might be none (for enumerations)
       c. Result of Fisher's test (Chi2, deg freedom, prob)
  2. Returns a population iterator containg
       a. A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
 Some loci have a None if the info is not available
 SE might be none (for enumerations)
       b. Result of Fisher's test (Chi2, deg freedom, prob)
  3. (Chi2, deg freedom, prob)

Definition at line 354 of file Controller.py.

00354 
00355         dememorization = 10000, batches = 20, iterations = 5000):
00356         """Hardy-Weinberg test based on probability.
00357 
00358            Returns 2 iterators and a final tuple:
00359 
00360           1. Returns a loci iterator containing
00361                b. A dictionary[pop_pos]=(P-val, SE, Fis-WC, Fis-RH, steps)
00362                  Some pops have a None if the info is not available
00363                  SE might be none (for enumerations)
00364                c. Result of Fisher's test (Chi2, deg freedom, prob)
00365           2. Returns a population iterator containg
00366                a. A dictionary[locus]=(P-val, SE, Fis-WC, Fis-RH, steps)
00367                  Some loci have a None if the info is not available
00368                  SE might be none (for enumerations)
00369                b. Result of Fisher's test (Chi2, deg freedom, prob)
00370           3. (Chi2, deg freedom, prob)
00371         """
00372         opts = self._get_opts(dememorization, batches, iterations, enum_test)
00373         self._run_genepop([ext], [1, 3], fname, opts)
00374         def hw_prob_loci_func(self): 
00375             return  _hw_func(self.stream, True, True)
00376         def hw_prob_pop_func(self): 
00377             return _hw_func(self.stream, False, True)
00378         shutil.copyfile(fname+".P", fname+".P2")
00379         f1 = open(fname + ".P")
00380         f2 = open(fname + ".P2")
00381         return _FileIterator(hw_prob_loci_func, f1, fname + ".P"), _FileIterator(hw_prob_pop_func, f2, fname + ".P2")

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 222 of file Controller.py.

Definition at line 592 of file Controller.py.

Definition at line 430 of file Controller.py.

Definition at line 583 of file Controller.py.

Definition at line 758 of file Controller.py.

Definition at line 588 of file Controller.py.


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