Back to index

python-biopython  1.60
Functions
Bio.PopGen.FDist.Utils Namespace Reference

Functions

def convert_genepop_to_fdist
def _convert_genepop_to_fdist
def _convert_genepop_to_fdist_big
def _convert_genepop_to_fdist_big_old
def approximate_fst

Function Documentation

Converts a standard GenePop record to a FDist one.

   Parameters:
   gp_rec - Genepop Record (Standard)

   Returns:
   FDist record.

Definition at line 30 of file Utils.py.

00030 
00031 def _convert_genepop_to_fdist(gp_rec):
00032     """Converts a standard GenePop record to a FDist one.
00033 
00034        Parameters:
00035        gp_rec - Genepop Record (Standard)
00036 
00037        Returns:
00038        FDist record.
00039     """
00040     fd_rec = Bio.PopGen.FDist.Record()
00041     
00042     fd_rec.data_org = 0
00043     fd_rec.num_loci = len(gp_rec.loci_list)
00044     fd_rec.num_pops = len(gp_rec.populations)
00045     for lc_i in range(len(gp_rec.loci_list)):
00046         alleles = []
00047         pop_data = []
00048         for pop_i in range(len(gp_rec.populations)):
00049             for indiv in gp_rec.populations[pop_i]:
00050                 for al in indiv[1][lc_i]:
00051                     if al is not None and al not in alleles:
00052                         alleles.append(al)
00053         alleles.sort() #Dominance requires this
00054 
00055         #here we go again (necessary...)
00056         for pop_i in range(len(gp_rec.populations)):
00057             allele_counts = {}
00058             for indiv in gp_rec.populations[pop_i]:
00059                 for al in indiv[1][lc_i]:
00060                     if al is not None:
00061                         count = allele_counts.get(al, 0)
00062                         allele_counts[al] = count + 1
00063             allele_array = [] #We need the same order as in alleles
00064             for allele in alleles:
00065                 allele_array.append(allele_counts.get(allele, 0))
00066             pop_data.append(allele_array)
00067             #if lc_i==3:
00068             #    print alleles, allele_counts#, pop_data
00069         fd_rec.loci_data.append((len(alleles), pop_data))
00070     return fd_rec

Here is the caller graph for this function:

def Bio.PopGen.FDist.Utils._convert_genepop_to_fdist_big (   gp_rec,
  report_pops = None 
) [private]
Converts a big GenePop record to a FDist one.

   Parameters:
   gp_rec - Genepop Record (Big)

   Returns:
   FDist record.

Definition at line 71 of file Utils.py.

00071 
00072 def _convert_genepop_to_fdist_big(gp_rec, report_pops = None):
00073     """Converts a big GenePop record to a FDist one.
00074 
00075        Parameters:
00076        gp_rec - Genepop Record (Big)
00077 
00078        Returns:
00079        FDist record.
00080     """
00081     fd_rec = Bio.PopGen.FDist.Record()
00082 
00083     fd_rec.data_org = 1
00084     fd_rec.num_loci = len(gp_rec.loci_list)
00085     num_loci = len(gp_rec.loci_list)
00086     loci = []
00087     for i in range(num_loci):
00088         loci.append(set())
00089     pops = []
00090     work_rec = FileParser.read(gp_rec.fname)
00091     lParser = work_rec.get_individual()
00092     def init_pop():
00093         my_pop = []
00094         for i in range(num_loci):
00095             my_pop.append({})
00096         return my_pop
00097     curr_pop = init_pop()
00098     num_pops = 1
00099     if report_pops:
00100         report_pops(num_pops)
00101     while lParser:
00102         if lParser != True:
00103             for loci_pos in range(num_loci):
00104                 for al in lParser[1][loci_pos]:
00105                     if al is not None:
00106                         loci[loci_pos].add(al)
00107                         curr_pop[loci_pos][al]= curr_pop[loci_pos].get(al,0)+1
00108         else:
00109             pops.append(curr_pop)
00110             num_pops += 1
00111             if report_pops:
00112                 report_pops(num_pops)
00113             curr_pop = init_pop()
00114         lParser = work_rec.get_individual()
00115     work_rec._handle.close() #TODO - Needs a proper fix
00116     pops.append(curr_pop)
00117     fd_rec.num_pops = num_pops
00118     for loci_pos in range(num_loci):
00119         alleles = list(loci[loci_pos])
00120         alleles.sort()
00121         loci_rec = [len(alleles), []]
00122         for pop in pops:
00123             pop_rec = []
00124             for allele in alleles:
00125                 pop_rec.append(pop[loci_pos].get(allele, 0))
00126             loci_rec[1].append(pop_rec)
00127         fd_rec.loci_data.append(tuple(loci_rec))
00128     return fd_rec
00129 

Here is the caller graph for this function:

