Browse code

bugfixes

FelixErnst authored on 12/01/2021 15:58:00
Showing8 changed files

... ...
@@ -1,8 +1,8 @@
1 1
 Package: RNAmodR
2 2
 Type: Package
3 3
 Title: Detection of post-transcriptional modifications in high throughput sequencing data
4
-Version: 1.5.2
5
-Date: 2020-12-12
4
+Version: 1.5.3
5
+Date: 2021-01-12
6 6
 Authors@R: c(person("Felix G.M.", 
7 7
                     "Ernst", 
8 8
                     email = "felix.gm.ernst@outlook.com", 
... ...
@@ -149,8 +149,12 @@ importClassesFrom(Rsamtools,BamFileList)
149 149
 importClassesFrom(Rsamtools,PileupFiles)
150 150
 importFrom(BSgenome,seqnames)
151 151
 importFrom(BiocParallel,SerialParam)
152
+importFrom(BiocParallel,bpisup)
152 153
 importFrom(BiocParallel,bplapply)
153 154
 importFrom(BiocParallel,bpmapply)
155
+importFrom(BiocParallel,bpparam)
156
+importFrom(BiocParallel,bpstart)
157
+importFrom(BiocParallel,bpstop)
154 158
 importFrom(BiocParallel,register)
155 159
 importFrom(Biostrings,"seqtype<-")
156 160
 importFrom(Biostrings,DNAString)
... ...
@@ -12,3 +12,7 @@ Changes in version 1.3.5 (2020-08-30)
12 12
 
13 13
 Changes in version 1.5.2 (2020-12-12)
14 14
 + bugfix for names plotted by plotCompareByCoord
15
+
16
+Changes in version 1.5.3 (2021-01-12)
17
++ bugfix for zero-length annotation
18
++ bugfix for settings function
... ...
@@ -176,13 +176,15 @@ ModInosine <- function(x, annotation, sequences, seqinfo, ...){
176 176
 #' @rdname ModInosine-functions
177 177
 #' @export
178 178
 setReplaceMethod(f = "settings", 
179
-                 signature = signature(x = "ModInosine"),
180
-                 definition = function(x, value){
181
-                   x <- callNextMethod()
182
-                   value <- .norm_ModInosine_settings(value)
183
-                   x@settings[names(value)] <- unname(value)
184
-                   x
185
-                 })
179
+    signature = signature(x = "ModInosine"),
180
+    definition = function(x, value){
181
+        x <- callNextMethod()
182
+        names <- names(value)
183
+        value <- .norm_ModInosine_settings(value)
184
+        x <- .add_settings_value(x, value, names)
185
+        x
186
+    }
187
+)
186 188
 
187 189
 # functions --------------------------------------------------------------------
188 190
 
... ...
@@ -643,37 +643,51 @@ NULL
643 643
 
644 644
 #' @rdname settings
645 645
 #' @export
646
-setMethod(f = "settings",
647
-          signature = signature(x = "Modifier"),
648
-          definition = function(x, name){
649
-            if(missing(name) || is.null(name)){
650
-              return(x@settings)
651
-            }
652
-            if(!.is_a_string(name)){
653
-              stop("'name' must be a single character value.",
654
-                   call. = FALSE)
655
-            }
656
-            x@settings[[name]]
657
-          }
646
+setMethod(f = "settings", signature = signature(x = "Modifier"),
647
+    definition = function(x, name){
648
+        if(missing(name) || is.null(name)){
649
+            return(x@settings)
650
+        }
651
+        if(!.is_a_string(name)){
652
+            stop("'name' must be a single character value.",
653
+                 call. = FALSE)
654
+        }
655
+        x@settings[[name]]
656
+    }
658 657
 )
659 658
 
659
+.add_settings_value <- function(x, value, names){
660
+    if(is.null(names)){
661
+        names <- names(value)
662
+    } else {
663
+        names <- names[names %in% names(value)]
664
+    }
665
+    if(length(names) != 0L){
666
+        value <- value[names]
667
+        x@settings[names(value)] <- unname(value)
668
+    }
669
+    x
670
+}
671
+
660 672
 #' @rdname settings
661 673
 #' @export
662 674
 setReplaceMethod(f = "settings",
663
-                 signature = signature(x = "Modifier"),
664
-                 definition = function(x, value){
665
-                   if(is.null(names(value)) && length(value) > 0L){
666
-                     stop("'value' has to be a named.", call. = FALSE)
667
-                   }
668
-                   if(!is.list(value)){
669
-                     value <- as.list(value)
670
-                   }
671
-                   value <- .norm_Modifier_settings(value)
672
-                   x@settings[names(value)] <- unname(value)
673
-                   x@aggregateValidForCurrentArguments <- FALSE
674
-                   x@modificationsValidForCurrentArguments <- FALSE
675
-                   x
676
-                 })
675
+    signature = signature(x = "Modifier"),
676
+    definition = function(x, value){
677
+        if(is.null(names(value)) && length(value) > 0L){
678
+            stop("'value' has to be a named.", call. = FALSE)
679
+        }
680
+        if(!is.list(value)){
681
+            value <- as.list(value)
682
+        }
683
+        names <- names(value)
684
+        value <- .norm_Modifier_settings(value)
685
+        x <- .add_settings_value(x, value, names)
686
+        x@aggregateValidForCurrentArguments <- FALSE
687
+        x@modificationsValidForCurrentArguments <- FALSE
688
+        x
689
+    }
690
+)
677 691
 
678 692
 # constructors -----------------------------------------------------------------
679 693
 
... ...
@@ -710,9 +724,15 @@ setReplaceMethod(f = "settings",
710 724
       data = data)
711 725
 }
712 726
 
727
+#' @importFrom BiocParallel bpparam bpisup bpstart bpstop bpmapply bplapply
713 728
 .load_SequenceData <- function(classes, bamfiles, annotation, sequences,
714 729
                                seqinfo, args){
715 730
   if(is.list(classes)){
731
+    BPPARAM <- bpparam()
732
+    if (!(bpisup(BPPARAM) || is(BPPARAM, "MulticoreParam"))) {
733
+      bpstart(BPPARAM)
734
+      on.exit(bpstop(BPPARAM), add = TRUE)
735
+    }
716 736
     if(is.list(bamfiles)){
717 737
       if(length(classes) != length(bamfiles)){
718 738
         stop("'x' has invalid length. '",paste(classes, collapse = "' and '"),
... ...
@@ -730,13 +750,15 @@ setReplaceMethod(f = "settings",
730 750
              call. = FALSE)
731 751
       }
732 752
       bamfiles <- bamfiles[match(class,names(bamfiles))]
733
-      data <- BiocParallel::bpmapply(.load_SequenceData, classes, bamfiles,
734
-                                     MoreArgs = list(annotation, sequences,
735
-                                                     seqinfo, args),
736
-                                     SIMPLIFY = FALSE)
753
+      data <- bpmapply(.load_SequenceData, classes, bamfiles,
754
+                       MoreArgs = list(annotation, sequences,
755
+                                       seqinfo, args),
756
+                       SIMPLIFY = FALSE,
757
+                       BPPARAM = BPPARAM)
737 758
     } else {
738
-      data <- BiocParallel::bplapply(classes, .load_SequenceData, bamfiles,
739
-                                     annotation, sequences, seqinfo, args)
759
+      data <- bplapply(classes, .load_SequenceData, bamfiles,
760
+                       annotation, sequences, seqinfo, args,
761
+                       BPPARAM = BPPARAM)
740 762
     }
741 763
     data <- as(data,"SequenceDataList")
742 764
   } else if(is.character(classes)){
... ...
@@ -767,6 +789,7 @@ setReplaceMethod(f = "settings",
767 789
   }
768 790
   bamfiles <- .norm_bamfiles(x, className) # check bam files
769 791
   # settings
792
+  settings(proto) <- list()
770 793
   settings(proto) <- list(...)
771 794
   #
772 795
   annotation <- .norm_annotation(annotation, className)
... ...
@@ -786,6 +809,7 @@ setReplaceMethod(f = "settings",
786 809
   # create Modifier object
787 810
   ans <- .Modifier(className, x)
788 811
   # settings
812
+  settings(ans) <- list()
789 813
   settings(ans) <- list(...)
790 814
   # aggregate data
791 815
   message("Aggregating data and calculating scores ... ", appendLF = FALSE)
... ...
@@ -503,35 +503,48 @@ setMethod(f = "settings",
503 503
 #' @rdname settings
504 504
 #' @export
505 505
 setReplaceMethod(f = "settings", 
506
-                 signature = signature(x = "ModifierSet"),
507
-                 definition = function(x, value){
508
-                   for(i in seq_along(x)){
509
-                     settings(x[[i]]) <- value
510
-                   }
511
-                   x
512
-                 })
506
+    signature = signature(x = "ModifierSet"),
507
+    definition = function(x, value){
508
+        for(i in seq_along(x)){
509
+            settings(x[[i]]) <- value
510
+        }
511
+        x
512
+    }
513
+)
513 514
 
514 515
 # aggregate/modify -------------------------------------------------------------
515 516
 
516 517
 #' @rdname aggregate
518
+#' @importFrom BiocParallel bpparam bpisup bpstart bpstop bpmapply bplapply
517 519
 #' @export
518 520
 setMethod(f = "aggregate", 
519
-          signature = signature(x = "ModifierSet"),
520
-          definition = 
521
-            function(x, force = FALSE){
522
-              ans <- BiocParallel::bplapply(x,aggregate,force)
523
-              ans <- RNAmodR::ModifierSet(class(x),ans)
524
-              ans
525
-            }
521
+    signature = signature(x = "ModifierSet"),
522
+    definition = 
523
+    function(x, force = FALSE){
524
+        BPPARAM <- bpparam()
525
+        if (!(bpisup(BPPARAM) || is(BPPARAM, "MulticoreParam"))) {
526
+            bpstart(BPPARAM)
527
+            on.exit(bpstop(BPPARAM), add = TRUE)
528
+        }
529
+        ans <- BiocParallel::bplapply(x,aggregate,force,BPPARAM=BPPARAM)
530
+        ans <- RNAmodR::ModifierSet(class(x),ans)
531
+        ans
532
+    }
526 533
 )
527 534
 #' @rdname modify
535
+#' @importFrom BiocParallel bpparam bpisup bpstart bpstop bpmapply bplapply
528 536
 #' @export
529 537
 setMethod(f = "modify", 
530
-          signature = signature(x = "ModifierSet"),
531
-          definition = 
532
-            function(x, force = FALSE){
533
-              ans <- BiocParallel::bplapply(x,modify,force)
534
-              ans <- RNAmodR::ModifierSet(class(x),ans)
535
-              ans
536
-            }
538
+    signature = signature(x = "ModifierSet"),
539
+    definition = 
540
+    function(x, force = FALSE){
541
+        BPPARAM <- bpparam()
542
+        if (!(bpisup(BPPARAM) || is(BPPARAM, "MulticoreParam"))) {
543
+            bpstart(BPPARAM)
544
+            on.exit(bpstop(BPPARAM), add = TRUE)
545
+        }
546
+        ans <- BiocParallel::bplapply(x,modify,force,BPPARAM=BPPARAM)
547
+        ans <- RNAmodR::ModifierSet(class(x),ans)
548
+        ans
549
+    }
537 550
 )
... ...
@@ -51,6 +51,10 @@ NULL
51 51
 }
52 52
 
53 53
 .norm_annotation_GRangesList <- function(annotation){
54
+  annotation <- annotation[lengths(annotation)!= 0]
55
+  if(length(annotation) == 0L){
56
+    stop("'annotation' has a length == 0L.")
57
+  }
54 58
   if(is.null(names(annotation))){
55 59
     stop("Elements of 'annotation' GRangesList must be named.")
56 60
   }
... ...
@@ -48,6 +48,16 @@ test_that("Modifier/ModifierSet:",{
48 48
   actual <- settings(msi[[1]])
49 49
   expect_type(actual,"list")
50 50
   expect_named(actual,c("minCoverage","minReplicate","find.mod","minScore"))
51
+  expect_equal(actual[["find.mod"]],TRUE)
52
+  settings(msi[[1]]) <- list("find.mod" = FALSE)
53
+  settings(msi[[1]]) <- list("minReplicate" = 3L)
54
+  settings(msi[[1]]) <- list("minCoverage" = 20L)
55
+  actual <- settings(msi[[1]])
56
+  expect_equal(actual[["find.mod"]],FALSE)
57
+  expect_equal(actual[["minReplicate"]],3L)
58
+  expect_equal(actual[["minCoverage"]],20L)
59
+  rm(msi)
60
+  data(msi,package = "RNAmodR")
51 61
   # Modifier accessors
52 62
   expect_type(names(msi[[1]]),"character")
53 63
   expect_type(modifierType(msi[[1]]),"character")