[28e211]: / R / DIscBIO-generic-FinalPreprocessing.R

Download this file

76 lines (74 with data), 2.6 kB

 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
#' @title Final Preprocessing
#' @description This function generates the final filtered normalized dataset.
#' @param object \code{DISCBIO} class object.
#' @param GeneFlitering GeneFlitering has to be one of the followings:
#' ["NoiseF","ExpF"]. Default is "NoiseF"
#' @param export A logical vector that allows writing the final gene list in
#' excel file. Default is TRUE.
#' @param quiet if `TRUE`, intermediary output is suppressed
#' @param fileName File name for exporting (if `export = TRUE`)
#' @return The DISCBIO-class object input with the FinalGeneList slot filled.
#' @examples
#' #sc <- DISCBIO(valuesG1msTest)
#' #sc <- NoiseFiltering(sc, percentile = 0.9, CV = 0.2, export = FALSE)
#' #sc <- FinalPreprocessing(sc, GeneFlitering = "NoiseF", export = FALSE)
#'
setGeneric(
"FinalPreprocessing",
function(object,
GeneFlitering = "NoiseF",
export = FALSE,
quiet = FALSE,
fileName = "filteredDataset") {
standardGeneric("FinalPreprocessing")
}
)
#' @export
#' @rdname FinalPreprocessing
setMethod(
"FinalPreprocessing",
signature = "DISCBIO",
definition = function(object, GeneFlitering, export, quiet, fileName) {
if (GeneFlitering == "NoiseF") {
if (length(object@noiseF) < 1) {
stop("run NoiseFiltering before running FinalPreprocessing")
}
if (nrow(object@fdata) < 1) {
stop("run Normalizedata before running FinalPreprocessing")
}
gene_list <- object@noiseF
gene_names <- rownames(object@fdata)
idx_genes <- is.element(gene_names, gene_list)
gene_names2 <- gene_names[idx_genes]
filteredDataset <- object@fdata[gene_names2, ]
object@fdata <- filteredDataset
object@FinalGeneList <- rownames(filteredDataset)
}
if (GeneFlitering == "ExpF") {
if (nrow(object@fdata) < 1) {
stop("run Normalizedata before running FinalPreprocessing")
}
filteredDataset <- object@fdata
object@FinalGeneList <- rownames(filteredDataset)
}
if (!quiet) {
message(
"The gene filtering method = Noise filtering\n\n",
"The Filtered Normalized dataset contains:\n",
"Genes: ", length(filteredDataset[, 1]), "\n",
"cells: ", length(filteredDataset[1, ]), "\n\n"
)
}
if (export) {
fileNameExt <- paste0(fileName, ".Rdata")
if (!quiet) {
message(
"The Filtered Normalized dataset was saved as: ",
fileNameExt
)
}
save(filteredDataset, file = fileNameExt)
}
return(object)
}
)