Skip to content

Commit c0a0bb8

Browse files
authored
Merge pull request #380 from netZoo/master
Merging Master into Devel
2 parents 3fcc47b + fc84ba7 commit c0a0bb8

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

R/DRAGON.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ dragon = function(layer1,layer2,pval = FALSE,gradient = "finite_difference", ver
389389
precmat = get_precision_matrix_dragon(layer1, layer2, lambdas)
390390
ggm = get_partial_correlation_dragon(layer1, layer2, lambdas)
391391

392+
# Propagate variable names from input layers to output matrices
393+
all_names = c(colnames(layer1), colnames(layer2))
394+
if(!is.null(all_names) && length(all_names) == ncol(shrunken_cov)) {
395+
rownames(shrunken_cov) = colnames(shrunken_cov) = all_names
396+
rownames(precmat) = colnames(precmat) = all_names
397+
rownames(ggm) = colnames(ggm) = all_names
398+
}
399+
392400
# if pval, return pval approx with finite difference
393401
if(pval)
394402
{

tests/testthat/test-dragon.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,37 @@ test_that("[DRAGON] dragon() exported function works on simulated data",
112112

113113
})
114114

115+
# test that output matrices carry input variable names (issue #319)
116+
test_that("[DRAGON] output matrices preserve input column names",
117+
{
118+
toy_layer1 = matrix(c(1,2,3,1,5,12),nrow=3,byrow=T)
119+
toy_layer2 = matrix(c(9,7,8),nrow=3,byrow=T)
120+
colnames(toy_layer1) = c("gene1","gene2")
121+
colnames(toy_layer2) = c("methyl1")
122+
123+
res = dragon(layer1 = toy_layer1, layer2 = toy_layer2, pval = F)
124+
expected_names = c("gene1","gene2","methyl1")
125+
126+
expect_equal(rownames(res$cov), expected_names)
127+
expect_equal(colnames(res$cov), expected_names)
128+
expect_equal(rownames(res$prec), expected_names)
129+
expect_equal(colnames(res$prec), expected_names)
130+
expect_equal(rownames(res$ggm), expected_names)
131+
expect_equal(colnames(res$ggm), expected_names)
132+
})
133+
134+
# test that dragon still works when inputs have no column names
135+
test_that("[DRAGON] output matrices work without input column names",
136+
{
137+
toy_layer1 = matrix(c(1,2,3,1,5,12),nrow=3,byrow=T)
138+
toy_layer2 = matrix(c(9,7,8),nrow=3,byrow=T)
139+
140+
res = dragon(layer1 = toy_layer1, layer2 = toy_layer2, pval = F)
141+
142+
expect_null(rownames(res$cov))
143+
expect_null(colnames(res$cov))
144+
})
145+
115146
# test log likelihood function
116147
# test_that("[DRAGON] Log likelihood function for estimation of kappa is correct",{
117148
# # log_lik_shrunken = function(kappa, p, lambda, rhos)

0 commit comments

Comments
 (0)