27
Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng, Olga Vitek Maintainer Cheng Zheng <[email protected]>, Olga Vitek <[email protected]> Description This package is for database-supported metabolite identification and quantification from 1H NMR spectra Depends mgcv, tmvtnorm, mvtnorm, Matrix, matrixcalc, MCMCpack, RColorBrewer, splines Suggests mgcv, tmvtnorm, mvtnorm, Matrix, matrixcalc, MCMCpack, RColorBrewer, splines License GPL-2 ZipData yes LazyLoad yes OS_type windows R topics documented: BQuant-package ...................................... 2 alpha_cov_sample_gamma ................................. 8 alpha_sample ........................................ 9 beta_phi_marg ....................................... 10 beta_phi_marg_sample_p_new ............................... 10 conv_10 ........................................... 11 conv_2 ............................................ 12 denoise ........................................... 12 det_peak ........................................... 13 DP_nmr ........................................... 13 filter_peak_nmr ....................................... 14 gen_P ............................................ 15 impute.inten ......................................... 15 JJ_sample_1 ......................................... 16 J_sample_full_4 ....................................... 17 lm_p ............................................. 18 1

Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

Package ‘BQuant’November 11, 2010

Title Bayesian Quantification

Version 1.0

Date 2010-11-1

Author Cheng Zheng, Olga Vitek

Maintainer Cheng Zheng <[email protected]>, Olga Vitek <[email protected]>

Description This package is for database-supported metabolite identification and quantification from1H NMR spectra

Depends mgcv, tmvtnorm, mvtnorm, Matrix, matrixcalc, MCMCpack, RColorBrewer, splines

Suggests mgcv, tmvtnorm, mvtnorm, Matrix, matrixcalc, MCMCpack, RColorBrewer, splines

License GPL-2

ZipData yes

LazyLoad yes

OS_type windows

R topics documented:BQuant-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2alpha_cov_sample_gamma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8alpha_sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9beta_phi_marg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10beta_phi_marg_sample_p_new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10conv_10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11conv_2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12denoise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12det_peak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13DP_nmr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13filter_peak_nmr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14gen_P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15impute.inten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15JJ_sample_1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16J_sample_full_4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17lm_p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

1

Page 2: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

2 BQuant-package

model_freq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18mvrnorm_p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19my_dcauchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19nmr_peaks_DA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20peak_shift_est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21plot_spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22pred_dcauchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22rand_est_full . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23re_peak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24rnorm_p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24sigma_sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Index 26

BQuant-package Bayesian Quantification

Description

This package is for database-supported metabolite identification and quantification from 1H NMRspectra

Details

Package: BQuantType: PackageVersion: 1.0Date: 2010-11-07License: GPL-2LazyLoad: yes

Author(s)

Cheng Zheng & Olga VitekMaintainer: <[email protected]> & <[email protected]>.

References

Zheng, C., Zhang, D., Ragg, S., Raftery, D. and Vitek, O. (2010). Identification and Quantificationof Metabolites in 1H NMR Spectra by Bayesian Model Selection, submitted.

Examples

################################################################ Demo example for NMR spectra deconvolution###############################################################

################################################################ Read in spectra

Page 3: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

BQuant-package 3

###############################################################

data(Spectra)spec_med = apply(y_M, 1, median)ppm = as.numeric(rownames(y_M))ll = min(ppm); ul = max(ppm)width_adj = 350data(AI_binning)edge.bin = sort(c(1, length(ppm), bin[,1]))

################################################################ Peak detection in spectra###############################################################

nmr.peaks.aligned = nmr_peaks_DA(nmr.norm = y_M, nmr.error.limit=0,impute.it=FALSE, min.diff.mean=5, min.diff=4, detect_span=18,factor1=0.3, f1=10^6, gap=-0.0065^2)nmr.peaks.imputed = impute.inten(x=nmr.peaks.aligned$nmr.peaks.aligned,y_M, max_shift=0)

#pdf(height=9/1.5, width=16/1.5, file="NMR_Spectra.pdf")plot_spectra(spectra=y_M, peaks=rownames(nmr.peaks.aligned$nmr.peaks.aligned),peaks.1=ppm[edge.bin], ll=min(ppm), ul=max(ppm))#dev.off()

################################################################ Peak detection in reference spectra###############################################################

data(CDB)CID = as.vector(unique(CDB[,1]))

peaks_info = NULLfor (i in CID){cat("Running ", which(setdiff(CID,10)==i), "\n")temp_DB = CDB[CDB[,1]==i,]temp_z = pred_dcauchy(mean_2=temp_DB[,5], scale_2=temp_DB[,7]/width_adj,h_2=temp_DB[,6], a=0, x=ppm)peaks_z = filter_peak_nmr(temp = temp_z, pm = ppm, min.diff=5,low.limit=0, detect_span=18)peaks_z_h = temp_z[peaks_z]peaks_keep = (peaks_z_h>0.05*max(peaks_z_h))temp_peaks_info = matrix(0, ncol=3, nrow=sum(peaks_keep))temp_peaks_info[,1] = itemp_peaks_info[,2] = (ppm[peaks_z])[peaks_keep]temp_peaks_info[,3] = (peaks_z_h/max(peaks_z_h))[peaks_keep]peaks_info = rbind(peaks_info, temp_peaks_info)

}peaks_info = as.data.frame(peaks_info)

############################################################################ Select subset of CID acording to ll and ul###########################################################################

record_CID = NULLfor (i in unique(peaks_info[,1]))

Page 4: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

4 BQuant-package

{temp_peaks_info = peaks_info[peaks_info[,1]==i,]if (!is.vector(temp_peaks_info)){if (sum((as.vector(temp_peaks_info[,2])<=ul) &(as.vector(temp_peaks_info[,2])>=ll))>0)record_CID = c(record_CID, i)

} else{if (sum((as.vector(temp_peaks_info[2])<=ul) &(as.vector(temp_peaks_info[2])>=ll))>0)record_CID = c(record_CID, i)

}}

################################################################ Estimate peak shift###############################################################

#pdf(height=9, width=12, file="peak_shift.pdf")peak_se = peak_shift_est(record_CID=record_CID, spec_med=spec_med,target=as.numeric(rownames(nmr.peaks.imputed)), edge.bin=edge.bin,plot.it.2=TRUE, glo_shift=0.01, loc_shift=0.008, CDB=CDB,width_adj=width_adj, peaks_info=peaks_info)CDB_shift = peak_se$CDB_shift#dev.off()

################################################################ Convert raw database into reference spectra###############################################################

L = length(record_CID)x_M = matrix(0, ncol=L, nrow=length(ppm))colnames(x_M) = record_CIDrownames(x_M) = ppmfor (index_CID in 1:ncol(x_M)){

cat("Running ", index_CID, " Metabolite ", record_CID[index_CID], "\n")temp_DB = CDB_shift[CDB_shift[,1]==record_CID[index_CID],]temp_z = pred_dcauchy(mean_2=temp_DB$loc_shift, scale_2=temp_DB$width/350,h_2=temp_DB$height, a=0, x=ppm)x_M[,index_CID] = temp_z

}

################################################################ Data reduction###############################################################

index_peaks = which(ppm %in% rownames(nmr.peaks.imputed))index_peaks = sort(c(index_peaks, which(ppm %in% ppm[edge.bin])))index_peaks = sort(unique(c(index_peaks, 1, length(ppm))))

################################################################# Design matrix for random and fixed effects# with scaling################################################################

Page 5: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

BQuant-package 5

y_m = as.vector(y_M[index_peaks,])y_adj = 10 / quantile(y_m, 0.95)y_m = y_m * y_adjx_m = x_M[index_peaks,]n = ncol(y_M)m = length(index_peaks)N = n * mgroup = rep(1:n, each=m)temp_knots = which(ppm %in% ppm[edge.bin])temp_knots = temp_knots[-c(1,length(temp_knots))]temp_bs = bs(1:length(ppm), knots=c(0, temp_knots), degree=3)temp_bs_1 = temp_bs[index_peaks,]x_m_1 = NULLtemp_bs_2 = NULLfor (i in 1:n){x_m_1 = rbind(x_m_1, x_m)temp_bs_2 = rbind(temp_bs_2, temp_bs_1)

}rownames(x_m_1) = NULLn_bs = ncol(temp_bs_2)

for (i in 1:ncol(x_m_1)){

f = max(x_m_1[,i])x_m_1[,i] = x_m_1[,i] / f / 4x_M[,i] = x_M[,i] / f / 4

}d_X = x_m_1d_Z = x_m_1d_S = temp_bs_2d_y = y_md_y_full = y_M * y_adjd_X_S_full = cbind(x_M, temp_bs)d_XX = t(d_X[1:m,]) %*% d_X[1:m,]

########################################################################### Determine the smoothness of the baseline##########################################################################

