-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot_gamma_solutions.R
executable file
·42 lines (34 loc) · 1.92 KB
/
plot_gamma_solutions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(ggplot2)
library(optparse)
## For now, test if commands are in original, trailing format, or new opt-parse format
option_list = list(
make_option(c("-f", "--solutionsFile"), type="character", default=NULL,
help="json file with gamma solutions from sequenza", metavar="character"),
make_option(c("-o", "--outputFile"), type="character", default=NULL,
help="output png file", metavar="character"),
make_option(c("-w", "--width"), type="integer", default="1200",
help="width of png file", metavar="integer"),
make_option(c("-h", "--height"), type="integer", default="400",
help="height of png file", metavar="integer"))
opt_parser = OptionParser(option_list = option_list, add_help_option = FALSE)
opt = parse_args(opt_parser);
solutionsFile = opt$solutionsFile
outFile = opt$outputFile
gamma.solutions<-read.csv(solutionsFile)
df.cellularity<-data.frame(gamma = gamma.solutions$gamma, value = gamma.solutions$cellularity, type="cellularity")
df.ploidy<-data.frame(gamma = gamma.solutions$gamma, value = gamma.solutions$ploidy, type="ploidy")
df.segmentation<-data.frame(gamma = gamma.solutions$gamma, value=gamma.solutions$no_segments, type="no. segments")
df<-rbind(df.segmentation, df.cellularity, df.ploidy)
df$type_f<-factor(df$type, levels = c('no. segments', 'cellularity','ploidy')) # determines panel order
df<-data.frame(df, y_min=0)
p<-ggplot(df, aes(x = gamma, y = value))+
geom_line(linetype = "dashed", aes(colour = type, group = type), size = 1)+
geom_point(aes(colour = type, group = type_f),size = 4)+
scale_x_continuous(breaks = as.numeric(gamma.solutions$gamma)) +
facet_grid(rows = vars(type), scales="free")+
theme_bw(base_size = 18)+
theme(legend.position = "none") +
geom_blank(aes(y = y_min)) # trick to set y-axis scale origin at the zero value
png(filename = file.path(outFile), type="cairo", width = opt$width, height = opt$height)
print(p)
dev.off()