Back to index

python-biopython  1.60
Classes | Functions
Bio.PopGen.GenePop.LargeFileParser Namespace Reference

Classes

class  Record

Functions

def get_indiv
def read

Function Documentation

Definition at line 23 of file LargeFileParser.py.

00023 
00024 def get_indiv(line):
00025     indiv_name, marker_line = line.split(',')
00026     markers = marker_line.replace('\t', ' ').split(' ')
00027     markers = [marker for marker in markers if marker!='']
00028     if len(markers[0]) in [2, 4]: #2 digits per allele
00029         marker_len = 2
00030     else:
00031         marker_len = 3
00032     try:
00033         allele_list = [(int(marker[0:marker_len]),
00034                        int(marker[marker_len:]))
00035                    for marker in markers]
00036     except ValueError: #Haploid
00037         allele_list = [(int(marker[0:marker_len]),)
00038                    for marker in markers]
00039     return indiv_name, allele_list, marker_len

Here is the caller graph for this function:

Parses a handle containing a GenePop file.

   handle is a file-like object that contains a GenePop record.

Definition at line 40 of file LargeFileParser.py.

00040 
00041 def read(handle):
00042     """Parses a handle containing a GenePop file.
00043 
00044        handle is a file-like object that contains a GenePop record.
00045     """
00046     record = Record(handle)
00047     record.comment_line = str(handle.readline()).rstrip()
00048     #We can now have one loci per line or all loci in a single line
00049     #separated by either space or comma+space...
00050     #We will remove all commas on loci... that should not be a problem
00051     sample_loci_line = str(handle.readline()).rstrip().replace(',', '')
00052     all_loci = sample_loci_line.split(' ')
00053     record.loci_list.extend(all_loci)
00054     line = handle.readline()
00055     while line!="":
00056         line = line.rstrip()
00057         if line.upper()=="POP":
00058             record.stack.append("POP")            
00059             break
00060         record.loci_list.append(line)
00061         line = handle.readline()
00062     next_line = handle.readline().rstrip()
00063     indiv_name, allele_list, record.marker_len = get_indiv(next_line)
00064     record.stack.append(next_line)
00065     return record
00066 

Here is the call graph for this function: