Skip to content
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 classify_clone_cell_type() #627

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dynamo/prediction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
rank_perturbation_cells,
rank_perturbation_genes,
)
from .state_graph import state_graph, tree_model
from .state_graph import classify_clone_cell_type, state_graph, tree_model
from .trajectory import GeneTrajectory, Trajectory
from .trajectory_analysis import (
calc_mean_exit_time,
Expand Down Expand Up @@ -45,5 +45,6 @@
"get_pulse_r0",
"calc_mean_exit_time",
"calc_mean_first_passage_time",
"classify_clone_cell_type",
"mean_first_passage_time",
]
28 changes: 21 additions & 7 deletions dynamo/prediction/state_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,29 @@
# from sklearn.preprocessing import OrdinalEncoder


def classify_clone_cell_type(adata, clone, clone_column, cell_type_column, cell_type_to_excluded):
"""find the dominant cell type of all the cells that are from the same clone"""
cell_ids = np.where(adata.obs[clone_column] == clone)[0]

to_check = adata[cell_ids].obs[cell_type_column].value_counts().index.isin(list(cell_type_to_excluded))
def classify_clone_cell_type(
adata: AnnData,
clone: str,
clone_column: str,
cell_type_column: str,
cell_type_to_excluded: Union[List, str],
) -> str:
"""Find the dominant cell type of all the cells that are from the given clone.

cell_type = np.where(to_check)[0]
Args:
adata: AnnData object.
clone: The clone name that specifies the clone group used to find the dominant cell type.
clone_column: The column name in `adata.obs` that corresponds to the clone information.
cell_type_column: The column name in `adata.obs` that corresponds to cell type information.
cell_type_to_excluded: The cell type name that will be excluded from the dominant cell type calculation.

return cell_type
Returns:
The dominant cell type of all the cells that are from the given clone.
"""
cell_ids = np.where(adata.obs[clone_column] == clone)[0]
cell_types_counts = adata[cell_ids].obs[cell_type_column].value_counts()
to_check = cell_types_counts.index.isin(list(cell_type_to_excluded))
return cell_types_counts[np.where(~to_check)[0]].index[0]


def prune_transition(
Expand Down