P1 = gen_P(n_bs)med_d = apply(d_y_full, 1, median)magic_X = d_X_S_full[,c(1:L,(L+1):(n_bs+L))]med_magic = magic(y=med_d, X=magic_X, sp=1, S=list(P1), off=L, gcv=TRUE)med_magic_post_proc = magic.post.proc(X=magic_X, med_magic)magic_sigma = sum((med_d - magic_X %*% med_magic$b)^2) /(length(med_d)-sum(med_magic_post_proc$hat))lambda = med_magic$sp / magic_sigma; P = lambda * gen_P(n_bs);

########################################################################### Initial values set up##########################################################################

set.seed(1)beta_prior_mean = rep(0, L)beta_prior_tau_1 = 10^2; beta_prior_tau_2 = 1^2;beta_prior_tau = rep(beta_prior_tau_1, L);

Page 6: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

6 BQuant-package

names(beta_prior_tau) = colnames(d_X)true_delta = sqrt(log(beta_prior_tau_1/beta_prior_tau_2)/(1/beta_prior_tau_2-1/beta_prior_tau_1))alpha_prior_tau_1 = beta_prior_tau_1/10;alpha_prior_tau_2 = beta_prior_tau_2/10;alpha_prior_tau = diag(alpha_prior_tau_1, L)phi_prior_tau = rep(beta_prior_tau_1, n_bs);alpha_s = matrix(0, n, L)alpha_cov_s = matrix(0, L, L)sigma_prior_a = 0.001sigma_prior_b = 0.001p0 = rep(0.2, L)sigma_s = 1beta_s = rep(0, L)phi_s = rep(0, n_bs)beta_lower = 0total_pos = 5000J = rep(0, L); names(J) = colnames(d_X)J[sample(L,1)] = 1; JJ = Jrecord_J = matrix(0, total_pos, L); record_sigma = rep(0, total_pos);record_beta = matrix(0, total_pos, L);record_phi = matrix(0, total_pos, n_bs);record_alpha_cov = vector("list", total_pos);record_JJ = record_J; index_J = 1;record_alpha = array(0, dim=c(nrow(alpha_s), ncol(alpha_s), total_pos))index_random = sample(L)

########################################################################### Gibbs sampling##########################################################################

rand_sum = rand_est_full(alpha_s, d_Z, group, n, N, J)for (i in 1:total_pos){cat("Running Gibbs ", i, ": ")alpha_cov_s = alpha_cov_sample_gamma(d_X, d_S, d_Z, d_y, J, JJ, beta_s,alpha_cov_s, alpha_s, phi_s, sigma_s, n, L, beta_prior_tau, alpha_prior_tau)beta_phi_s = beta_phi_marg_sample_p_new(d_X, d_S, d_y, group, L, n_bs, n, J,beta_prior_tau, phi_prior_tau, sigma_s, alpha_cov_s, delta=beta_lower,P, d_XX)beta_s = beta_phi_s$est[1:L]; phi_s = beta_phi_s$est[(L+1):(L+n_bs)]alpha_s = alpha_sample(J, alpha_cov_s, beta_s, alpha_s, phi_s, sigma_s, n, L,d_y, d_X, d_S, d_Z, group)rand_sum = rand_est_full(alpha_s, d_Z, group, n, N, J)cat("sigma_s = ", sigma_s, "\n")J = J_sample_full_4(L, rand_sum, d_y, d_X, d_S, d_Z, group, n, n_bs, N,beta_prior_tau, alpha_cov_s, sigma_s, beta_s, phi_s, p0, J, delta=beta_lower,set_J=index_random[(i%%L+1)], P, d_XX, beta_phi_s)sigma_s = sigma_sample(J, N, n, L, rand_sum, d_y, d_X, d_S, beta_s, alpha_s,phi_s, alpha_cov_s)JJ_1 = JJJ_1[J==1] = JJ_sample_1(J, N, n, L, beta_prior_tau_1, beta_prior_tau_2,rand_sum, d_y, d_X, d_S, beta_s, alpha_s, phi_s, alpha_cov_s,delta=beta_lower, JJ)JJ = JJ_1beta_prior_tau = rep(beta_prior_tau_1, L);beta_prior_tau[J==1 & JJ==0] = beta_prior_tau_2

Page 7: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

BQuant-package 7

diag(alpha_prior_tau)[JJ==1] = alpha_prior_tau_1;diag(alpha_prior_tau)[JJ==0 & J==1] = alpha_prior_tau_2record_J[index_J,] = J; record_JJ[index_J,] = JJ;record_sigma[index_J] = sigma_s;record_beta[index_J,] = beta_s; record_phi[index_J,] = phi_s;record_alpha_cov[[index_J]] = alpha_cov_s; record_alpha[,,index_J] = alpha_sindex_J = index_J+1

}

