comparison lib.r @ 11:37d31fd64eb4 draft

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 0dcc8bcb1e645574c7f81ec1a43f86be38acd065"
author workflow4metabolomics
date Tue, 21 Jul 2020 09:17:54 -0400
parents dbd877060ac3
children 0cab69429e1e
comparison
equal deleted inserted replaced
10:dbd877060ac3 11:37d31fd64eb4
147 getPlotChromPeakDensity <- function(xdata, param = NULL, mzdigit=4) { 147 getPlotChromPeakDensity <- function(xdata, param = NULL, mzdigit=4) {
148 pdf(file="plotChromPeakDensity.pdf", width=16, height=12) 148 pdf(file="plotChromPeakDensity.pdf", width=16, height=12)
149 149
150 par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5)) 150 par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5))
151 151
152 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") 152 if(length(unique(xdata$sample_group))<10){
153 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
154 }else{
155 group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
156 }
153 names(group_colors) <- unique(xdata$sample_group) 157 names(group_colors) <- unique(xdata$sample_group)
158 col_per_samp <- as.character(xdata$sample_group)
159 for(i in 1:length(group_colors)){col_per_samp[col_per_samp==(names(group_colors)[i])]<-group_colors[i]}
154 160
155 xlim <- c(min(featureDefinitions(xdata)$rtmin), max(featureDefinitions(xdata)$rtmax)) 161 xlim <- c(min(featureDefinitions(xdata)$rtmin), max(featureDefinitions(xdata)$rtmax))
156 for (i in 1:nrow(featureDefinitions(xdata))) { 162 for (i in 1:nrow(featureDefinitions(xdata))) {
157 mzmin = featureDefinitions(xdata)[i,]$mzmin 163 mzmin = featureDefinitions(xdata)[i,]$mzmin
158 mzmax = featureDefinitions(xdata)[i,]$mzmax 164 mzmax = featureDefinitions(xdata)[i,]$mzmax
159 plotChromPeakDensity(xdata, param = param, mz=c(mzmin,mzmax), col=group_colors, pch=16, xlim=xlim, main=paste(round(mzmin,mzdigit),round(mzmax,mzdigit))) 165 plotChromPeakDensity(xdata, param = param, mz=c(mzmin,mzmax), col=col_per_samp, pch=16, xlim=xlim, main=paste(round(mzmin,mzdigit),round(mzmax,mzdigit)))
160 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) 166 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
161 } 167 }
162 168
163 dev.off() 169 dev.off()
164 } 170 }
168 getPlotAdjustedRtime <- function(xdata) { 174 getPlotAdjustedRtime <- function(xdata) {
169 175
170 pdf(file="raw_vs_adjusted_rt.pdf", width=16, height=12) 176 pdf(file="raw_vs_adjusted_rt.pdf", width=16, height=12)
171 177
172 # Color by group 178 # Color by group
173 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") 179 if(length(unique(xdata$sample_group))<10){
180 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
181 }else{
182 group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
183 }
174 if (length(group_colors) > 1) { 184 if (length(group_colors) > 1) {
175 names(group_colors) <- unique(xdata$sample_group) 185 names(group_colors) <- unique(xdata$sample_group)
176 plotAdjustedRtime(xdata, col = group_colors[xdata$sample_group]) 186 plotAdjustedRtime(xdata, col = group_colors[xdata$sample_group])
177 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) 187 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
178 } 188 }
237 main <- paste(type,":",adjusted,"data") 247 main <- paste(type,":",adjusted,"data")
238 248
239 pdf(pdfname, width=16, height=10) 249 pdf(pdfname, width=16, height=10)
240 250
241 # Color by group 251 # Color by group
242 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") 252 if(length(unique(xdata$sample_group))<10){
253 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
254 }else{
255 group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
256 }
243 if (length(group_colors) > 1) { 257 if (length(group_colors) > 1) {
244 names(group_colors) <- unique(xdata$sample_group) 258 names(group_colors) <- unique(xdata$sample_group)
245 plot(chrom, col = group_colors[as.factor(chrom$sample_group)], main=main, peakType = "none") 259 plot(chrom, col = group_colors[as.factor(chrom$sample_group)], main=main, peakType = "none")
246 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) 260 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
247 } 261 }