Bio.PopGen:族群遺傳學

Bio.PopGen 是一個 Biopython 模組,支援族群遺傳學,可於 Biopython 1.44 及更高版本中使用。該模組的目標是支援廣泛使用的資料格式、應用程式和資料庫。

GenePop

GenePop(http://genepop.curtin.edu.au/)是一個流行的族群遺傳學軟體套件,支援 Hardy-Weinberg 檢定、連鎖不平衡、族群分化、基本統計、\(F_{st}\) 和遷徙估計等。GenePop 不提供基於序列的統計數據,因為它不處理序列資料。GenePop 檔案格式受到廣泛其他族群遺傳學軟體應用程式的支援,因此使其成為族群遺傳學領域中的相關格式。

Bio.PopGen 提供 GenePop 檔案格式的剖析器和產生器。還提供了操作記錄內容的工具。以下是如何讀取 GenePop 檔案的範例(你可以在 Biopython 的 Test/PopGen 目錄中找到範例 GenePop 資料檔案)

from Bio.PopGen import GenePop

with open("example.gen") as handle:
    rec = GenePop.read(handle)

這將讀取一個名為 example.gen 的檔案並進行剖析。如果你執行 print rec,該記錄將再次以 GenePop 格式輸出。

rec 中最重要的資訊將會是基因座名稱和族群資訊(但還有更多 – 使用 help(GenePop.Record) 檢查 API 文件)。基因座名稱可以在 rec.loci_list 上找到。族群資訊可以在 rec.populations 上找到。populations 是一個列表,每個族群有一個元素。每個元素本身是一個個體的列表,每個個體是由個體名稱和一個等位基因列表(每個標記 2 個)組成的一對,以下是 rec.populations 的範例

[
    [
        ("Ind1", [(1, 2), (3, 3), (200, 201)]),
        ("Ind2", [(2, None), (3, 3), (None, None)]),
    ],
    [
        ("Other1", [(1, 1), (4, 3), (200, 200)]),
    ],
]

所以我們有兩個族群,第一個族群有兩個個體,第二個族群只有一個。第一個族群的第一個個體稱為 Ind1,每個 3 個基因座的等位基因資訊如下。請注意,對於任何基因座,資訊都可能遺失(例如,參見上面的 Ind2)。

提供了一些實用函數來操作 GenePop 記錄,以下是一個範例

from Bio.PopGen import GenePop

# Imagine that you have loaded rec, as per the code snippet above...

rec.remove_population(pos)
# Removes a population from a record, pos is the population position in
# rec.populations, remember that it starts on position 0.
# rec is altered.

rec.remove_locus_by_position(pos)
# Removes a locus by its position, pos is the locus position in
#  rec.loci_list, remember that it starts on position 0.
#  rec is altered.

rec.remove_locus_by_name(name)
# Removes a locus by its name, name is the locus name as in
# rec.loci_list. If the name doesn't exist the function fails
# silently.
# rec is altered.

rec_loci = rec.split_in_loci()
# Splits a record in loci, that is, for each loci, it creates a new
# record, with a single loci and all populations.
# The result is returned in a dictionary, being each key the locus name.
# The value is the GenePop record.
# rec is not altered.

rec_pops = rec.split_in_pops(pop_names)
# Splits a record in populations, that is, for each population, it creates
# a new record, with a single population and all loci.
# The result is returned in a dictionary, being each key
# the population name. As population names are not available in GenePop,
# they are passed in array (pop_names).
# The value of each dictionary entry is the GenePop record.
# rec is not altered.

GenePop 不支援族群名稱,這有時會是一個麻煩的限制。目前正計劃為 Biopython 提供啟用族群名稱的功能。這些擴充功能不會以任何方式破壞與標準格式的相容性。在中期,我們也希望支援 GenePop 網路服務。