Skip to content

Commit 2c68e95

Browse files
committed
Support AvgExpression single cell step
1 parent 4d79e37 commit 2c68e95

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
for (datasetId in names(seuratObjects)) {
2+
seuratObj <- seuratObjects[[datasetId]]
3+
seuratObjects[[datasetId]] <- NULL
4+
5+
ret <- Seurat::AverageExpression(seuratObj, assays = NULL, features = rownames(seuratObj), group.by = groupField, slot = "counts", verbose = FALSE)
6+
cellsPerGroup <- t(as.matrix(table(seuratObj[[assay]][[groupField]])))
7+
rownames(cellsPerGroup) <- 'TotalCells'
8+
ret[['CellsPerGroup']] <- cellsPerGroup
9+
10+
saveFile <- paste0(outputPrefix, '.', datasetId, '.avg.', groupField, '.rds')
11+
saveRDS(ret, file = saveFile)
12+
13+
# Cleanup
14+
rm(seuratObj)
15+
gc()
16+
}

singlecell/src/org/labkey/singlecell/SingleCellModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.labkey.singlecell.button.CellHashingButton;
4242
import org.labkey.singlecell.button.CiteSeqButton;
4343
import org.labkey.singlecell.pipeline.singlecell.AppendCiteSeq;
44+
import org.labkey.singlecell.pipeline.singlecell.AvgExpression;
4445
import org.labkey.singlecell.pipeline.singlecell.CiteSeqDimRedux;
4546
import org.labkey.singlecell.pipeline.singlecell.CiteSeqWnn;
4647
import org.labkey.singlecell.pipeline.singlecell.DoubletFinder;
@@ -176,6 +177,7 @@ public static void registerPipelineSteps()
176177
SequencePipelineService.get().registerPipelineStep(new SubsetSeurat.Provider());
177178
SequencePipelineService.get().registerPipelineStep(new CiteSeqDimRedux.Provider());
178179
SequencePipelineService.get().registerPipelineStep(new CiteSeqWnn.Provider());
180+
SequencePipelineService.get().registerPipelineStep(new AvgExpression.Provider());
179181
}
180182

181183
@Override
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.labkey.singlecell.pipeline.singlecell;
2+
3+
import org.json.JSONObject;
4+
import org.labkey.api.sequenceanalysis.pipeline.AbstractPipelineStepProvider;
5+
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
6+
import org.labkey.api.singlecell.pipeline.SeuratToolParameter;
7+
import org.labkey.api.singlecell.pipeline.SingleCellStep;
8+
9+
import java.util.Arrays;
10+
11+
public class AvgExpression extends AbstractCellMembraneStep
12+
{
13+
public AvgExpression(PipelineContext ctx, AvgExpression.Provider provider)
14+
{
15+
super(provider, ctx);
16+
}
17+
18+
public static class Provider extends AbstractPipelineStepProvider<SingleCellStep>
19+
{
20+
public Provider()
21+
{
22+
super("AvgExpression", "Avg. Expression", "Seurat", "This will run AverageExpression on the raw counts, producing a matrix with the average per group. This matrix will have a row labeled TotalCells appended, which is the total cells per group.", Arrays.asList(
23+
SeuratToolParameter.create("groupField", "Grouping Field", "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.", "textfield", new JSONObject(){{
24+
put("allowBlank", false);
25+
}}, null)
26+
), null, null);
27+
}
28+
29+
@Override
30+
public AvgExpression create(PipelineContext ctx)
31+
{
32+
return new AvgExpression(ctx, this);
33+
}
34+
}
35+
}
36+

0 commit comments

Comments
 (0)