Browse code

Improve messages for classifier

Tiago Silva authored on 05/10/2023 16:45:17
Showing 1 changed files

... ...
@@ -56,15 +56,14 @@ gliomaClassifier <- function(data){
56 56
 
57 57
         # keep only probes used in the model
58 58
         aux <- met[,colnames(met) %in% colnames(model$trainingData),drop = FALSE]
59
-
60 59
         # This should not happen!
61 60
         if(any(apply(aux,2,function(x) all(is.na(x))))) {
62
-            print("NA columns")
61
+            print("Probes has NA for all samples. Setting to 0.5 since model does not accept NA")
63 62
             aux[,apply(aux,2,function(x) all(is.na(x)))] <- 0.5
64 63
         }
65 64
 
66 65
         if(any(apply(aux,2,function(x) any(is.na(x))))) {
67
-            print("NA values")
66
+            print("Probes has NA values for some samples. Setting values a the median of the sample since model does not accept NA ")
68 67
             colMedians <- colMedians(aux,na.rm = TRUE)
69 68
             x <- which(is.na(aux),arr.ind = TRUE)
70 69
             for(l in 1:nrow(x)){
... ...
@@ -74,9 +73,12 @@ gliomaClassifier <- function(data){
74 73
 
75 74
         # For missing probes add values to 0.5
76 75
         missing_probes <- setdiff(colnames(model$trainingData), colnames(met))
77
-        missing_probes_matrix <- matrix(rep(0.5, nrow(met) * length(missing_probes)),nrow = nrow(met))
78
-        colnames(missing_probes_matrix) <- missing_probes
79
-        aux <- bind_cols(aux,missing_probes_matrix)
76
+        if(length(missing_probes) > 0) {
77
+            print("Probes are missing. Setting dummy probes to matrix with 0.5 value to all samples.")
78
+            missing_probes_matrix <- matrix(rep(0.5, nrow(met) * length(missing_probes)),nrow = nrow(met))
79
+            colnames(missing_probes_matrix) <- missing_probes
80
+            aux <- bind_cols(aux,missing_probes_matrix)
81
+        }
80 82
 
81 83
         pred <- predict(model, aux)
82 84
         pred.prob <- predict(model, aux, type = "prob")