Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.PopGen.GenePop.Record Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def split_in_pops
def split_in_loci
def remove_population
def remove_locus_by_position
def remove_locus_by_name

Public Attributes

 marker_len
 comment_line
 loci_list
 pop_list
 populations

Detailed Description

Holds information from a GenePop record.

Members:
marker_len         The marker length (2 or 3 digit code per allele).    

comment_line       Comment line.

loci_list          List of loci names.

pop_list           List of population names.

populations        List of population data.

In most genepop files, the population name is not trustable.
It is strongly recommended that populations are referred by index.

populations has one element per population. Each element is itself
a list of individuals, each individual is a pair composed by individual
name and a list of alleles (2 per marker or 1 for haploids): Example
[
    [
        ('Ind1', [(1,2),    (3,3), (200,201)],
        ('Ind2', [(2,None), (3,3), (None,None)],
    ],
    [
        ('Other1', [(1,1),  (4,3), (200,200)],
    ]
]

Definition at line 91 of file __init__.py.


Constructor & Destructor Documentation

Definition at line 123 of file __init__.py.

00123 
00124     def __init__(self):
00125         self.marker_len      = 0
00126         self.comment_line    = ""
00127         self.loci_list       = []
00128         self.pop_list        = []
00129         self.populations     = []


Member Function Documentation

Returns (reconstructs) a GenePop textual representation.

Definition at line 130 of file __init__.py.

00130 
00131     def __str__(self):
00132         """Returns (reconstructs) a GenePop textual representation.
00133         """
00134         rep  = [self.comment_line + '\n']
00135         rep.append('\n'.join(self.loci_list) + '\n')
00136         for pop in self.populations:
00137             rep.append('Pop\n')
00138             for indiv in pop:
00139                 name, markers = indiv
00140                 rep.append(name)
00141                 rep.append(',')
00142                 for marker in markers:
00143                     rep.append(' ')
00144                     for al in marker:
00145                         if al == None:
00146                             al = '0'
00147                         aStr = str(al)
00148                         while len(aStr)<self.marker_len:
00149                             aStr = "".join(['0', aStr])
00150                         rep.append(aStr)
00151                 rep.append('\n')
00152         return "".join(rep)

Removes a locus by name.

Definition at line 210 of file __init__.py.

00210 
00211     def remove_locus_by_name(self, name):
00212         """Removes a locus by name.
00213         """
00214         for i in range(len(self.loci_list)):
00215             if self.loci_list[i] == name:
00216                 self.remove_locus_by_position(i)
00217                 return
00218         #If here than locus not existent... Maybe raise exception?
00219         #   Although it should be Ok... Just a boolean return, maybe?
00220     
00221 

Here is the call graph for this function:

Removes a locus by position.

Definition at line 201 of file __init__.py.

00201 
00202     def remove_locus_by_position(self, pos):
00203         """Removes a locus by position.
00204         """
00205         del self.loci_list[pos]
00206         for pop in self.populations:
00207             for indiv in pop:
00208                 name, loci = indiv
00209                 del loci[pos]

Here is the caller graph for this function:

Removes a population (by position).

Definition at line 196 of file __init__.py.

00196 
00197     def remove_population(self, pos):
00198         """Removes a population (by position).
00199         """
00200         del self.populations[pos]
    
def Bio.PopGen.GenePop.Record.split_in_loci (   self,
  gp 
)
Splits a GP record in a dictionary with 1 locus per entry.

    Given a record with n pops and m loci returns a dictionary
    of records (key locus name) where each item is a record
    with a single locus and n pops.

Definition at line 173 of file __init__.py.

00173 
00174     def split_in_loci(self, gp):
00175         """Splits a GP record in a dictionary with 1 locus per entry.
00176 
00177             Given a record with n pops and m loci returns a dictionary
00178             of records (key locus name) where each item is a record
00179             with a single locus and n pops.
00180         """
00181         gp_loci = {}
00182         for i in range(len(self.loci_list)):
00183             gp_pop = Record()
00184             gp_pop.marker_len = self.marker_len
00185             gp_pop.comment_line = self.comment_line
00186             gp_pop.loci_list = [self.loci_list[i]]
00187             gp_pop.populations = []
00188             for pop in self.populations:
00189                 my_pop = []
00190                 for indiv in pop:
00191                     my_pop.append((indiv[0], [indiv[1][i]]))
00192                 gp_pop.populations.append(my_pop)
00193             gp_loci[gp_pop.loci_list[0]] = gp_pop
00194         return gp_loci
00195 

def Bio.PopGen.GenePop.Record.split_in_pops (   self,
  pop_names 
)
Splits a GP record in a dictionary with 1 pop per entry.

    Given a record with n pops and m loci returns a dictionary
    of records (key pop_name) where each item is a record
    with a single pop and m loci.

    Parameters:
    pop_names - Population names

Definition at line 153 of file __init__.py.

00153 
00154     def split_in_pops(self, pop_names):
00155         """Splits a GP record in a dictionary with 1 pop per entry.
00156 
00157             Given a record with n pops and m loci returns a dictionary
00158             of records (key pop_name) where each item is a record
00159             with a single pop and m loci.
00160 
00161             Parameters:
00162             pop_names - Population names
00163         """
00164         gp_pops = {}
00165         for i in range(len(self.populations)):
00166             gp_pop = Record()
00167             gp_pop.marker_len = self.marker_len
00168             gp_pop.comment_line = self.comment_line
00169             gp_pop.loci_list = deepcopy(self.loci_list)
00170             gp_pop.populations = [deepcopy(self.populations[i])]
00171             gp_pops[pop_names[i]] = gp_pop
00172         return gp_pops


Member Data Documentation

Definition at line 125 of file __init__.py.

Definition at line 126 of file __init__.py.

Definition at line 124 of file __init__.py.

Definition at line 127 of file __init__.py.

Definition at line 128 of file __init__.py.


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