########################################################################### Summary of the gibbs sampling results##########################################################################

index_range = c(2001:total_pos)record_beta_m = apply(record_beta[index_range,], 2, mean)record_phi_m = apply(record_phi[index_range,], 2, mean)record_alpha_m = apply(record_alpha[,,index_range], c(1,2), mean)JJ_m = model_freq(record_JJ[index_range,])[1,1]JJ_m = as.numeric(strsplit(as.vector(JJ_m),"")[[1]])JJ_m = c(rep(0,length(record_beta_m)-length(JJ_m)), JJ_m)J_m = model_freq(record_J[index_range,])[1,1]J_m = as.numeric(strsplit(as.vector(J_m),"")[[1]])J_m = c(rep(0,length(record_beta_m)-length(J_m)), J_m)

set.seed(1); mypalette = sample(rainbow(L))sub_index = 1:length(ppm)#pdf(height=9, width=16, file="Decon.NMR.pdf")for (i in 1:n){

sub_index_1 = sub_index[length(sub_index):1]temp_y = y_M[,i] * y_adjmu_est = record_beta_m + record_alpha_m[i,]pred_y = x_M %*% mu_est + temp_bs %*% record_phi_mtemp_re = temp_y - pred_ysub_index_plot = seq(1, length(sub_index_1), length.out=5)plot(ppm[sub_index_1], temp_y, type="l", ylim=c(-max(y_M*y_adj)*0.1,max(y_M*y_adj)), xlab="ppm", ylab="Intensity", xaxt = "n",main=paste("Deconvolution for sample ", i, sep=""))axis(1, at = round(ppm[sub_index_1][sub_index_plot],3),labels = round(ppm[sub_index_1][sub_index_plot[length(sub_index_plot):1]],3),cex.axis=0.8, las=1)lines(ppm[sub_index_1], temp_re, col="red", lwd=1, lty=2)lines(ppm[sub_index_1], pred_y, col="black", lwd=2, lty=2)lines(ppm[sub_index_1], temp_bs %*% record_phi_m, col="dark red", lwd=2)for (j in 1:L)lines(ppm[sub_index_1], x_M[,j] * mu_est[j],col=mypalette[(j %% L)+1], lwd=4)abline(v=ppm[sub_index_1][index_peaks], col="grey")

}#dev.off()

meta_abun = matrix(0, n, L)rownames(meta_abun) = 1:n; colnames(meta_abun) = colnames(d_X)for (i in 1:n)meta_abun[i,] = record_beta_m + record_alpha_m[i,]meta_abun_sig = meta_abun[,J_m==1]

Page 8: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

8 alpha_cov_sample_gamma

model_pos = t(apply(record_beta[index_range,J_m==1], 2,function(x) c(mean(x), quantile(x,0.025), quantile(x,0.975))))model_pos = cbind(model_pos, apply(record_J[index_range,J_m==1], 2, mean))colnames(model_pos) = c("Mean", "2.5%", "97.5%", "Freq_Gamma");rownames(model_pos) = colnames(d_X)[J_m==1]

alpha_cov_sample_gammaFunction to sample covariance matrix of random effect

Description

To sample covariance matrix of random effect

Usage

alpha_cov_sample_gamma(d_X, d_S, d_Z, d_y, J, JJ, beta_s, alpha_cov_s,alpha_s, phi_s, sigma_s, n, L, beta_prior_tau, alpha_prior_tau)

Arguments

d_X full design matrix for reference spectral data (fixed effects)d_S full design matrix for B-spline base functions representing baselined_Z full design matrix for reference spectral data (random effects)d_y reduced observed spectral data (only at peak locations and bin edges)J draw of the vector of indicator variables corresponding to the statistcal signifi-

cance of metabolitesJJ draw of the vector of indicator variables corresponding to the practical signifi-

cance of metabolitesbeta_s draw of beta (fixed effects representing average abundance)alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-

litesalpha_s draw of alpha (random effects representing subject-specific abundance)phi_s draw of phi (representing the coefficients of B-spline basis functions for base-

line)sigma_s draw of sigma^2n number of samplesL number of candidate metabolitesbeta_prior_tau

