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

need to fix missing rows too #59

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 14 additions & 5 deletions ktplotspy/plot/plot_cpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,38 @@ def plot_cpdb(

if special_character_regex_pattern is None:
special_character_regex_pattern = DEFAULT_SPEC_PAT
swapr = True if (cell_type1 == ".") or (cell_type2 == ".") else False
swapr = False if (cell_type1 == ".") or (cell_type2 == ".") else True
# prepare data
metadata = adata.obs.copy()
means_mat = prep_table(data=means)
pvals_mat = prep_table(data=pvals)
missing_cols = []
col_start = (
DEFAULT_V5_COL_START if pvals_mat.columns[DEFAULT_CLASS_COL] == "classification" else DEFAULT_COL_START
) # in v5, there are 12 columns before the values
missing_cols, missing_rows = [], []
for col in means_mat.columns:
if col not in pvals_mat.columns:
missing_cols.append(col)
for row in means_mat.index:
if row not in pvals_mat.index:
missing_rows.append(row)
if len(missing_cols) > 0:
epty = np.zeros((pvals_mat.shape[0], len(missing_cols))) + 1
missing_df = pd.DataFrame(epty, columns=missing_cols, index=pvals_mat.index)
pvals_mat = pd.concat([pvals_mat, missing_df], axis=1)
if len(missing_rows) > 0:
epty = np.zeros((len(missing_rows), pvals_mat.shape[1])) + 1
missing_df1 = means_mat.loc[missing_rows, means_mat.columns[:col_start]]
missing_df = pd.DataFrame(epty, columns=pvals_mat.columns, index=missing_rows)
missing_df.update(missing_df1)
pvals_mat = pd.concat([pvals_mat, missing_df], axis=0)
if (interaction_scores is not None) & (cellsign is not None):
raise KeyError("Please specify either interaction scores or cellsign, not both.")

if interaction_scores is not None:
interaction_scores_mat = prep_table(data=interaction_scores)
elif cellsign is not None:
cellsign_mat = prep_table(data=cellsign)
col_start = (
DEFAULT_V5_COL_START if pvals_mat.columns[DEFAULT_CLASS_COL] == "classification" else DEFAULT_COL_START
) # in v5, there are 12 columns before the values
if degs_analysis:
pvals_mat.iloc[:, col_start : pvals_mat.shape[1]] = 1 - pvals_mat.iloc[:, col_start : pvals_mat.shape[1]]
# front load the dictionary construction here
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ktplotspy"
version = "0.2.2"
version = "0.2.3"
description = "Python library for plotting Cellphonedb results. Ported from ktplots R package."
authors = ["Kelvin Tuong <[email protected]>"]
license = "MIT"
Expand Down
Loading