|
4 | 4 | import numpy as np |
5 | 5 | import pandas as pd |
6 | 6 | import loompy as lp |
7 | | -from sklearn.manifold.t_sne import TSNE |
| 7 | +from sklearn.manifold import TSNE |
8 | 8 | from .aucell import aucell |
9 | 9 | from .genesig import Regulon |
10 | 10 | from typing import List, Mapping, Union, Sequence, Optional |
@@ -95,9 +95,7 @@ def export2loom(ex_mtx: pd.DataFrame, regulons: List[Regulon], out_fname: str, |
95 | 95 | embeddings_Y = pd.merge(embeddings_Y, embedding['_Y'].to_frame().rename(columns={'_Y': str(embedding_id)}), left_index=True, right_index=True) |
96 | 96 |
|
97 | 97 | # Calculate the number of genes per cell. |
98 | | - binary_mtx = ex_mtx.copy() |
99 | | - binary_mtx[binary_mtx != 0] = 1.0 |
100 | | - ngenes = binary_mtx.sum(axis=1).astype(int) |
| 98 | + ngenes = np.count_nonzero(ex_mtx, axis=1) |
101 | 99 |
|
102 | 100 | # Encode genes in regulons as "binary" membership matrix. |
103 | 101 | genes = np.array(ex_mtx.columns) |
@@ -127,7 +125,7 @@ def create_structure_array(df): |
127 | 125 | default_embedding.columns=['_X', '_Y'] |
128 | 126 | column_attrs = { |
129 | 127 | "CellID": ex_mtx.index.values.astype('str'), |
130 | | - "nGene": ngenes.values, |
| 128 | + "nGene": ngenes, |
131 | 129 | "Embedding": create_structure_array(default_embedding), |
132 | 130 | "RegulonsAUC": create_structure_array(auc_mtx), |
133 | 131 | "Clusterings": create_structure_array(clusterings), |
|
0 commit comments