- Biopython 教程
- Biopython - 首頁
- Biopython - 簡介
- Biopython - 安裝
- 建立簡單的應用程式
- Biopython - 序列
- 高階序列操作
- 序列 I/O 操作
- Biopython - 序列比對
- Biopython - BLAST 概述
- Biopython - Entrez 資料庫
- Biopython - PDB 模組
- Biopython - 基元物件
- Biopython - BioSQL 模組
- Biopython - 群體遺傳學
- Biopython - 基因組分析
- Biopython - 表型微陣列
- Biopython - 繪圖
- Biopython - 聚類分析
- Biopython - 機器學習
- Biopython - 測試技術
- Biopython 資源
- Biopython - 快速指南
- Biopython - 有用資源
- Biopython - 討論
Biopython - 群體遺傳學
群體遺傳學在進化論中扮演著重要的角色。它分析物種之間以及同一種類中兩個或多個個體之間的遺傳差異。
Biopython 提供 Bio.PopGen 模組用於群體遺傳學,主要支援 `GenePop`,這是一個由 Michel Raymond 和 Francois Rousset 開發的流行遺傳學軟體包。
一個簡單的解析器
讓我們編寫一個簡單的應用程式來解析 GenePop 格式並理解其概念。
下載 Biopython 團隊提供的 GenePop 檔案,連結如下:https://raw.githubusercontent.com/biopython/biopython/master/Tests/PopGen/c3line.gen
使用以下程式碼片段載入 GenePop 模組:
from Bio.PopGen import GenePop
使用 GenePop.read 方法解析檔案,如下所示:
record = GenePop.read(open("c3line.gen"))
顯示如下所示的基因座和群體資訊:
>>> record.loci_list
['136255903', '136257048', '136257636']
>>> record.pop_list
['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)])]]
>>>
這裡,檔案中存在三個基因座和三組群體:第一組群體有 4 條記錄,第二組群體有 3 條記錄,第三組群體有 5 條記錄。record.populations 顯示所有包含每個基因座等位基因資料的群體集。
操作 GenePop 檔案
Biopython 提供了刪除基因座和群體資料的選項。
按位置移除群體集:
>>> 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)])]]
>>>
按位置移除基因座:
>>> record.remove_locus_by_position(0)
>>> record.loci_list
['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)])]]
>>>
按名稱移除基因座:
>>> record.remove_locus_by_name('136257636') >>> record.loci_list
['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)])]]
>>>
與 GenePop 軟體互動
Biopython 提供了與 GenePop 軟體互動的介面,從而暴露出其許多功能。Bio.PopGen.GenePop 模組用於此目的。一個易於使用的介面是 EasyController。讓我們檢查如何解析 GenePop 檔案並使用 EasyController 進行一些分析。
首先,安裝 GenePop 軟體並將安裝資料夾放在系統路徑中。要獲取有關 GenePop 檔案的基本資訊,請建立一個 EasyController 物件,然後呼叫 get_basic_info 方法,如下所示:
>>> from Bio.PopGen.GenePop.EasyController import EasyController
>>> ec = EasyController('c3line.gen')
>>> print(ec.get_basic_info())
(['4', 'b3', '5'], ['136255903', '136257048', '136257636'])
>>>
這裡,第一項是群體列表,第二項是基因座列表。
要獲取特定基因座的所有等位基因列表,請透過傳遞基因座名稱來呼叫 get_alleles_all_pops 方法,如下所示:
>>> allele_list = ec.get_alleles_all_pops("136255903")
>>> print(allele_list)
[2, 3]
要獲取特定群體和基因座的等位基因列表,請透過傳遞基因座名稱和群體位置來呼叫 get_alleles 方法,如下所示:
>>> allele_list = ec.get_alleles(0, "136255903") >>> print(allele_list) [] >>> allele_list = ec.get_alleles(1, "136255903") >>> print(allele_list) [] >>> allele_list = ec.get_alleles(2, "136255903") >>> print(allele_list) [2, 3] >>>
同樣,EasyController 公開了許多功能:等位基因頻率、基因型頻率、多基因座 F 統計量、Hardy-Weinberg 平衡、連鎖不平衡等。