-
Notifications
You must be signed in to change notification settings - Fork 18
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
610 Add script to apply SEACells to AnnData objects #658
610 Add script to apply SEACells to AnnData objects #658
Conversation
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 looks good to me overall! A few of my comments focus on some choices that the script makes, so more docs may be helpful there.
In addition, I do think we want to explain somewhere in the docs the values that you had to recalculate to run SEAcells. The main purpose of that is to be clear how the input data for (at least 1 script in) this module slightly differs from the processed objects.
I'm also think it makes sense to activate the module GHA before developing further, but that should probably be in a separate PR.
|
||
## Input files | ||
|
||
Initial analysis is expected use processed `SingleCellExperiment` objects from the ScPCA Portal, in AnnData format. | ||
|
||
For initial testing, files were downloaded with: |
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.
Just confirming this code is right - since you wrote testing, I wondered if you meant to include the test flag? If not, then not!
""" | ||
Seacells Analysis Script | ||
Joshua Shapiro | ||
2024-07-18 |
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 seems like it will get out of date real fast, for example, now.
---------- | ||
adata : anndata.AnnData | ||
An annData object containing the data to run the SEACells algorithm on. | ||
Should contain an X_pca field with the PCA coordinates of the cells. |
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.
We might want to formally check that X_pca
if present. It doesn't seem necessary at this stage, but it might be helpful later, so can't hurt now?
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 going to modify this to actually call the convert function from within this function.
adata : anndata.AnnData | ||
An annData object containing the data to run the SEACells algorithm on. | ||
Should contain an X_pca field with the PCA coordinates of the cells. | ||
cell_ratio : float |
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.
Can you add a bit here about where the 75 default comes from?
# initialize and fit model | ||
model.construct_kernel_matrix() | ||
model.initialize_archetypes() | ||
model.fit(min_iter=10, max_iter=50) |
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 think this is the function - any reason to not keep their max_iter=100
? Is it super slow?
https://github.com/dpeerlab/SEACells/blob/3462c624ffae0df6d3930490f345f00196c3503e/SEACells/cpu.py#L653-L659
parser.add_argument( | ||
"--logfile", type=pathlib.Path, help="File path for log outputs" | ||
) |
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'd mention that this also controls the verbosity of SEAcells
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 don't think it is necessary for the argument definition. The point is that if you want logs I will put all the info there. If you don't want logs, the verbosity is just annoying.
|
||
## Output files | ||
|
||
TBD | ||
Currently, the script outputs three files per library: an updated AnnData object, a pickled SEACells model object, and a log file. |
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.
Currently it looks like it only outputs a logfile if one specified
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.
Which it is in the run script!
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.
yeah, fair! Since I was mostly reviewing python, "the script" meant the python script to me, but that's not what it means here! 👍
Co-authored-by: Stephanie Spielman <[email protected]>
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.
Thanks for the review. I will be implementing many of your suggestions
|
||
## Output files | ||
|
||
TBD | ||
Currently, the script outputs three files per library: an updated AnnData object, a pickled SEACells model object, and a log file. |
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.
Which it is in the run script!
) | ||
|
||
# recompute principal components and umap (adds additional metadata) | ||
sc.tl.pca(adata, n_comps=50, mask_var="highly_variable") |
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.
Intent here is to keep it the same as the values already present, but I will make that explicit and check.
---------- | ||
adata : anndata.AnnData | ||
An annData object containing the data to run the SEACells algorithm on. | ||
Should contain an X_pca field with the PCA coordinates of the cells. |
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 going to modify this to actually call the convert function from within this function.
parser.add_argument( | ||
"--logfile", type=pathlib.Path, help="File path for log outputs" | ||
) |
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 don't think it is necessary for the argument definition. The point is that if you want logs I will put all the info there. If you don't want logs, the verbosity is just annoying.
call `convert` from within the main function other responses to review
This reverts commit 06e495f.
I think this is pretty much ready for another review. I briefly tried activating the action, but I ran into trouble which I expect is related to small samples sizes. I will investigate those as part of a separate PR when I activate the action for real. |
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.
LGTM! Left a few small comments but nothing I need to see again. Makes sense to deal with GHA separately, as well.
n_comps = min(50, adata.n_vars, adata.n_obs) | ||
sc.tl.pca(adata, n_comps=n_comps, mask_var="highly_variable") | ||
|
||
# recompute principal components and umap |
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.
left over comment?
Co-authored-by: Stephanie Spielman <[email protected]>
Closes #610
This PR adds a python script to apply the SEACells algorithm to AnnData objects.
The main steps and default parameters are derived from https://github.com/dpeerlab/SEACells/blob/main/notebooks/SEACell_computation.ipynb and associated SEACells source code.
One thing to note was that there are few subtleties to the expected formats and associated metadata for things like PCA and UMAP, so it was necessary to recalculate those values, so I wrote a small function to do that. I initally thought I might be able to get away with just renaming the matrices, but it seemed like some of the metadata stored when
scanpy
calculates the dimension reduction matrices was required downstream, so recalculation seemed the way to go. In my testing, the PCA results were nearly identical, but UMAP were subtly different, as might be expected.I am currently writing out both the updated AnnData object and the SEACells model object (as a pickle) in order to have access to both for the later analysis.
The model object seems most useful for checking convergence, so it may not really be needed in most cases, but it is relatively small, so easy to keep.
The wrapper script currently runs only on one sample, and exists mostly just for tracking the commands used for testing.