Dear Gitlab users, due to maintenance reasons, Gitlab will not be available on Thursday 30.09.2021 from 5:00 pm to approximately 5:30 pm.

Commit bd0b3a7a authored by joerg.buescher's avatar joerg.buescher
Browse files

unified sorting of samples across all outputs

parent 00a3abb9
......@@ -344,7 +344,7 @@ if (prm$verbose >= 1) {
# write template for training solution to xlsx file
wb <- openxlsx::createWorkbook()
openxlsx::addWorksheet(wb, 'Sheet1')
openxlsx::writeData(wb, 'Sheet1', smpl$filenames, startCol = 1, startRow = 4, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, 'Sheet1', smpl$filenames[prm$typeorder], startCol = 1, startRow = 4, rowNames = FALSE, colNames = FALSE)
for (im in 1:prm$nmet) {
nowcol <- 3*im
......@@ -353,8 +353,8 @@ if (prm$verbose >= 1) {
options("openxlsx.numFmt" = "0")
openxlsx::writeData(wb, 'Sheet1', rep(1,prm$nsmpl) , startCol = nowcol, startRow = 4, rowNames = FALSE, colNames = FALSE)
options("openxlsx.numFmt" = "0.00")
openxlsx::writeData(wb, 'Sheet1', prm$unirt[pstartmat[ ,im]] , startCol = nowcol+1, startRow = 4, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, 'Sheet1', prm$unirt[pendmat[ ,im]] , startCol = nowcol+2, startRow = 4, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, 'Sheet1', prm$unirt[pstartmat[prm$typeorder ,im]] , startCol = nowcol+1, startRow = 4, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, 'Sheet1', prm$unirt[pendmat[prm$typeorder ,im]] , startCol = nowcol+2, startRow = 4, rowNames = FALSE, colNames = FALSE)
}
openxlsx::saveWorkbook(wb, file.path(prm$batchdir, "manual_peakcheck_template.xlsx"), overwrite = TRUE)
}
......
......@@ -16,7 +16,7 @@ initialize_prm <- function() {
prm$polarmets <- TRUE
prm$sosomets <- FALSE
prm$expertmode <- FALSE
prm$fancyformat <- TRUE
prm$fancyformat <- FALSE
prm$verbose <- 1
......
......@@ -13,7 +13,7 @@ plot_peaks <- function(metab, smpl, msd, prm) {
layout(matrix(c(1:(prm$nmet*prm$nsmpl)), prm$nsmpl, prm$nmet, byrow = TRUE)) # initiate subplots
# Reverse looping and indexing according to Jörg plotting logic (samples first, then metabolites)
for (id in 1:prm$nsmpl){
for (id in prm$typeorder){ # 1:prm$nsmpl){
for (im in 1:prm$nmet){
if (prm$verbose >=2) {
cat('\r', paste('plot_peaks: metab', im, 'sample', id, ' '))
......@@ -40,6 +40,7 @@ plot_peaks <- function(metab, smpl, msd, prm) {
nowheight[is.infinite(nowheight)] <- 0
ylim12 <- c(0, max(c(100, 1.1 * nowheight[1:2],na.rm = TRUE) ))
ylim13 <- c(0, max(c(120, 1.4 * nowheight[3])))
xlim123 <- range(prm$unirt[nowgoody])
if (sum(nowgoody) < 2) {
nowgoodplot <- FALSE
......@@ -55,6 +56,7 @@ plot_peaks <- function(metab, smpl, msd, prm) {
type = 'l',
main = msd[[im]][[id]]$label2, col.main = main_col,
ylim = ylim12, # msd[[im]][[id]]$ylim,
xlim = xlim123,
xlab='', ylab='',
cex.main=0.7)
} else {
......@@ -62,6 +64,7 @@ plot_peaks <- function(metab, smpl, msd, prm) {
type = 'l',
main = msd[[im]][[id]]$label1, col.main = main_col,
ylim = ylim12, # msd[[im]][[id]]$ylim,
xlim = xlim123,
xlab='', ylab='',
cex.main=0.7)
}
......@@ -137,7 +140,7 @@ plot_peaks <- function(metab, smpl, msd, prm) {
par(new = TRUE)
plot(prm$unirt[nowgoody], nowy[nowgoody],
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", col = 'green',
ylim = ylim13)
ylim = ylim13, xlim = xlim123)
axis(side=4, at = pretty(ylim13), col = 'green', col.axis= 'green')
} else {
......@@ -145,7 +148,7 @@ plot_peaks <- function(metab, smpl, msd, prm) {
par(new = TRUE)
plot(prm$unirt[nowgoody], nowy[nowgoody],
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", col = 'green', lty = 2,
ylim = ylim13)
ylim = ylim13, xlim = xlim123)
axis(side=4, at = pretty(ylim13), col = 'green', col.axis= 'green')
}
# text(textxpos,0.75*msd[[im]][[id]]$ylim[2], metab[[im]]$qual13c$MRM , col = 'green', cex=0.5, pos=4)
......
......@@ -116,6 +116,7 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
# get additional info from sample.info
smpl <- read_sampleinfo(smpl, prm)
prm$typeorder <- order(smpl$sorttype)
# Read out metabolite db / set up quantifier, 13C/12C quantifiers ------------------------------
metab <- read_metabdb(prm)
......@@ -181,7 +182,7 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
cat('qqq_auto_integrate complete.')
# Reset par to default
par(pardefault)
# par(pardefault)
# Return msd object if argument is set
if (return_msd){
......
......@@ -13,12 +13,12 @@ write_peakinfo <- function(metab, smpl, msd, prm){
}
if (prm$expertmode) sheetname <- c(sheetname, 'LuckyDip', 'Lucky13C')
nowQuantTransition <- unlist(sapply(metab, '[[', 'qual12c') ['MRM', ])
nowQuantTransition <- unlist(sapply(metab, '[[', 'quant') ['MRM', ])
# nowQuantTransition <- character(prm$nmet)
# for (im in 1:prm$nmet) {
# nowQuantTransition[im] <- metabdb_data$quantifier[goodmets[im]][[1]]$MRM
# }
typeorder <- order(smpl$nowtype)
# typeorder <- order(smpl$nowtype)
uniquetype <- unique(smpl$nowtype)
for (ish in 1:length(sheetname)) {
......@@ -28,7 +28,7 @@ write_peakinfo <- function(metab, smpl, msd, prm){
openxlsx::addWorksheet(wb, sheetname[ish])
# mzml_data$samplenames
openxlsx::writeData(wb, sheetname[ish], smpl$samplenames[typeorder], startCol = 1, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$samplenames[prm$typeorder], startCol = 1, startRow = 7, rowNames = FALSE, colNames = FALSE)
# metabolitenames
openxlsx::writeData(wb, sheetname[ish], t(sapply(metab, '[[', 'name')) , startCol = 11, startRow = 1, rowNames = FALSE, colNames = FALSE)
# quantifier transition
......@@ -39,15 +39,15 @@ write_peakinfo <- function(metab, smpl, msd, prm){
# additionalinfo
openxlsx::writeData(wb, sheetname[ish], t(c('Group 1', 'Group 2', 'Group 3', 'Amount', 'Cultivation', 'Organism', 'Celltype', 'Date', 'Plate position')), startCol = 2, startRow = 6, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$type1[typeorder], startCol = 2, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$type2[typeorder], startCol = 3, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$type3[typeorder], startCol = 4, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$amount[typeorder], startCol = 5, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$cultivation[typeorder], startCol = 6, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$organism[typeorder], startCol = 7, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$celltype[typeorder], startCol = 8, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$date[typeorder], startCol = 9, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$platepos[typeorder], startCol = 10, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$type1[prm$typeorder], startCol = 2, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$type2[prm$typeorder], startCol = 3, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$type3[prm$typeorder], startCol = 4, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$amount[prm$typeorder], startCol = 5, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$cultivation[prm$typeorder], startCol = 6, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$organism[prm$typeorder], startCol = 7, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$celltype[prm$typeorder], startCol = 8, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$date[prm$typeorder], startCol = 9, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb, sheetname[ish], smpl$platepos[prm$typeorder], startCol = 10, startRow = 7, rowNames = FALSE, colNames = FALSE)
# Col header annotations
openxlsx::writeData(wb, sheetname[ish], c('Metabolite','QuantTrans','HMDB ID', 'KEGG ID', 'ANOVA'), startCol = 10, startRow = 1, rowNames = FALSE, colNames = FALSE)
......@@ -65,18 +65,18 @@ write_peakinfo <- function(metab, smpl, msd, prm){
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(border = 'Bottom', textDecoration = 'bold'), rows = 6, cols = 1:10+prm$nmet )
if (regexpr('Norm',sheetname[ish]) > 0) {
for (il in 1:length(typeorder)) {
for (il in 1:length(prm$typeorder)) {
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(fontColour = '#000088'), cols = 1:99, rows =6+il )
}
for (iut in 1:length(uniquetype)) {
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(border = 'Bottom', fontColour = '#000088'), rows = 6+max(which(smpl$nowtype[typeorder] == uniquetype[iut])), cols = 1:(10+prm$nmet) )
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(border = 'Bottom', fontColour = '#000088'), rows = 6+max(which(smpl$nowtype[prm$typeorder] == uniquetype[iut])), cols = 1:(10+prm$nmet) )
}
} else {
for (il in 1:length(typeorder)) {
for (il in 1:length(prm$typeorder)) {
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(fontColour = '#006600'), cols = 1:99, rows = 6+il )
}
for (iut in 1:length(uniquetype)) {
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(border = 'Bottom', fontColour = '#006600'), rows = 6+max(which(smpl$nowtype[typeorder] == uniquetype[iut])), cols = 1:(10+prm$nmet) )
openxlsx::addStyle(wb, sheetname[ish], openxlsx::createStyle(border = 'Bottom', fontColour = '#006600'), rows = 6+max(which(smpl$nowtype[prm$typeorder] == uniquetype[iut])), cols = 1:(10+prm$nmet) )
}
}
......@@ -95,16 +95,16 @@ write_peakinfo <- function(metab, smpl, msd, prm){
# data
options("openxlsx.numFmt" = "0")
if (prm$polarmets){
openxlsx::writeData(wb,'NormArea', msd2matrix(msd, prm, 'normarea'), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'NormHeight', msd2matrix(msd, prm, 'normheight'), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'13CArea', msd2matrix(msd, prm, 'area13'), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'NormArea', msd2matrix(msd, prm, 'normarea')[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'NormHeight', msd2matrix(msd, prm, 'normheight')[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'13CArea', msd2matrix(msd, prm, 'area13')[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
}
if (prm$expertmode) {
openxlsx::writeData(wb,'LuckyDip', msd2matrix(msd, prm, 'area', expert = TRUE), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'Lucky13C', msd2matrix(msd, prm, 'area13', expert = TRUE), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'LuckyDip', msd2matrix(msd, prm, 'area', expert = TRUE)[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'Lucky13C', msd2matrix(msd, prm, 'area13', expert = TRUE)[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
}
openxlsx::writeData(wb,'RawArea', msd2matrix(msd, prm, 'area'), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'RawHeight', msd2matrix(msd, prm, 'height'), startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'RawArea', msd2matrix(msd, prm, 'area')[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
openxlsx::writeData(wb,'RawHeight', msd2matrix(msd, prm, 'height')[prm$typeorder, ], startCol = 11, startRow = 7, rowNames = FALSE, colNames = FALSE)
# read additional batch info
openxlsx::addWorksheet(wb, 'info')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment