Skip to content

Commit bf1f6d1

Browse files
committed
fix card_processing
1 parent 6f453b3 commit bf1f6d1

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/helpers/utils.R

+14-13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ generate_moransI <- function(adata) {
2020

2121

2222
generate_cosine <- function(real, sim) {
23+
requireNamespace("lsa", quietly = TRUE)
2324
real_new <- real[!is.na(real) & !is.na(sim)]
2425
sim_new <- sim[!is.na(real) & !is.na(sim)]
2526
similarity <- lsa::cosine(lsa::as.textmatrix(cbind(as.vector(real_new$Morans.I), as.vector(sim_new$Morans.I))))
@@ -70,23 +71,24 @@ calculate_recall <- function(real_svg, sim_svg) {
7071
}
7172

7273
# cell type deconvolution
73-
CARD_processing <- function(sp_adata, sc_adata){
74+
CARD_processing <- function(sp_adata, sc_adata) {
75+
requireNamespace("MuSiC", quietly = TRUE)
76+
requireNamespace("CARD", quietly = TRUE)
77+
7478
spatial_count <- Matrix::t(sp_adata$layers[["counts"]])
75-
spatial_location <- cbind.data.frame(
76-
x = sp_adata$obs$col,
77-
y = sp_adata$obs$row
79+
spatial_location <- data.frame(
80+
x = as.numeric(sp_adata$obs$col),
81+
y = as.numeric(sp_adata$obs$row)
7882
)
79-
spatial_location$col <- as.numeric(spatial_location$col)
80-
spatial_location$row <- as.numeric(spatial_location$row)
8183
sc_count <- Matrix::t(sc_adata$layers[["counts"]])
82-
sc_meta <- cbind.data.frame(
84+
sc_meta <- data.frame(
8385
cellID = rownames(sc_adata),
84-
cellType = input_sc$obs$cell_type,
85-
sampleInfo = input_sc$obs$donor_id
86+
cellType = sc_adata$obs$cell_type,
87+
sampleInfo = sc_adata$obs$donor_id
8688
)
8789
rownames(sc_meta) <- sc_meta$cellID
8890
rownames(spatial_location) <- colnames(spatial_count)
89-
print(89)
91+
9092
CARD_obj <- CARD::createCARDObject(
9193
sc_count = sc_count,
9294
sc_meta = sc_meta,
@@ -96,10 +98,9 @@ CARD_processing <- function(sp_adata, sc_adata){
9698
ct.select = unique(sc_meta$cellType),
9799
sample.varname = "sampleInfo",
98100
minCountGene = 100,
99-
minCountSpot = 5)
100-
print(100)
101+
minCountSpot = 5)
101102
CARD_obj <- CARD::CARD_deconvolution(CARD_object = CARD_obj)
102-
print(102)
103+
103104
Proportion_CARD <- as.matrix(CARD_obj@Proportion_CARD)
104105

105106
return(Proportion_CARD)

0 commit comments

Comments
 (0)