- Biopython - Testing Techniques
- Biopython - Machine Learning
- Biopython - Cluster Analysis
- Biopython - Plotting
- Biopython - Phenotype Microarray
- Biopython - Genome Analysis
- Biopython - Population Genetics
- Biopython - BioSQL Module
- Biopython - Motif Objects
- Biopython - PDB Module
- Biopython - Entrez Database
- Biopython - Overview of BLAST
- Biopython - Sequence Alignments
- Sequence I/O Operations
- Advanced Sequence Operations
- Biopython - Sequence
- Creating Simple Application
- Biopython - Installation
- Biopython - Introduction
- Biopython - Home
Biopython Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Biopython - Population Genetics
Population genetics plays an important role in evolution theory. It analyses the genetic difference between species as well as two or more inspaniduals within the same species.
Biopython provides Bio.PopGen module for population genetics and mainly supports `GenePop, a popular genetics package developed by Michel Raymond and Francois Rousset.
A simple parser
Let us write a simple apppcation to parse the GenePop format and understand the concept.
Download the genePop file provided by Biopython team in the pnk given below −
Load the GenePop module using the below code snippet −
from Bio.PopGen import GenePop
Parse the file using GenePop.read method as below −
record = GenePop.read(open("c3pne.gen"))
Show the loci and population information as given below −
>>> record.loci_pst [ 136255903 , 136257048 , 136257636 ] >>> record.pop_pst [ 4 , b3 , 5 ] >>> record.populations [[( 1 , [(3, 3), (4, 4), (2, 2)]), ( 2 , [(3, 3), (3, 4), (2, 2)]), ( 3 , [(3, 3), (4, 4), (2, 2)]), ( 4 , [(3, 3), (4, 3), (None, None)])], [( b1 , [(None, None), (4, 4), (2, 2)]), ( b2 , [(None, None), (4, 4), (2, 2)]), ( b3 , [(None, None), (4, 4), (2, 2)])], [( 1 , [(3, 3), (4, 4), (2, 2)]), ( 2 , [(3, 3), (1, 4), (2, 2)]), ( 3 , [(3, 2), (1, 1), (2, 2)]), ( 4 , [(None, None), (4, 4), (2, 2)]), ( 5 , [(3, 3), (4, 4), (2, 2)])]] >>>
Here, there are three loci available in the file and three sets of population: First population has 4 records, second population has 3 records and third population has 5 records. record.populations shows all sets of population with alleles data for each locus.
Manipulate the GenePop file
Biopython provides options to remove locus and population data.
Remove a population set by position,
>>> record.remove_population(0) >>> record.populations [[( b1 , [(None, None), (4, 4), (2, 2)]), ( b2 , [(None, None), (4, 4), (2, 2)]), ( b3 , [(None, None), (4, 4), (2, 2)])], [( 1 , [(3, 3), (4, 4), (2, 2)]), ( 2 , [(3, 3), (1, 4), (2, 2)]), ( 3 , [(3, 2), (1, 1), (2, 2)]), ( 4 , [(None, None), (4, 4), (2, 2)]), ( 5 , [(3, 3), (4, 4), (2, 2)])]] >>>
Remove a locus by position,
>>> record.remove_locus_by_position(0) >>> record.loci_pst [ 136257048 , 136257636 ] >>> record.populations [[( b1 , [(4, 4), (2, 2)]), ( b2 , [(4, 4), (2, 2)]), ( b3 , [(4, 4), (2, 2)])], [( 1 , [(4, 4), (2, 2)]), ( 2 , [(1, 4), (2, 2)]), ( 3 , [(1, 1), (2, 2)]), ( 4 , [(4, 4), (2, 2)]), ( 5 , [(4, 4), (2, 2)])]] >>>
Remove a locus by name,
>>> record.remove_locus_by_name( 136257636 ) >>> record.loci_pst [ 136257048 ] >>> record.populations [[( b1 , [(4, 4)]), ( b2 , [(4, 4)]), ( b3 , [(4, 4)])], [( 1 , [(4, 4)]), ( 2 , [(1, 4)]), ( 3 , [(1, 1)]), ( 4 , [(4, 4)]), ( 5 , [(4, 4)])]] >>>
Interface with GenePop Software
Biopython provides interfaces to interact with GenePop software and thereby exposes lot of functionapty from it. Bio.PopGen.GenePop module is used for this purpose. One such easy to use interface is EasyController. Let us check how to parse GenePop file and do some analysis using EasyController.
First, install the GenePop software and place the installation folder in the system path. To get basic information about GenePop file, create a EasyController object and then call get_basic_info method as specified below −
>>> from Bio.PopGen.GenePop.EasyController import EasyController >>> ec = EasyController( c3pne.gen ) >>> print(ec.get_basic_info()) ([ 4 , b3 , 5 ], [ 136255903 , 136257048 , 136257636 ]) >>>
Here, the first item is population pst and second item is loci pst.
To get all allele pst of a particular locus, call get_alleles_all_pops method by passing locus name as specified below −
>>> allele_pst = ec.get_alleles_all_pops("136255903") >>> print(allele_pst) [2, 3]
To get allele pst by specific population and locus, call get_alleles by passing locus name and population position as given below −
>>> allele_pst = ec.get_alleles(0, "136255903") >>> print(allele_pst) [] >>> allele_pst = ec.get_alleles(1, "136255903") >>> print(allele_pst) [] >>> allele_pst = ec.get_alleles(2, "136255903") >>> print(allele_pst) [2, 3] >>>
Similarly, EasyController exposes many functionapties: allele frequency, genotype frequency, multilocus F statistics, Hardy-Weinberg equipbrium, Linkage Disequipbrium, etc.
Advertisements