Entering edit mode
Hi all!
I am trying to get a Q-matrix from the best snmf() run. This only works for me when there is a single run, if I am setting the repetitions to > 1, however, I am not able to generate a Q matrix from the best run. Can anyone help?
#snmf with 10 repetitions
df <- data.frame(id= c(1,1,1,2,2,2,2,3,3,3),
marker1= c(1,1,1,2,2,2,2,3,3,3),
marker2 = c(1,1,1,2,2,2,2,3,3,3),
marker3 = c(1,1,1,2,2,2,2,3,3,3),
marker4 = c(1,1,1,2,2,2,2,3,3,3),
marker5 = c(1,1,1,2,2,2,3,3,3,3),
marker6 = c(1,1,1,2,2,2,3,3,3,3),
marker7 = c(1,1,1,2,2,2,3,3,3,3),
marker8 = c(1,1,1,2,2,2,3,3,3,3),
marker9 = c(1,1,1,2,2,2,3,3,3,3))
write.table(df, "df.txt", sep="\t", row.names=F, col.names=T, quote=F)
struct2geno(file = "df.txt", TESS = F, diploid = TRUE, FORMAT = 2,
extra.row = 1, extra.col = 1, output = "./df.geno")
obj.snmf <- snmf("df.geno", K = 3, entropy=T, repetitions = 10, project = "new")
best <- which.min(cross.entropy(obj.snmf, K = 3))
best_data <- obj.snmf@runs[[best]]
qmatrix <- Q(best_data, K = 3)
#calling qmatrix - this is not what I wanted
qmatrix
function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)
{
if (is.object(data) || !is.atomic(data))
data <- as.vector(data)
.Internal(matrix(data, nrow, ncol, byrow, dimnames, missing(nrow),
missing(ncol)))
}
<bytecode: 0x000002180d85b5f0>
<environment: namespace:base>
Now there is only one run and it works.
df <- data.frame(id= c(1,1,1,2,2,2,2,3,3,3),
marker1= c(1,1,1,2,2,2,2,3,3,3),
marker2 = c(1,1,1,2,2,2,2,3,3,3),
marker3 = c(1,1,1,2,2,2,2,3,3,3),
marker4 = c(1,1,1,2,2,2,2,3,3,3),
marker5 = c(1,1,1,2,2,2,3,3,3,3),
marker6 = c(1,1,1,2,2,2,3,3,3,3),
marker7 = c(1,1,1,2,2,2,3,3,3,3),
marker8 = c(1,1,1,2,2,2,3,3,3,3),
marker9 = c(1,1,1,2,2,2,3,3,3,3))
write.table(df, "df.txt", sep="\t", row.names=F, col.names=T, quote=F)
struct2geno(file = "df.txt", TESS = F, diploid = TRUE, FORMAT = 2,
extra.row = 1, extra.col = 1, output = "./df.geno")
obj.snmf <- snmf("df.geno", K = 3, project = "new")
qmatrix <- Q(obj.snmf, K = 3)
#Calling qmatrix (desired output)
qmatrix
V1 V2 V3
[1,] 9.998e-01 9.999e-05 9.999e-05
[2,] 9.998e-01 9.999e-05 9.999e-05
[3,] 9.999e-05 9.998e-01 9.999e-05
[4,] 9.999e-05 9.999e-05 9.998e-01
[5,] 9.999e-05 9.999e-05 9.998e-01
Does anyone know how to generate a Q-matrix from the best run? This would be highly appreciated! And also, as I am new to LEA, would anyone have suggestions on how many repetitions to chose?
Any help would be highly appreceated, thank you!
Best, Janis
And last but not least the sessionInfo:
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 LC_MONETARY=German_Austria.1252 LC_NUMERIC=C
[5] LC_TIME=German_Austria.1252
system code page: 65001
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_1.5-29 dplyr_1.0.8 RColorBrewer_1.1-2 fields_13.3 viridis_0.6.2 viridisLite_0.4.0 spam_2.8-0
[8] mapplots_1.5.1 sp_1.4-6 LEA_3.4.0
loaded via a namespace (and not attached):
[1] magrittr_2.0.2 maps_3.4.0 tidyselect_1.1.2 munsell_0.5.0 colorspace_2.0-2 lattice_0.20-45 R6_2.5.1 rlang_1.0.1
[9] fansi_1.0.2 tools_4.1.2 dotCall64_1.0-1 grid_4.1.2 gtable_0.3.0 utf8_1.2.2 DBI_1.1.2 cli_3.1.1
[17] ellipsis_0.3.2 assertthat_0.2.1 tibble_3.1.6 lifecycle_1.0.1 crayon_1.5.1 gridExtra_2.3 purrr_0.3.4 ggplot2_3.3.5
[25] vctrs_0.3.8 glue_1.6.1 compiler_4.1.2 pillar_1.7.0 generics_0.1.2 scales_1.1.1 pkgconfig_2.0.3
>