Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix/aggregate_expression' into l…
Browse files Browse the repository at this point in the history
…is_vignette_updates
  • Loading branch information
zskylarli committed Nov 15, 2023
2 parents 82421fb + 218d622 commit 3724d0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
25 changes: 23 additions & 2 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,8 @@ PseudobulkExpression.Seurat <- function(
stop("Number of layers provided does not match number of assays")
}
data <- FetchData(object = object, vars = rev(x = group.by))
#only keep meta-data columns that are in object
group.by <- intersect(group.by, colnames(data))
data <- data[which(rowSums(x = is.na(x = data)) == 0), , drop = F]
if (nrow(x = data) < ncol(x = object)) {
inform("Removing cells with NA for 1 or more grouping variables")
Expand Down Expand Up @@ -1460,7 +1462,9 @@ PseudobulkExpression.Seurat <- function(
)
colnames(category.matrix) <- col.names
inform(
message = "Pseudobulk group.by variables are numeric, appending `g` to column names/cells of pseudobulked output.",
message = paste0("group.by variable `", group.by[1],
"` starts with a number, appending `g` to `", group.by[1],
"` variable to ensure\nvalid variable names"),
.frequency = "regularly",
.frequency_id = "PseudobulkExpression"
)
Expand Down Expand Up @@ -1600,7 +1604,24 @@ PseudobulkExpression.Seurat <- function(
}
#set idents to pseudobulk variables
Idents(toRet) <- cells
toRet$orig.ident <- cells

#make orig.ident variable
#orig.ident = ident if group.by includes `ident`
#if not, orig.ident is equal to pseudobulk cell names
if(any(group.by == "ident")) {
i = which(group.by == "ident")
v <- sapply(
strsplit(cells, "_"),
function(x) {return(x[i])}
)
names(v) <- cells
toRet <- AddMetaData(toRet,
metadata = v,
col.name = "orig.ident"
)
} else {
toRet$orig.ident <- cells
}
return(toRet)
} else {
return(data.return)
Expand Down
12 changes: 5 additions & 7 deletions vignettes/ParseBio_sketch_integration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,9 @@ bulk <- AggregateExpression(object, return.seurat = T, slot = 'counts',
# each sample is an individual-specific celltype-specific pseudobulk profile
tail(Cells(bulk))
bulk$celltype <- sapply(strsplit(Cells(bulk), split = "_"), '[', 1)
bulk$donor <- sapply(strsplit(Cells(bulk), split = "_"), '[', 2)
bulk$disease <- sapply(strsplit(bulk$donor, split = "-"), '[', 1)
bulk$disease <- factor(x = bulk$disease, levels = c('H', 'D'))
cd14.bulk <- subset(bulk,celltype == "CD14 Mono")
cd14.bulk <- subset(bulk,celltype.full == "CD14 Mono")
Idents(cd14.bulk) <- 'disease'
de_markers <- FindMarkers(cd14.bulk, ident.1 = 'D',ident.2 = 'H', slot = 'counts', test.use = 'DESeq2', verbose = F )
de_markers$gene <- rownames(de_markers)
Expand All @@ -180,7 +176,9 @@ We do not necessarily expect to see a strong transcriptomic signature of diabete

```{r,height = 12, width=6}
# each dot represents a pseudobulk average from an individual
VlnPlot(bulk, features = c("C1R"),group.by = 'celltype', split.by = 'disease', cols = c('#377eb8','#e41a1c'))
VlnPlot(bulk, features = c("C1R"),group.by = 'celltype.full', split.by = 'disease', cols = c('#377eb8','#e41a1c'))
```


Expand All @@ -189,4 +187,4 @@ VlnPlot(bulk, features = c("C1R"),group.by = 'celltype', split.by = 'disease', c
```{r}
sessionInfo()
```
</details>
</details>

0 comments on commit 3724d0c

Please sign in to comment.