在 GitHub 上編輯此頁面

使用 Bio.SeqUtils.Mapper 模組對應基因座標。

由 Lenna X. Peterson 貢獻

在不同的座標系統之間對應基因位置是許多基因體分析的重要部分。這是 SeqMapper 模組的簡短介紹。

注意:這使用目前在我的 分支 上可用的座標對應器。這反過來又是 Peter 的分支的一個分支,引入了 CompoundLocations。它將無法與舊式的 SeqFeature 一起使用。

設定

對應器和對應位置將所有位置儲存在 Python 座標中,即以 0 為起始。許多使用者正在使用以 1 為起始的資料,例如 GenBank 或 HGVS。每個對應位置類型都有一個 “to_hgvs” 和 “to_genbank” 方法,方便轉換。也可以將對應位置的預設列印表示設定為這些格式中的任一種

from Bio.SeqUtils.Mapper import MapPosition


def use_genbank(self):
    return str(self.to_genbank())


MapPosition.__str__ = use_genbank

對應

使用對應器的第一步是從 GenBank 或類似檔案取得外顯子。對應器將接受外顯子作為一對序列、具有 CDS 特徵的 SeqRecord 或 CDS SeqFeature。此範例中使用的檔案位於 Biopython 原始碼的 Tests 目錄中。

from Bio.SeqUtils.Mapper import CoordinateMapper
from Bio import SeqIO


def get_first_CDS(parser):
    for rec in parser:
        for feat in rec.features:
            if feat.type == "CDS" and len(feat.location.parts) > 1:
                return feat


exons = get_first_CDS(SeqIO.parse("GenBank/cor6_6.gb", "genbank"))
cm = CoordinateMapper(exons)

建構對應器後,其方法可用於轉換位於給定 CDS 內的位置。請注意,嘗試轉錄和轉譯不在 CDS 內的基因組位置將會引發例外。另請注意,列印列表會顯示位置的 repr,它們是以 Python 的 0 為起始的座標。

sample_g_values = [50, 150, 250, 350, 450, 550, 650]

protein_positions = []
for raw_g_pos in sample_g_values:
    # EAFP method
    try:
        # Dialect argument converts g_pos from Genbank to Python coordinates
        p_pos = cm.g2p(raw_g_pos, dialect="genbank")
    except ValueError:
        p_pos = None
    protein_positions.append(p_pos)
print(protein_positions)

以下是一個範例函式,它會列印一個表格,其中包含給定座標對應器和基因組值列表的基因組、CDS 和蛋白質座標。

from Bio.SeqUtils.Mapper import GenomePosition


def gcp_table(mapper, g_list):
    """Print a table of genomic, CDS, and protein coordinates"""
    # Print header
    print("%4s | %6s | %2s" % ("g", "CDS", "p"))
    print("-" * 20)
    for g_pos in g_list:
        # Directly convert g_pos from Genbank to Python coordinates
        g_pos = GenomePosition.from_dialect("genbank", g_pos)
        c_pos = mapper.g2c(g_pos)
        # LBYL method:
        if c_pos.pos_type == "exon":
            p_pos = mapper.c2p(c_pos)
        else:
            p_pos = ""
        # Print formatted row
        print("%4s | %6s | %2s" % (g_pos, c_pos, p_pos))


gcp_table(cm, sample_g_values)

此範例中顯示的程式碼可在此處下載:https://gist.github.com/lennax/10600113 使用的範例檔案位於 Biopython 原始碼的 Tests 目錄中。