@@ -20,6 +20,7 @@ generate_moransI <- function(adata) {
20
20
21
21
22
22
generate_cosine <- function (real , sim ) {
23
+ requireNamespace(" lsa" , quietly = TRUE )
23
24
real_new <- real [! is.na(real ) & ! is.na(sim )]
24
25
sim_new <- sim [! is.na(real ) & ! is.na(sim )]
25
26
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) {
70
71
}
71
72
72
73
# 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
+
74
78
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 )
78
82
)
79
- spatial_location $ col <- as.numeric(spatial_location $ col )
80
- spatial_location $ row <- as.numeric(spatial_location $ row )
81
83
sc_count <- Matrix :: t(sc_adata $ layers [[" counts" ]])
82
- sc_meta <- cbind. data.frame(
84
+ sc_meta <- data.frame (
83
85
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
86
88
)
87
89
rownames(sc_meta ) <- sc_meta $ cellID
88
90
rownames(spatial_location ) <- colnames(spatial_count )
89
- print( 89 )
91
+
90
92
CARD_obj <- CARD :: createCARDObject(
91
93
sc_count = sc_count ,
92
94
sc_meta = sc_meta ,
@@ -96,10 +98,9 @@ CARD_processing <- function(sp_adata, sc_adata){
96
98
ct.select = unique(sc_meta $ cellType ),
97
99
sample.varname = " sampleInfo" ,
98
100
minCountGene = 100 ,
99
- minCountSpot = 5 )
100
- print(100 )
101
+ minCountSpot = 5 )
101
102
CARD_obj <- CARD :: CARD_deconvolution(CARD_object = CARD_obj )
102
- print( 102 )
103
+
103
104
Proportion_CARD <- as.matrix(CARD_obj @ Proportion_CARD )
104
105
105
106
return (Proportion_CARD )
0 commit comments