-
Notifications
You must be signed in to change notification settings - Fork 1
/
3_Annotation_render.Rmd
executable file
·138 lines (111 loc) · 4.18 KB
/
3_Annotation_render.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
130
131
132
133
134
135
136
137
138
---
output:
flexdashboard::flex_dashboard:
self_contained: false
orientation: rows
params:
vt_file:
value: x
af_file:
value: x
title:
value: x
id_file:
value: x
pamsites:
value: x
startrange:
value: x
endrange:
value: x
title: "`r params$title`"
---
```{r setup, include=FALSE}
library(dplyr)
library(crosstalk)
library(DT)
```
Variant Allele Frequency (CRISPResso)
=======================================================================
Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
vt_full=readRDS(params$vt_file)
afch=readRDS(params$af_file)
pamsites=unlist(strsplit(as.character(params$pamsites),","))
startrange=as.numeric(params$startrange)
endrange=as.numeric(params$endrange)
newdt=left_join(afch[[params$id_file]],vt_full[[params$id_file]],by="af.id") %>%
mutate(Biallelic=case_when(
nchar(ALT)==1 & ALT!="-" ~ "Biallelic",
TRUE~"Indel/Multiallelic")) %>%
mutate(WithinRange=case_when(
(Start <= startrange|Start >= endrange)~"OutsideRange",
(End <= startrange|End >= endrange)~"OutsideRange",
TRUE~ "WithinRange")) %>%
mutate(AlignError=case_when(
grepl("-",Aligned) & (n_deleted==0)~"CRISPRessoError",
TRUE~"NoError")) %>%
group_by(af.id) %>%
mutate(TotalPAMSites = sum(unique(Start) %in% pamsites))%>%
mutate(PAMsite = case_when(
TotalPAMSites==length(pamsites) ~ paste(as.character(pamsites),collapse="|"),
TotalPAMSites==1 & any(Start %in% pamsites[1]) ~as.character(pamsites[1]),
TotalPAMSites==1 & any(Start %in% pamsites[2])~as.character(pamsites[2])
)) %>%
ungroup() %>%
dplyr::select(-TotalPAMSites) %>%
relocate(Aligned,.after=ALT) %>%
relocate(Reference,.after=Aligned) %>% distinct()
newdt1=filter(newdt,
PAMsite %in% c(paste(as.character(pamsites),collapse="|"),pamsites) &
AlignError=='NoError' & WithinRange=="WithinRange" & Biallelic=="Biallelic" &
n_deleted==0 & n_inserted==0 & Start!=startrange & Start!=endrange)
newdt2=newdt1 %>%
group_by(chr,Start,REF,ALT) %>%
summarize(Reads_total=sum(Reads_n),Reads_prop_total=sum(Reads_prop))
#shared_dt1=SharedData$new(afch[[params$id_file]],~af.id,group="id_subset")
#shared_dt2=SharedData$new(vt_full[[params$id_file]],~af.id,group="id_subset")
#shared_dt3=SharedData$new(newdt,~af.id,group="id_subset")
shared_dt3=SharedData$new(newdt)
####Create the boxes
bscols(
list(filter_slider("n_mutated", "Number of Mutations", shared_dt3, ~n_mutated),
filter_slider("n_deletions", "Number of Deletions", shared_dt3, ~n_deleted),
filter_slider("n_inserted", "Number of Insertions", shared_dt3, ~n_inserted),
filter_checkbox('PAMsite',"PAM site mutations",shared_dt3,~PAMsite),
filter_checkbox("WithinRange", "Within Expected Range", shared_dt3, ~WithinRange),
filter_checkbox("Biallelic", "Biallelic", shared_dt3, ~Biallelic),
filter_checkbox("AlignError", "Alignment Error", shared_dt3, ~AlignError)
)
)
```
Column
-----------------------------------------------------------------------
```{r}
DT::datatable(shared_dt3,rownames=F,fillContainer = F,
extensions="Buttons",
options=list( dom = 'Bfrtip', deferRender=TRUE,
columnDefs = list(list(width = '200px', targets = "_all")))) %>%
formatRound('Reads_prop', 3)
```
Final Table
=======================================================================
```{r}
DT::datatable(newdt1,rownames=F,fillContainer = F,
extensions="Buttons",
caption = 'Table 1: Final Filtered Allele IDs',
options=list( dom = 'Bfrtip', deferRender=TRUE,
columnDefs = list(list(width = '200px', targets = "_all")))) %>%
formatRound('Reads_prop', 3)
```
Row
-----------------------------------------------------------------------
```{r}
DT::datatable(newdt2,rownames=F,fillContainer = F,
extensions="Buttons",
caption = 'Table 2: Summed Reads by Common SNVs',
options=list( dom = 'Bfrtip', deferRender=TRUE,
columnDefs = list(list(width = '200px', targets = "_all")))) %>%
formatRound('Reads_prop_total', 3)
```