-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho-lines-for-each-column.R
executable file
·57 lines (45 loc) · 1.46 KB
/
o-lines-for-each-column.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env Rscript
#
# generates lines for each column in a given TAB delimited file:
#
library(reshape)
library(gtools)
library(ggplot2)
args <- commandArgs(trailingOnly = TRUE)
csv_path <- args[1]
output_file_prefix <- args[2]
title_text <- args[3]
if(invalid(title_text))
title_text <- "Unknown Title"
if(invalid(output_file_prefix))
output_file_prefix <- "unknown"
data <- as.data.frame(read.csv(csv_path, header=TRUE, sep="\t"))
row.names <- data$samples
col.names <- colnames(data)
df <- melt(data , id = 'samples', variable_name = 'bins')
P <- function(){
p = ggplot(df, aes(x = samples, y = value, colour = bins, group = bins))
p <- p + geom_line()
p <- p + geom_point()
p <- p + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5), legend.position = 'top')
p <- p + labs(x='', y='Number of Reads')
p <- p + theme(plot.title = element_text(hjust=0, vjust=1))
print(p)
}
num_samples <- length(row.names)
pdf_w <- num_samples / 4
if(num_samples < 32)
pdf_w <- 8
png_w = pdf_w * 100
if (png_w > 20000)
png_w <- 20000
# PDF
pdf_output <- paste(output_file_prefix,".pdf",sep="")
pdf(pdf_output, width = pdf_w, height = 4)
P()
sprintf("Lines PDF: '%s'", pdf_output)
# PNG
png_output <- paste(output_file_prefix,".png",sep="")
png(png_output, width = png_w, height = 400, units = "px", pointsize = 12, bg = "transparent", type = c("cairo", "cairo-png", "Xlib", "quartz"))
P()
sprintf("Lines PNG: '%s'", png_output)