Browse code

Added support for lower case modbam tags

shians authored on 09/10/2023 06:15:35
Showing 6 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: NanoMethViz
2 2
 Type: Package
3 3
 Title: Visualise methlation data from Oxford Nanopore sequencing
4
-Version: 2.7.8
4
+Version: 2.7.9
5 5
 Authors@R: c(
6 6
     person("Shian", "Su", email = "[email protected]", role = c("cre", "aut")))
7 7
 Description: NanoMethViz is a toolkit for visualising methylation data from 
... ...
@@ -103,31 +103,31 @@ read_bam <- function(bam_file, query = NULL) {
103 103
             Rsamtools::ScanBamParam(
104 104
                 flag = Rsamtools::scanBamFlag(isUnmappedQuery = FALSE),
105 105
                 what = c("qname", "rname", "strand", "pos", "cigar", "seq"),
106
-                tag = c("MM", "ML"),
106
+                tag = c("MM", "ML", "Mm", "Ml"),
107 107
                 which = query
108 108
             )
109 109
         } else {
110 110
             Rsamtools::ScanBamParam(
111 111
                 flag = Rsamtools::scanBamFlag(isUnmappedQuery = FALSE),
112 112
                 what = c("qname", "rname", "strand", "pos", "cigar", "seq"),
113
-                tag = c("MM", "ML")
113
+                tag = c("MM", "ML", "Mm", "Ml")
114 114
             )
115 115
         }
116 116
     }
117 117
 
118
-    # determine_tag <- function(records) {
119
-    #     if (is.null(records$tag$Mm) && is.null(records$tag$Ml)) {
120
-    #         records$tag$Mm <- NULL
121
-    #         records$tag$Ml <- NULL
122
-    #     } else (is.null(records$tag$MM) && is.null(records$tag$ML)) {
123
-    #         records$tag$MM <- records$tag$Mm
124
-    #         records$tag$ML <- records$tag$Ml
125
-    #         records$tag$Mm <- NULL
126
-    #         records$tag$Ml <- NULL
127
-    #     }
128
-    #
129
-    #     records
130
-    # }
118
+    determine_tag <- function(records) {
119
+        if (is.null(records$tag$Mm) && is.null(records$tag$Ml)) {
120
+            records$tag$Mm <- NULL
121
+            records$tag$Ml <- NULL
122
+        } else {
123
+            records$tag$MM <- records$tag$Mm
124
+            records$tag$ML <- records$tag$Ml
125
+            records$tag$Mm <- NULL
126
+            records$tag$Ml <- NULL
127
+        }
128
+
129
+        records
130
+    }
131 131
 
132 132
     filter_modbam <- function(x) {
133 133
         tag <- x$tag
... ...
@@ -150,6 +150,7 @@ read_bam <- function(bam_file, query = NULL) {
150 150
         bam_file,
151 151
         param = modbam_param(query = query)
152 152
     ) %>%
153
+        map(determine_tag) %>%
153 154
         map(filter_modbam)
154 155
 }
155 156
 
... ...
@@ -81,7 +81,7 @@ plot_gene_annotation <- function(exons_df, plot_start, plot_end) {
81 81
     .filter_regions <- function(exons_df, plot_start, plot_end) {
82 82
         transcripts <- exons_df %>%
83 83
             dplyr::summarise(
84
-                .by = .data$transcript_id,
84
+                .by = "transcript_id",
85 85
                 start = min(.data$start),
86 86
                 end = max(.data$end)
87 87
             )
88 88
new file mode 100644
89 89
Binary files /dev/null and b/inst/peg3_lower_case.bam differ
90 90
new file mode 100644
91 91
Binary files /dev/null and b/inst/peg3_lower_case.bam.bai differ
... ...
@@ -2,6 +2,15 @@ test_that("Plotting gene works", {
2 2
     # setup
3 3
     nmr <- load_example_nanomethresult()
4 4
     mbr <- load_example_modbamresult()
5
+
6
+    mbr_lower <- load_example_modbamresult()
7
+    methy(mbr_lower) <- ModBamFiles(
8
+        paths = system.file(package = "NanoMethViz", "peg3_lower_case.bam"),
9
+        samples = "sample1"
10
+    )
11
+
12
+    data_list <- list(nmr, mbr, mbr_lower)
13
+
5 14
     params <- expand.grid(
6 15
         heatmap = c(TRUE, FALSE),
7 16
         spaghetti = c(TRUE, FALSE),
... ...
@@ -9,7 +18,7 @@ test_that("Plotting gene works", {
9 18
     )
10 19
 
11 20
     # test plot_gene() ----
12
-    for (x in list(nmr, mbr)) {
21
+    for (x in data_list) {
13 22
         expect_silent(p <- plot_gene(x, "Peg3"))
14 23
         expect_s3_class(p, "ggplot")
15 24
 
... ...
@@ -44,7 +53,7 @@ test_that("Plotting gene works", {
44 53
     }
45 54
 
46 55
     # test plot_region() ----
47
-    for (x in list(nmr, mbr)) {
56
+    for (x in data_list) {
48 57
         expect_silent(p <- plot_region(x, "chr7", 6703892, 6730431))
49 58
         expect_s3_class(p, "ggplot")
50 59
 
... ...
@@ -75,7 +84,7 @@ test_that("Plotting gene works", {
75 84
 
76 85
     # test plot_grange() ----
77 86
     grange <- GenomicRanges::GRanges("chr7:6703892-6730431")
78
-    for (x in list(nmr, mbr)) {
87
+    for (x in data_list) {
79 88
         for (i in 1:nrow(params)) {
80 89
             expect_silent(
81 90
                 p <- plot_grange(