From 6ae2cb8eb8aca2f93db847bdf4c707ab1ae73a8e Mon Sep 17 00:00:00 2001 From: wfenglund <72128748+wfenglund@users.noreply.github.com> Date: Wed, 1 May 2024 00:52:45 +0200 Subject: [PATCH 1/2] add so that plotting colors can be specified by user add option to add a comma-separated list of colors with the flag -c or --color. If no color list is given the default rainbow palette is used. --- plotADMIXTURE.r | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plotADMIXTURE.r b/plotADMIXTURE.r index 2a4f9ca..ce00ce8 100644 --- a/plotADMIXTURE.r +++ b/plotADMIXTURE.r @@ -29,7 +29,9 @@ option_list = list( make_option(c("-l", "--populations"), type="character", default=NULL, help="comma-separated list of populations/species in the order to be plotted", metavar="character"), make_option(c("-o", "--outPrefix"), type="character", default="default", - help="output prefix (default: name provided with prefix)", metavar="character") + help="output prefix (default: name provided with prefix)", metavar="character"), + make_option(c("-c", "--color"), type="character", default="default", + help="comma-separated list of colors to use in the plot (default: rainbow palette)", metavar="character") ) opt_parser = OptionParser(option_list=option_list) opt = parse_args(opt_parser) @@ -52,6 +54,15 @@ if (is.null(opt$prefix)){ # If no output prefix is given, use the input prefix if(opt$outPrefix=="default") opt$outPrefix=opt$prefix +# If no color input is given use built in rainbow, else use input +if(opt$color=="default") { + palette<-rainbow(n=opt$maxK) +} else { + palette<-unlist(strsplit(opt$color, split=",")) +} + +print(palette) + # Assign the first argument to prefix prefix=opt$prefix @@ -82,10 +93,10 @@ spaces<-spaces[-length(spaces)] tiff(file=paste0(opt$outPrefix,".tiff"),width = 2000, height = 1200,res=200) par(mfrow=c(maxK-1,1),mar=c(0,1,0,0),oma=c(2,1,9,1),mgp=c(0,0.2,0),xaxs="i",cex.lab=1.2,cex.axis=0.8) # Plot minK - bp<-barplot(t(as.matrix(tbl[[1]][order(labels$n),])), col=rainbow(n=minK),xaxt="n", border=NA,ylab=paste0("K=",minK),yaxt="n",space=spaces) + bp<-barplot(t(as.matrix(tbl[[1]][order(labels$n),])), col=palette,xaxt="n", border=NA,ylab=paste0("K=",minK),yaxt="n",space=spaces) axis(3,at=bp,labels=labels$ind[order(labels$n)],las=2,tick=F,cex=0.6) # Plot higher K values - if(maxK>minK)lapply(2:(maxK-1), function(x) barplot(t(as.matrix(tbl[[x]][order(labels$n),])), col=rainbow(n=x+1),xaxt="n", border=NA,ylab=paste0("K=",x+1),yaxt="n",space=spaces)) + if(maxK>minK)lapply(2:(maxK-1), function(x) barplot(t(as.matrix(tbl[[x]][order(labels$n),])), col=palette,xaxt="n", border=NA,ylab=paste0("K=",x+1),yaxt="n",space=spaces)) axis(1,at=c(which(spaces==0.5),bp[length(bp)])-diff(c(1,which(spaces==0.5),bp[length(bp)]))/2, labels=unlist(strsplit(opt$populations,","))) dev.off() From cc4331f5427842c935069b367455aad2d5fe87cb Mon Sep 17 00:00:00 2001 From: wfenglund <72128748+wfenglund@users.noreply.github.com> Date: Wed, 1 May 2024 00:54:44 +0200 Subject: [PATCH 2/2] remove temporary print statement --- plotADMIXTURE.r | 2 -- 1 file changed, 2 deletions(-) diff --git a/plotADMIXTURE.r b/plotADMIXTURE.r index ce00ce8..220f444 100644 --- a/plotADMIXTURE.r +++ b/plotADMIXTURE.r @@ -61,8 +61,6 @@ if(opt$color=="default") { palette<-unlist(strsplit(opt$color, split=",")) } -print(palette) - # Assign the first argument to prefix prefix=opt$prefix