diagonal components of the prior variance-covariance matrix of betaalpha_prior_tau

prior information on alpha_cov_s

Value

alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-lites

Examples

Part of the Gibbs sampling

Page 9: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

alpha_sample 9

alpha_sample Function to sample random effects

Description

To sample random effects

Usage

alpha_sample(J, alpha_cov_s, beta_s, alpha_s, phi_s, sigma_s, n, L, d_y,d_X, d_S, d_Z, group)

Arguments

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-lites

beta_s draw of beta (fixed effects representing average abundance)

alpha_s draw of alpha (random effects representing subject-specific abundance)

phi_s draw of phi (representing the coefficients of B-spline basis functions for base-line)

sigma_s draw of sigma^2

n number of samples

L number of candidate metabolites

d_y reduced observed spectral data (only at peak locations and bin edges)

d_X full design matrix for reference spectral data (fixed effects)

d_S full design matrix for B-spline base functions representing baseline

d_Z full design matrix for reference spectral data (random effects)

group sample label information for reduced observed spectral data

Value

alpha_s draw of alpha (random effects representing subject-specific abundance)

Examples

Part of the Gibbs sampling

Page 10: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

10 beta_phi_marg_sample_p_new

beta_phi_marg Function to calculate the marginal posterior of beta and phi (internaluse only)

Description

To calculate the marginal posterior of beta and phi (internal use only)

Usage

beta_phi_marg(d_X, d_S, d_y, group, L, n_bs, n, J, beta_prior_tau,phi_prior_tau, sigma_s, alpha_cov_s, delta, C, P, d_XX)

Arguments

internal use only

Value

internal use only

Examples

Internal use only

beta_phi_marg_sample_p_newFunction to sample beta and phi from their marginal posterior

Description

To sample beta and phi from their marginal posterior

Usage

beta_phi_marg_sample_p_new(d_X, d_S, d_y, group, L, n_bs, n, J,beta_prior_tau, phi_prior_tau, sigma_s, alpha_cov_s, delta, P, d_XX)

Arguments

d_X full design matrix for reference spectral data (fixed effects)

d_S full design matrix for B-spline base functions representing baseline

d_y reduced observed spectral data (only at peak locations and bin edges)

group sample label information for reduced observed spectral data

L number of candidate metabolites

n_bs number of base functions for baseline

n number of samples

Page 11: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

conv_10 11

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

beta_prior_taudiagonal components of the prior variance-covariance matrix of beta

phi_prior_tauprior variance of phi

sigma_s draw of sigma^2

alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-lites

delta lower bound for beta_s

P penalty matrix for controlling the smoothness of B-spline

d_XX d_X’ %*% d_X

Value

est beta_s & phi_s

para related parameters for internal use only

Examples

Part of the Gibbs sampling

conv_10 Function to convert a number in base-10 into base-2

Description

To convert a number in base-10 into base-2

Usage

conv_10(temp_sum)

Arguments

internal use only

Value

internal use only

Examples

internal use only

Page 12: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

12 denoise

conv_2 Function to convert a number in base-2 into base-10

Description

To convert a number in base-2 into base-10

Usage

conv_2(temp_J)

Arguments

internal use only

Value

internal use only

Examples

internal use only

denoise Function to remove peaks with intensity smaller than a threshold

Description

To remove peaks with intensity smaller than a threshold

Usage

denoise(peaks.sample.list, nmr.error.limit, nmr.norm)

Argumentspeaks.sample.list

peak listnmr.error.limit

lower bound for peak

nmr.norm original spectra data

Valuepeaks.sample.list

peak list after denoise

Examples

internal use only

Page 13: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

det_peak 13

det_peak Function to detect individual peaks

Description

To detect individual peaks

Usage

det_peak(a, temp1, res, min.diff, low.limit = 0)

Arguments

internal use only

Value

internal use only

Examples

internal use only

DP_nmr Function to perform peak alignement by dynamic programming

Description

To perform peak alignement by dynamic programming

Usage

DP_nmr(seq_1, seq_2, f1 = 10^6, f2 = 0, plot.it = TRUE,print.it = TRUE, gap = -0.0065^2)

Arguments

seq_1 first sequence of peak locations

seq_2 second sequence of peak locations

f1 parameter used by dynamic programming

f2 parameter used by dynamic programming

plot.it whether plot result

print.it whether print result

gap parameter used by dynamic programming

Page 14: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

