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

Address a potential problem while creating a training dataset with dense array inputs #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions gears/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def get_dropout_non_zero_genes(adata):
for i, j in conditions2index.items():
condition2mean_expression[i] = np.mean(adata.X[j], axis = 0)
pert_list = np.array(list(condition2mean_expression.keys()))
mean_expression = np.array(list(condition2mean_expression.values())).reshape(len(adata.obs.condition.unique()), adata.X.toarray().shape[1])
# to handle the non-sparse data input
try :
adata.X = adata.X.toarray()
mean_expression = np.array(list(condition2mean_expression.values())).reshape(len(adata.obs.condition.unique()), adata.X.shape[1])
except:
mean_expression = np.array(list(condition2mean_expression.values())).reshape(len(adata.obs.condition.unique()), adata.X.shape[1])
ctrl = mean_expression[np.where(pert_list == 'ctrl')[0]]

## in silico modeling and upperbounding
Expand Down Expand Up @@ -408,4 +413,4 @@ def get_genes_from_perts(self, perts):
gene_list = [p.split('+') for p in np.unique(perts)]
gene_list = [item for sublist in gene_list for item in sublist]
gene_list = [g for g in gene_list if g != 'ctrl']
return np.unique(gene_list)
return np.unique(gene_list)
9 changes: 7 additions & 2 deletions gears/pertdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,13 @@ def create_cell_graph_dataset(self, split_adata, pert_category,
# Create cell graphs
cell_graphs = []
for X, y in zip(Xs, ys):
cell_graphs.append(self.create_cell_graph(X.toarray(),
y.toarray(), de_idx, pert_category, pert_idx))
try:
cell_graphs.append(self.create_cell_graph(X.toarray(),
y, de_idx, pert_category, pert_idx))
except:
y = y.toarray()
cell_graphs.append(self.create_cell_graph(X.toarray(),
y, de_idx, pert_category, pert_idx))

return cell_graphs

Expand Down