Mercurial > repos > ppericard > viscorvar
comparison additional_functions_block_splsda.R @ 0:d0b77b926863 draft
"planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
author | ppericard |
---|---|
date | Tue, 23 Jun 2020 19:57:35 -0400 |
parents | |
children | e93350dc99f1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d0b77b926863 |
---|---|
1 #' @title Check if a block contains missing values | |
2 #' @description Check if a block contains missing values | |
3 #' @param list_X type : list of matrix. This list is used to perform the data integration. | |
4 #' @details This function checks if a block contains missing values. | |
5 #' @return type : boolean. If at least one block contains missing values, | |
6 #' this function returns TRUE, otherwise this function returns FALSE. | |
7 #' @examples | |
8 #' X1 = matrix(1:9, nrow = 3, ncol = 3) | |
9 #' X2 = matrix(10:18, nrow = 3, ncol = 3) | |
10 #' list_X = list() | |
11 #' list_X[[1]] = X1 | |
12 #' list_X[[2]] = X2 | |
13 #' names(list_X) = c("X1", "X2") | |
14 #' boolean_block_missing_values = blockMissingValues(list_X) | |
15 #' @export | |
16 blockMissingValues <-function(list_X) | |
17 { | |
18 name_blocks = names(list_X) | |
19 name_blocks_missing_values = c() | |
20 boolean_block_missing_values = FALSE | |
21 | |
22 for(i in 1:length(list_X)) | |
23 { | |
24 X_i = list_X[[i]] | |
25 name_block_i = name_blocks[i] | |
26 | |
27 vec = sapply(1:dim(X_i)[2], FUN = function(j){ | |
28 res = any(is.na(X_i[, j])) | |
29 | |
30 return(res) | |
31 }) | |
32 | |
33 if(any(vec)) | |
34 { | |
35 name_blocks_missing_values = c(name_blocks_missing_values, name_block_i) | |
36 | |
37 } | |
38 | |
39 } # End for(i in 1:length(list_X)). | |
40 | |
41 if(length(name_blocks_missing_values) != 0) | |
42 { | |
43 stop(paste("The data integration can not be performed if a block contains missing values : ", paste(name_blocks_missing_values, collapse = ", "), " contains missing values. ")) | |
44 boolean_block_missing_values = TRUE | |
45 | |
46 } | |
47 | |
48 return(boolean_block_missing_values) | |
49 | |
50 } | |
51 | |
52 | |
53 #' @title Determination of selected variables for all components | |
54 #' @description The function unionSelectBlockVariables determines, for each block, the selected block variables | |
55 #' for all components. | |
56 #' @param res_block_splsda type : sgccda. This parameter is the output of block.splsda function | |
57 #' mixOmics. | |
58 #' @details For each block, the function unionSelectBlockVariables returns 1 if the block variable is selected for | |
59 #' at least one component. Otherwise, this function returns 0. | |
60 #' @return type : list of matrix. For each block, if the block variable is selected, the value 1 is associated with | |
61 #' this block variable. Otherwise the value 0 is associated with this block variable. | |
62 #' @examples | |
63 #' data(res_data_integration) | |
64 #' list_union_selected_block_variables = unionSelectBlockVariables(res_data_integration) | |
65 #' @export | |
66 unionSelectBlockVariables <-function(res_block_splsda) | |
67 { | |
68 ncomp = res_block_splsda$ncomp[1] | |
69 | |
70 names_blocks = names(res_block_splsda$loadings) | |
71 index_Y = which(names_blocks == "Y") | |
72 names_blocks = names_blocks[ - index_Y] | |
73 list_select_block_variables = list() | |
74 | |
75 for(i in 1:length(names_blocks)) | |
76 { | |
77 mat_loadings_i = res_block_splsda$loadings[[i]] | |
78 index_i = c() | |
79 | |
80 for(j in 1:ncomp) | |
81 { | |
82 loadings_i_j = mat_loadings_i[, j] | |
83 index_i_j = which(loadings_i_j != 0) | |
84 | |
85 index_i = c(index_i, index_i_j) | |
86 | |
87 } # End for(j 1:ncomp). | |
88 | |
89 index_i = unique(index_i) | |
90 | |
91 mat_select_block_variables = matrix(0, | |
92 nrow = dim(mat_loadings_i)[1], | |
93 ncol = 1) | |
94 mat_select_block_variables[index_i, 1] = rep(1, length(index_i)) | |
95 rownames(mat_select_block_variables) = rownames(mat_loadings_i) | |
96 | |
97 list_select_block_variables[[i]] = mat_select_block_variables | |
98 | |
99 } # End for(i in 1:length(names_blocks)). | |
100 | |
101 names(list_select_block_variables) = names_blocks | |
102 | |
103 return(list_select_block_variables) | |
104 } |