14 filter_peak_nmr

Value

Score_M, Track_M, Sim_M, Sim_M_fixed, Sim_M_shift, Diff_M, ppm_Minternal use only

index_1 aligned index for the first sequence

index_2 aligned index for the second sequence

Examples

internal use only

filter_peak_nmr Function to detect peaks in spectrum by Loess smoothing

Description

To detect peaks in spectrum by Loess smoothing

Usage

filter_peak_nmr(temp, pm, detect_span = 10, check.diff = 1,min.diff = 2, low.limit = 0)

Arguments

temp spectral internsity

pm ppm

detect_span parameter by Loess smoothing

check.diff parameter for checking local maximum

min.diff parameter for checking under-smoothing

low.limit lower limit for peak height

Value

peaks peak list

Examples

internal use only

Page 15: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

gen_P 15

gen_P Function to generate a penalty matrix for penalized B-spline

Description

To generate a penalty matrix for penalized B-spline

Usage

gen_P(n_bs)

Arguments

n_bs

Value

P1 penalty matrix for penalized B-spline

Examples

gen_P(n_bs=3)

impute.inten Function to perform imputation by spectral intensity at the peak loca-tions

Description

To perform imputation by spectral intensity at the peak locations

Usage

impute.inten(x, nmr.norm, nmr.error.limit = NULL, max_shift = 15)

Arguments

x peak list

nmr.norm spectral datanmr.error.limit

lower limit for peak height

max_shift searching range for local maximum

Value

z imputed peak list

Examples

see the demo example

Page 16: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

16 JJ_sample_1

JJ_sample_1 Function to sample JJ for practical significant metabolites

Description

To sample JJ for practical significant metabolites

Usage

JJ_sample_1(J, N, n, L, beta_prior_tau_1, beta_prior_tau_2, rand_sum,d_y, d_X, d_S, beta_s, alpha_s, phi_s, alpha_cov_s, delta, JJ)

Arguments

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

N total number of data points

n number of samples

L number of candidate metabolitesbeta_prior_tau_1

parameter to construct beta_prior_taubeta_prior_tau_2

parameter to construct beta_prior_tau

rand_sum overall random effect

d_y reduced observed spectral data (only at peak locations and bin edges)

d_X full design matrix for reference spectral data (fixed effects)

d_S full design matrix for B-spline base functions representing baseline

beta_s draw of beta (fixed effects representing average abundance)

alpha_s draw of alpha (random effects representing subject-specific abundance)

phi_s draw of phi (representing the coefficients of B-spline basis functions for base-line)

alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-lites

delta lower bound for beta_s

JJ draw of the vector of indicator variables corresponding to the practical signifi-cance of metabolites

Value

JJ draw of the vector of indicator variables corresponding to the practical signifi-cance of metabolites

Examples

Part of the Gibbs sampling

Page 17: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

J_sample_full_4 17

J_sample_full_4 Function to sample J for statistcal significance of metabolites

Description

To sample J for statistcal significance of metabolites

Usage

J_sample_full_4(L, rand_sum, d_y, d_X, d_S, d_Z, group, n, n_bs, N,beta_prior_tau, alpha_cov_s, sigma_s, beta_s, phi_s, p0, J, delta,set_J, P, d_XX, beta_phi_s)

Arguments

L number of candidate metabolites

rand_sum overall random effect

d_y reduced observed spectral data (only at peak locations and bin edges)

d_X full design matrix for reference spectral data (fixed effects)

d_S full design matrix for B-spline base functions representing baseline

d_Z full design matrix for reference spectral data (random effects)

group sample label information for reduced observed spectral data

n number of samples

n_bs number of base functions for baseline

N total number of data pointsbeta_prior_tau

diagonal components of the prior variance-covariance matrix of beta

alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-lites

sigma_s draw of sigma^2

beta_s draw of beta (fixed effects representing average abundance)

phi_s draw of phi (representing the coefficients of B-spline basis functions for base-line)

p0 prior proportion of statistical significant metabolites

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

delta lower bound for beta_s

set_J order for updating J

P penalty matrix for controlling the smoothness of B-spline

d_XX d_X’ %*% d_X

beta_phi_s beta_s & phi_s

Value

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

Page 18: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

18 model_freq

Examples

part of the Gibbs sampling

lm_p Function to fit a linear regression with positivity constraints and nointercept

Description

To fit a linear regression with positivity constraints and no intercept

Usage

lm_p(y_1, x_1)

