此模組提供與 PAML (最大概似法親緣關係分析) 程式套件的介面。目前,已包含與程式 codeml、baseml 和 yn00 的介面,以及 chi2 的 Python 重新實作。
此模組可於 Biopython 1.58 及更新版本中使用。
若要使用此模組,您的系統上必須安裝 PAML 4.1 或更新版本。
codeml 介面在以下模組中提供
from Bio.Phylo.PAML import codeml
該介面實作為一個物件,用於維護程式選項。為了執行 codeml,通常會提供一個控制檔案,指出比對檔案、樹狀圖檔案和輸出檔案的位置,以及一系列決定軟體如何執行的選項。在 Codeml
物件中,這三個檔案位置會儲存為字串屬性。這三個檔案位置以及所需工作目錄的位置,可以在 Codeml
建構函式中指定如下
cml = codeml.Codeml(
alignment="align.phylip",
tree="species.tree",
out_file="results.out",
working_dir="./scratch",
)
它們也可以單獨設定
cml = codeml.Codeml()
cml.alignment = "align.phylip"
cml.tree = "species.tree"
cml.out_file = "results.out"
cml.working_dir = "./scratch"
請注意,所有檔案位置都會轉換為相對於工作目錄的位置。PAML 程式對檔案位置字串的長度有限制;轉換為相對位置將縮短這些字串,讓您通常可以避開此限制。
codeml 執行時選項儲存在一個字典物件中,該物件以選項名稱為鍵。如需這些選項用法的更多資訊,請參閱 PAML 使用者手冊。
可以印出完整的選項集及其目前的值
>>> cml.print_options()
verbose = None
CodonFreq = None
cleandata = None
fix_blength = None
NSsites = None
fix_omega = None
clock = None
ncatG = None
runmode = None
fix_kappa = None
fix_alpha = None
Small_Diff = None
method = None
Malpha = None
aaDist = None
RateAncestor = None
aaRatefile = None
icode = None
alpha = None
seqtype = None
omega = None
getSE = None
noisy = None
Mgene = None
kappa = None
model = None
ndata = None
將選項設定為 None
值會導致 codeml 忽略它(它將從最終控制檔案中省略)。可以使用 set_option()
函式設定選項,並且可以使用 get_option()
函式擷取其值
>>> cml.set_options(clock=1)
>>> cml.set_options(NSsites=[0, 1, 2])
>>> cml.set_options(aaRatefile="wag.dat")
>>> cml.get_option("NSsites")
[0, 1, 2]
NSsites
選項值得特別注意:在 codeml 控制檔案中,NSsites 模型會輸入為以空格分隔的數字清單,例如 0 1 2,而在 Codeml
物件中,它會儲存為 Python 清單。
最後,可以從現有的 codeml 控制檔案讀取選項,也可以將選項寫入新檔案。寫入檔案並非必要,因為這會在執行 run()
方法時自動完成(請參閱下文)。要讀取的控制檔案會作為 read_ctl_file()
方法的引數提供,而 write_ctl_file()
方法會寫入 Codeml
物件的 ctl_file
屬性
>>> cml.read_ctl_file("codeml.ctl")
>>> cml.print_options()
verbose = 1
CodonFreq = 2
cleandata = 1
fix_blength = None
NSsites = 0
fix_omega = 0
clock = 0
ncatG = 8
runmode = 0
fix_kappa = 0
fix_alpha = 1
Small_Diff = 5e-07
method = 0
Malpha = 0
aaDist = 0
RateAncestor = 1
aaRatefile = dat/jones.dat
icode = 0
alpha = 0.0
seqtype = 2
omega = 0.4
getSE = 0
noisy = 9
Mgene = 0
kappa = 2
model = 2
ndata = None
>>> cml.ctl_file = "control2.ctl"
>>> cml.write_ctl_file()
執行物件的 run()
方法將會使用目前的選項執行 codeml,並在字典物件中傳回已剖析的結果(請參閱下文)。您也可以將一些選用引數傳遞給 run()
方法
verbose
(布林值):預設會抑制 codeml 的螢幕輸出;將此引數設定為 True
即可查看產生時的所有輸出。如果 codeml 失敗,而且您需要查看其錯誤訊息,這會很有用。parse
(布林值):設定為 False
可略過剖析結果。 run()
將會改為傳回 None
ctl_file
(字串):提供要執行的現有控制檔案路徑。該檔案不會被剖析並讀取到 Codeml
的選項字典中。如果設定為 None
(預設值),則選項字典會寫入控制檔案,然後由 codeml 使用。command
(字串):提供 codeml 可執行檔的路徑。預設會設定為 “codeml”,因此如果程式在您的系統路徑中,應該就足夠了。如果它不在您的系統路徑中,或者,例如,如果您使用多個版本的 PAML,則可以改為提供可執行檔的完整路徑。如果 codeml 程序以錯誤結束,則會引發 PamlError
例外狀況。
如先前所述,Codeml.run()
方法會傳回一個字典,其中包含從 codeml 的主要輸出檔案剖析的結果。或者,可以使用 read()
函式剖析現有的輸出檔案
results = codeml.read()
結果字典是以階層方式組織的,並且(在大多數情況下)會根據輸出檔案中使用的術語設定索引鍵。數值會自動轉換為數值的 Python 類型。由於 codeml 的輸出會隨著所使用的參數而有很大差異,因此結果字典的內容也會相應地變化。同樣地,在發生執行時錯誤時,結果字典可能會是空的或缺少內容。因此,建議使用 Python 的 dict.get(key)
方法,而不是 dict[key]
,以便妥善處理遺失的元素。
結果字典的所有可能索引鍵組織如下
與 baseml 和 yn00 的介面在以下模組中提供
from Bio.Phylo.PAML import baseml, yn00
bml = baseml.Baseml()
yn = yn00.Yn00()
Baseml
和 Yn00
與 Codeml
共享相同的方法和屬性,因此以相同的方式使用。但是,應該注意的是,Yn00
沒有樹狀圖屬性,因為 yn00 不需要樹狀圖檔案。
Baseml 選項中可用的參數為
>>> bml.print_options()
verbose = None
cleandata = None
fix_blength = None
nparK = None
model_options = None
clock = None
ncatG = None
runmode = None
fix_kappa = None
fix_alpha = None
noisy = None
method = None
fix_rho = None
Malpha = None
nhomo = None
RateAncestor = None
icode = None
rho = None
alpha = None
getSE = None
Small_Diff = None
Mgene = None
kappa = None
model = None
ndata = None
以下是 Baseml
結果檔中所有可能的內容:
Yn00
選項中可用的參數如下:
>>> yn.print_options()
commonf3x4 = None
weighting = None
icode = None
ndata = None
verbose = None
以下是 Yn00
結果檔中所有可能的內容:
chi2
模組提供了一種簡單的方法,可以從卡方累積分布函數中檢索 *p* 值,這些值通常在使用 PAML 程式時執行概似比檢定。截至目前版本的 PAML,*chi2* 程式不允許將檢定統計量和自由度作為命令列引數傳遞。因此,chi2
模組目前包含以純 Python 重新實作 Ziheng Yang 的原始程式碼。在大多數情況下,這不應該影響您,但是當使用非常大的自由度時,例如在 *codeml* 中的 FMutSel vs FMutSel0 模型檢定(41 個自由度),此 Python 版本執行速度明顯慢於原始版本。
要檢索 *p* 值,只需匯入模組
from Bio.Phylo.PAML.chi2 import cdf_chi2
並使用 cdf_chi2()
函數
>>> df = 2
>>> statistic = 7.21
>>> cdf_chi2(df, statistic)
0.027187444813595696