Bioconductor Package 'baseline'

library(baseline)
library(reshape2)
current_directory="XXX"   #適宜設定
setwd(current_directory)
files <- list.files(path=current_directory,pattern="jdx$")
#今回はjcapmファイルを使用
#jcampファイルはRETENTION_TIME,m/z,Intensityの3列と想定 mat <- NULL matcor <- NULL for (j in 1:length(files)) { dat <- read.table(files[[j]],header=TRUE) dat <- dat[,-5] #必要に応じて不要な行を削除 #Reshape2のacastでマトリックス化。引数marginsは小計を含むか否かを示す
mat[[j]] <- acast(melt(dat,id.var=c("m_z","RETENTION_TIME"), measure.var="Intensity"), m_z ~ RETENTION_TIME, sum, margins = FALSE)
print(paste("j =",j,"reshaping is done")) bc.irls <- baseline(mat[[j]][,,drop=FALSE],method="irls") matcor[[j]] <- bc.irls@corrected #baseline補正後のマトリックス print(paste("j =",j,"baseline correction is done")) write.table(matcor[[j]],file=paste(files[[j]],".txt",sep=""), row.names=TRUE,col.names=TRUE,sep="\t") #保存 print(paste("j =",j,"is done")) print(paste("size of matcor[[",j,"]] =", nrow(matcor[[j]]), ncol(matcor[[j]]))) }