def Bio.PopGen.FDist.Utils._convert_genepop_to_fdist_big_old (   gp_rec,
  report_loci = None 
) [private]
Converts a big GenePop record to a FDist one.

   Parameters:
   gp_rec - Genepop Record (Big)

   Returns:
   FDist record.

Definition at line 130 of file Utils.py.

00130 
00131 def _convert_genepop_to_fdist_big_old(gp_rec, report_loci = None):
00132     """Converts a big GenePop record to a FDist one.
00133 
00134        Parameters:
00135        gp_rec - Genepop Record (Big)
00136 
00137        Returns:
00138        FDist record.
00139     """
00140     fd_rec = Bio.PopGen.FDist.Record()
00141 
00142     def countPops(rec):
00143         f2 = FileParser.read(rec.fname)
00144         popCnt = 1
00145         while f2.skip_population():
00146             popCnt += 1
00147         return popCnt
00148 
00149     
00150     fd_rec.data_org = 0
00151     fd_rec.num_loci = len(gp_rec.loci_list)
00152     work_rec0 = FileParser.read(gp_rec.fname)
00153     fd_rec.num_pops = countPops(work_rec0)
00154 
00155     num_loci = len(gp_rec.loci_list)
00156     for lc_i in range(num_loci):
00157         if report_loci:
00158             report_loci(lc_i, num_loci)
00159         work_rec = FileParser.read(gp_rec.fname)
00160         work_rec2 = FileParser.read(gp_rec.fname)
00161 
00162         alleles = []
00163         pop_data = []
00164         lParser = work_rec.get_individual()
00165         while lParser:
00166             if lParser != True:
00167                 for al in lParser[1][lc_i]:
00168                     if al is not None and al not in alleles:
00169                         alleles.append(al)
00170             lParser = work_rec.get_individual()
00171         #here we go again (necessary...)
00172         alleles.sort()
00173         def process_pop(pop_data, alleles, allele_counts):
00174             allele_array = [] #We need the same order as in alleles
00175             for allele in alleles:
00176                 allele_array.append(allele_counts.get(allele, 0))
00177             pop_data.append(allele_array)
00178         lParser = work_rec2.get_individual()
00179         allele_counts = {}
00180         for allele in alleles:
00181             allele_counts[allele] = 0
00182         allele_counts[None]=0
00183         while lParser:
00184             if lParser == True:
00185                 process_pop(pop_data, alleles, allele_counts)
00186                 allele_counts = {}
00187                 for allele in alleles:
00188                     allele_counts[allele] = 0
00189                 allele_counts[None]=0
00190             else:
00191                 for al in lParser[1][lc_i]:
00192                     allele_counts[al] += 1
00193             lParser = work_rec2.get_individual()
00194         process_pop(pop_data, alleles, allele_counts)
00195         fd_rec.loci_data.append((len(alleles), pop_data))
00196     return fd_rec
00197 

Here is the call graph for this function:

def Bio.PopGen.FDist.Utils.approximate_fst (   desired_fst,
  simulated_fst,
  parameter_fst,
  max_run_fst = 1,
  min_run_fst = 0,
  limit = 0.005 
)
Calculates the next Fst attempt in order to approximate a
   desired Fst.

Definition at line 199 of file Utils.py.

00199 
00200            max_run_fst = 1, min_run_fst = 0, limit = 0.005):
00201     """Calculates the next Fst attempt in order to approximate a
00202        desired Fst.
00203     
00204     """
00205     if abs(simulated_fst - desired_fst) < limit:
00206         return parameter_fst, max_run_fst, min_run_fst
00207     if simulated_fst > desired_fst:
00208         max_run_fst = parameter_fst
00209         next_parameter_fst = (min_run_fst + parameter_fst)/2
00210     else:
00211         min_run_fst = parameter_fst
00212         next_parameter_fst = (max_run_fst + parameter_fst)/2
00213     return next_parameter_fst, max_run_fst, min_run_fst
00214 

Here is the caller graph for this function:

def Bio.PopGen.FDist.Utils.convert_genepop_to_fdist (   gp_rec,
  report_pops = None 
)
Converts a GenePop record to a FDist one.

   Parameters:
   gp_rec - Genepop Record (either standard or big)

   Returns:
   FDist record.

Definition at line 16 of file Utils.py.

00016 
00017 def convert_genepop_to_fdist(gp_rec, report_pops = None):
00018     """Converts a GenePop record to a FDist one.
00019 
00020        Parameters:
00021        gp_rec - Genepop Record (either standard or big)
00022 
00023        Returns:
00024        FDist record.
00025     """
00026     if hasattr(gp_rec, "populations"):
00027         return _convert_genepop_to_fdist(gp_rec)
00028     else:
00029         return _convert_genepop_to_fdist_big(gp_rec, report_pops)

Here is the call graph for this function:

Here is the caller graph for this function: