Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom color option #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions plotADMIXTURE.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -52,6 +54,13 @@ 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=","))
}

# Assign the first argument to prefix
prefix=opt$prefix

Expand Down Expand Up @@ -82,10 +91,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()