-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: updates for cellranger 9.0 #9541
base: develop
Are you sure you want to change the base?
feature: updates for cellranger 9.0 #9541
Conversation
Thanks for this! I'm excited to try the automatic cell type calling in Cellranger 9.0. |
100%. Comments welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate it!
#' @param filename Name of H5 file containing the feature barcode matrix | ||
#' @param filter.matrix Only keep spots that have been determined to be over | ||
#' tissue | ||
#' @param to.upper Converts all feature names to upper case. This can provide an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Preemptive-- this parameter doesn't seem to be implemented yet)
In my opinion, it would be better not to suggest that blind uppercasing is ever an appropriate way of finding mouse-human orthologs, even in an exploratory analysis.
If the user has some good reason to convert all the symbols to uppercase, they can simply use toupper
and replace the rownames of the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option was put in originally by the seurat team. I'll let them address the usefulness here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter was introduced well before my time but I tend to agree with @rharao.
7cd4ae0
to
90cd6d7
Compare
@dcollins15 sorry for the little formatting edits. Not really sure where those were introduced. Feel free to fix and roxygenise and push directly to my branch as it seems what I'm going on my side is introducing little diffs. |
4e91581
to
3038586
Compare
@evolvedmicrobe I wanted to give you a heads up on this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
R/preprocessing.R
Outdated
) | ||
}) | ||
|
||
for (i in 1:seq_along(seurat.list)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:seq_along(seurat.list)
should be seq_along(seurat.list)
.
Alternatively, you could replace the for loop with:
seurat.list <- lapply(seurat.list, \(x) if (Assays(x) %in% c("Gene Expression", "RNA")) {Add_10X_CellTypes(data.dir, x)} else {x})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did also notice that if Add_10X_CellTypes
doesn't find a cell types csv, it returns the original without warning or error, so if you want to rely on that, you could skip the conditional here.
counts <- Read10X_h5(counts.path, ...) | ||
|
||
if (to.upper) { | ||
counts <- imap(counts, ~{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: because this formula operates on the counts matrices only and doesn't use the list's names, I think the imap
call could be replaced by base::sapply
.
Frankly, I'm not sure why this package imports purrr::imap
anyway, as I can't find it used anywhere in the codebase, not even in Load10X_Spatial
. But that's an issue for another time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally, I like the simplicity and readability of tidy functions. I'll leave it up to the seruat developers to decide if they mind the extra import. I haven't heard any complaints since we wrote this function a few years ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really an issue; the choice one way or another doesn't affect me. (Personally, I agree; I always prefer the purrr functions in my own scripts.) I only wanted to mention it for the attention of the dev team.
Thanks for your receptiveness 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to replacing the imap
call with a sapply
to match the current implementation of Load10X_Spatial
.
Frankly, I'm not sure why this package imports purrr::imap anyway, as I can't find it used anywhere in the codebase, not even in Load10X_Spatial. But that's an issue for another time.
This is also a good point, @importFrom purrr imap
should be dropped from Load10X_Spatial
and as a suggested dependency. Now that you mention it, @importFrom grid rasterGrob
could also be dropped from the function. I'll include these tweaks in #9556 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great 🎉 Big thanks to @rharao for the code review 🙌
For these types of loader functions, I think the two main priorities should be:
- Backward compatibility
- Consistency
You've done a great job emulating the existing Load10X_Spatial
but I wonder if the two functions can or should share more logic 🤔
I’d also appreciate a bit more clarity on how Load10X is intended to relate to Read10X. Specifically:
- What versions of Cell Ranger output are compatible with each?
- As far as I can tell, Read10X hasn't been updated since just before the release of Cell Ranger v7.1.0.
I suspect that we could be doing a better job of making Load10X_Spatial
and LoadXenium
more mutually coherent cohesive but I'm not very familiar with the datatypes or output structure to propose specific suggestions.
On a related note, what's the easiest way to access 10x datasets in their "canonical" structure? I typically download datasets from the 10x Portal but end up having to manually configure the data.dir
for Seurat
. I assume there’s a better method that I’m just ignorant of.
This leads nicely into my other concern: testing. Creating small, representative datasets for testing was one of the more tedious parts of the Visium HD updates. Any thoughts on streamlining this process would be great.
@stephenwilliams22, now that I’ve had a thorough look, I think it would be best to hold off on merging this until after the next release (v5.2.0).
counts <- Read10X_h5(counts.path, ...) | ||
|
||
if (to.upper) { | ||
counts <- imap(counts, ~{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to replacing the imap
call with a sapply
to match the current implementation of Load10X_Spatial
.
Frankly, I'm not sure why this package imports purrr::imap anyway, as I can't find it used anywhere in the codebase, not even in Load10X_Spatial. But that's an issue for another time.
This is also a good point, @importFrom purrr imap
should be dropped from Load10X_Spatial
and as a suggested dependency. Now that you mention it, @importFrom grid rasterGrob
could also be dropped from the function. I'll include these tweaks in #9556 👌
#' @param filename Name of H5 file containing the feature barcode matrix | ||
#' @param filter.matrix Only keep spots that have been determined to be over | ||
#' tissue | ||
#' @param to.upper Converts all feature names to upper case. This can provide an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter was introduced well before my time but I tend to agree with @rharao.
} else { | ||
object <- CreateSeuratObject(counts, assay = assay) | ||
if (Assays(object) %in% c("Gene Expression", "RNA")) { | ||
object <- Add_10X_CellTypes(data.dir, object) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that is.list(counts)
conditional is necessary. Instead, you can just force counts
to always be a list, and then you can do without the else
block.
It looks like there's just one CellTypes
file per data.dir
? If that's the case, this could be simplified even more—the call to Add_10X_CellTypes
could be made on the merged.object
.
This PR adds support for cellranger 9.0 which performs automatic cell type annotation. Creates a simple loading function similar to
Load10x_spatial
for 10x single cell data which will also put cell annotations in themeta.data
.Changes to other .Rd files result from theroxygenize()
functiondecided to let @dcollins15 roxigenize on his end to get formatting and documentation that matches the rest of the repo