Skip to content

Commit 800209e

Browse files
committed
Add support for additionalFieldsToAggregate
1 parent 0041ee6 commit 800209e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

singlecell/resources/chunks/AvgExpression.R

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

18-
a <- CellMembrane::PseudobulkSeurat(seuratObj, groupFields = groupFields, assays = assayName)
18+
if (!all(is.null(additionalFieldsToAggregate))) {
19+
if (any(grepl(additionalFieldsToAggregate, pattern = '\\*'))) {
20+
additionalFieldsToAggregateExpanded <- c()
21+
for (fn in additionalFieldsToAggregate) {
22+
if (grepl(fn, pattern = '\\*')) {
23+
matchingCols <- grep(names(seuratObj@meta.data), pattern = fn, value = T)
24+
print(paste0('Expanding ', fn, ' into: ', paste0(matchingCols, collapse = ', ')))
25+
additionalFieldsToAggregateExpanded <- c(additionalFieldsToAggregateExpanded, matchingCols)
26+
} else {
27+
additionalFieldsToAggregateExpanded <- c(additionalFieldsToAggregateExpanded, fn)
28+
}
29+
30+
additionalFieldsToAggregate <- unique(additionalFieldsToAggregateExpanded)
31+
}
32+
}
33+
}
34+
35+
a <- CellMembrane::PseudobulkSeurat(seuratObj, groupFields = groupFields, assays = assayName, additionalFieldsToAggregate = additionalFieldsToAggregate)
1936

2037
if (addMetadata) {
2138
a <- Rdiscvr::QueryAndApplyMetadataUsingCDNA(a)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ public Provider()
3434
}}, true),
3535
SeuratToolParameter.create("assayName", "Assay Name", "The assay to use", "textfield", new JSONObject(){{
3636

37-
}}, "RNA")
37+
}}, "RNA"),
38+
SeuratToolParameter.create("additionalFieldsToAggregate", "Additional Field(s) to Aggregate", "Each field in this list must match a meta.data field. That field will be aggregated per group, and the mean reported in meta.data of the pseudobulk output object. Note: this also supports wildcards (which must contain asterisk). Any term containing asterisk will be interpreted as a regex and passed to grep() to find matching meta.data fields.", "sequenceanalysis-trimmingtextarea", new JSONObject(){{
39+
put("allowBlank", true);
40+
put("height", 150);
41+
put("delimiter", ",");
42+
put("stripCharsRe", "/['\"]/g");
43+
}}, "*UCell$").delimiter(",")
3844
), null, null);
3945
}
4046

0 commit comments

Comments
 (0)