Skip to content

Commit 10a3260

Browse files
committed
solution proposed in #333
1 parent 2d5c1ab commit 10a3260

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

R/application_prediction.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ nichenet_seuratobj_aggregate = function(receiver, seurat_obj, condition_colname,
10321032
# step2 nichenet analysis: define background and gene list of interest: here differential expression between two conditions of cell type of interest
10331033
if (verbose == TRUE){print("Perform DE analysis in receiver cell")}
10341034

1035-
seurat_obj_receiver= subset(seurat_obj, idents = receiver)
1035+
seurat_obj_receiver[[assay_oi]]= subset(seurat_obj[[assay_oi]], idents = receiver)
10361036
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[[condition_colname, drop=TRUE]])
10371037
DE_table_receiver = FindMarkers(object = seurat_obj_receiver, ident.1 = condition_oi, ident.2 = condition_reference, min.pct = expression_pct, assay = assay_oi) %>% rownames_to_column("gene")
10381038

@@ -1190,7 +1190,7 @@ nichenet_seuratobj_aggregate = function(receiver, seurat_obj, condition_colname,
11901190

11911191
if (are_there_senders == TRUE){
11921192
if (verbose == TRUE){print("Perform DE analysis in sender cells")}
1193-
seurat_obj = subset(seurat_obj, features = potential_ligands)
1193+
seurat_obj[[assay_oi]] = subset(seurat_obj[[assay_oi]], features = potential_ligands)
11941194

11951195
DE_table_all = Idents(seurat_obj) %>% levels() %>% intersect(sender_celltypes) %>% lapply(get_lfc_celltype, seurat_obj = seurat_obj, condition_colname = condition_colname, condition_oi = condition_oi, condition_reference = condition_reference, expression_pct = expression_pct, celltype_col = NULL) %>% reduce(full_join, by = "gene") # use this if cell type labels are the identities of your Seurat object -- if not: indicate the celltype_col properly
11961196
DE_table_all[is.na(DE_table_all)] = 0
@@ -1215,7 +1215,7 @@ nichenet_seuratobj_aggregate = function(receiver, seurat_obj, condition_colname,
12151215
order_ligands_adapted = real_makenames_conversion[order_ligands]
12161216
names(order_ligands_adapted) = NULL
12171217

1218-
seurat_obj_subset = seurat_obj %>% subset(idents = sender_celltypes)
1218+
seurat_obj_subset[[assay_oi]] = seurat_obj[[assay_oi]] %>% subset(idents = sender_celltypes)
12191219
seurat_obj_subset = SetIdent(seurat_obj_subset, value = seurat_obj_subset[[condition_colname, drop=TRUE]]) %>% subset(idents = condition_oi) ## only shows cells of the condition of interest
12201220
rotated_dotplot = DotPlot(seurat_obj %>% subset(cells = Cells(seurat_obj_subset)), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
12211221
rm(seurat_obj_subset)
@@ -1376,7 +1376,7 @@ get_expressed_genes.Seurat = function(celltype_oi, seurat_obj, pct = 0.1, assay_
13761376
#cells_oi_in_matrix <- intersect(colnames(seurat_obj[[assay_oi]]@data), cells_oi)
13771377
#exprs_mat = seurat_obj[[assay_oi]]@data %>% .[, cells_oi_in_matrix]
13781378

1379-
exprs_mat <- subset(seurat_obj, idents = celltype_oi) %>%
1379+
exprs_mat <- subset(seurat_obj[[assay_oi]], idents = celltype_oi) %>%
13801380
GetAssayData(assay = assay_oi, ...)
13811381

13821382
if (length(cells_oi) != ncol(exprs_mat)){
@@ -1739,7 +1739,7 @@ nichenet_seuratobj_cluster_de = function(seurat_obj, receiver_affected, receiver
17391739
real_makenames_conversion = lr_network$from %>% unique() %>% magrittr::set_names(lr_network$from %>% unique() %>% make.names())
17401740
order_ligands_adapted = real_makenames_conversion[order_ligands]
17411741
names(order_ligands_adapted) = NULL
1742-
rotated_dotplot = DotPlot(seurat_obj %>% subset(idents = sender_celltypes), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
1742+
rotated_dotplot = DotPlot(seurat_obj[[assay_oi]] %>% subset(idents = sender_celltypes), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
17431743

17441744
} else {
17451745
rotated_dotplot = NULL
@@ -1948,13 +1948,13 @@ nichenet_seuratobj_aggregate_cluster_de = function(seurat_obj, receiver_affected
19481948
# step2 nichenet analysis: define background and gene list of interest: here differential expression between two conditions of cell type of interest
19491949
if (verbose == TRUE){print("Perform DE analysis between two receiver cell clusters")}
19501950

1951-
seurat_obj_receiver_affected= subset(seurat_obj, idents = receiver_affected)
1951+
seurat_obj_receiver_affected= subset(seurat_obj[[assay_oi]], idents = receiver_affected)
19521952
seurat_obj_receiver_affected = SetIdent(seurat_obj_receiver_affected, value = seurat_obj_receiver_affected[[condition_colname, drop=TRUE]])
1953-
seurat_obj_receiver_affected= subset(seurat_obj_receiver_affected, idents = condition_oi)
1953+
seurat_obj_receiver_affected= subset(seurat_obj_receiver_affected[[assay_oi]], idents = condition_oi)
19541954

1955-
seurat_obj_receiver_reference= subset(seurat_obj, idents = receiver_reference)
1955+
seurat_obj_receiver_reference= subset(seurat_obj[[assay_oi]], idents = receiver_reference)
19561956
seurat_obj_receiver_reference = SetIdent(seurat_obj_receiver_reference, value = seurat_obj_receiver_reference[[condition_colname, drop=TRUE]])
1957-
seurat_obj_receiver_reference= subset(seurat_obj_receiver_reference, idents = condition_reference)
1957+
seurat_obj_receiver_reference= subset(seurat_obj_receiver_reference[[assay_oi]], idents = condition_reference)
19581958

19591959
seurat_obj_receiver = merge(seurat_obj_receiver_affected, seurat_obj_receiver_reference)
19601960

@@ -2121,7 +2121,7 @@ nichenet_seuratobj_aggregate_cluster_de = function(seurat_obj, receiver_affected
21212121
real_makenames_conversion = lr_network$from %>% unique() %>% magrittr::set_names(lr_network$from %>% unique() %>% make.names())
21222122
order_ligands_adapted = real_makenames_conversion[order_ligands]
21232123
names(order_ligands_adapted) = NULL
2124-
rotated_dotplot = DotPlot(seurat_obj %>% subset(idents = sender_celltypes), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
2124+
rotated_dotplot = DotPlot(seurat_obj[[assay_oi]] %>% subset(idents = sender_celltypes), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
21252125

21262126
} else {
21272127
rotated_dotplot = NULL
@@ -2176,10 +2176,10 @@ get_lfc_celltype = function(celltype_oi, seurat_obj, condition_colname, conditio
21762176
requireNamespace("dplyr")
21772177
if(!is.null(celltype_col)){
21782178
seurat_obj_celltype = SetIdent(seurat_obj, value = seurat_obj[[celltype_col, drop=TRUE]])
2179-
seuratObj_sender = subset(seurat_obj_celltype, idents = celltype_oi)
2179+
seuratObj_sender = subset(seurat_obj_celltype[[assay_oi]], idents = celltype_oi)
21802180

21812181
} else {
2182-
seuratObj_sender = subset(seurat_obj, idents = celltype_oi)
2182+
seuratObj_sender = subset(seurat_obj[[assay_oi]], idents = celltype_oi)
21832183

21842184
}
21852185

0 commit comments

Comments
 (0)