Skip to content

Commit

Permalink
fix nan handling
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgayoso authored and ivirshup committed Jul 29, 2020
1 parent 3b26ccf commit c8be573
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions scanpy/preprocessing/_highly_variable_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ def _highly_variable_genes_seurat_v3(

# this is done in SelectIntegrationFeatures() in Seurat v3
ranked_norm_gene_vars = ranked_norm_gene_vars.astype(np.float32)
ranked_norm_gene_vars[ranked_norm_gene_vars >= n_top_genes] = np.nan
ranked_norm_gene_vars = np.ma.masked_invalid(ranked_norm_gene_vars)
median_ranked = np.median(ranked_norm_gene_vars, axis=0)
num_batches_high_var = np.sum(
(ranked_norm_gene_vars < n_top_genes).astype(int), axis=0
)
ranked_norm_gene_vars = np.ma.filled(ranked_norm_gene_vars, fill_value=np.nan)
ranked_norm_gene_vars[ranked_norm_gene_vars >= n_top_genes] = np.nan
ma_ranked = np.ma.masked_invalid(ranked_norm_gene_vars)
median_ranked = np.ma.median(ma_ranked, axis=0).filled(np.nan)

df = pd.DataFrame(index=np.array(adata.var_names))
df['highly_variable_nbatches'] = num_batches_high_var
Expand Down

0 comments on commit c8be573

Please sign in to comment.