Closed niksa01 closed 6 months ago
Hi,
Did you try already running PrepSCTFindMarkers() prior to running the code above, as suggested by the error message?
Yes, I did
What happens when you run FindMarkers
on your object? get_lfc_celltype
uses FindMarkers
internally, so could you try running this (assuming that the Idents()
of your object is the celltype)?
FindMarkers(seuratObj, ident.1 = condition_oi, ident.2 = condition_reference, subset.ident = celltype_name, group.by = condition_colname, min.pct = 0.1, logfc.threshold = 0.05)
For instance, if I run this on the example data,
FindMarkers(seuratObj, ident.1 = 'LCMV', ident.2 = 'SS', subset.ident = 'Mono', group.by = 'aggregate', min.pct = 0.1, logfc.threshold = 0.05)
It would give me the DE genes between LCMV and SS conditions in monocytes, which corresponds to the 'Mono' column returned by get_lfc_celltype
.
I just recalled that to fix this issue, you should set recorrect_umi = FALSE
in FindMarkers()
:
https://satijalab.org/seurat/archive/v4.3/sctransform_v2_vignette
If running on a subset of the original object after running PrepSCTFindMarkers(), FindMarkers() should be invoked with recorrect_umi = FALSE to use the existing corrected counts:
However, get_lfc_celltype
currently doesn't allow you to pass extra parameters into FindMarkers
. You can reproduce the results of get_lfc_celltype
with something like this:
lapply(Idents(seuratObj) %>% levels() %>% intersect(sender_celltypes),
function(ct) FindMarkers(seuratObj, ident.1 = condition_oi, ident.2 = condition_reference, subset.ident = ct,
group.by = "aggregate", min.pct = 0.1, logfc.threshold = 0.05, recorrect_umi = FALSE) %>%
rownames_to_column("gene") %>% select(gene, avg_log2FC) %>% rename(!!ct := avg_log2FC)) %>%
reduce(full_join)
In the next patch where I fix some bugs with Seurat V5 objects, I will allow for extra arguments to be passed from get_lfc_celltype
.
get_lfc_celltype
now allows you to pass extra arguments to FindMarkers
Hi,
I was running the following code (from the seurat_steps vignette) to find the log fold change information of ligands from sender cells
DE_table_all = Idents(seuratObj) %>% levels() %>% intersect(sender_celltypes) %>% lapply(get_lfc_celltype, seurat_obj = seuratObj, condition_colname = "orig.ident", condition_oi = condition_oi, condition_reference = condition_reference, expression_pct = 0.10, celltype_col = "clustergroup" ) %>% reduce(full_join)
but I ran into the following error
Error in FindMarkers.SCTAssay(object = data.use, latent.vars = latent.vars, : Object contains multiple models with unequal library sizes. Run
PrepSCTFindMarkers()
before runningFindMarkers()
Could anyone help with this? Thanks!