Arguments

y_1 response variable

x_1 design matrix

Value

b regression coefficient

Examples

internal use only

model_freq Function to calculate model frequency from the draws of J

Description

To calculate model frequency from the draws of J

Usage

model_freq(record_J)

Arguments

record_J draws of J

Value

freq model frequency

Examples

internal use only

Page 19: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

mvrnorm_p 19

mvrnorm_p Function to approximately sample from a truncated MVN distribution

Description

To approximately sample from a truncated MVN distribution

Usage

mvrnorm_p(mean_full, cov_full, delta)

Arguments

internal use only

Value

internal use only

Examples

internal use only

my_dcauchy Function for cauchy density with a scalar

Description

Cauchy density with a scalar

Usage

my_dcauchy(x, location, scale)

Arguments

x values at which Cauchy density aer evaluated

location location parameter for Cauchy density

scale scale parameter for Cauchy density

Value

h Cauchy density at x

Examples

my_dcauchy(0, 0, 1)

Page 20: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

20 nmr_peaks_DA

nmr_peaks_DA Function to perform peak detection and peak alignment by dynamicprogramming (DP)

Description

To perform peak detection and peak alignment by dynamic programming (DP)

Usage

nmr_peaks_DA(nmr.norm, nmr.error.limit = 0, impute.it = TRUE,min.diff.mean = 3, min.diff = 2, detect_span = 10, factor1 = 0.1,f1 = 10^6, gap)

Arguments

nmr.norm Spectra datanmr.error.limit

lower limit for peak heightimpute.it whether to impute the missing peak heightmin.diff.mean

parameter for peak detectionmin.diff parameter for peak detectiondetect_span parameter for peak detectionfactor1 parameter for DPf1 parameter for DPgap parameter for DP

Valuenmr.peaks.aligned

peak height datanmr.ppm.aligned

peak list across spectra in a matrixpeaks.sample.list

peak list across spectra in a listppm.peaks.mean

peak list for the mean spectrumnmr.mean mean spectrumint.peaks.sample

peak height across spectra before peak alignmentppm.peaks.sample

peak list across spectra before peak alignmentnmr.peaks.aligned.raw

peak height data before removing inconsistent peaks

Examples

see the demo example

Page 21: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

peak_shift_est 21

peak_shift_est Function to estimate the difference between the observed spectra andNMR spectral database

Description

To estimate the difference between the observed spectra and NMR spectral database

Usage

peak_shift_est(record_CID, spec_med, edge.bin,target = as.numeric(rownames(nmr.peaks.imputed)),plot.it.1 = FALSE, plot.it.2 = FALSE, glo_shift = 0.01,loc_shift = 0.008, CDB = CDB,width_adj = width_adj, target_range = TRUE, peaks_info)

Arguments

record_CID candidate metabolite list

spec_med mean spectrum

edge.bin bin edges

target peak list for the spectral data

plot.it.1 whether to plot peak matching results after global shift

plot.it.2 whether to plot peak matching results after local shift

glo_shift parameter for controlling the global shift

loc_shift parameter for controlling the local shift

CDB NMR spectral database

width_adj constant for adjusting linewidth of peaks

target_range internal use only

peaks_info peak list for the NMR spectral database

Value

target peak list for the spectral data

record_CID candidate metabolite list

R2 score for metabolite ranking

CDB_shift NMR spectral database with shift estimaterecord_bestscore

best score for metabolite ranking

Examples

see the demo example

Page 22: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

22 pred_dcauchy

plot_spectra Function to plot part of multiple spectra

Description

To plot part of multiple spectra

Usage

plot_spectra(spectra, peaks, peaks.1, mycol = NULL, ll, ul,main_1 = "NMR Spectra")

Arguments

spectra spectral data

peaks peak list1

peaks.1 peak list2

mycol color for spectral plot

ll lower limit for ppm

ul upper limit for ppm

main_1 optional title for the plot

Examples

see the demo example

pred_dcauchy Function for the sum of multiple Cauchy density functions

Description

Sum of multiple Cauchy density functions

Usage

pred_dcauchy(mean_2, scale_2, h_2, a, x)

Arguments

mean_2 list of location parameters for the Cauchy density functions

scale_2 list of scale parameters for the Cauchy density functions

h_2 list of the scalars for the Cauchy density functions

a a additive constant baseline

x values at which Cauchy density are evaluated

Page 23: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

rand_est_full 23

Value

h Cauchy density at x

Examples

internal use only

