Mercurial > repos > yguitton > metams_rungc
diff lib_metams.r @ 5:b8d4129dd2a6 draft
planemo upload for repository https://github.com/workflow4metabolomics/metaMS commit c7a518686137f6d62b7415715152e8d5a9953ed7
author | yguitton |
---|---|
date | Fri, 06 Sep 2019 06:09:10 -0400 |
parents | c10824185547 |
children | d1ce2634135f |
line wrap: on
line diff
--- a/lib_metams.r Wed Jul 03 05:14:32 2019 -0400 +++ b/lib_metams.r Fri Sep 06 06:09:10 2019 -0400 @@ -162,13 +162,13 @@ ##ADDITIONS FROM Y. Guitton getBPC <- function(file,rtcor=NULL, ...) { object <- xcmsRaw(file) - sel <- profRange(object, ...) - cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) + sel <- profRange(object, ...) + cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) } getBPC2s <- function (files, xset = NULL, pdfname="BPCs.pdf", rt = c("raw","corrected"), scanrange=NULL) { require(xcms) - + #create sampleMetadata, get sampleMetadata and class if(!is.null(xset)) { #When files come from XCMS3 directly before metaMS @@ -184,10 +184,10 @@ } N <- dim(sampleMetadata)[1] - TIC <- vector("list",N) + BPC <- vector("list",N) for (j in 1:N) { - TIC[[j]] <- getBPC(files[j]) + BPC[[j]] <- getBPC(files[j]) #good for raw # seems strange for corrected #errors if scanrange used in xcmsSetgeneration @@ -196,7 +196,7 @@ }else{ rtcor <- NULL } - TIC[[j]] <- getBPC(files[j],rtcor=rtcor) + BPC[[j]] <- getBPC(files[j],rtcor=rtcor) } pdf(pdfname,w=16,h=10) @@ -204,8 +204,10 @@ lty = 1:N pch = 1:N #search for max x and max y in BPCs - xlim = range(sapply(TIC, function(x) range(x[,1]))) - ylim = range(sapply(TIC, function(x) range(x[,2]))) + + xlim = range(sapply(BPC, function(x) range(x[,1]))) + ylim = range(sapply(BPC, function(x) range(x[,2]))) + ylim = c(-ylim[2], ylim[2]) ##plot start @@ -216,15 +218,15 @@ plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Base Peak Chromatograms \n","BPCs_",class[k]," vs ",class[l], sep=""), xlab = "Retention Time (min)", ylab = "BPC") colvect<-NULL for (j in 1:length(classnames[[k]])) { - tic <- TIC[[classnames[[k]][j]]] - # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") - points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") + bpc <- BPC[[classnames[[k]][j]]] + # points(bpc[,1]/60, bpc[,2], col = cols[i], pch = pch[i], type="l") + points(bpc[,1]/60, bpc[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") colvect<-append(colvect,cols[classnames[[k]][j]]) } for (j in 1:length(classnames[[l]])) { # i=class2names[j] - tic <- TIC[[classnames[[l]][j]]] - points(tic[,1]/60, -tic[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") + bpc <- BPC[[classnames[[l]][j]]] + points(bpc[,1]/60, -bpc[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") colvect<-append(colvect,cols[classnames[[l]][j]]) } legend("topright",paste(gsub("(^.+)\\..*$","\\1",basename(files[c(classnames[[k]],classnames[[l]])]))), col = colvect, lty = lty, pch = pch) @@ -239,15 +241,15 @@ plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Base Peak Chromatograms \n","BPCs_",class[k],"vs",class[l], sep=""), xlab = "Retention Time (min)", ylab = "BPC") for (j in 1:length(classnames[[k]])) { - tic <- TIC[[classnames[[k]][j]]] - # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") - points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") + bpc <- BPC[[classnames[[k]][j]]] + # points(bpc[,1]/60, bpc[,2], col = cols[i], pch = pch[i], type="l") + points(bpc[,1]/60, bpc[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") colvect<-append(colvect,cols[classnames[[k]][j]]) } for (j in 1:length(classnames[[l]])) { # i=class2names[j] - tic <- TIC[[classnames[[l]][j]]] - points(tic[,1]/60, -tic[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") + bpc <- BPC[[classnames[[l]][j]]] + points(bpc[,1]/60, -bpc[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") colvect<-append(colvect,cols[classnames[[l]][j]]) } legend("topright",paste(gsub("(^.+)\\..*$","\\1",basename(files[c(classnames[[k]],classnames[[l]])]))), col = colvect, lty = lty, pch = pch) @@ -255,14 +257,16 @@ if (length(class)==1){ k=1 - ylim = range(sapply(TIC, function(x) range(x[,2]))) + + ylim = range(sapply(BPC, function(x) range(x[,2]))) + colvect<-NULL plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Base Peak Chromatograms \n","BPCs_",class[k], sep=""), xlab = "Retention Time (min)", ylab = "BPC") for (j in 1:length(classnames[[k]])) { - tic <- TIC[[classnames[[k]][j]]] - # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") - points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") + bpc <- BPC[[classnames[[k]][j]]] + # points(bpc[,1]/60, bpc[,2], col = cols[i], pch = pch[i], type="l") + points(bpc[,1]/60, bpc[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") colvect<-append(colvect,cols[classnames[[k]][j]]) } legend("topright",paste(gsub("(^.+)\\..*$","\\1",basename(files[c(classnames[[k]])]))), col = colvect, lty = lty, pch = pch) @@ -297,7 +301,6 @@ TIC <- vector("list",N) for (i in 1:N) { - cat(files[i],"\n") if (!is.null(xcmsSet) && rt == "corrected") rtcor <- xcmsSet@rt$corrected[[i]] else @@ -318,7 +321,7 @@ if (length(class)>2){ for (k in 1:(length(class)-1)){ for (l in (k+1):length(class)){ - print(paste(class[k],"vs",class[l],sep=" ")) + cat(paste(class[k],"vs",class[l],"\n",sep=" ")) plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Total Ion Chromatograms \n","TICs_",class[k]," vs ",class[l], sep=""), xlab = "Retention Time (min)", ylab = "TIC") colvect<-NULL for (j in 1:length(classnames[[k]])) { @@ -500,4 +503,4 @@ } graphics.off() }#end for unkn[l] -}#end function \ No newline at end of file +}#end function