1
2
3
4
5
6
7 """
8 This module provides code to work with FDist.
9
10 See http://www.rubic.rdg.ac.uk/~mab/software.html .
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 Obsolete classes:
20 RecordParser Parses a FDist record (file) into a Record object.
21
22 _Scanner Scans a FDist record.
23 _RecordConsumer Consumes FDist data to a Record object.
24
25
26 """
27
28
29
30
53
54
56 """Holds information from a FDist record.
57
58 Members:
59 data_org Data organization (0 pops by rows, 1 alleles by rows).
60 The Record will behave as if data was 0 (converting if needed)
61
62 num_pops Number of populations
63
64 num_loci Number of loci
65
66 loci_data Loci data
67
68 loci_data is a list, where each element represents a locus. Each element
69 is a tuple, the first element is the number of alleles, the second
70 element a list. Each element of the list is the count of each allele
71 per population.
72
73 """
79
81 rep = ['0\n']
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
95
96
97 from Bio.ParserSupport import *
98
100 """Parses FDist data into a Record object (OBSOLETE).
101
102 This function is OBSOLETE; plesae use the read() function in this module
103 instead.
104 """
108
109 - def parse(self, handle):
110 self._scanner.feed(handle, self._consumer)
111 return self._consumer.data
112
114 """Scans a FDist record (OBSOLETE).
115
116 There is only one record per file.
117
118 This function is OBSOLETE; plesae use the read() function in this module
119 instead.
120 """
121
122 - def feed(self, handle, consumer):
155
157 """Consumer that converts a FDist record to a Record object (OBSOLETE).
158
159 Members:
160 data Record with FDist data.
161
162 This function is OBSOLETE; plesae use the read() function in this module
163 instead.
164 """
167
170
173
176
179
182
184 self.data.loci_data.append((num_alleles, pop_data))
185