rand_est_full Function to calculate the overall random effect

Description

To calculate the overall random effect

Usage

rand_est_full(alpha_s, d_Z, group, n, N, J)

Arguments

alpha_s draw of alpha (random effects representing subject-specific abundance)

d_Z full design matrix for reference spectral data (random effects)

group sample label information for reduced observed spectral data

n number of samples

N total number of data points

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

Value

sum overall random effect

Examples

Part of the Gibbs sampling

Page 24: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

24 rnorm_p

re_peak Function to remove peaks that are too closed to each other

Description

To remove peaks that are too closed to each other

Usage

re_peak(dart.mean, peaks.mean, limit)

Arguments

internal use only

Value

internal use only

Examples

internal use only

rnorm_p Function to sample from a truncated normal distribution

Description

To sample from a truncated normal distribution

Usage

rnorm_p(mu, Sigma, delta)

Arguments

mu mu

Sigma sigma

delta lower limit

Value

x sampled value

Examples

rnorm_p(0, 1, 0)

Page 25: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

sigma_sample 25

sigma_sample Function to sample sigma^2

Description

To sample sigma^2

Usage

sigma_sample(J, N, n, L, rand_sum, d_y, d_X, d_S, beta_s, alpha_s,phi_s, alpha_cov_s)

Arguments

J draw of the vector of indicator variables corresponding to the statistcal signifi-cance of metabolites

N total number of data points

n number of samples

L number of candidate metabolites

rand_sum overall random effect

d_y reduced observed spectral data (only at peak locations and bin edges)

d_X full design matrix for reference spectral data (fixed effects)

d_S full design matrix for B-spline base functions representing baseline

beta_s draw of beta (fixed effects representing average abundance)

alpha_s draw of alpha (random effects representing subject-specific abundance)

phi_s draw of phi (representing the coefficients of B-spline basis functions for base-line)

alpha_cov_s draw of variance-covariance matrix of alpha for practically significant metabo-lites

Value

sigma_s draw of sigma^2

Examples

Part of the Gibbs sampling

Page 26: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

Index

∗Topic \textasciitildekwd1alpha_cov_sample_gamma, 7alpha_sample, 8beta_phi_marg, 9beta_phi_marg_sample_p_new,

10conv_10, 11conv_2, 11denoise, 12det_peak, 12DP_nmr, 13filter_peak_nmr, 13gen_P, 14impute.inten, 15J_sample_full_4, 16JJ_sample_1, 15lm_p, 17model_freq, 18mvrnorm_p, 18my_dcauchy, 19nmr_peaks_DA, 19peak_shift_est, 20plot_spectra, 21pred_dcauchy, 22rand_est_full, 22re_peak, 23rnorm_p, 23sigma_sample, 24

∗Topic \textasciitildekwd2alpha_cov_sample_gamma, 7alpha_sample, 8beta_phi_marg, 9beta_phi_marg_sample_p_new,

10conv_10, 11conv_2, 11denoise, 12det_peak, 12DP_nmr, 13filter_peak_nmr, 13gen_P, 14impute.inten, 15J_sample_full_4, 16

JJ_sample_1, 15lm_p, 17model_freq, 18mvrnorm_p, 18my_dcauchy, 19nmr_peaks_DA, 19peak_shift_est, 20plot_spectra, 21pred_dcauchy, 22rand_est_full, 22re_peak, 23rnorm_p, 23sigma_sample, 24

∗Topic packageBQuant-package, 1

alpha_cov_sample_gamma, 7alpha_sample, 8

beta_phi_marg, 9beta_phi_marg_sample_p_new, 10BQuant (BQuant-package), 1BQuant-package, 1

conv_10, 11conv_2, 11

denoise, 12det_peak, 12DP_nmr, 13

filter_peak_nmr, 13

gen_P, 14

impute.inten, 15

J_sample_full_4, 16JJ_sample_1, 15

lm_p, 17

model_freq, 18mvrnorm_p, 18my_dcauchy, 19

26

Page 27: Package ‘BQuant’ovitek/BQuant-Web/BQuant/BQuant_1.0_Man… · Package ‘BQuant’ November 11, 2010 Title Bayesian Quantification Version 1.0 Date 2010-11-1 Author Cheng Zheng,

INDEX 27

nmr_peaks_DA, 19

peak_shift_est, 20plot_spectra, 21pred_dcauchy, 22

rand_est_full, 22re_peak, 23rnorm_p, 23

sigma_sample, 24