-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfeaturetypesreal.R
More file actions
executable file
·62 lines (38 loc) · 1.76 KB
/
featuretypesreal.R
File metadata and controls
executable file
·62 lines (38 loc) · 1.76 KB
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
58
59
60
61
62
library(ggplot2)
library(reshape2)
library(scales)
args <- commandArgs(trailingOnly = TRUE)
outtype = ""
if(length(args) > 2){
outtype = args[3]
}
#args <- c("hg19-genomictrailertable.txt","hg19-genomicbarplot.png")
#args =c("repfragtypenormcounts.txt","barplot.png")
#Rscript trailerbarplot.R hg19-trailertable.txt hg19-barplot.png
counts <- read.table(args[1],check.names=FALSE)
selectcounts = counts
temp = cbind(selectcounts, seq = factor(rownames(selectcounts),rev(rownames(selectcounts))))
#levels(temp$seq) <- rev(rownames(selectcounts))
countsmelt = melt(temp, id.vars = c('seq'))
countsmelt = within(countsmelt, seq <- factor(seq,
rownames(selectcounts)))
#head(countsmelt)
sampletotals = aggregate(countsmelt$value, list(countsmelt$variable), sum)
#countsmelt
#sampletotals$x[countsmelt$variable]
#countsmelt = countsmelt[countsmelt$value > 100,]
countsmelt = countsmelt[countsmelt$value > 0,]
if(outtype != "all"){
countsmelt = countsmelt[countsmelt$value > sampletotals$x[countsmelt$variable] / 100,] #filters out those types below a certain level
}
#countsmelt = countsmelt
#countsmelt
currplot = ggplot(countsmelt,aes(x = variable, y = value,fill = seq, stat="identity")) + theme_bw() + theme(panel.border = element_rect(linetype = "blank"), panel.grid = element_line(linetype = "blank")) +
geom_bar(stat="identity") +
geom_bar(stat="identity",color="black",show.legend=FALSE) +
theme(axis.text.x = element_text(size=5))+
xlab("Sample") +
ylab("Total Reads") +
labs(fill="Read\nType") +
theme(axis.title.x = element_text(face="bold", size=15), axis.text.x = element_text(face="bold", size=9,angle = 90, vjust = .5))
ggsave(filename=args[2],currplot, width = 3 + .25*length(unique(countsmelt$variable)), limitsize = FALSE)