Skip to content

Commit 414f9a7

Browse files
adding matrix around ncols
1 parent 05d5e69 commit 414f9a7

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

R/estimatecc.R

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,13 @@ estimatecc <- function(object, find_dmrs_object = NULL, region_mat = NULL,
117117

118118
# set up objects
119119
cell_counts <- data.frame(array(NA, dim=c(n,K)))
120-
# theta_final <- data.frame(array(NA, dim=c(n,6)))
121120
nregions_final = array(NA, dim = n)
122121
samples_with_na <- apply(ymat, 2, function(x) { any(is.na(x)) })
123122

124123
## Include verbose messages about parameter estimation
125124
if(verbose){
126125
mes <- "[estimatecc] Starting parameter estimation using %s regions."
127-
message(sprintf(mes, R, n))
126+
message(sprintf(mes, R))
128127
}
129128

130129
if(any(samples_with_na)){
@@ -153,14 +152,12 @@ estimatecc <- function(object, find_dmrs_object = NULL, region_mat = NULL,
153152
epsilon=epsilon, max_iter = max_iter)
154153

155154
cell_counts[ii,] <- as.data.frame(finalMLEs$pi_mle)
156-
# theta_final[ii,] <- as.data.frame(
157-
# finalMLEs$theta[nrow(finalMLEs$theta), ])
158-
}
155+
}
159156
}
160157

161158
if(any(!samples_with_na)){
162159

163-
ymat_sub <- ymat[, !samples_with_na]
160+
ymat_sub <- as.matrix(ymat[, !samples_with_na])
164161
cut_samples <- factor(cut(seq_len(ncol(ymat_sub)),
165162
breaks = unique(c(seq(0, ncol(ymat_sub), by = 100),
166163
ncol(ymat_sub)))))
@@ -173,31 +170,24 @@ estimatecc <- function(object, find_dmrs_object = NULL, region_mat = NULL,
173170
init_step <-
174171
.initializeMLEs(init_param_method = init_param_method,
175172
n = n, K = K,
176-
Ys = ymat_sub[, keep_inds], Zs = zmat,
173+
Ys = as.matrix(ymat_sub[, keep_inds]), Zs = zmat,
177174
a0init = a0init, a1init = a1init,
178175
sig0init = sig0init, sig1init = sig1init,
179176
tauinit = tauinit)
180177

181178
# Run EM algorithm
182179
finalMLEs <-
183-
.methylcc_engine(Ys = ymat_sub[, keep_inds], Zs = zmat,
180+
.methylcc_engine(Ys = as.matrix(ymat_sub[, keep_inds]), Zs = zmat,
184181
current_pi_mle = init_step$init_pi_mle,
185182
current_theta = init_step$init_theta,
186183
epsilon=epsilon, max_iter = max_iter)
187184
final_mles <- rbind(final_mles, finalMLEs$pi_mle)
188-
print(levels(cut_samples)[ind])
185+
# print(levels(cut_samples)[ind])
189186
}
190187

191188
# recored results
192189
cell_counts[!samples_with_na,] <- as.data.frame(final_mles)
193190
nregions_final[!samples_with_na] <- rep(R, sum(!samples_with_na))
194-
# if(all(!samples_with_na)){
195-
# theta_all_final <- as.data.frame(finalMLEs$theta)
196-
# } else {
197-
# theta_final[!samples_with_na,] <-
198-
# as.data.frame(t(replicate(sum(!samples_with_na),
199-
# c(finalMLEs$theta[nrow(finalMLEs$theta), ]))))
200-
# }
201191
}
202192

203193
if(verbose){
@@ -208,11 +198,6 @@ estimatecc <- function(object, find_dmrs_object = NULL, region_mat = NULL,
208198

209199
colnames(cell_counts) <- ids
210200
results@cell_counts <- cell_counts
211-
# if(all(!samples_with_na)){
212-
# results@theta <- theta_all_final
213-
# } else {
214-
# results@theta <- theta_final
215-
# }
216201
results@summary <- list("class" = class(object),
217202
"n_samples" = n, "celltypes" = ids,
218203
"sample_names" = colnames(ymat),

0 commit comments

Comments
 (0)