Browse code

v1.6.6: NA values are omitted

neobernad authored on 28/04/2021 17:00:48
Showing 6 changed files

... ...
@@ -2,7 +2,7 @@ Package: evaluomeR
2 2
 Type: Package
3 3
 Title: Evaluation of Bioinformatics Metrics
4 4
 URL: https://github.com/neobernad/evaluomeR
5
-Version: 1.6.5
5
+Version: 1.6.6
6 6
 Authors@R: c(
7 7
     person("José Antonio", "Bernabé-Díaz", email = "[email protected]", role = c("aut", "cre")),
8 8
     person("Manuel", "Franco", email = "[email protected]", role = "aut"),
... ...
@@ -21,6 +21,8 @@
21 21
 metricsCorrelations <- function(data, margins=c(0,10,9,11), getImages=TRUE) {
22 22
 
23 23
   data <- as.data.frame(assay(data))
24
+  data <- removeNAValues(data)
25
+  dfStats(data)
24 26
 
25 27
   MatCorr <- cor(data[,2:length(data)])
26 28
 
... ...
@@ -168,6 +168,39 @@ helperGetCBI <- function(cbi=pkg.env$cbi, krange) {
168 168
          }
169 169
   )
170 170
 }
171
+# Remove rows from a dataframe 'df' where for a certain column the row provides 'NA' value
172
+removeNAValues <- function(df, verbose=TRUE) {
173
+  rowNames = df[[1]]
174
+  affected = which(rowSums(is.na(df)) > 0)
175
+  if (verbose && length(affected) > 0) {
176
+    message("Warning: There are rows with NA values. I will remove these...")
177
+  }
178
+  for (row_i in affected) {
179
+    if (verbose) {
180
+      message("Row '", rowNames[row_i], "' was removed. NA values found in columns:")
181
+    }
182
+    for (column in colnames(df)) {
183
+      naDetected = is.na(df[row_i, column])
184
+      if (verbose && naDetected) {
185
+        message("- '", column,"' ")
186
+      }
187
+    }
188
+  }
189
+  df <- na.omit(df)
190
+  if (verbose) {
191
+    message("")
192
+  }
193
+  return (df)
194
+}
195
+
196
+# Basic stats of a dataframe
197
+dfStats <- function(df) {
198
+  message("Data loaded.\n",
199
+          "Number of rows: ", nrow(df), "\n",
200
+          "Number of columns: ", ncol(df), "\n\n"
201
+  )
202
+}
203
+
171 204
 #' @title Get supported CBIs in evaluomeR.
172 205
 #' @aliases evaluomeRSupportedCBI
173 206
 #' @description
... ...
@@ -208,6 +208,10 @@ runQualityIndicesSilhouette <- function(data, k.min=NULL, k.max=NULL, bs,
208 208
   if (is.null(k.min) && is.null(k.max) && is.null(k.set)) {
209 209
     stop("runQualityIndicesSilhouette: All k parameters are null!")
210 210
   }
211
+
212
+  data <- removeNAValues(data)
213
+  dfStats(data)
214
+
211 215
   datos.bruto=data
212 216
   names.metr=names(datos.bruto)[-c(1)]
213 217
   pkg.env$names.metr = names.metr
... ...
@@ -588,6 +592,7 @@ runSilhouetteIMG <- function(data, k) {
588 592
 }
589 593
 
590 594
 runSilhouetteTable <- function(data, k) {
595
+  data = removeNAValues(data, verbose=FALSE)
591 596
   names.metr = pkg.env$names.metr
592 597
   datos.bruto = data
593 598
   estable = pkg.env$estable
... ...
@@ -202,6 +202,10 @@ runStabilityIndex <- function(data, k.min=NULL, k.max=NULL, bs,
202 202
   if (is.null(k.min) && is.null(k.max) && is.null(k.set)) {
203 203
     stop("runStabilityIndex: All k parameters are null!")
204 204
   }
205
+
206
+  data <- removeNAValues(data)
207
+  dfStats(data)
208
+
205 209
   inversa=NULL
206 210
   m.stab.global = NULL
207 211
   m.stab.global.csv = NULL # To store new CSV output measures without altering legacy code
208 212
deleted file mode 100755
... ...
@@ -1,4 +0,0 @@
1
-library(evaluomeR)
2
-
3
-globalMetricDf = globalMetric(rnaMetrics, k.range = c(2,3), nrep=10, criterion="AIC", PCA=TRUE)
4
-globalMetricDf