Skip to content

Commit

Permalink
minor changes in strandSpecific function and properties
Browse files Browse the repository at this point in the history
  • Loading branch information
AtaJadidAhari committed Apr 25, 2024
1 parent 731fcdd commit 8cc5f33
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
13 changes: 12 additions & 1 deletion R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,25 @@ setMethod("strandSpecific", "FraserDataSet", function(object) {
warning("Strand is not specified. Please set the used RNA-seq",
" protocol by using 'strandSpecific(object) <- c(...)'.",
"\n\nWe assume as default a non stranded protocol.")
return(0)
return(rep(0, ncol(object)))
}
return(colData(object)$strand)
})

#' @export
#' @rdname fds-methods
setReplaceMethod("strandSpecific", "FraserDataSet", function(object, value) {
if (length(value) != ncol(object)){
if(length(value) == 1){
warning("Only one value is provided as strand for all samples.\n",
" We assume that all samples are of the same provided strand.")
strandSpecific(object) <- rep(value, ncol(object))
}
else{
stop("Number of strand values should be equal to the number of samples: (",
paste0(length(value), " != ", ncol(object), ")"))
}
}
if(is.logical(value)){
value <- as.integer(value)
}
Expand Down
4 changes: 2 additions & 2 deletions R/FraserDataSet-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ validateStrandSpecific <- function(object) {
# Check mixed strand type
ss <- strandSpecific(object)
if ((any(ss == 0) && any(ss == 1)) || (any(ss == 0) && any(ss == 2))){
stop(paste("Error: Data contains a mix of stranded and unstranded samples.\n ",
"Please consider analyzing them separately."))
stop(paste("Data contains a mix of stranded and unstranded samples.\n ",
"Please analyse them separately to ensure consistency during counting."))
}
NULL
}
Expand Down
10 changes: 2 additions & 8 deletions R/annotationOfRanges.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,8 @@ findAnnotatedJunction <- function(fds, annotation, annotateNames=TRUE,
gr <- rowRanges(fds, type="psi5")

#
if(0 %in% stranded){
if(length(unique(stranded)) > 1){
warning("You use a mixture of stranded and unstranded data.",
" This is highly discouraged and ",
" can lead to unwanted results. We treat all as stranded.")
} else {
strand(gr) <- "*"
}
if(isFALSE(as.logical(unique(stranded)))){
strand(gr) <- "*"
}

# set correct seq level names
Expand Down
8 changes: 6 additions & 2 deletions R/helper-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,12 @@ getBPParam <- function(worker, tasks=0, ...){
}

getStrandString <- function(fds){
strand <- sapply(strandSpecific(fds)+1L, switch, "no", "yes", "reverse")
strand <- paste(collapse=", ", strand)
strand <- sapply(strandSpecific(fds)+1L, switch, "no", "yes (forward)", "yes (reverse)")
if (length(unique(strand)) == 2){
strand <- "yes (forward and reverse)"
} else {
strand <- unique(strand)
}
return(strand)
}

Expand Down

0 comments on commit 8cc5f33

Please sign in to comment.