-
Notifications
You must be signed in to change notification settings - Fork 59
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
Debug h5ad saving #580
Debug h5ad saving #580
Changes from 17 commits
e6915f6
5cd67ec
05ec638
52b7128
7018bc1
902ac4b
e092c80
29d0d66
b681814
ffa41cd
4ff1eec
e70f895
321cc8c
36a8591
2ef5e0c
02af0f2
8d1cc70
97b279b
6ec2fd5
514a2a6
0a5e5d9
12cdc52
8f3cc0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,7 +243,7 @@ def plot_nullclines( | |
NCx, NCy = None, None | ||
|
||
# if nullcline is not previously calculated, calculate and plot them | ||
if vecfld_dict is None or "nullcline" not in vecfld_dict.keys(): | ||
if vecfld_dict is None or "NCx" not in vecfld_dict.keys() or "NCy" not in vecfld_dict.keys(): | ||
if vecfld_dict is not None: | ||
X_basis = vecfld_dict["X"][:, :2] | ||
min_, max_ = X_basis.min(0), X_basis.max(0) | ||
|
@@ -265,7 +265,10 @@ def plot_nullclines( | |
|
||
NCx, NCy = vecfld2d.NCx, vecfld.NCy | ||
else: | ||
NCx, NCy = vecfld_dict["nullcline"][0], vecfld_dict["nullcline"][1] | ||
NCx, NCy = ( | ||
[vecfld_dict["NCx"][index] for index in vecfld_dict["NCx"]], | ||
[vecfld_dict["NCy"][index] for index in vecfld_dict["NCy"]], | ||
Comment on lines
+268
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what will be the behaviors for this? will this reorder the x/y coordinates of the nullclines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will read the nullclines from the dictionary to form a list of x and y coordinates. The order should be the same. Here is a reference indicating regular dictionaries have kept their items in the same order that they were inserted into the underlying dictionary since python 3.6. |
||
) | ||
|
||
if ax is None: | ||
ax = plt.gca() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
main_info_insert_adata, | ||
main_warning, | ||
) | ||
from ..preprocessing.pca import pca_inverse_transform | ||
from ..tools.connectivity import construct_mapper_umap | ||
from ..tools.utils import fetch_states, getTseq | ||
from ..vectorfield import vector_field_function | ||
from ..vectorfield.utils import vecfld_from_adata, vector_transformation | ||
|
@@ -164,18 +166,34 @@ def fate( | |
# this requires umap 0.4; reverse project to PCA space. | ||
if prediction.ndim == 1: | ||
prediction = prediction[None, :] | ||
exprs = adata.uns["umap_fit"]["fit"].inverse_transform(prediction) | ||
|
||
params = adata.uns["umap_fit"] | ||
mapper = construct_mapper_umap( | ||
params["X_data"], | ||
n_components=params["umap_kwargs"]["n_components"], | ||
metric=params["umap_kwargs"]["metric"], | ||
min_dist=params["umap_kwargs"]["min_dist"], | ||
spread=params["umap_kwargs"]["spread"], | ||
max_iter=params["umap_kwargs"]["max_iter"], | ||
alpha=params["umap_kwargs"]["alpha"], | ||
gamma=params["umap_kwargs"]["gamma"], | ||
negative_sample_rate=params["umap_kwargs"]["negative_sample_rate"], | ||
init_pos=params["umap_kwargs"]["init_pos"], | ||
random_state=params["umap_kwargs"]["random_state"], | ||
umap_kwargs=params["umap_kwargs"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. umap_kwargs=params["umap_kwargs"] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. umap_kwargs=params["umap_kwargs"] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
exprs = mapper.inverse_transform(prediction) | ||
|
||
# further reverse project back to raw expression space | ||
PCs = adata.uns["PCs"].T | ||
if PCs.shape[0] == exprs.shape[1]: | ||
exprs = np.expm1(exprs @ PCs + adata.uns["pca_mean"]) | ||
|
||
ndim = adata.uns["umap_fit"]["fit"]._raw_data.shape[1] | ||
ndim = mapper._raw_data.shape[1] | ||
|
||
if "X" in adata.obsm_keys(): | ||
if ndim == adata.obsm[DKM.X_PCA].shape[1]: # lift the dimension up again | ||
exprs = adata.uns["pca_fit"].inverse_transform(prediction) | ||
exprs = pca_inverse_transform(prediction, PCs=PCs.T, mean=adata.uns["pca_mean"]) | ||
|
||
if adata.var.use_for_dynamics.sum() == exprs.shape[1]: | ||
valid_genes = adata.var_names[adata.var.use_for_dynamics] | ||
|
@@ -189,12 +207,12 @@ def fate( | |
|
||
adata.uns[fate_key] = { | ||
"init_states": init_states, | ||
"init_cells": init_cells, | ||
"init_cells": list(init_cells), | ||
"average": average, | ||
"t": t, | ||
"prediction": prediction, | ||
# "VecFld": VecFld, | ||
"VecFld_true": VecFld_true, | ||
# "VecFld_true": VecFld_true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VecFld_true means the groundtruth vector field. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we need this in the pipeline? |
||
"genes": valid_genes, | ||
} | ||
if exprs is not None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -601,7 +601,7 @@ def least_action( | |
|
||
adata.uns[LAP_key] = { | ||
"init_states": init_states, | ||
"init_cells": init_cells, | ||
"init_cells": list(init_cells), | ||
Comment on lines
604
to
+605
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why list only applies to init_cells instead of init_states? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"t": t, | ||
"mftp": mftp, | ||
"prediction": prediction, | ||
|
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.
why not add this to the place where kmc is saved to adata.uns?
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.
In this way, we can keep a
kmc
object when we run the Dynamo analysis. If we need it, we just read it from theadata.uns
.Umap
object uses a different saving strategy, which means umap parameters will be saved instead of the object itself. My idea is that it is possible to avoid creating a umap in the pipeline even if we run the umap dimension reduction. Unless the user wants to perform inverse transform in a specific analysis likefate
, they don't need this Umap instance. While the creation ofKMC
is inevitable if the user enables thekmc
method intl.cell_velocities
. Since we have already createdKMC
, we can keep it for future usage until saving to h5ad.