-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork_combine-gtfs_processed-ncRNA_part-0.Rmd
185 lines (152 loc) · 4.71 KB
/
work_combine-gtfs_processed-ncRNA_part-0.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
182
183
184
185
---
title: "work_combine-gtfs_processed-ncRNA_part-0.Rmd"
author: "KA"
email: "[email protected]"
output:
html_notebook:
toc: yes
toc_float: true
---
## Get situated
### Code
<details>
<summary><i>Code: Get situated</i></summary>
```{r Get situated, results='hide', message=FALSE, warning=FALSE}
#!/usr/bin/env Rscript
library(GenomicRanges)
library(IRanges)
library(plyr)
library(readxl)
library(rtracklayer)
library(tidyverse)
options(scipen = 999)
options(ggrepel.max.overlaps = Inf)
if(base::isTRUE(stringr::str_detect(getwd(), "kalavattam"))) {
p_local <- "/Users/kalavattam/Dropbox/FHCC"
} else {
p_local <- "/Users/kalavatt/projects-etc"
}
p_wd <- "2022-2023_RRP6-NAB3/results/2023-0215"
setwd(paste(p_local, p_wd, sep = "/"))
getwd()
rm(p_local, p_wd)
```
</details>
<br />
<br />
## Load and combine `gtf`s
### Load `gtf` files [derived/"processed" from R64-1-1](./work_assess-process_R64-1-1_gff3_part-1.Rmd)
#### Code
<details>
<summary><i>Code: Load `gtf` files derived/"processed" from R64-1-1</i></summary>
```{r Load gtf files derived/processed from R64-1-1, results='hide', message=FALSE, warning=FALSE}
#!/usr/bin/env Rscript
read_processed_gtf <- function(file) {
tbl <- file %>%
rtracklayer::import() %>%
tibble::as_tibble() %>%
dplyr::select(-c(width, score, phase)) %>%
dplyr::rename(feature = type.1) %>%
dplyr::arrange(seqnames, start)
tbl[tbl == "NA"] <- NA_character_
return(tbl)
}
p_processed <- "./outfiles_gtf-gff3/comprehensive/S288C_reference_genome_R64-1-1_20110203"
f_gene <- "processed_gene_sense.gtf"
f_PG <- "processed_PG_sense.gtf"
f_snRNA <- "processed_snRNA_sense.gtf"
f_snoRNA <- "processed_snoRNA_sense.gtf"
f_TE <- "processed_TE_sense.gtf"
t_gene <- paste(p_processed, f_gene, sep = "/") %>% read_processed_gtf()
t_PG <- paste(p_processed, f_PG, sep = "/") %>% read_processed_gtf()
t_snRNA <- paste(p_processed, f_snRNA, sep = "/") %>% read_processed_gtf()
t_snoRNA <- paste(p_processed, f_snoRNA, sep = "/") %>% read_processed_gtf()
t_TE <- paste(p_processed, f_TE, sep = "/") %>% read_processed_gtf()
t_processed <- dplyr::bind_rows(t_gene, t_PG, t_snRNA, t_snoRNA, t_TE) %>%
dplyr::arrange(seqnames, start)
rm(p_processed, f_gene, f_PG, f_snRNA, f_snoRNA, f_TE)
rm(t_gene, t_PG, t_snRNA, t_snoRNA, t_TE)
```
</details>
<br />
### Load [ncRNA `gtf` file](./work_representative-non-coding-transcriptome_part-4.Rmd)
`#TODO` *Update the above link (if necessary)*
#### Code
<details>
<summary><i>Code: Load ncRNA `gtf` file</i></summary>
```{r}
#!/usr/bin/env Rscript
read_ncRNA_gtf <- function(file) {
tbl <- file %>%
rtracklayer::import() %>%
tibble::as_tibble() %>%
dplyr::select(-c(width, score, phase, liftOver)) %>%
dplyr::rename(feature = type.1) %>%
dplyr::mutate(
orf_classification = NA_character_,
source_id = NA_character_
) %>%
dplyr::arrange(seqnames, start)
return(tbl)
}
p_ncRNA <- "./outfiles_gtf-gff3/representation"
f_ncRNA <- "Greenlaw-et-al_ncRNAs.gtf"
t_ncRNA <- paste(p_ncRNA, f_ncRNA, sep = "/") %>% read_ncRNA_gtf()
rm(p_ncRNA, f_ncRNA)
```
</details>
<br />
### Row-bind the "processed" and ncRNA `gtf`s
<details>
<summary><i>Code: Row-bind the "processed" and ncRNA `gtf`s</i></summary>
```{r}
#!/usr/bin/env Rscript
t_bound <- dplyr::bind_rows(t_processed, t_ncRNA) %>%
dplyr::arrange(seqnames, start)
```
</details>
<br />
<br />
## Write out combined "processed" and ncRNA `gtf`
### Code
<details>
<summary><i>Code: Row-bind the "processed" and ncRNA `gtf`s</i></summary>
```{r}
#!/usr/bin/env Rscript
write_gtf <- function(x, y) {
# ...
# :param x: tibble
# :param y: outfile
# :return: NA
readr::write_tsv(
x,
y,
col_names = FALSE,
quote = "none",
escape = "none"
)
}
p_gtf <- "./outfiles_gtf-gff3/representation"
f_gtf <- "Greenlaw-et-al_representative-coding-ncRNA-transcriptome.gtf"
t_gtf <- t_bound %>%
dplyr::mutate(score = ".", frame = ".") %>%
dplyr::relocate(c("seqnames", "source", "type"), .before = "start") %>%
dplyr::relocate(c("score", "strand", "frame"), .after = "end") %>%
dplyr::mutate(
attribute = paste(
paste0("gene_id \"", gene_id, "\""),
paste0("transcript_id \"", transcript_id, "\""),
paste0("type \"", feature, "\""),
paste0("orf_classification \"", orf_classification, "\""),
paste0("source_id \"", source_id, "\""),
sep = "; "
)
) %>%
dplyr::select(
-c(gene_id, transcript_id, feature, orf_classification, source_id)
)
write_gtf(t_gtf, paste(p_gtf, f_gtf, sep = "/"))
rm(p_gtf, f_gtf)
```
</details>
<br />