-
Notifications
You must be signed in to change notification settings - Fork 0
/
G39.rmd
181 lines (143 loc) · 6.48 KB
/
G39.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---
title: "IGHV4-38-2/IGHV4-39"
output:
distill::distill_article:
toc: true
toc_float: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = F, error=F, message = F)
pacman::p_load('dplyr', 'tidyr', 'htmltools', 'bbplot',
'ggplot2', 'rdrop2', 'shiny', 'BiocManager',
'dendextend', 'data.table', 'Biostrings', 'alakazam', "unikn",
'plotly', 'ggdendro', "RColorBrewer", install = F)
```
```{r}
source("functions.R")
```
```{r, echo=FALSE}
load("data.rda")
chain = "IGH"
func <- data.frame(allele = names(vgerms[[chain]]), functionality = !grepl("(ORF|P)",sapply(seqinr::getAnnot(vgerms_full[[chain]]), function(x) unlist(strsplit(x,"[|]"))[4])), sign = sapply(seqinr::getAnnot(vgerms_full[[chain]]), function(x) unlist(strsplit(x,"[|]"))[4]), stringsAsFactors = F)
mat <- mat_list$IGH$functional$nonsingle$all$`318`
load("data_frac_new2.rda")
data <- setDT(data_frac$IGH$functional$nonsingle$all$`318`$complete$`95`)
data[,v_call:=paste0(v_gene,"*",v_allele)]
load("alleles_dbs.rda")
allele_db <- alleles_dbs$IGH$functional$nonsingle$all$`318`$complete$`95`
allele_db <- allele_db %>% dplyr::rowwise() %>% dplyr::mutate(gene = alakazam::getGene(or_allele, strip_d = F, omit_nl = F), group = strsplit(gsub(gene, "", new_allele),"[*]")[[1]][1], gene_group = alakazam::getGene(new_allele, strip_d = F, omit_nl = F))
load("functional_groups.rda")
func_groups <- functional_groups$IGH$functional$nonsingle$all$`318`$complete$`95`
cols <- c("#FAAB18", "#1380A1","#990000", "#588300")
pal <- cols %>%
newpal(names = c("orangy", "bluish", "redish", "greeny"))
edit_links <- readLines("edit_links.txt")
share_links <- readLines("share_links.txt")
```
```{r,echo=FALSE}
g_group = "IGHV4-38-2G39"
group = names(func_groups)[func_groups==g_group]
gr <- allele_db %>% filter(gene_group == g_group) %>% pull(group) %>% unique()
g <- allele_db %>% filter(gene_group == g_group) %>% pull(gene) %>% unique()
```
## Allele appearnce
The group of `r group` includes `r sum(grepl(paste0(g,"[*]", collapse = "|"), func$allele))` alleles, `r sum(func$functionality[grepl(paste0(g,"[*]", collapse = "|"), func$allele)])` out of the alleles are functional.
For each allele we counted the number of appearances across the population, any appearance was considered valid.
```{r}
allele_appearance(data, g_group)
```
## Group alignment
Based on the viewd alleles, we calculated the distance between the germline sequences.
```{r, fig.width=18,fig.height=30}
v_calls <- unique(data[grepl(g_group,v_gene),v_call])
seq_align(v_calls, allele_db, vgerms, chain, mat, g_group)
```
## Sequence depth
To examine the potential cutoff we observed the sequence depth for each allele
```{r}
sequence_depth(data, g_group)
```
## 0.5% cutoff
We set an initial cutoff of $0.5\%$ to determine the potential genotype priors. For this cutoff we examined the zygousity state, such as homozygousity, heterozygousity and so on.
```{r}
tmp_allele_db <-
allele_db %>% dplyr::filter(grepl(as.character(g_group), new_allele)) %>%
dplyr::group_by(new_allele) %>% dplyr::summarise(or_allele = paste0(or_allele, collapse = "/"))
or_allele <-
setNames(gsub(chain, "", as.character(tmp_allele_db$or_allele)), as.character(gsub(
paste0(g_group, "[*]"),
"",
tmp_allele_db$new_allele
)))
allele_thresh = 0.5
tmp <- data_cutoff(data, func_g_groups, g_group, allele_thresh, or_allele)
```
With the selected cutoff we saw that there are `r length(unique(tmp %>% arrange(zygousity_state) %>% pull(zygousity_state)))` zygousity states.
```{r, warning = F, error=F, message = F}
p_list <- c()
for(i in as.character(unique(tmp %>% dplyr::arrange(zygousity_state) %>% dplyr::pull(zygousity_state)))){
p_list[[i]] <- plot_zygousity(tmp, i, allele_thresh, g_group) %>% config(edits = list(shapePosition = TRUE),
scrollZoom = FALSE) %>% layout(title = paste0("state ", i))
#
}
tagList(p_list)
```
## Observations
This section is editable by clicking on the edit button below. To refresh the section click on the refresh button
You can access the file also from [here](`r edit_links[grep(g_group,edit_links)]`)
```{r, message=F, echo=F, warning=F}
knitr::include_url(paste0("https://peresay.shinyapps.io/G2_group/?group=",g_group))
# # Authenticate and save token for later use2
# token <- drop_auth(rdstoken = "dropbox_token.rds")
#
# # Retrieveing your file is as simple as
# drop_download("public/conclusions/IGHV1-2.docx", local_path = "docs/IGHV1-2.docx",
# overwrite = TRUE, verbose = FALSE, progress = FALSE)
# drop_df <- textreadr::read_docx("docs/IGHV1-2.docx")
# invisible(rmarkdown::pandoc_convert(input = "IGHV1-2.docx", to = "markdown", output = "IGHV1-2_docx.md", options = c("--wrap=none","--reference-links","--metadata-file=metadata.yaml","--standalone"), wd = "docs", verbose = FALSE))
#
# ui <- fluidPage(
#
# # Application title
# mainPanel(
# shiny::actionButton(inputId='ab1', label="Edit text",
# icon = icon("edit"),
# onclick ="window.open('https://www.dropbox.com/scl/fi/crphl3u49fmkw8wnb5v71/IGHV1-2.docx?dl=0&rlkey=l54oqhrlxx8wyp6bywr224sx0')"),
#
# shiny::actionButton(inputId='ab2', label="Reload text",
# icon = icon("sync-alt")),
#
# #htmlOutput("df_output"),
# uiOutput('markdown')
# )
# )
#
# server <- function(input, output) {
#
# observeEvent(input$ab2, {
# drop_download("public/conclusions/IGHV1-2.docx", local_path = "docs/IGHV1-2.docx",
# overwrite = TRUE, verbose = F)
# #drop_df <- textreadr::read_docx("docs/IGHV1-2.docx")
#
# rmarkdown::pandoc_convert(input = "IGHV1-2.docx", to = "markdown", output = "IGHV1-2_docx.md", options = c("--wrap=none","--reference-links","--metadata-file=metadata.yaml","--standalone"), wd = "docs", verbose = F)
# output$markdown <- renderUI({
# #withMathJax(includeMarkdown(knitr::knit('IGHV1-2_docx.md', quiet = TRUE)))
# HTML(markdown::markdownToHTML(knitr::knit('docs/IGHV1-2_docx.md', quiet = TRUE)))
# })
#
# })
#
# # output$df_output <- renderUI({
# # if(input$ab2) return()
# # HTML(paste(drop_df, collapse = "<br/><br/>"))
# # })
#
# output$markdown <- renderUI({
# #withMathJax(includeMarkdown(knitr::knit('docs/IGHV1-2_docx.md', quiet = TRUE)))
# HTML(markdown::markdownToHTML(knitr::knit('docs/IGHV1-2_docx.md', quiet = TRUE)))
# })
# }
#
# shinyApp(ui = ui, server = server)
```
## Conclusions