Package Bio :: Package PopGen :: Package FDist
[hide private]
[frames] | no frames]

Source Code for Package Bio.PopGen.FDist

 1  # Copyright 2007 by Tiago Antao <tiagoantao@gmail.com>.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """This module provides code to work with FDist (DEPRECATED). 
 7   
 8  See http://www.rubic.rdg.ac.uk/~mab/software.html (old) and 
 9  http://www.maths.bris.ac.uk/~mamab/ (new) for downloading the 
10  FDist tool by Mark Beaumont. 
11   
12  Classes: 
13  Record           Holds FDist data. 
14   
15  Functions: 
16  read             Parses a FDist record (file) into a Record object. 
17   
18   
19  """ 
20   
21  import warnings 
22   
23  from Bio import BiopythonDeprecationWarning 
24   
25  warnings.warn("Bio.PopGen.FDist has been deprecated, and we intend to remove" 
26                " it in a future release of Biopython. If you would like to" 
27                " continue using it, please contact the Biopython developers" 
28                " via the mailing list.", BiopythonDeprecationWarning) 
29   
30   
31 -def read(handle):
32 """Parses FDist data into a Record object. 33 34 handle is a file-like object that contains a FDist record. 35 """ 36 record = Record() 37 record.data_org = int(str(next(handle)).rstrip()) 38 record.num_pops = int(str(next(handle)).rstrip()) 39 record.num_loci = int(str(next(handle)).rstrip()) 40 for i in range(record.num_loci): 41 next(handle) 42 num_alleles = int(str(next(handle)).rstrip()) 43 pops_data = [] 44 if record.data_org == 0: 45 for j in range(record.num_pops): 46 line_comp = str(next(handle)).rstrip().split(' ') 47 pop_dist = [int(x) for x in line_comp] 48 pops_data.append(pop_dist) 49 else: 50 raise NotImplementedError('1/alleles by rows not implemented') 51 record.loci_data.append((num_alleles, pops_data)) 52 return record
53 54
55 -class Record(object):
56 """Holds information from a FDist record. 57 58 Members: 59 60 - data_org Data organization (0 pops by rows, 1 alleles by rows). 61 The Record will behave as if data was 0 (converting if needed) 62 63 - num_pops Number of populations 64 65 - num_loci Number of loci 66 67 - loci_data Loci data 68 69 loci_data is a list, where each element represents a locus. Each element 70 is a tuple, the first element is the number of alleles, the second 71 element a list. Each element of the list is the count of each allele 72 per population. 73 """
74 - def __init__(self):
75 self.data_org = 0 76 self.num_pops = 0 77 self.num_loci = 0 78 self.loci_data = []
79
80 - def __str__(self):
81 rep = ['0\n'] # We only export in 0 format, even if originally was 1 82 rep.append(str(self.num_pops) + '\n') 83 rep.append(str(self.num_loci) + '\n') 84 rep.append('\n') 85 for locus_data in self.loci_data: 86 num_alleles, pops_data = locus_data 87 rep.append(str(num_alleles) + '\n') 88 for pop_data in pops_data: 89 for allele_count in pop_data: 90 rep.append(str(allele_count) + ' ') 91 rep.append('\n') 92 rep.append('\n') 93 return "".join(rep)
94