Browse code

Fix faith (#642)

Tuomas Borman authored on 17/09/2024 12:28:54 • GitHub committed on 17/09/2024 12:28:54
Showing 2 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 Package: mia
2 2
 Type: Package
3
-Version: 1.13.39
3
+Version: 1.13.40
4 4
 Authors@R:
5 5
     c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"),
6 6
              email = "felix.gm.ernst@outlook.com",
... ...
@@ -311,20 +311,25 @@ NULL
311 311
             call. = FALSE)
312 312
     }
313 313
     
314
-    # Subset and rename rows of the assay to correspond node_labs
314
+    # Subset rows of the assay to correspond node_labs (if there are any NAs
315
+    # in node labels)
315 316
     if( !is.null(node.label) && any(is.na(node.label)) ){
316
-        # Subset
317
-        if( !any(is.na(node.label)) ){
318
-            warning(
319
-                "The tree named does not include all the ",
320
-                "rows. 'x' is subsetted.", call. = FALSE)
321
-            mat <- mat[ !is.na(node.label), ]
322
-            node.label <- node.label[ !is.na(node.label) ]
323
-        }
324
-        # Rename
317
+        warning(
318
+            "The tree named does not include all the ",
319
+            "rows. 'x' is subsetted.", call. = FALSE)
320
+        mat <- mat[ !is.na(node.label), ]
321
+        node.label <- node.label[ !is.na(node.label) ]
322
+    }
323
+    # If there are node labels (any TreeSE should have because they are rowLinks
324
+    # by default), rename the features in matrix to match with labels found in
325
+    # tree.
326
+    if( !is.null(node.label) ){
325 327
         rownames(mat) <- node.label
326 328
     }
327
-    # To calculate faith, the assay must have rownames
329
+    
330
+    # To calculate faith, the assay must have rownames. TreeSE has always
331
+    # rownames at this point, but if the object is SE, it might be that it is
332
+    # missing rownames.
328 333
     if( is.null(rownames(mat)) ){
329 334
         stop("'x' must have rownames.", call. = FALSE)
330 335
     }