Skip to content

Commit 53356c8

Browse files
committed
Switch from Seurat AvgExpression to Pseudobulk
1 parent a204bf3 commit 53356c8

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

singlecell/resources/chunks/AvgExpression.R

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,7 @@ GenerateAveragedData <- function(seuratObj, groupFields, addMetadata) {
1515
stop('When addMetadata=TRUE, cDNA_ID must be part of groupFields')
1616
}
1717

18-
meta <- unique(seuratObj@meta.data[,groupFields, drop = F])
19-
rownames(meta) <- apply(meta, 1, function(y){
20-
return(paste0(y, collapse = '_'))
21-
})
22-
23-
Seurat::Idents(seuratObj) <- rownames(meta)
24-
25-
for (assayName in names(seuratObj@assays)) {
26-
if (!(!identical(seuratObj@assays[[assayName]]@counts, seuratObj@assays[[assayName]]@data))){
27-
print(paste0('Seurat assay', assayName, ' does not appear to be normalized, running now:'))
28-
seuratObj <- Seurat::NormalizeData(seuratObj, verbose = FALSE, assay = assayName)
29-
}
30-
}
31-
32-
a <- Seurat::AverageExpression(seuratObj, return.seurat = T, verbose = F)
33-
a <- Seurat::AddMetaData(a, meta)
34-
35-
totals <- seuratObj@meta.data %>% group_by_at(groupFields) %>% summarise(TotalCells = n())
36-
a$TotalCells <- totals$TotalCells
18+
a <- CellMembrane::PseudobulkSeurat(seuratObj, groupFields = groupFields, assays = assayName)
3719

3820
if (addMetadata) {
3921
a <- Rdiscvr::QueryAndApplyMetadataUsingCDNA(a)

singlecell/src/org/labkey/singlecell/pipeline/singlecell/AvgExpression.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class Provider extends AbstractPipelineStepProvider<SingleCellStep
2222
{
2323
public Provider()
2424
{
25-
super("AvgExpression", "Avg. Expression", "Seurat", "This will run AverageExpression on the raw counts, grouping using the provided fields. It will generate a seurat object with aggregate counts.", Arrays.asList(
25+
super("AvgExpression", "Pseudobulk", "CellMembrane/Seurat", "This will run Pseudobulking on the raw counts, grouping using the provided fields. It will generate a seurat object with sum of counts per group/feature.", Arrays.asList(
2626
SeuratToolParameter.create("groupFields", "Grouping Field(s)", "This field will be used to group cells of the seurat object. For each unique value of this field, count averages will be computed and saved into a matrix with one column per group. Any cells lacking a value in this field will be discarded.", "sequenceanalysis-trimmingtextarea", new JSONObject(){{
2727
put("allowBlank", false);
2828
put("height", 150);
@@ -31,7 +31,10 @@ public Provider()
3131
}}, "cDNA_ID").delimiter(","),
3232
SeuratToolParameter.create("addMetadata", "Query Metadata?", "If checked, Rdiscvr::QueryAndApplyMetadataUsingCDNA will be run after aggregation. This requires a cDNA_ID column to exist.", "checkbox", new JSONObject(){{
3333
put("checked", true);
34-
}}, true)
34+
}}, true),
35+
SeuratToolParameter.create("assayName", "Assay Name", "The assay to use", "textfield", new JSONObject(){{
36+
37+
}}, "RNA")
3538
), null, null);
3639
}
3740

0 commit comments

Comments
 (0)