-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
music_prop_toast needs a 'markers' argument #108
Comments
Ah, same issue applies for |
I am experiencing the same issue, is there a solution? (other than using music_prop() instead) |
Judging by the number of unanswered issues in this repository, I don't think the lab is interested in fixing anything or maintaining this tool. I think the only solution right now is to download the source code and fix it locally. I've stopped trying because of the number of issues that would need fixing before it was functional. |
Alright thanks! I did find it hard to navigate this tools using my own data as it is so incoherent - fixing source code seems like too much effort, I'll probably just switch to another deconvolution tool. |
Here is my temporary solution, FYI:Copy the source code of the function from the package and modify it in two places:
music2_prop_toast = function(bulk.control.mtx, bulk.case.mtx, sc.sce, clusters, samples, select.ct, expr_low=20, prop_r=0.1,
eps_c=0.05, eps_r=0.01, cutoff_c=10^(-3), cutoff_r=10^(-3), cap=0.3, maxiter = 200){ new code (add markers, ct.cov, cell_size , centered , normalize to the argument list): music2_prop_toast <- function (bulk.control.mtx, bulk.case.mtx, sc.sce, clusters,
samples, select.ct, expr_low = 20, prop_r = 0.1, eps_c = 0.05,
eps_r = 0.01, cutoff_c = 10^(-3), cutoff_r = 10^(-3), cap = 0.3,
maxiter = 200, markers = NULL, ct.cov = FALSE, cell_size = NULL,
centered = FALSE, normalize = FALSE) {
res_table<- csTest(fitted_model, coef = "group", verbose = F) new code (change group to condition, see line 505): res_table<- csTest(fitted_model, coef = "condition", verbose = F) Define a new function in my R script and use the new function:my_music2_prop_toast <- function (bulk.control.mtx, bulk.case.mtx, sc.sce, clusters,
samples, select.ct, expr_low = 20, prop_r = 0.1, eps_c = 0.05,
eps_r = 0.01, cutoff_c = 10^(-3), cutoff_r = 10^(-3), cap = 0.3,
maxiter = 200, markers = NULL, ct.cov = FALSE, cell_size = NULL,
centered = FALSE, normalize = FALSE) {
gene.bulk = intersect(rownames(bulk.control.mtx), rownames(bulk.case.mtx))
if (length(gene.bulk) < 0.1 * min(nrow(bulk.control.mtx),
nrow(bulk.case.mtx))) {
stop("Not enough genes for bulk data! Please check gene annotations.")
}
bulk.mtx = cbind(bulk.control.mtx[gene.bulk, ], bulk.case.mtx[gene.bulk,
])
Pheno = data.frame(condition = factor(c(rep("control", ncol(bulk.control.mtx)),
rep("case", ncol(bulk.case.mtx))), levels = c("control",
"case")))
rownames(Pheno) = colnames(bulk.mtx)
gene_all = intersect(gene.bulk, rownames(sc.sce))
if (length(gene_all) < 0.2 * min(length(gene.bulk), nrow(sc.sce))) {
stop("Not enough genes between bulk and single-cell data! Please check gene annotations.")
}
bulk.mtx = bulk.mtx[gene_all, ]
sc.iter.sce = sc.sce[gene_all, ]
expr = apply(bulk.mtx, 1, mean)
exp_genel = names(expr[expr >= expr_low])
bulk.control = bulk.mtx[, colnames(bulk.control.mtx)]
bulk.case = bulk.mtx[, colnames(bulk.case.mtx)]
prop_control = music_prop(bulk.mtx = bulk.control, sc.sce = sc.sce,
clusters = clusters, samples = samples, select.ct = select.ct,
markers = markers, cell_size = cell_size, ct.cov = ct.cov,
iter.max = 1000, nu = 1e-04, eps = 0.01, centered = centered,
normalize = normalize, verbose = F)$Est.prop.weighted
prop_case_fix = NULL
prop_case_ini = music_prop(bulk.mtx = bulk.case, sc.sce = sc.sce,
clusters = clusters, samples = samples, select.ct = select.ct,
markers = markers, cell_size = cell_size, ct.cov = ct.cov,
iter.max = 1000, nu = 1e-04, eps = 0.01, centered = centered,
normalize = normalize, verbose = F)$Est.prop.weighted
prop_CASE = prop_case_ini
prop_all = rbind(prop_control, prop_CASE)
iter = 1
ncell = length(select.ct)
id_conv = NULL
while (iter <= maxiter) {
Y_raw = log1p(bulk.mtx)
design = Pheno
Prop <- prop_all[rownames(Pheno), ]
Design_out <- makeDesign(design, Prop)
fitted_model <- fitModel(Design_out, Y_raw)
res_table <- csTest(fitted_model, coef = "condition", verbose = F)
mex = apply(prop_all, 2, mean)
lr = NULL
for (celltype in select.ct) {
m = mex[celltype]
DE = res_table[[celltype]]
pval = DE$fdr
names(pval) = rownames(DE)
pval = pval[names(pval) %in% exp_genel]
if (m >= prop_r) {
lr = c(lr, names(pval[pval <= cutoff_c & pval <=
quantile(pval, prob = cap)]))
}
else {
lr = c(lr, names(pval[pval <= cutoff_r & pval <=
quantile(pval, prob = cap)]))
}
}
lr = unique(lr)
l = setdiff(gene_all, lr)
sc.iter.sce = sc.sce[l, ]
if (length(id_conv) > 0) {
case_sample = bulk.case[, !colnames(bulk.case) %in%
id_conv]
}
else {
case_sample = bulk.case
}
prop_case = music_prop(bulk.mtx = case_sample, sc.sce = sc.iter.sce,
clusters = clusters, samples = samples, select.ct = select.ct,
verbose = F)$Est.prop.weighted
prop_CASE = rbind(prop_case, prop_case_fix)
if (length(id_conv) == 1) {
rownames(prop_CASE) = c(rownames(prop_case), id_conv)
}
prop_all = rbind(prop_control, prop_CASE)
prop_case = prop_case[rownames(prop_case_ini), ]
pc = abs(prop_case - prop_case_ini)
conv = pc
conv[, ] = 1
conv[prop_case_ini <= prop_r] = ifelse(pc[prop_case_ini <=
prop_r] < eps_r, 0, 1)
pc[prop_case_ini > prop_r] = pc[prop_case_ini > prop_r]/prop_case_ini[prop_case_ini >
prop_r]
conv[prop_case_ini > prop_r] = ifelse(pc[prop_case_ini >
prop_r] < eps_c, 0, 1)
convf = apply(conv, 1, function(x) {
all(x == 0)
})
all_converge = FALSE
id_conv = c(id_conv, names(convf[convf == TRUE]))
prop_case_ini = prop_CASE[!rownames(prop_CASE) %in%
id_conv, ]
prop_case_fix = prop_CASE[rownames(prop_CASE) %in% id_conv,
]
if (is.vector(prop_case_ini)) {
all_converge = TRUE
break
}
else if (nrow(prop_case_ini) == 0) {
all_converge = TRUE
break
}
iter = iter + 1
}
if (all_converge) {
return(list(Est.prop = prop_all, convergence = TRUE,
n.iter = iter, DE.genes = lr))
}
else {
return(list(Est.prop = prop_all, convergence = FALSE,
id.not.converge = rownames(prop_case_ini)))
}
}
my_music2_prop_toast(
bulk.control.mtx = bulk.control.mtx,
bulk.case.mtx = bulk.case.mtx,
sc.sce = seger.sce,
clusters = 'cellType',
samples = 'sampleID',
select.ct = c('acinar','alpha','beta','delta','ductal','gamma')
) -> est
|
In the function
music_prop_toast
, it callsmusic_prop
several times with argumentmarkers = markers
. Howevermarkers
is never defined in the mainmusic_prop_toast
function and it isn't an input argument to the function. So callingmusic_prop_toast
results in the following error:The text was updated successfully, but these errors were encountered: