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 7""" 8This module provides code to work with FDist. 910See http://www.rubic.rdg.ac.uk/~mab/software.html (old) and11http://www.maths.bris.ac.uk/~mamab/ (new) for downloading the12FDist tool by Mark Beaumont.1314Classes:15Record Holds FDist data.1617Functions:18read Parses a FDist record (file) into a Record object.192021"""2223__docformat__="restructuredtext en"24

26"""Parses FDist data into a Record object.2728 handle is a file-like object that contains a FDist record.29 """30record=Record()31record.data_org=int(str(next(handle)).rstrip())32record.num_pops=int(str(next(handle)).rstrip())33record.num_loci=int(str(next(handle)).rstrip())34foriinrange(record.num_loci):35next(handle)36num_alleles=int(str(next(handle)).rstrip())37pops_data=[]38ifrecord.data_org==0:39forjinrange(record.num_pops):40line_comp=str(next(handle)).rstrip().split(' ')41pop_dist=[int(x)forxinline_comp]42pops_data.append(pop_dist)43else:44raiseNotImplementedError('1/alleles by rows not implemented')45record.loci_data.append((num_alleles,pops_data))46returnrecord

50"""Holds information from a FDist record.5152 Members:5354 - data_org Data organization (0 pops by rows, 1 alleles by rows).55 The Record will behave as if data was 0 (converting if needed)5657 - num_pops Number of populations5859 - num_loci Number of loci6061 - loci_data Loci data6263 loci_data is a list, where each element represents a locus. Each element64 is a tuple, the first element is the number of alleles, the second65 element a list. Each element of the list is the count of each allele66 per population.67 """

75rep=['0\n']# We only export in 0 format, even if originally was 176rep.append(str(self.num_pops)+'\n')77rep.append(str(self.num_loci)+'\n')78rep.append('\n')79forlocus_datainself.loci_data:80num_alleles,pops_data=locus_data81rep.append(str(num_alleles)+'\n')82forpop_datainpops_data:83forallele_countinpop_data:84rep.append(str(allele_count)+' ')85rep.append('\n')86rep.append('\n')87return"".join(rep)