Skip to content

Commit 946a4ae

Browse files
authored
Merge pull request #41 from KrishnaswamyLab/dev
Fix EB tutorial memory issue
2 parents d524144 + 39bc484 commit 946a4ae

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Python/tutorial/EmbryoidBody.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,12 @@
281281
"source": [
282282
"mito_genes = [gene_symbol.startswith('MT-') for gene_symbol in EBT_counts.columns] # Get all mitochondrial genes. There are 14, FYI.\n",
283283
"\n",
284-
"lib_size = EBT_counts.sum(axis=1)\n",
284+
"lib_size = EBT_counts.to_coo().tocsr().sum(axis=1)\n",
285285
"\n",
286-
"mito_expression = np.mean(EBT_counts.loc[:,mito_genes].values / lib_size.values[:,None], axis=1)\n",
286+
"mito_expression = (EBT_counts.loc[:,mito_genes].to_coo().tocsr().multiply(1 / lib_size)).mean(axis=1)\n",
287+
"\n",
288+
"mito_expression = np.array(mito_expression).flatten() # mean returns a matrix, we want an array\n",
289+
"lib_size = np.array(lib_size).flatten()\n",
287290
"\n",
288291
"top_pct = np.percentile(mito_expression, 90) # top 10 percentile"
289292
]
@@ -386,7 +389,7 @@
386389
"metadata": {},
387390
"outputs": [],
388391
"source": [
389-
"genes_keep = np.sum(EBT_counts > 0, axis=0) > 10\n",
392+
"genes_keep = (EBT_counts > 0).sum(axis=0) > 10\n",
390393
"EBT_counts = EBT_counts.loc[:,genes_keep]"
391394
]
392395
},

0 commit comments

Comments
 (0)