-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenefeatures.R
More file actions
executable file
·102 lines (66 loc) · 2.51 KB
/
genefeatures.R
File metadata and controls
executable file
·102 lines (66 loc) · 2.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#library(ggsci)
library(ggplot2)
library(reshape2)
library(scales)
library(RColorBrewer)
args <- commandArgs(trailingOnly = TRUE)
counts <- read.table(args[1],check.names=FALSE)
selectcounts = counts
temp = cbind(selectcounts, seq = factor(rownames(selectcounts),rev(rownames(selectcounts)), ordered = TRUE))
countsmelt = melt(temp, id.vars = c('seq'))
countsmelt = within(countsmelt, seq <- factor(seq,
rownames(selectcounts),
ordered = FALSE))
sampletotals = aggregate(countsmelt$value, list(countsmelt$variable), sum)
#sampletotals$x[countsmelt$variable]
#countsmelt = countsmelt[countsmelt$value > 100,]
countsmelt = countsmelt[countsmelt$value > sampletotals$x[countsmelt$variable] / 100,]
#unique(countsmelt$seq)
colourCount = length(unique(countsmelt$seq))+1
#getPalette = colorRampPalette(brewer.pal(8, "Dark2"))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
#unique(head(countsmelt))
# other #f2dab2
# tRNA #6666cc
# pretRNA #a1ade5
# miRNA #b4008d
# snRNA #74531d
# Mt_tRNA #87e275
# Mt_rRNA #00754a
# rRNA #a5e5d9
# snoRNA #ff9e18
# misc_RNA #b2b2b2
typepal <- c(
"tRNA" = "#6666cc",
"pretRNA" = "#a1ade5",
"miRNA" = "#b4008d",
"snRNA" = "#74531d",
"Mt_tRNA" = "#87e275",
"Mt_rRNA" = "#00754a",
"rRNA" = "#a5e5d9",
"snoRNA" = "#ff9e18",
"misc_RNA" = "#b2b2b2",
"other" = "#f2dab2"
)
#print(typepal)
#print(setdiff(unique(countsmelt$seq),names(typepal)))
extragenes = setdiff(unique(countsmelt$seq),names(typepal))
otherpal = getPalette(length(extragenes))
names(otherpal) = extragenes
#print(otherpal)
typepal = c(typepal, otherpal)
#print(typepal)
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(position = "fill",stat="identity") +
geom_bar(position = "fill",stat="identity",color="black",show.legend=FALSE) +
scale_y_continuous(labels = percent_format()) +
theme(axis.text.x = element_text(size=5))+
xlab("Sample") +
ylab("Percentage of Total Reads") +
labs(fill="Read\nType")+
#scale_fill_ucscgb()+
#scale_fill_brewer(palette = "Dark2")+
#scale_fill_manual(values = getPalette(colourCount))+
scale_fill_manual(values = typepal)+
theme(axis.title.x = element_text(face="bold", size=15), axis.text.x = element_text(face="bold", size=9,angle = 90, vjust = .5)) #+scale_colour_gradient() #+ scale_fill_brewer( palette="RdPu")
ggsave(filename=args[2])