-
Notifications
You must be signed in to change notification settings - Fork 1
/
rice_1st_nucleotide_preferences.Rmd
129 lines (121 loc) · 4.15 KB
/
rice_1st_nucleotide_preferences.Rmd
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: "First_nucleotide_preferences"
author: "Chenxin Li"
date: "January 14, 2019"
output:
html_notebook:
number_sections: yes
toc: yes
toc_float: yes
html_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ggplot2)
library(emmeans)
library(tidyr)
library(dplyr)
library(readr)
library(readxl)
library(vegan)
library(edgeR)
library(RColorBrewer)
library(svglite)
```
#1st nucleotide preferences by length
```{r}
first_n <- read_excel("C:/Users/cxli9/Desktop/Li/PBI/PBI299 (Sundar Lab)/smRNA project/CLVS08/first_nucleotide_pre/rice_siRNA_1st_nt_by_length.xlsx")
first_n
```
```{r}
first_n_l <- first_n %>%
gather("nucleotide", "proportion", 3:6) %>%
mutate(nt = as.factor(length)) %>%
mutate(nucleotide = factor(nucleotide, levels = c("A", "C", "G", "U")))
first_n_l %>%
group_by(sample_type, length) %>%
arrange(desc(nucleotide))
#first_n_l[order(first_n_l$nucleotide, decreasing = T), ]
```
```{r}
first_n_l %>%
ggplot(aes(x = sample_type, y = proportion)) +
facet_grid(. ~ nt, scales = "free") +
geom_bar(stat = "identity", aes(fill = nucleotide), position = position_stack(reverse = T)) +
labs(x = NULL,
fill = NULL) +
scale_fill_brewer(palette = "Set2") +
scale_x_discrete(label = c("egg", "ovary", "pollen VC", "sd shoot", "sperm")) +
theme_minimal()+
theme(text = element_text(size = 14, face="bold")) +
theme(axis.text.x = element_text(colour="black", angle = 45, hjust = 1)) +
theme(axis.text.y = element_text(colour="black"))
ggsave(filename = "first_nucleotide.png")
```
```{r}
#egg sperm seedling only
first_n_l %>%
filter(sample_type == "egg" |
sample_type == "seedling" |
sample_type == "sperm") %>%
ggplot(aes(x = sample_type, y = proportion)) +
facet_grid(. ~ nt, scales = "free") +
geom_bar(stat = "identity", aes(fill = nucleotide), position = position_stack(reverse = T)) +
labs(x = NULL,
fill = NULL,
y = NULL) +
scale_fill_brewer(palette = "Set2") +
theme_minimal()+
theme(legend.position = "bottom") +
theme(text = element_text(size = 18, face="bold")) +
theme(axis.text.x = element_text(colour="black", angle = 45, hjust = 1)) +
theme(axis.text.y = element_text(colour="black"))
ggsave(filename = "first_nucleotide_ECSDSP.svg", width = 3.5, height = 4.3)
```
#by tissue specificity
```{r}
first_by_bin <- read_excel("C:/Users/cxli9/Desktop/Li/PBI/PBI299 (Sundar Lab)/smRNA project/CLVS08/first_nucleotide_pre/rice_siRNA_1st_nt_by_bin_type.xlsx")
```
```{r}
first_by_bin
```
```{r}
first_by_bin_l <- first_by_bin %>%
gather("nucleotide", "proportion", 4:7) %>%
mutate(nt = as.factor(length)) %>%
mutate(nucleotide = factor(nucleotide, levels = c("A", "C", "G", "U"))) %>%
group_by(sample_type, length) %>%
arrange(desc(nucleotide))
```
```{r}
first_by_bin_l %>%
mutate(loci = case_when(
str_detect(bin, "egg") ~ "egg-\nspecific\nloci",
str_detect(bin, "seedling") ~ "seedling\nshoot-\nspecific\nloci",
str_detect(bin, "sperm") ~ "sperm-\nspecific\nloci",
str_detect(bin, "intersect") ~ "intersect."
)) %>%
mutate(loci_f = factor(loci, levels = c(
"egg-\nspecific\nloci",
"seedling\nshoot-\nspecific\nloci",
"sperm-\nspecific\nloci",
"intersect."
))) %>%
filter(loci_f != "intersect.") %>%
ggplot(aes(x = sample_type, y = proportion)) +
#facet_grid(. ~ loci_f, scales = "free", space = "free") +
geom_bar(stat = "identity", aes(fill = nucleotide), position = position_stack(reverse = T)) +
labs(x = NULL,
fill = NULL) +
scale_fill_brewer(palette = "Set2") +
scale_x_discrete(labels = c("egg", "seedling", "sperm")) +
theme_minimal()+
theme(text = element_text(size = 18, face="bold")) +
theme(axis.text.x = element_text(colour="black", angle = 45, hjust = 1)) +
theme(axis.text.y = element_text(colour="black"))
ggsave(filename = "first_nucleotide_by_specificity.svg", width = 3, height = 5)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.