Browse code

Get RNAmodR ready for the switch to virtual DataFrame (in S4Vectors package)

Hervé Pagès authored on 05/11/2021 01:34:40
Showing1 changed files
... ...
@@ -226,7 +226,8 @@ setClass("Modifier",
226 226
                    settings = "list",
227 227
                    aggregateValidForCurrentArguments = "logical",
228 228
                    modificationsValidForCurrentArguments = "logical"),
229
-         prototype = list(aggregateValidForCurrentArguments = FALSE,
229
+         prototype = list(aggregate = new("CompressedSplitDFrameList"),
230
+                          aggregateValidForCurrentArguments = FALSE,
230 231
                           modificationsValidForCurrentArguments = FALSE))
231 232
 
232 233
 # validity ---------------------------------------------------------------------
Browse code

internal bugfix for "length > 1 in coercion to logical"

FelixErnst authored on 27/07/2021 19:21:18
Showing1 changed files
... ...
@@ -249,7 +249,7 @@ setClass("Modifier",
249 249
          "required", call. = FALSE)
250 250
   }
251 251
   elementTypes <- elementTypes[match(elementTypes,dataType(x))]
252
-  if(is.na(elementTypes) || any(elementTypes != dataType(x))){
252
+  if(any(is.na(elementTypes)) || any(elementTypes != dataType(x))){
253 253
     stop("Type of SequenceData elements does not match the requirements of ",
254 254
          class(x),". '",paste(dataType(x), collapse = "','"),"' are ",
255 255
          "required", call. = FALSE)
Browse code

bugfixes

FelixErnst authored on 12/01/2021 15:58:00
Showing1 changed files
... ...
@@ -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)
Browse code

reworked dependent on assertive package

FelixErnst authored on 18/07/2020 08:13:55
Showing1 changed files
... ...
@@ -302,10 +302,10 @@ setClass("Modifier",
302 302
   if(is(seqdata,"SequenceData")){
303 303
     seqdata <- list(seqdata)
304 304
   }
305
-  if(!assertive::is_a_bool(x@aggregateValidForCurrentArguments)){
305
+  if(!.is_a_bool(x@aggregateValidForCurrentArguments)){
306 306
     return("Invalid slot: 'aggregateValidForCurrentArguments'")
307 307
   }
308
-  if(!assertive::is_a_bool(x@aggregateValidForCurrentArguments)){
308
+  if(!.is_a_bool(x@aggregateValidForCurrentArguments)){
309 309
     return("Invalid slot: 'modificationsValidForCurrentArguments'")
310 310
   }
311 311
   if(hasAggregateData(x)){
... ...
@@ -448,8 +448,9 @@ setMethod(f = "modifications",
448 448
           signature = signature(x = "Modifier"),
449 449
           definition =
450 450
             function(x, perTranscript = FALSE){
451
-              if(!assertive::is_a_bool(perTranscript)){
452
-                stop("'perTranscript' has to be a single logical value.")
451
+              if(!.is_a_bool(perTranscript)){
452
+                stop("'perTranscript' has to be a single logical value.",
453
+                     call. = FALSE)
453 454
               }
454 455
               valid <- c(validAggregate(x), validModification(x))
455 456
               if(!all(valid)){
... ...
@@ -554,7 +555,7 @@ setMethod(f = "sequences",
554 555
           signature = signature(x = "Modifier"),
555 556
           definition =
556 557
             function(x, modified = FALSE){
557
-              if(!assertive::is_a_bool(modified)){
558
+              if(!.is_a_bool(modified)){
558 559
                 stop("'modified' has to be a single logical value.",
559 560
                      call. = FALSE)
560 561
               }
... ...
@@ -648,8 +649,9 @@ setMethod(f = "settings",
648 649
             if(missing(name) || is.null(name)){
649 650
               return(x@settings)
650 651
             }
651
-            if(!assertive::is_a_string(name)){
652
-              stop("'name' must be a single character value.")
652
+            if(!.is_a_string(name)){
653
+              stop("'name' must be a single character value.",
654
+                   call. = FALSE)
653 655
             }
654 656
             x@settings[[name]]
655 657
           }
... ...
@@ -975,7 +977,10 @@ setMethod(f = "aggregate",
975 977
           signature = signature(x = "Modifier"),
976 978
           definition =
977 979
             function(x, force = FALSE){
978
-              assertive::assert_is_a_bool(force)
980
+              if(!.is_a_bool(force)){
981
+                stop("'force' has to be TRUE or FALSE.",
982
+                     call. = FALSE)
983
+              }
979 984
               if(!hasAggregateData(x) || force){
980 985
                 x@aggregate <- .check_aggregate_modifier(aggregateData(x), x)
981 986
                 x@aggregateValidForCurrentArguments <- TRUE
... ...
@@ -1065,7 +1070,10 @@ setMethod(f = "modify",
1065 1070
           signature = signature(x = "Modifier"),
1066 1071
           definition =
1067 1072
             function(x, force = FALSE){
1068
-              assertive::assert_is_a_bool(force)
1073
+              if(!.is_a_bool(force)){
1074
+                stop("'force' has to be TRUE or FALSE.",
1075
+                     call. = FALSE)
1076
+              }
1069 1077
               if(!validAggregate(x) | force){
1070 1078
                 x <- aggregate(x, force = TRUE)
1071 1079
               }
Browse code

added additional check for options input

FelixErnst authored on 25/01/2020 11:57:45
Showing1 changed files
... ...
@@ -661,7 +661,7 @@ setReplaceMethod(f = "settings",
661 661
                  signature = signature(x = "Modifier"),
662 662
                  definition = function(x, value){
663 663
                    if(is.null(names(value)) && length(value) > 0L){
664
-                     stop("'value' has to be a named.")
664
+                     stop("'value' has to be a named.", call. = FALSE)
665 665
                    }
666 666
                    if(!is.list(value)){
667 667
                      value <- as.list(value)
Browse code

small bugfixes

FelixErnst authored on 25/11/2019 23:05:39
Showing1 changed files
... ...
@@ -791,11 +791,9 @@ setReplaceMethod(f = "settings",
791 791
   # search for modifications
792 792
   if(settings(ans,"find.mod")){
793 793
     if(seqtype(ans) == seqtype(RNAString())){
794
-      f <- which(Modstrings::shortName(Modstrings::ModRNAString()) %in% modType(ans))
795
-      modName <- Modstrings::fullName(Modstrings::ModRNAString())[f]
794
+      modName <- .get_modification_full_name(ans,seqtype(ans))
796 795
     } else if(seqtype(ans) == seqtype(DNAString())){
797
-      f <- which(Modstrings::shortName(Modstrings::ModDNAString()) %in% modType(ans))
798
-      modName <- Modstrings::fullName(Modstrings::ModDNAString())[f]
796
+      modName <- .get_modification_full_name(ans,seqtype(ans))
799 797
     } else {
800 798
       stop("")
801 799
     }
Browse code

Removed fixed RNA focus for Modifier and SequenceData* classes

All classes can now be used to detect RNA and DNA modification. For this the seqtype slot was added to Modifier class via inheritance to RNAModifier and DNAModifier classes. seqtype getter is available for Modifier class, and getter/setter for SequenceData* classes.

Felix Ernst authored on 27/09/2019 16:13:26
Showing1 changed files
... ...
@@ -23,8 +23,13 @@ invalidMessage <- paste0("Settings were changed after data aggregation or ",
23 23
 #' Each subclass has to implement the following functions:
24 24
 #'
25 25
 #' \itemize{
26
-#' \item{\code{\link{aggregateData}}: }{used for specific data aggregation}
27
-#' \item{\code{\link{findMod}}: }{used for specific search for modifications}
26
+#' \item{Slot \code{nucleotide}: } {Either "RNA" or "DNA". For conveniance the
27
+#' subclasses \code{RNAModifier} and \code{DNAModifier} are already available
28
+#' and can be inherited from.}
29
+#' \item{Function \code{\link{aggregateData}}: }{used for specific data 
30
+#' aggregation}
31
+#' \item{Function \code{\link{findMod}}: }{used for specific search for 
32
+#' modifications}
28 33
 #' }
29 34
 #'
30 35
 #' Optionally the function \code{\link[=Modifier-functions]{settings<-}} can be
... ...
@@ -106,9 +111,12 @@ invalidMessage <- paste0("Settings were changed after data aggregation or ",
106 111
 #' objects, if \code{x} is not a \code{SequenceData} object or a list of
107 112
 #' \code{SequenceData} objects.
108 113
 #'
114
+#' @slot nucleotide a \code{character} value, which needs to contain "RNA" or 
115
+#' "DNA"
109 116
 #' @slot mod a \code{character} value, which needs to contain one or more
110 117
 #' elements from the alphabet of a
111
-#' \code{\link[Modstrings:ModRNAString]{ModRNAString}} class.
118
+#' \code{\link[Modstrings:ModRNAString]{ModRNAString}} or 
119
+#' \code{\link[Modstrings:ModDNAString]{ModDNAString}} class.
112 120
 #' @slot score the main score identifier used for visualizations
113 121
 #' @slot dataType the class name(s) of the \code{SequenceData} class used
114 122
 #' @slot bamfiles the input bam files as \code{BamFileList}
... ...
@@ -145,8 +153,9 @@ NULL
145 153
 #'
146 154
 #' @param x,object a \code{Modifier} or \code{ModifierSet} class
147 155
 #' @param modified For \code{sequences}: \code{TRUE} or \code{FALSE}: Should
148
-#' the sequences be returned as a \code{ModRNAString} with the found
149
-#' modifications added on top of the \code{RNAString}? See
156
+#' the sequences be returned as a \code{ModRNAString}/\code{ModDNAString} with
157
+#' the found modifications added on top of the \code{RNAString}/
158
+#' \code{DNAString}? See 
150 159
 #' \code{\link[Modstrings:separate]{combineIntoModstrings}}.
151 160
 #' @param perTranscript \code{TRUE} or \code{FALSE}: Should the positions shown
152 161
 #' per transcript? (default: \code{perTranscript = FALSE})
... ...
@@ -156,6 +165,10 @@ NULL
156 165
 #' \itemize{
157 166
 #' \item{\code{modifierType}:} {a character vector with the appropriate class
158 167
 #' Name of a \code{\link[=Modifier-class]{Modifier}}.}
168
+#' \item{\code{modType}:} {a character vector with the modifications detected by
169
+#' the \code{Modifier} class.}
170
+#' \item{\code{seqtype}:} {a single character value defining if either
171
+#' "RNA" or "DNA" modifications are detected by the \code{Modifier} class.}
159 172
 #' \item{\code{mainScore}:} {a character vector.}
160 173
 #' \item{\code{sequenceData}:} {a \code{SequenceData} object.}
161 174
 #' \item{\code{modifications}:} {a \code{GRanges} or \code{GRangesList} object
... ...
@@ -177,7 +190,9 @@ NULL
177 190
 #' data(msi,package="RNAmodR")
178 191
 #' mi <- msi[[1]]
179 192
 #' modifierType(mi) # The class name of the Modifier object
180
-#' modifierType(msi) #
193
+#' modifierType(msi)
194
+#' seqtype(mi)
195
+#' modType(mi)
181 196
 #' mainScore(mi)
182 197
 #' sequenceData(mi)
183 198
 #' modifications(mi)
... ...
@@ -198,7 +213,8 @@ setClassUnion("list_OR_BamFileList",
198 213
 #' @export
199 214
 setClass("Modifier",
200 215
          contains = c("VIRTUAL"),
201
-         slots = c(mod = "character", # this have to be populated by subclass
216
+         slots = c(seqtype = "character", # this have to be populated by subclass,
217
+                   mod = "character", # this have to be populated by subclass
202 218
                    score = "character", # this have to be populated by subclass
203 219
                    dataType = "list_OR_character", # this have to be populated by subclass
204 220
                    bamfiles = "list_OR_BamFileList",
... ...
@@ -265,7 +281,18 @@ setClass("Modifier",
265 281
 }
266 282
 
267 283
 .valid_Modifier <- function(x){
284
+  if(is.null(x@seqtype)){
285
+    return("'seqtype' slot not populated.")
286
+  }
287
+  if(!.is_valid_nucleotide_seqtype(seqtype(x))){
288
+    return(paste0("'seqtype' slot must contain the character value '",
289
+                  seqtype(RNAString()),"' or '",seqtype(DNAString()),"'."))
290
+  }
268 291
   seqdata <- x@data
292
+  if(seqtype(x) != seqtype(seqdata)){
293
+    return("'seqtype' does not match seqtype() of SequenceData contained ",
294
+           "within Modifier object.")
295
+  }
269 296
   if(is.list(x@bamfiles)){
270 297
     test <- !vapply(x@bamfiles,is,logical(1),"BamFileList")
271 298
     if(any(test)){
... ...
@@ -345,7 +372,9 @@ setMethod(
345 372
         "with",length(object@data),"elements.\n")
346 373
     files <- BiocGenerics::path(object@bamfiles)
347 374
     cat("| Input files:\n",paste0("  - ",names(files),": ",files,"\n"))
348
-    cat("| Modification type(s): ",paste0(object@mod, collapse = " / "),"\n")
375
+    cat("| Nucleotide - Modification type(s): ",
376
+        paste0(seqtype(object), collapse = " / ")," - ",
377
+        paste0(modType(object), collapse = " / "),"\n")
349 378
     cat("| Modifications found:",ifelse(length(object@modifications) != 0L,
350 379
                                       paste0("yes (",
351 380
                                              length(object@modifications),
... ...
@@ -377,6 +406,7 @@ setMethod(
377 406
 setMethod(f = "bamfiles",
378 407
           signature = signature(x = "Modifier"),
379 408
           definition = function(x){x@bamfiles})
409
+
380 410
 #' @rdname Modifier-functions
381 411
 #' @export
382 412
 setMethod(f = "conditions",
... ...
@@ -384,6 +414,7 @@ setMethod(f = "conditions",
384 414
           definition = function(object){
385 415
             object@condition
386 416
           })
417
+
387 418
 #' @rdname Modifier-functions
388 419
 #' @export
389 420
 setMethod(f = "mainScore",
... ...
@@ -430,31 +461,37 @@ setMethod(f = "modifications",
430 461
               x@modifications
431 462
             }
432 463
 )
464
+
433 465
 #' @rdname Modifier-functions
434 466
 #' @export
435 467
 setMethod(f = "modifierType",
436 468
           signature = signature(x = "Modifier"),
437
-          definition = function(x){class(x)[[1]]})
469
+          definition = function(x){class(x)[[1L]]})
470
+
438 471
 #' @rdname Modifier-functions
439 472
 #' @export
440 473
 setMethod(f = "modType",
441 474
           signature = signature(x = "Modifier"),
442 475
           definition = function(x){x@mod})
476
+
443 477
 #' @rdname Modifier-functions
444 478
 #' @export
445 479
 setMethod(f = "dataType",
446 480
           signature = signature(x = "Modifier"),
447 481
           definition = function(x){x@dataType})
482
+
448 483
 #' @rdname Modifier-functions
449 484
 #' @export
450 485
 setMethod(f = "names",
451 486
           signature = signature(x = "Modifier"),
452 487
           definition = function(x){names(sequenceData(x))})
488
+
453 489
 #' @rdname Modifier-functions
454 490
 #' @export
455 491
 setMethod(f = "ranges",
456 492
           signature = signature(x = "Modifier"),
457 493
           definition = function(x){ranges(sequenceData(x))})
494
+
458 495
 #' @rdname Modifier-functions
459 496
 #' @export
460 497
 setMethod(f = "replicates",
... ...
@@ -462,11 +499,55 @@ setMethod(f = "replicates",
462 499
           definition = function(x){
463 500
             x@replicate
464 501
           })
502
+
503
+#' @rdname Modifier-functions
504
+#' @export
505
+setMethod(f = "seqinfo",
506
+          signature = signature(x = "Modifier"),
507
+          definition = function(x){seqinfo(sequenceData(x))}
508
+)
509
+
510
+#' @rdname Modifier-functions
511
+#' @export
512
+setMethod(f = "seqtype",
513
+          signature = signature(x = "Modifier"),
514
+          definition = function(x){x@seqtype}
515
+)
516
+
465 517
 #' @rdname Modifier-functions
466 518
 #' @export
467 519
 setMethod(f = "sequenceData",
468 520
           signature = signature(x = "Modifier"),
469 521
           definition = function(x){x@data})
522
+
523
+.get_modified_sequences <- function(x, modified){
524
+  if(is(x,"Modifier")){
525
+    seqData <- sequenceData(x)
526
+  } else if(is(x,"ModifierSet")) {
527
+    seqData <- sequenceData(x[[1L]])
528
+  } else {
529
+    stop("")
530
+  }
531
+  if(!modified){
532
+    return(sequences(seqData))
533
+  }
534
+  mod <- .get_modifications_per_transcript(x)
535
+  mod <- .rebase_seqnames(mod, mod$Parent)
536
+  mod <- split(mod,factor(mod$Parent, levels = mod$Parent))
537
+  if(seqtype(x) == seqtype(RNAString())){
538
+    ans <- ModRNAStringSet(sequences(seqData))
539
+  } else if(seqtype(x) == seqtype(DNAString())){
540
+    ans <- ModDNAStringSet(sequences(seqData))
541
+  } else {
542
+    stop("")
543
+  }
544
+  modSeqList <- ans[names(ans) %in% names(mod)]
545
+  mod <- mod[match(names(mod),names(modSeqList))]
546
+  ans[names(ans) %in% names(mod)] <-
547
+    Modstrings::combineIntoModstrings(modSeqList, mod)
548
+  ans
549
+}
550
+
470 551
 #' @rdname Modifier-functions
471 552
 #' @export
472 553
 setMethod(f = "sequences",
... ...
@@ -477,32 +558,17 @@ setMethod(f = "sequences",
477 558
                 stop("'modified' has to be a single logical value.",
478 559
                      call. = FALSE)
479 560
               }
480
-              if(!modified){
481
-                return(sequences(sequenceData(x)))
482
-              }
483
-              mod <- .get_modifications_per_transcript(x)
484
-              mod <- .rebase_seqnames(mod, mod$Parent)
485
-              mod <- split(mod,factor(mod$Parent, levels = mod$Parent))
486
-              ans <- ModRNAStringSet(sequences(sequenceData(x)))
487
-              modSeqList <- ans[names(ans) %in% names(mod)]
488
-              mod <- mod[match(names(mod),names(modSeqList))]
489
-              ans[names(ans) %in% names(mod)] <-
490
-                Modstrings::combineIntoModstrings(modSeqList, mod)
491
-              ans
561
+              .get_modified_sequences(x, modified)
492 562
             }
493 563
 )
494
-#' @rdname Modifier-functions
495
-#' @export
496
-setMethod(f = "seqinfo",
497
-          signature = signature(x = "Modifier"),
498
-          definition = function(x){seqinfo(sequenceData(x))}
499
-)
564
+
500 565
 #' @rdname Modifier-functions
501 566
 #' @export
502 567
 setMethod(f = "validAggregate",
503 568
           signature = signature(x = "Modifier"),
504 569
           definition = function(x) x@aggregateValidForCurrentArguments
505 570
 )
571
+
506 572
 #' @rdname Modifier-functions
507 573
 #' @export
508 574
 setMethod(f = "validModification",
... ...
@@ -635,7 +701,7 @@ setReplaceMethod(f = "settings",
635 701
   replicate <- replicates[m]
636 702
   # create Modifier object
637 703
   new(className,
638
-      mod = .norm_mod(proto@mod, className),
704
+      mod = .norm_mod(proto),
639 705
       bamfiles = bamfiles,
640 706
       condition = condition,
641 707
       replicate = replicate,
... ...
@@ -695,7 +761,7 @@ setReplaceMethod(f = "settings",
695 761
   proto <- new(className)
696 762
   # short cut for creating an empty object
697 763
   if(is.null(x)){
698
-    return(new2(className, mod = .norm_mod(proto@mod, className)))
764
+    return(new2(className, mod = .norm_mod(proto)))
699 765
   }
700 766
   bamfiles <- .norm_bamfiles(x, className) # check bam files
701 767
   # settings
... ...
@@ -709,7 +775,8 @@ setReplaceMethod(f = "settings",
709 775
   # get SequenceData
710 776
   data <- .load_SequenceData(dataType(proto), bamfiles = bamfiles,
711 777
                              annotation = annotation, sequences = sequences,
712
-                             seqinfo = seqinfo, args = settings(proto))
778
+                             seqinfo = seqinfo,
779
+                             args = list(settings(proto),seqtype(proto)))
713 780
   .new_ModFromSequenceData(className, data, ...)
714 781
 }
715 782
 
... ...
@@ -723,8 +790,15 @@ setReplaceMethod(f = "settings",
723 790
   ans <- aggregate(ans)
724 791
   # search for modifications
725 792
   if(settings(ans,"find.mod")){
726
-    f <- which(Modstrings::shortName(Modstrings::ModRNAString()) %in% ans@mod)
727
-    modName <- Modstrings::fullName(Modstrings::ModRNAString())[f]
793
+    if(seqtype(ans) == seqtype(RNAString())){
794
+      f <- which(Modstrings::shortName(Modstrings::ModRNAString()) %in% modType(ans))
795
+      modName <- Modstrings::fullName(Modstrings::ModRNAString())[f]
796
+    } else if(seqtype(ans) == seqtype(DNAString())){
797
+      f <- which(Modstrings::shortName(Modstrings::ModDNAString()) %in% modType(ans))
798
+      modName <- Modstrings::fullName(Modstrings::ModDNAString())[f]
799
+    } else {
800
+      stop("")
801
+    }
728 802
     message("Starting to search for '", paste(tools::toTitleCase(modName),
729 803
                                               collapse = "', '"),
730 804
             "' ... ", appendLF = FALSE)
... ...
@@ -1013,3 +1087,17 @@ setMethod(f = "findMod",
1013 1087
                    '",class(x),"'.",call. = FALSE)
1014 1088
             }
1015 1089
 )
1090
+
1091
+# RNAModifier and DNAModifier --------------------------------------------------
1092
+
1093
+#' @rdname Modifier-class
1094
+#' @export
1095
+setClass("RNAModifier",
1096
+         contains = c("VIRTUAL","Modifier"),
1097
+         prototype = list(seqtype = seqtype(RNAString())))
1098
+
1099
+#' @rdname Modifier-class
1100
+#' @export
1101
+setClass("DNAModifier",
1102
+         contains = c("VIRTUAL","Modifier"),
1103
+         prototype = list(seqtype = seqtype(DNAString())))
Browse code

Imports updated and dataType function added for SequenceData/Frame class

Felix Ernst authored on 10/07/2019 12:07:41
Showing1 changed files
... ...
@@ -337,7 +337,6 @@ S4Vectors::setValidity2(Class = "Modifier", .valid_Modifier)
337 337
 }
338 338
 
339 339
 #' @rdname Modifier-functions
340
-#' @importFrom BiocGenerics path
341 340
 setMethod(
342 341
   f = "show",
343 342
   signature = signature(object = "Modifier"),
Browse code

refactored results of conditions and replicates functions

refactored results of conditions and replicates of SequenceDataSet and SequenceDataList

Felix Ernst authored on 31/05/2019 11:52:50
Showing1 changed files
... ...
@@ -627,12 +627,19 @@ setReplaceMethod(f = "settings",
627 627
   proto <- new(className)  # create prototype object for mod normalization only
628 628
   data <- .norm_Modifier_input_SequenceData_elements(data, proto)
629 629
   bamfiles <- bamfiles(data)
630
-  condition <- factor(names(bamfiles))
630
+  # setup conditions and replicates
631
+  conditions <- .norm_conditions(data)
632
+  replicates <- .norm_replicates(data)
633
+  ia <- as.integer(interaction(conditions,replicates))
634
+  m <- match(unique(ia),ia)
635
+  condition <- conditions[m]
636
+  replicate <- replicates[m]
637
+  # create Modifier object
631 638
   new(className,
632 639
       mod = .norm_mod(proto@mod, className),
633 640
       bamfiles = bamfiles,
634 641
       condition = condition,
635
-      replicate = .get_replicate_number(condition),
642
+      replicate = replicate,
636 643
       data = data)
637 644
 }
638 645
 
Browse code

added support for c, cbind, rbind and relist function for SequenceData objects

Felix Ernst authored on 30/05/2019 22:25:57
Showing1 changed files
... ...
@@ -383,7 +383,7 @@ setMethod(f = "bamfiles",
383 383
 setMethod(f = "conditions",
384 384
           signature = signature(object = "Modifier"),
385 385
           definition = function(object){
386
-            conditions(sequenceData(object))
386
+            object@condition
387 387
           })
388 388
 #' @rdname Modifier-functions
389 389
 #' @export
... ...
@@ -461,7 +461,7 @@ setMethod(f = "ranges",
461 461
 setMethod(f = "replicates",
462 462
           signature = signature(x = "Modifier"),
463 463
           definition = function(x){
464
-            replicates(sequenceData(x))
464
+            x@replicate
465 465
           })
466 466
 #' @rdname Modifier-functions
467 467
 #' @export
... ...
@@ -628,12 +628,12 @@ setReplaceMethod(f = "settings",
628 628
   data <- .norm_Modifier_input_SequenceData_elements(data, proto)
629 629
   bamfiles <- bamfiles(data)
630 630
   condition <- factor(names(bamfiles))
631
-  new2(className,
632
-       mod = .norm_mod(proto@mod, className),
633
-       bamfiles = bamfiles,
634
-       condition = condition,
635
-       replicate = .get_replicate_number(bamfiles, condition),
636
-       data = data)
631
+  new(className,
632
+      mod = .norm_mod(proto@mod, className),
633
+      bamfiles = bamfiles,
634
+      condition = condition,
635
+      replicate = .get_replicate_number(condition),
636
+      data = data)
637 637
 }
638 638
 
639 639
 .load_SequenceData <- function(classes, bamfiles, annotation, sequences,
Browse code

refactored SequenceData and SequenceDataFrame classes

Felix Ernst authored on 30/05/2019 11:33:10
Showing1 changed files
... ...
@@ -283,7 +283,7 @@ setClass("Modifier",
283 283
   }
284 284
   if(hasAggregateData(x)){
285 285
     data <- getAggregateData(x)
286
-    if(is.null(rownames(data@unlistData))){
286
+    if(is.null(rownames(unlist(data, use.names = FALSE)))){
287 287
       return("rownames of aggregate data is not set.")
288 288
     } else {
289 289
       seqs <- .seqs_rl_strand(ranges(x))
... ...
@@ -871,7 +871,7 @@ NULL
871 871
 .check_aggregate_modifier <- function(data, x){
872 872
   score <- x@score
873 873
   if(is(data,"CompressedSplitDataFrameList")){
874
-    columns <- colnames(data@unlistData)
874
+    columns <- colnames(unlist(data, use.names = FALSE))
875 875
   } else {
876 876
     stop("aggregate data has to be a 'CompressedSplitDataFrameList' object. ",
877 877
          "Contact the maintainer of the class used.",
Browse code

refactored input checks

Felix Ernst authored on 24/05/2019 19:33:06
Showing1 changed files
... ...
@@ -3,6 +3,7 @@
3 3
 #' @include SequenceDataSet-class.R
4 4
 #' @include SequenceDataList-class.R
5 5
 #' @include Modifier-utils.R
6
+#' @include settings.R
6 7
 NULL
7 8
 
8 9
 invalidMessage <- paste0("Settings were changed after data aggregation or ",
... ...
@@ -120,7 +121,7 @@ invalidMessage <- paste0("Settings were changed after data aggregation or ",
120 121
 #' \code{dataType} is used.
121 122
 #' @slot aggregate the aggregated data as a \code{SplitDataFrameList}
122 123
 #' @slot modifications the found modifications as a \code{GRanges} object
123
-#' @slot arguments arguments used for the analysis as a \code{list}
124
+#' @slot settings arguments used for the analysis as a \code{list}
124 125
 #' @slot aggregateValidForCurrentArguments \code{TRUE} or \code{FALSE} whether
125 126
 #' the aggregate data was constructed with the current arguments
126 127
 #' @slot modificationsValidForCurrentArguments \code{TRUE} or \code{FALSE}
... ...
@@ -206,7 +207,7 @@ setClass("Modifier",
206 207
                    data = "SD_or_SDS_or_SDL",
207 208
                    aggregate = "CompressedSplitDataFrameList",
208 209
                    modifications = "GRanges",
209
-                   arguments = "list",
210
+                   settings = "list",
210 211
                    aggregateValidForCurrentArguments = "logical",
211 212
                    modificationsValidForCurrentArguments = "logical"),
212 213
          prototype = list(aggregateValidForCurrentArguments = FALSE,
... ...
@@ -495,40 +496,8 @@ setMethod(f = "sequences",
495 496
 #' @export
496 497
 setMethod(f = "seqinfo",
497 498
           signature = signature(x = "Modifier"),
498
-          definition = function(x){seqinfo(sequenceData(x))})
499
-
500
-.norm_args <- function(input){
501
-  minCoverage <- 10L
502
-  minReplicate <- 1L
503
-  find.mod <- TRUE
504
-  if(!is.null(input[["minCoverage"]])){
505
-    minCoverage <- input[["minCoverage"]]
506
-    if(!is.integer(minCoverage) ||
507
-       minCoverage < 0L ||
508
-       length(minCoverage) != 1){
509
-      stop("'minCoverage' must be a single positive integer value.")
510
-    }
511
-  }
512
-  if(!is.null(input[["minReplicate"]])){
513
-    minReplicate <- input[["minReplicate"]]
514
-    if(!is.integer(minReplicate) ||
515
-       minReplicate < 0L ||
516
-       length(minReplicate) != 1){
517
-      stop("'minReplicate' must be a single positive integer value.")
518
-    }
519
-  }
520
-  if(!is.null(input[["find.mod"]])){
521
-    find.mod <- input[["find.mod"]]
522
-    if(!assertive::is_a_bool(find.mod)){
523
-      stop("'find.mod' must be a single logical value.")
524
-    }
525
-  }
526
-  args <- list(minCoverage = minCoverage,
527
-               minReplicate = minReplicate,
528
-               find.mod = find.mod)
529
-  args
530
-}
531
-
499
+          definition = function(x){seqinfo(sequenceData(x))}
500
+)
532 501
 #' @rdname Modifier-functions
533 502
 #' @export
534 503
 setMethod(f = "validAggregate",
... ...
@@ -582,18 +551,42 @@ setMethod(f = "validModification",
582 551
 #' settings(mi) <- list(minCoverage = 11L)
583 552
 NULL
584 553
 
554
+.Modifier_settings <- data.frame(
555
+  variable = c("minCoverage",
556
+               "minReplicate",
557
+               "find.mod"),
558
+  testFUN = c(".not_integer_bigger_than_zero",
559
+              ".not_integer_bigger_than_zero",
560
+              ".is_a_bool"),
561
+  errorValue = c(TRUE,
562
+                 TRUE,
563
+                 FALSE),
564
+  errorMessage = c("'minCoverage' must be a single positive integer value.",
565
+                   "'minReplicate' must be a single positive integer value.",
566
+                   "'find.mod' must be a single logical value."),
567
+  stringsAsFactors = FALSE)
568
+
569
+.norm_Modifier_settings <- function(input){
570
+  minCoverage <- 10L
571
+  minReplicate <- 1L
572
+  find.mod <- TRUE
573
+  args <- .norm_settings(input, .Modifier_settings, minCoverage, minReplicate,
574
+                         find.mod)
575
+  args
576
+}
577
+
585 578
 #' @rdname settings
586 579
 #' @export
587 580
 setMethod(f = "settings",
588 581
           signature = signature(x = "Modifier"),
589 582
           definition = function(x, name){
590 583
             if(missing(name) || is.null(name)){
591
-              return(x@arguments)
584
+              return(x@settings)
592 585
             }
593 586
             if(!assertive::is_a_string(name)){
594 587
               stop("'name' must be a single character value.")
595 588
             }
596
-            x@arguments[[name]]
589
+            x@settings[[name]]
597 590
           }
598 591
 )
599 592
 
... ...
@@ -608,8 +601,8 @@ setReplaceMethod(f = "settings",
608 601
                    if(!is.list(value)){
609 602
                      value <- as.list(value)
610 603
                    }
611
-                   value <- .norm_args(value)
612
-                   x@arguments[names(value)] <- unname(value)
604
+                   value <- .norm_Modifier_settings(value)
605
+                   x@settings[names(value)] <- unname(value)
613 606
                    x@aggregateValidForCurrentArguments <- FALSE
614 607
                    x@modificationsValidForCurrentArguments <- FALSE
615 608
                    x
Browse code

refactored code based upon review

Felix Ernst authored on 23/05/2019 08:51:38
Showing1 changed files
... ...
@@ -5,6 +5,10 @@
5 5
 #' @include Modifier-utils.R
6 6
 NULL
7 7
 
8
+invalidMessage <- paste0("Settings were changed after data aggregation or ",
9
+                         "modification search. Rerun with modify(x,force = ",
10
+                         "TRUE) to update with current settings.")
11
+
8 12
 #' @name Modifier-class
9 13
 #' @aliases Modifier
10 14
 #'
... ...
@@ -61,6 +65,11 @@ NULL
61 65
 #' For this example a \code{list} of \code{character} vectors is expected.
62 66
 #' Each element must be named according to the names of \code{dataType()} and
63 67
 #' contain a \code{character} vector for creating a \code{SequenceData} object.
68
+#' 
69
+#' All additional options must be named and will be passed to the
70
+#' \code{\link[=settings]{settings}} function and onto the \code{SequenceData}
71
+#' objects, if \code{x} is not a \code{SequenceData} object or a list of
72
+#' \code{SequenceData} objects.
64 73
 #'
65 74
 #' @param className The name of the class which should be constructed.
66 75
 #' @param x the input which can be of the following types
... ...
@@ -89,10 +98,12 @@ NULL
89 98
 #' \item{\code{find.mod}:} {\code{TRUE} or \code{FALSE}: should the search for
90 99
 #' for modifications be triggered upon construction? If not the search can be
91 100
 #' started by calling the \code{modify()} function.}
101
+#' \item{additional parameters depending on the specific \code{Modifier} class}
92 102
 #' }
93
-#' All other arguments will be passed onto the \code{SequenceData} objects, if
94
-#' \code{x} is not a \code{SequenceData} object or a list of \code{SequenceData}
95
-#' objects.
103
+#' All additional options must be named and will be passed to the
104
+#' \code{\link[=settings]{settings}} function and onto the \code{SequenceData}
105
+#' objects, if \code{x} is not a \code{SequenceData} object or a list of
106
+#' \code{SequenceData} objects.
96 107
 #'
97 108
 #' @slot mod a \code{character} value, which needs to contain one or more
98 109
 #' elements from the alphabet of a
... ...
@@ -125,10 +136,13 @@ NULL
125 136
 #' @description
126 137
 #' For the \code{Modifier} and  \code{ModifierSet} classes a number of functions
127 138
 #' are implemented to access the data stored by the object.
139
+#' 
140
+#' The \code{validAggregate} and \code{validModification} functions check if
141
+#' \code{\link[=settings]{settings}} have been modified, after the data was 
142
+#' loaded. This potentially invalidates them. To update the data, run the
143
+#' \code{aggregate} or the \code{modify} function.
128 144
 #'
129 145
 #' @param x,object a \code{Modifier} or \code{ModifierSet} class
130
-#' @param name For \code{settings}: name of the setting to be returned or set
131
-#' @param value For \code{settings}: value of the setting to be set
132 146
 #' @param modified For \code{sequences}: \code{TRUE} or \code{FALSE}: Should
133 147
 #' the sequences be returned as a \code{ModRNAString} with the found
134 148
 #' modifications added on top of the \code{RNAString}? See
... ...
@@ -142,7 +156,6 @@ NULL
142 156
 #' \item{\code{modifierType}:} {a character vector with the appropriate class
143 157
 #' Name of a \code{\link[=Modifier-class]{Modifier}}.}
144 158
 #' \item{\code{mainScore}:} {a character vector.}
145
-#' \item{\code{settings}:} {a \code{Seqinfo} object.}
146 159
 #' \item{\code{sequenceData}:} {a \code{SequenceData} object.}
147 160
 #' \item{\code{modifications}:} {a \code{GRanges} or \code{GRangesList} object
148 161
 #' describing the found modifications.}
... ...
@@ -151,7 +164,13 @@ NULL
151 164
 #' \item{\code{ranges}:} {a \code{GRangesList} object with each element per
152 165
 #' transcript.}
153 166
 #' \item{\code{bamfiles}:} {a \code{BamFileList} object.}
167
+#' \item{\code{validAggregate}:} {\code{TRUE} or \code{FALSE}. Checks if current
168
+#' settings are the same for which the data was aggregate}
169
+#' \item{\code{validModification}:} {\code{TRUE} or \code{FALSE}. Checks if 
170
+#' current settings are the same for which modification were found}
154 171
 #' }
172
+#' 
173
+#' @seealso \code{\link[=settings]{settings}}
155 174
 #'
156 175
 #' @examples
157 176
 #' data(msi,package="RNAmodR")
... ...
@@ -159,7 +178,6 @@ NULL
159 178
 #' modifierType(mi) # The class name of the Modifier object
160 179
 #' modifierType(msi) #
161 180
 #' mainScore(mi)
162
-#' settings(mi)
163 181
 #' sequenceData(mi)
164 182
 #' modifications(mi)
165 183
 #' # general accessors
... ...
@@ -196,18 +214,18 @@ setClass("Modifier",
196 214
 
197 215
 # validity ---------------------------------------------------------------------
198 216
 
199
-.check_SequenceData_elements <- function(x, list){
200
-  if(is(list,"SequenceData")){
201
-    list <- list(list)
202
-  } else if(is(list,"list")){
203
-    elementTypeMatch <- !vapply(list,is,logical(1),"SequenceData")
217
+.check_SequenceData_elements <- function(x, data){
218
+  if(is(data,"SequenceData")){
219
+    data <- list(data)
220
+  } else if(is(data,"list")){
221
+    elementTypeMatch <- !vapply(data,is,logical(1),"SequenceData")
204 222
     if(any(elementTypeMatch)){
205 223
       stop("Not all elements are 'SequenceData' objects.", call. = FALSE)
206 224
     }
207
-  } else if(!is(list,"SequenceDataSet")){
208
-   stop("Something went wrong.")
225
+  } else if(!is(data,"SequenceDataSet")){
226
+    stop("")
209 227
   }
210
-  elementTypes <- vapply(list,class,character(1))
228
+  elementTypes <- vapply(data,class,character(1))
211 229
   if(length(elementTypes) != length(dataType(x))){
212 230
     stop("Number of 'SequenceData' elements does not match the requirements of",
213 231
          " ",class(x),". '",paste(dataType(x), collapse = "','"),"' are ",
... ...
@@ -222,8 +240,8 @@ setClass("Modifier",
222 240
   NULL
223 241
 }
224 242
 
225
-.check_SequenceDataList_data_elements <- function(x, list){
226
-  ans <- lapply(list, .check_SequenceData_elements, x)
243
+.check_SequenceDataList_data_elements <- function(x, data){
244
+  ans <- lapply(data, .check_SequenceData_elements, x)
227 245
   if(all(vapply(ans,is.null))) {
228 246
     return(NULL)
229 247
   }
... ...
@@ -296,9 +314,9 @@ S4Vectors::setValidity2(Class = "Modifier", .valid_Modifier)
296 314
                        settings[,f,drop = FALSE]
297 315
                      })
298 316
   if(is.null(rownames(settings[[1]]))){
299
-    names <- rep(" ",nrow(settings[[1]]))
317
+    setting_names <- rep(" ",nrow(settings[[1]]))
300 318
   } else {
301
-    names <- rownames(settings[[1]])
319
+    setting_names <- rownames(settings[[1]])
302 320
   }
303 321
   for(i in seq_along(settings)){
304 322
     out <-
... ...
@@ -312,7 +330,7 @@ S4Vectors::setValidity2(Class = "Modifier", .valid_Modifier)
312 330
       }), use.names = FALSE), nrow = 1,
313 331
       dimnames = list("", colnames(out)))
314 332
     out <- rbind(classinfo, out)
315
-    rownames(out) <- c(" ",names)
333
+    rownames(out) <- c(" ",setting_names)
316 334
     print(out, quote = FALSE, right = TRUE)
317 335
   }
318 336
 }
... ...
@@ -347,9 +365,7 @@ setMethod(
347 365
     .show_settings(settings)
348 366
     valid <- c(validAggregate(object), validModification(object))
349 367
     if(!all(valid)){
350
-      warning("Settings were changed after data aggregation or modification ",
351
-              "search. Rerun with modify(x,force = TRUE) to update with ",
352
-              "current settings.", call. = FALSE)
368
+      warning(invalidMessage, call. = FALSE)
353 369
     }
354 370
   }
355 371
 )
... ...
@@ -404,6 +420,10 @@ setMethod(f = "modifications",
404 420
               if(!assertive::is_a_bool(perTranscript)){
405 421
                 stop("'perTranscript' has to be a single logical value.")
406 422
               }
423
+              valid <- c(validAggregate(x), validModification(x))
424
+              if(!all(valid)){
425
+                warning(invalidMessage, call. = FALSE)
426
+              }
407 427
               if(perTranscript){
408 428
                 return(.get_modifications_per_transcript(x))
409 429
               }
... ...
@@ -457,7 +477,7 @@ setMethod(f = "sequences",
457 477
                 stop("'modified' has to be a single logical value.",
458 478
                      call. = FALSE)
459 479
               }
460
-              if(modified == FALSE){
480
+              if(!modified){
461 481
                 return(sequences(sequenceData(x)))
462 482
               }
463 483
               mod <- .get_modifications_per_transcript(x)
... ...
@@ -511,6 +531,59 @@ setMethod(f = "seqinfo",
511 531
 
512 532
 #' @rdname Modifier-functions
513 533
 #' @export
534
+setMethod(f = "validAggregate",
535
+          signature = signature(x = "Modifier"),
536
+          definition = function(x) x@aggregateValidForCurrentArguments
537
+)
538
+#' @rdname Modifier-functions
539
+#' @export
540
+setMethod(f = "validModification",
541
+          signature = signature(x = "Modifier"),
542
+          definition = function(x) x@modificationsValidForCurrentArguments
543
+)
544
+
545
+# settings ---------------------------------------------------------------------
546
+
547
+#' @name settings
548
+#' 
549
+#' @title Settings for \code{Modifier} objects
550
+#' 
551
+#' @description 
552
+#' Depending on data prepation, quality and desired stringency of a modification
553
+#' strategy, settings for cut off parameters or other variables may need to be 
554
+#' adjusted. This should be rarely the case, but a function for changing these
555
+#' settings, is implemented as the... \code{settings} function.
556
+#' 
557
+#' For changing values the input can be either a \code{list} or something 
558
+#' coercible to a \code{list}. Upon changing a setting, the validity of the
559
+#' value in terms of type(!) and dimensions will be checked. 
560
+#' 
561
+#' If settings have been modified after the data was loaded, the data is 
562
+#' potentially invalid. To update the data, run the \code{aggregate} or the 
563
+#' \code{modify} function.
564
+#' 
565
+#' @param x a \code{Modifier} or \code{ModifierSet} class
566
+#' @param name name of the setting to be returned or set
567
+#' @param value value of the setting to be set
568
+#' 
569
+#' @return 
570
+#' If \code{name} is omitted, \code{settings} returns a list of all settings.
571
+#' If \code{name} is set, \code{settings} returns a single settings or 
572
+#' \code{NULL}, if a value for \code{name} is not available. 
573
+#' 
574
+#' @examples 
575
+#' data(msi,package="RNAmodR")
576
+#' mi <- msi[[1]]
577
+#' # returns a list of all settings
578
+#' settings(mi)
579
+#' # accesses a specific setting
580
+#' settings(mi,"minCoverage")
581
+#' # modification of setting
582
+#' settings(mi) <- list(minCoverage = 11L)
583
+NULL
584
+
585
+#' @rdname settings
586
+#' @export
514 587
 setMethod(f = "settings",
515 588
           signature = signature(x = "Modifier"),
516 589
           definition = function(x, name){
... ...
@@ -523,36 +596,24 @@ setMethod(f = "settings",
523 596
             x@arguments[[name]]
524 597
           }
525 598
 )
526
-#' @rdname Modifier-functions
527
-#' @export
528
-setReplaceMethod(f = "settings",
529
-          signature = signature(x = "Modifier"),
530
-          definition = function(x, value){
531
-            if(is.null(names(value)) && length(value) > 0L){
532
-              stop("'value' has to be a named.")
533
-            }
534
-            if(!is.list(value)){
535
-              value <- as.list(value)
536
-            }
537
-            value <- .norm_args(value)
538
-            x@arguments[names(value)] <- unname(value)
539
-            x@aggregateValidForCurrentArguments <- FALSE
540
-            x@modificationsValidForCurrentArguments <- FALSE
541
-            x
542
-          })
543 599
 
544
-#' @rdname Modifier-functions
545
-#' @export
546
-setMethod(f = "validAggregate",
547
-          signature = signature(x = "Modifier"),
548
-          definition = function(x) x@aggregateValidForCurrentArguments
549
-)
550
-#' @rdname Modifier-functions
600
+#' @rdname settings
551 601
 #' @export
552
-setMethod(f = "validModification",
553
-          signature = signature(x = "Modifier"),
554
-          definition = function(x) x@modificationsValidForCurrentArguments
555
-)
602
+setReplaceMethod(f = "settings",
603
+                 signature = signature(x = "Modifier"),
604
+                 definition = function(x, value){
605
+                   if(is.null(names(value)) && length(value) > 0L){
606
+                     stop("'value' has to be a named.")
607
+                   }
608
+                   if(!is.list(value)){
609
+                     value <- as.list(value)
610
+                   }
611
+                   value <- .norm_args(value)
612
+                   x@arguments[names(value)] <- unname(value)
613
+                   x@aggregateValidForCurrentArguments <- FALSE
614
+                   x@modificationsValidForCurrentArguments <- FALSE
615
+                   x
616
+                 })
556 617
 
557 618
 # constructors -----------------------------------------------------------------
558 619
 
... ...
@@ -560,7 +621,7 @@ setMethod(f = "validModification",
560 621
   if(is(ans,"character") && extends(ans,"Modifier")){
561 622
     ans <- getClass(ans)@prototype
562 623
   } else if(!is(ans,"Modifier")) {
563
-    stop("Something went wrong.")
624
+    stop("")
564 625
   }
565 626
   .check_Modifier_data_elements(ans, list)
566 627
   if(length(list) == 1L){
... ...
@@ -604,7 +665,8 @@ setMethod(f = "validModification",
604 665
       bamfiles <- bamfiles[match(class,names(bamfiles))]
605 666
       data <- BiocParallel::bpmapply(.load_SequenceData, classes, bamfiles,
606 667
                                      MoreArgs = list(annotation, sequences,
607
-                                                     seqinfo, args))
668
+                                                     seqinfo, args),
669
+                                     SIMPLIFY = FALSE)
608 670
     } else {
609 671
       data <- BiocParallel::bplapply(classes, .load_SequenceData, bamfiles,
610 672
                                      annotation, sequences, seqinfo, args)
... ...
@@ -621,7 +683,7 @@ setMethod(f = "validModification",
621 683
                    })
622 684
     data <- as(data,"SequenceDataSet")
623 685
   } else {
624
-    stop("Something went wrong.")
686
+    stop("")
625 687
   }
626 688
   data
627 689
 }
... ...
@@ -678,7 +740,7 @@ setMethod(f = "validModification",
678 740
 #' @export
679 741
 setGeneric(
680 742
   name = "Modifier",
681
-  signature = c("x"),
743
+  signature = "x",
682 744
   def = function(className, x, annotation, sequences, seqinfo, ...)
683 745
     standardGeneric("Modifier")
684 746
 )
... ...
@@ -842,9 +904,6 @@ setMethod(f = "aggregate",
842 904
           signature = signature(x = "Modifier"),
843 905
           definition =
844 906
             function(x, force = FALSE){
845
-              if(missing(force)){
846
-                force <- FALSE
847
-              }
848 907
               assertive::assert_is_a_bool(force)
849 908
               if(!hasAggregateData(x) || force){
850 909
                 x@aggregate <- .check_aggregate_modifier(aggregateData(x), x)
... ...
@@ -935,9 +994,6 @@ setMethod(f = "modify",
935 994
           signature = signature(x = "Modifier"),
936 995
           definition =
937 996
             function(x, force = FALSE){
938
-              if(missing(force)){
939
-                force <- FALSE
940
-              }
941 997
               assertive::assert_is_a_bool(force)
942 998
               if(!validAggregate(x) | force){
943 999
                 x <- aggregate(x, force = TRUE)
Browse code

examples simplified even more

Felix Ernst authored on 29/04/2019 10:18:13
Showing1 changed files
... ...
@@ -811,7 +811,6 @@ setMethod("Modifier",
811 811
 #' # the Modifier or ModifierSet object
812 812
 #' sdfl <- aggregate(e5sd)
813 813
 #' mi <- aggregate(msi[[1]])
814
-#' msi <- aggregate(msi)
815 814
 NULL
816 815
 
817 816
 .check_aggregate_modifier <- function(data, x){
... ...
@@ -927,7 +926,6 @@ setMethod(f = "hasAggregateData",
927 926
 #' data(msi,package="RNAmodR")
928 927
 #' # modify() triggers the search for modifications in the data contained in
929 928
 #' # the Modifier or ModifierSet object
930
-#' msi <- modify(msi)
931 929
 #' mi <- modify(msi[[1]])
932 930
 NULL
933 931
 
Browse code

Merge branch 'master' of https://github.com/FelixErnst/RNAmodR

Felix Ernst authored on 29/04/2019 09:31:56
Showing0 changed files
Browse code

findMod argument changed to find.mod

Felix Ernst authored on 29/04/2019 09:26:04
Showing1 changed files
... ...
@@ -28,7 +28,7 @@ NULL
28 28
 #' 
29 29
 #' \code{Modifier} objects are constructed centrally by calling 
30 30
 #' \code{Modifier()} with a \code{className} matching the specific class to be
31
-#' constructed. This will trigger the immediate analysis, if \code{findMod} is
31
+#' constructed. This will trigger the immediate analysis, if \code{find.mod} is
32 32
 #' not set to \code{TRUE}.
33 33
 #' 
34 34
 #' 
... ...
@@ -83,7 +83,7 @@ NULL
83 83
 #' subset the transcripts analyzed on a chromosome basis.
84 84
 #' @param ... Additional otpional parameters:
85 85
 #' \itemize{
86
-#' \item{findMod: }{\code{TRUE} or \code{FALSE}: should the search for for 
86
+#' \item{\code{find.mod}:} {\code{TRUE} or \code{FALSE}: should the search for for 
87 87
 #' modifications be triggered upon construction? If not the search can be 
88 88
 #' started by calling the \code{modify()} function.}
89 89
 #' }
... ...
@@ -476,7 +476,7 @@ setMethod(f = "seqinfo",
476 476
 .norm_args <- function(input){
477 477
   minCoverage <- 10L
478 478
   minReplicate <- 1L
479
-  findMod <- TRUE
479
+  find.mod <- TRUE
480 480
   if(!is.null(input[["minCoverage"]])){
481 481
     minCoverage <- input[["minCoverage"]]
482 482
     if(!is.integer(minCoverage) || 
... ...
@@ -493,15 +493,15 @@ setMethod(f = "seqinfo",
493 493
       stop("'minReplicate' must be a single positive integer value.")
494 494
     }
495 495
   }
496
-  if(!is.null(input[["findMod"]])){
497
-    findMod <- input[["findMod"]]
498
-    if(!assertive::is_a_bool(findMod)){
499
-      stop("'findMod' must be a single logical value.")
496
+  if(!is.null(input[["find.mod"]])){
497
+    find.mod <- input[["find.mod"]]
498
+    if(!assertive::is_a_bool(find.mod)){
499
+      stop("'find.mod' must be a single logical value.")
500 500
     }
501 501
   }
502 502
   args <- list(minCoverage = minCoverage,
503 503
                minReplicate = minReplicate,
504
-               findMod = findMod)
504
+               find.mod = find.mod)
505 505
   args
506 506
 }
507 507
 
... ...
@@ -657,7 +657,7 @@ setMethod(f = "validModification",
657 657
   message("Aggregating data and calculating scores ... ", appendLF = FALSE)
658 658
   ans <- aggregate(ans)
659 659
   # search for modifications
660
-  if(settings(ans,"findMod")){
660
+  if(settings(ans,"find.mod")){
661 661
     f <- which(Modstrings::shortName(Modstrings::ModRNAString()) %in% ans@mod)
662 662
     modName <- Modstrings::fullName(Modstrings::ModRNAString())[f]
663 663
     message("Starting to search for '", paste(tools::toTitleCase(modName), 
... ...
@@ -774,8 +774,8 @@ setMethod("Modifier",
774 774
 #' @examples 
775 775
 #' data(e5sd,package="RNAmodR")
776 776
 #' data(msi,package="RNAmodR")
777
-#' # aggregate() triggers the aggregation of data contained in a SequenceData,
778
-#' # Modifier or ModifierSet objects
777
+#' # modify() triggers the search for modifications in the data contained in
778
+#' # the Modifier or ModifierSet object
779 779
 #' sdfl <- aggregate(e5sd)
780 780
 #' mi <- aggregate(msi[[1]])
781 781
 #' msi <- aggregate(msi)
... ...
@@ -869,11 +869,12 @@ setMethod(f = "hasAggregateData",
869 869
 #' the results inside the \code{Modifier} object. The results can be accessed
870 870
 #' via the \code{modifications()} function.
871 871
 #' 
872
+#' \code{modifications} is the accessor for the found modifications.
873
+#' 
872 874
 #' \code{findMod} just returns the found modifications as a \code{GRanges} 
873 875
 #' object. It does not check for validity of the aggregate data in side the
874
-#' \code{Modifier} object.
875
-#' 
876
-#' \code{modifications} is the accessor for the found modifications.
876
+#' \code{Modifier} object. This function should only used internally or when
877
+#' developing a new \code{Modifier} class.
877 878
 #' 
878 879
 #' @param x a \code{Modifier} object.
879 880
 #' @param force force to run \code{aggregate} again, if data is already stored
Browse code

updated man pages

Felix Ernst authored on 28/04/2019 14:58:30
Showing1 changed files
... ...
@@ -11,15 +11,15 @@ NULL
11 11
 #' @title The Modifier class
12 12
 #' 
13 13
 #' @description
14
-#' The \code{Modifier} class is a virtual class, which provides the central 
15
-#' functionality for searching for patterns of post-transcriptional RNA 
16
-#' modifications in high throughput sequencing data.
14
+#' The \code{Modifier} class is a virtual class, which provides the central
15
+#' functionality to search for post-transcriptional RNA modification patterns in
16
+#' high throughput sequencing data.
17 17
 #' 
18 18
 #' Each subclass has to implement the following functions:
19 19
 #' 
20 20
 #' \itemize{
21
-#' \item{\code{\link{aggregate}}: }{used for specific data aggregation}
22
-#' \item{\code{\link{modify}}: }{used for specific search for modifications}
21
+#' \item{\code{\link{aggregateData}}: }{used for specific data aggregation}
22
+#' \item{\code{\link{findMod}}: }{used for specific search for modifications}
23 23
 #' }
24 24
 #' 
25 25
 #' Optionally the function \code{\link[=Modifier-functions]{settings<-}} can be
... ...
@@ -28,8 +28,8 @@ NULL
28 28
 #' 
29 29
 #' \code{Modifier} objects are constructed centrally by calling 
30 30
 #' \code{Modifier()} with a \code{className} matching the specific class to be
31
-#' constructed. This will trigger the immediate analysis, if \code{findMod} is
32
-#' not set to \code{TRUE}.
31
+#' constructed. This will trigger the immediate analysis, if \code{find.mod} is
32
+#' not set to \code{FALSE}.
33 33
 #' 
34 34
 #' 
35 35
 #' @section Creation: 
... ...
@@ -51,11 +51,12 @@ NULL
51 51
 #' is constructed/expected.}
52 52
 #' }
53 53
 #' 
54
-#' The cases for a \code{SequenceData} or \code{SequenceDataSet} are rather
55
-#' obvious, since the input remains the same. The last case is special, since
56
-#' it is a hypothetical option in case bam files from to different methods 
57
-#' have to be combined to reliably detect a single modification (The elements of
58
-#' a \code{SequenceDataList} don't have to be created from the bamfiles). 
54
+#' The cases for a \code{SequenceData} or \code{SequenceDataSet} are straight
55
+#' forward, since the input remains the same. The last case is special, since it
56
+#' is a hypothetical option, in which bam files from two or more different
57
+#' methods have to be combined to reliably detect a single modification (The
58
+#' elements of a \code{SequenceDataList} don't have to be created from the
59
+#' bamfiles, whereas from a \code{SequenceDataSet} they have to be).
59 60
 #' 
60 61
 #' For this example a \code{list} of \code{character} vectors is expected.
61 62
 #' Each element must be named according to the names of \code{dataType()} and 
... ...
@@ -64,30 +65,34 @@ NULL
64 65
 #' @param className The name of the class which should be constructed.
65 66
 #' @param x the input which can be of the following types
66 67
 #' \itemize{
67
-#' \item{\code{SequenceData}:} {a single \code{SequenceData} or a list containg
68
-#' only \code{SequenceData} objects. The input will just be used as elements of
69
-#' the \code{Modifier} and must match the requirements of specific
70
-#' \code{Modifier} class }
68
+#' \item{\code{SequenceData}:} {a single \code{SequenceData} or a list
69
+#' containing only \code{SequenceData} objects. The input will just be used to
70
+#' file the \code{data} slot of the \code{Modifier} and must match the
71
+#' requirements of specific \code{Modifier} class.}
71 72
 #' \item{\code{BamFileList}:} {a named \code{BamFileList}}
72 73
 #' \item{\code{character}:} {a \code{character} vector, which must be coercible
73 74
 #' to a named \code{BamFileList} referencing existing bam files. Valid names are
74 75
 #' \code{control} and \code{treated} to define conditions and replicates}
75 76
 #' }
76 77
 #' @param annotation annotation data, which must match the information contained
77
-#' in the BAM files. This is parameter is only required if \code{x} if not a 
78
-#' \code{Modifier} object.
79
-#' @param sequences sequences matching the target sequences the reads were 
80
-#' mapped onto. This must match the information contained in the BAM files. This
81
-#' is parameter is only required if \code{x} if not a \code{Modifier} object.
82
-#' @param seqinfo optional \code{\link[GenomeInfoDb:Seqinfo]{Seqinfo}} to 
83
-#' subset the transcripts analyzed on a chromosome basis.
78
+#' in the BAM files. This parameter is only required if \code{x} is not a 
79
+#' \code{SequenceData} object or a list of \code{SequenceData} objects.
80
+#' @param sequences sequences matching the target sequences the reads were
81
+#'   mapped onto. This must match the information contained in the BAM files.
82
+#'   TThis parameter is only required if \code{x} is not a \code{SequenceData}
83
+#'   object or a list of \code{SequenceData} objects.
84
+#' @param seqinfo An optional \code{\link[GenomeInfoDb:Seqinfo-class]{Seqinfo}} 
85
+#' argument or character vector, which can be coerced to one, to subset the 
86
+#' sequences to be analyzed on a per chromosome basis.
84 87
 #' @param ... Additional otpional parameters:
85 88
 #' \itemize{
86
-#' \item{findMod: }{\code{TRUE} or \code{FALSE}: should the search for for 
89
+#' \item{find.mod: }{\code{TRUE} or \code{FALSE}: should the search for for 
87 90
 #' modifications be triggered upon construction? If not the search can be 
88 91
 #' started by calling the \code{modify()} function.}
89 92
 #' }
90
-#' All other arguments will be passed onto the \code{SequenceData} objects.
93
+#' All other arguments will be passed onto the \code{SequenceData} objects, if
94
+#' \code{x} is not a \code{SequenceData} object or a list of \code{SequenceData}
95
+#' objects.
91 96
 #' 
92 97
 #' @slot mod a \code{character} value, which needs to contain one or more 
93 98
 #' elements from the alphabet of a 
... ...
@@ -134,19 +139,18 @@ NULL
134 139
 #' 
135 140
 #' @return
136 141
 #' \itemize{
137
-#' \item{\code{modifierType}} {a character vector with the appropriate class
138
-#' Name of a \code{\link[=Modifier-class]{Modifier}}. Works for both 
139
-#' \code{Modifier} and \code{ModifierSet} objects.}
140
-#' \item{\code{mainScore}} {a character vector}
141
-#' \item{\code{settings}} {a \code{Seqinfo} object}
142
-#' \item{\code{sequenceData}} {a \code{SequenceData} object}
143
-#' \item{\code{modifications}} {a \code{GRanges} or \code{GRangesList} object
142
+#' \item{\code{modifierType}:} {a character vector with the appropriate class
143
+#' Name of a \code{\link[=Modifier-class]{Modifier}}.}
144
+#' \item{\code{mainScore}:} {a character vector.}
145
+#' \item{\code{settings}:} {a \code{Seqinfo} object.}
146
+#' \item{\code{sequenceData}:} {a \code{SequenceData} object.}
147
+#' \item{\code{modifications}:} {a \code{GRanges} or \code{GRangesList} object
144 148
 #' describing the found modifications.}
145
-#' \item{\code{seqinfo}} {a \code{Seqinfo} object}
146
-#' \item{\code{sequences}} {a \code{RNAStingSet} object}
147
-#' \item{\code{ranges}} {a \code{GRangesList} object with each element per 
148
-#' transcript}
149
-#' \item{\code{bamfiles}} {a \code{BamFileList} object}
149
+#' \item{\code{seqinfo}:} {a \code{Seqinfo} object.}
150
+#' \item{\code{sequences}:} {a \code{RNAStingSet} object.}
151
+#' \item{\code{ranges}:} {a \code{GRangesList} object with each element per 
152
+#' transcript.}
153
+#' \item{\code{bamfiles}:} {a \code{BamFileList} object.}
150 154
 #' }
151 155
 #' 
152 156
 #' @examples
... ...
@@ -670,6 +674,15 @@ setMethod(f = "validModification",
670 674
   ans
671 675
 }
672 676
 
677
+#' @rdname Modifier-class
678
+#' @export
679
+setGeneric( 
680
+  name = "Modifier",
681
+  signature = c("x"),
682
+  def = function(className, x, annotation, sequences, seqinfo, ...)
683
+    standardGeneric("Modifier")
684
+) 
685
+
673 686
 #' @rdname Modifier-class
674 687
 #' @export
675 688
 setMethod("Modifier",
... ...
@@ -727,19 +740,35 @@ setMethod("Modifier",
727 740
 #' @name aggregate
728 741
 #' @aliases hasAggregateData aggregateData getAggregateData
729 742
 #' 
730
-#' @title Aggreagte data per positions
743
+#' @title Aggregate data per positions
731 744
 #' 
732 745
 #' @description 
733
-#' The aggregate function is defined per
734
-#' \code{\link[=SequenceData-class]{SequenceData}} object and can be triggered
735
-#' by either using the a \code{\link[=SequenceData-class]{SequenceData}} or
736
-#' \code{\link[=Modifier-class]{Modifier}}. For the letter it will just redirect
737
-#' to the \code{\link[=SequenceData-class]{SequenceData}} object, but will store
738
-#' the result. The data is then used for subsequent tasks, such as search for
739
-#' modifications and visualization of the results.
740
-#' 
741
-#' @param x a \code{\link[=SequenceData-class]{SequenceData}} or
742
-#'   \code{\link[=Modifier-class]{Modifier}} object.
746
+#' The \code{aggregate} function is defined for each
747
+#' \code{\link[=SequenceData-class]{SequenceData}} object and can be used
748
+#' directly on a \code{\link[=SequenceData-class]{SequenceData}} object or
749
+#' indirectly via a \code{\link[=Modifier-class]{Modifier}} object.
750
+#' 
751
+#' For the letter the call is redirect to the
752
+#' \code{\link[=SequenceData-class]{SequenceData}} object, the result summarized
753
+#' as defined for the individual \code{Modifier} class and stored in the
754
+#' \code{aggregate} slot of the \code{Modifier} object. The data is then used
755
+#' for subsequent tasks, such as search for modifications and visualization of
756
+#' the results.
757
+#' 
758
+#' The summarization is implemented in the \code{aggregateData} for each type of
759
+#' \code{Modifier} class. The stored data from the \code{aggregate} slot can be
760
+#' retrieved using the \code{getAggregateData} function.