annotate population_structure.r @ 0:879cbc69a0ee default tip

Uploaded
author rico
date Thu, 05 Apr 2012 15:28:27 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
879cbc69a0ee Uploaded
rico
parents:
diff changeset
1 library(RColorBrewer)
879cbc69a0ee Uploaded
rico
parents:
diff changeset
2
879cbc69a0ee Uploaded
rico
parents:
diff changeset
3 args = commandArgs(trailingOnly=TRUE)
879cbc69a0ee Uploaded
rico
parents:
diff changeset
4 q_file = args[[1]]
879cbc69a0ee Uploaded
rico
parents:
diff changeset
5 output_file = args[[2]]
879cbc69a0ee Uploaded
rico
parents:
diff changeset
6 populations = args[[3]]
879cbc69a0ee Uploaded
rico
parents:
diff changeset
7
879cbc69a0ee Uploaded
rico
parents:
diff changeset
8 tbl <- read.table(q_file)
879cbc69a0ee Uploaded
rico
parents:
diff changeset
9
879cbc69a0ee Uploaded
rico
parents:
diff changeset
10 if ( populations >= 3 && populations <= 12 ) {
879cbc69a0ee Uploaded
rico
parents:
diff changeset
11 colors = brewer.pal(populations, 'Paired')
879cbc69a0ee Uploaded
rico
parents:
diff changeset
12 } else {
879cbc69a0ee Uploaded
rico
parents:
diff changeset
13 colors = rainbow(populations)
879cbc69a0ee Uploaded
rico
parents:
diff changeset
14 }
879cbc69a0ee Uploaded
rico
parents:
diff changeset
15
879cbc69a0ee Uploaded
rico
parents:
diff changeset
16 pdf(file=output_file, onefile=TRUE, width=7, height=3)
879cbc69a0ee Uploaded
rico
parents:
diff changeset
17 barplot(t(as.matrix(tbl)), col=colors, xlab="Individual #", ylab="Ancestry", border=NA)
879cbc69a0ee Uploaded
rico
parents:
diff changeset
18
879cbc69a0ee Uploaded
rico
parents:
diff changeset
19 dev.off()