stefpeschel / NetCoMi

Network construction, analysis, and comparison for microbial compositional data
GNU General Public License v3.0
143 stars 24 forks source link

Error in length of dimnames after permutation testing #112

Closed joshqsumner closed 6 months ago

joshqsumner commented 6 months ago

Hello, I am trying to use the permutation testing functionality from NetCoMi::netCompare but I am running into some problems with several of my datasets. I think the error is coming from around line 865 of NetCoMi::netCompare based on the final error, the permutation running, and the progress bar not closing before the error is reported but I do not know the helper functions well enough to have a more informed guess. My input matrices are not particularly sparse and do not have any rows/columns that sum to 0 but maybe during the permutation tests things shuffle and make combinations that cause problems. With this toy example the errors all seem to have happened on the 7th column, which is pretty sparse in d1. Thank you for your time and for your work on NetCoMi!

> d1 <- structure(c(18356, 19037, 18146, 11833, 13851, 9618, 230, 206, 
232, 19991, 1202, 139, 430, 282, 119, 617, 62, 49, 43, 12, 0, 
17, 78, 386, 368, 490, 1090, 1195, 1302, 35, 22, 63, 46, 534, 
315, 388, 1129, 1065, 795, 0, 103, 100, 316, 446, 111, 491, 80, 
15, 20, 16, 0, 268, 222, 2700, 2582, 3677, 9608, 10562, 8541, 
75, 0, 0, 0, 23, 0, 138, 0, 0, 0, 0, 0, 7, 10, 0, 5, 125, 4, 
6, 0, 8, 0, 0, 0, 64, 30, 68, 176, 214, 169, 0, 0, 65, 80, 471, 
588, 696, 1449, 1430, 1035, 0), dim = c(10L, 10L), dimnames = list(
    c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), c("Pseudomonadaceae", 
    "Burkholderiaceae", "Bacillaceae_1", "Bradyrhizobiaceae", 
    "Sphingomonadaceae", "Not_Assigned", "Erwiniaceae", "Enterobacteriaceae", 
    "Azospirillaceae", "Gaiellaceae")))
> d2 <- structure(c(10210, 17296, 20174, 6802, 17168, 15065, 466, 211, 
399, 10812, 3167, 2119, 0, 248, 65, 58, 108, 19, 35, 23, 20, 
11, 0, 412, 211, 335, 1026, 1192, 1909, 16, 173, 26, 13, 553, 
205, 197, 1270, 1246, 589, 428, 85, 156, 6, 208, 77, 32, 78, 
0, 9, 621, 11, 208, 46, 4471, 892, 2141, 8695, 10862, 9878, 1176, 
0, 47, 0, 26, 36, 3, 0, 0, 0, 0, 93, 7, 0, 136, 0, 8, 0, 0, 0, 
225, 0, 0, 0, 68, 0, 43, 205, 184, 196, 53, 0, 3, 0, 637, 189, 
270, 1422, 1377, 1191, 57), dim = c(10L, 10L), dimnames = list(
    c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), c("Pseudomonadaceae", 
    "Burkholderiaceae", "Bacillaceae_1", "Bradyrhizobiaceae", 
    "Sphingomonadaceae", "Not_Assigned", "Erwiniaceae", "Enterobacteriaceae", 
    "Azospirillaceae", "Gaiellaceae")))

>   mn <- netConstruct(data=d1, data2 = d2, dataType="counts",
+                      measure="spearman",
+                      normMethod = "clr",
+                      sparsMethod = "t-test",
+                      filtSamp = "none",
+                      weighted=TRUE, verbose=2, seed=123)
Checking input arguments ... Done.
Infos about changed arguments:
Zero replacement needed for clr transformation. "multRepl" used.

10 taxa and 10 samples remaining in group 1.
10 taxa and 10 samples remaining in group 2.

Zero treatment in group 1:
Execute multRepl() ... Done.

Zero treatment in group 2:
Execute multRepl() ... Done.

Normalization in group 1:
Execute clr(){SpiecEasi} ... Done.

Normalization in group 2:
Execute clr(){SpiecEasi} ... Done.

Calculate 'spearman' associations ... Done.

Calculate associations in group 2 ... Done.

Sparsify associations via 't-test' ... 
Adjust for multiple testing via 'adaptBH' ... Done.
Done.

Sparsify associations in group 2 ... 
Adjust for multiple testing via 'adaptBH' ... Done.
Done.
>   mnp <- netAnalyze(mn, weightDeg=TRUE)
Argument 'normDeg' set to FALSE
(no normalization implemented for weighted degree).
>   mnc <- netCompare(mnp, permTest=TRUE)
Checking input arguments ... Done.
Calculate network properties ... Done.
Execute permutation tests ... 
  |============================================================================================================================| 100%Error in { : 
  task 119 failed - "length of 'dimnames' [2] not equal to array extent"
In addition: There were 38 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In (function (X, label = NULL, dl = NULL, frac = 0.65,  ... :
  Column no. 7 containing >100% zeros/unobserved values deleted (can modify threshold using argument z.warning).

2: In (function (X, label = NULL, dl = NULL, frac = 0.65,  ... :
  Column no. 7 containing >100% zeros/unobserved values deleted (can modify threshold using argument z.warning).

3: In (function (X, label = NULL, dl = NULL, frac = 0.65,  ... :
  Column no. 7 containing >100% zeros/unobserved values deleted (can modify threshold using argument z.warning).

{etc, same type of error but on different columns}

Edit: I have not been able to get around this error using the zeroMethod and zeroPar arguments to netConstruct to pass arguments to the zCompositions options but I may be missing something in those. Using the pseudo/pseudoZO options giving a pseudocount of 1 let my example data run, albeit more slowly. Since that works I'm going to close this issue.

stefpeschel commented 6 months ago

Hi, Thanks for the detailed explanations. Unfortunately, I don't have the time to take a closer look at this issue this week. Even though it's closed, I'll try to find out what's wrong with zCompositions.