BATMAN 是一個用來分析核磁共振(NMR)頻譜的 R 套件,這裡介紹其使用方式。

名稱:BATMAN
網址:http://batman.r-forge.r-project.org/

模型

BATMAN 使用貝氏統計模型來分析,將頻譜拆成已經編目的頻譜 \(\mathbf{y}^c\) 與未知的頻譜 \(\mathbf{y}^u\):
\[\mathbf{y}=\mathbf{y}^c+\mathbf{y}^u+\epsilon, \epsilon \sim N(0,\mathbf{I}/\lambda)\]
關於此模型的詳細說明請參考 BATMAN 網站上相關的論文。

安裝

安裝 doSNOWplotrix 兩個 R 套件:

install.packages("doSNOW")
install.packages("plotrix")

從 BATMAN 官方網站下載原始碼,安裝最新版的 BATMAN:

install.packages("batman", repos="http://R-Forge.R-project.org")

測試

R-Forge 網站上下載 BATMAN 的測試資料 Test4.zip

載入 batman 套件:

library(batman)

單一頻譜

執行測試。

bm <- batman()
Running batman...
Number of burn-in iterations:  200 
Number of post-burn-in iterations:  100 

The template file used is
 2: The user input template of multiplets in multi_data_user.csv file.
 
Loading multi_data_user.csv...
Percentage completed...
  |                                                                            |   0%
Size of each spectrum is 682.
Size of metabolite list is 6.
of which 6 have resonances in/near the specified region and will be fit.
Constructing chain data structure...
time used is 0 seconds.
Running MCMC...
  |===================================================                         |  67%
time used for burnin is 12 seconds.
  |============================================================================| 100%
time used is 18 seconds.
saving posteriors...
 
time elapsed 
 18.052 
 second.
Reading in saved data in folder
/home/gtwang/runBATMAN/BatmanOutput/17_ 8月_09_50_39
This operating system may not support X11, no plot will be displayed, figures in .pdf format will be saved in output folder.
Check input argument 'showPlot' for more detail.
Completed.

輸出的結果為:

batman-output-1

圖中藍色的是原始的頻譜(Original Spectrum),綠色的是分析出來的 Metabolites Fit,紅色的是未知的 Wavelet Fit,黑色的是整個模型配適的結果,也就是綠色加上紅色。

多頻譜

BATMAN 可以使用平行化的方式計算,使用多顆 CPU 加速計算。

修改 runBATMAN/BatmanInput/batmanOptions.txt 設定檔,修改以下參數:

specNo - Ranges of spectra number to be included (e.g. 1,3-4 etc.):  1-4
paraProc - No of parallel processes (multicores) (only 1 core will be used for single spectrum): 4
nItBurnin - Number of burn-in iterations: 7000
nItPostBurnin - Number of post-burn-in iterations: 1000

重新執行 R 指令:

bm <- batman()
Running batman...
Number of burn-in iterations:  7000 
Number of post-burn-in iterations:  1000 

The template file used is
 2: The user input template of multiplets in multi_data_user.csv file.
 
Loading multi_data_user.csv...

Number of parallel processes (multicores) used to run the multi-spectra analysis:  4 

 Parallel processing of multi spectra currently cannot display the progress
 bar (or any words), please be patient for the results :)

time elapsed 
881.004 
 second.
Reading in saved data in folder
/home/gtwang/runBATMAN/BatmanOutput/17_ 8月_10_16_41
This operating system may not support X11, no plot will be displayed, figures in .pdf format will be saved in output folder.
Check input argument 'showPlot' for more detail.
Completed.

輸出的結果為:

batman-output-2

batman-output-3

執行 batman 時會自動將圖形輸出至 PDF 檔,亦可使用 plotBatmanFitStack 自行繪製圖形:

plotBatmanFitStack(bm, offset = 0.8, placeLegend = 'topleft', yto = 5)

簡報檔:BATMAN.pdf

參考資料:NMR基礎原理介紹INMR 基礎原理介紹II科學 Online