-
Notifications
You must be signed in to change notification settings - Fork 0
/
pegrna_alignment_strandedness.R
83 lines (81 loc) · 2.32 KB
/
pegrna_alignment_strandedness.R
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
source("pegrna_plots.R")
pegrna_alignment_strandedness <- function(sequence_name,
mix = NA,
start_offset = NA) {
plot_data <- get_pegrna_plot_data(
sequence_name = sequence_name,
normalization_factor = "grch38_mapped_reads",
mix = mix
)
counts_by_strand <-
tibble(
sequence_name = character(),
sample_unit = character(),
type = character(),
strand = character(),
count = numeric()
)
for (s in names(plot_data)) {
if (is.na(start_offset)) {
primary_granges <- plot_data[[s]][["concordant_granges"]]
primary_type <- "concordant"
secondary_granges <- plot_data[[s]][["discordant_granges"]]
secondary_type <- "discordant"
} else {
concordant_granges <- plot_data[[s]][["concordant_granges"]]
start_site <- GRanges(
seqnames = rna_species,
ranges = IRanges(
start = plot_range$start,
end = plot_range$start + start_offset
)
)
primary_granges <- subsetByOverlaps(concordant_granges, start_site)
primary_type <- "concordant_full"
secondary_granges <-
concordant_granges[concordant_granges %outside% start_site]
secondary_type <- "concordant_partial"
}
counts_by_strand <- rows_append(
counts_by_strand,
tibble(
sequence_name = sequence_name,
sample_unit = s,
type = primary_type,
strand = "+",
count = sum(strand(primary_granges) == "+")
)
)
counts_by_strand <- rows_append(
counts_by_strand,
tibble(
sequence_name = sequence_name,
sample_unit = s,
type = primary_type,
strand = "-",
count = sum(strand(primary_granges) == "-")
)
)
counts_by_strand <- rows_append(
counts_by_strand,
tibble(
sequence_name = sequence_name,
sample_unit = s,
type = secondary_type,
strand = "+",
count = sum(strand(primary_granges) == "+")
)
)
counts_by_strand <- rows_append(
counts_by_strand,
tibble(
sequence_name = sequence_name,
sample_unit = s,
type = secondary_type,
strand = "-",
count = sum(strand(primary_granges) == "-")
)
)
}
return(counts_by_strand)
}