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 RecordParser Parses a FDist record (file) into a Record object.
15
16 _Scanner Scans a FDist record.
17 _RecordConsumer Consumes FDist data to a Record object.
18
19
20 """
21 from types import *
22
23
24 from Bio import File
25 from Bio.ParserSupport import *
26
27
28
30 """Holds information from a FDist record.
31
32 Members:
33 data_org Data organization (0 pops by rows, 1 alleles by rows).
34 The Record will behave as if data was 0 (converting if needed)
35
36 num_pops Number of populations
37
38 num_loci Number of loci
39
40 loci_data Loci data
41
42 loci_data is a list, where each element represents a locus. Each element
43 is a tuple, the first element is the number of alleles, the second
44 element a list. Each element of the list is the count of each allele
45 per population.
46
47 """
53
55 rep = ['0\n']
56 rep.append(str(self.num_pops) + '\n')
57 rep.append(str(self.num_loci) + '\n')
58 rep.append('\n')
59 for locus_data in self.loci_data:
60 num_alleles, pops_data = locus_data
61 rep.append(str(num_alleles) + '\n')
62 for pop_data in pops_data:
63 for allele_count in pop_data:
64 rep.append(str(allele_count) + ' ')
65 rep.append('\n')
66 rep.append('\n')
67 return "".join(rep)
68
69
71 """Parses FDist data into a Record object.
72
73 """
77
79 self._scanner.feed(handle, self._consumer)
80 return self._consumer.data
81
83 """Scans a FDist record.
84
85 There is only one record per file.
86
87 """
88
89 - def feed(self, handle, consumer):
122
124 """Consumer that converts a FDist record to a Record object.
125
126 Members:
127 data Record with FDist data.
128
129 """
132
135
138
141
144
147
149 self.data.loci_data.append((num_alleles, pop_data))
150