KrishnaswamyLab / MAGIC

MAGIC (Markov Affinity-based Graph Imputation of Cells), is a method for imputing missing values restoring structure of large biological datasets.
GNU General Public License v2.0
341 stars 97 forks source link

Error when providing specific value for t #155

Closed surgebiswas closed 5 years ago

surgebiswas commented 5 years ago

When I run magic with a specific value for t as follows:

magic_op = magic.MAGIC(knn=10, t=10)
imp_log10_parent_count_df = magic_op.fit_transform(log10_parent_count_df.T).T

I get the following error. Is there an easy fix? Running version 1.5.5 on python 3.5

---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
<ipython-input-34-6f7298b2be79> in <module>
      1 magic_op = magic.MAGIC(knn=10, t=10)
----> 2 imp_log10_parent_count_df = magic_op.fit_transform(log10_parent_count_df.T).T

~/.local/lib/python3.5/site-packages/magic/magic.py in fit_transform(self, X, graph, **kwargs)
    572         tasklogger.log_start('MAGIC')
    573         self.fit(X, graph=graph)
--> 574         X_magic = self.transform(**kwargs)
    575         tasklogger.log_complete('MAGIC')
    576         return X_magic

~/.local/lib/python3.5/site-packages/magic/magic.py in transform(self, X, genes, t_max, plot_optimal_t, ax)
    516         else:
    517             X_magic = self._impute(graph, t_max=t_max,
--> 518                                    plot=plot_optimal_t, ax=ax)
    519             if store_result:
    520                 self.X_magic = X_magic

~/.local/lib/python3.5/site-packages/magic/magic.py in _impute(self, data, t_max, plot, ax, max_genes_compute_t, threshold)
    669         if (t_opt is not None) and \
    670                 (self.diff_op.shape[1] < data_imputed.shape[1]):
--> 671             diff_op_t = np.linalg.matrix_power(self.diff_op, t_opt)
    672             data_imputed = diff_op_t.dot(data_imputed)
    673 

/usr/local/lib/python3.5/dist-packages/numpy/linalg/linalg.py in matrix_power(a, n)
    599     """
    600     a = asanyarray(a)
--> 601     _assertRankAtLeast2(a)
    602     _assertNdSquareness(a)
    603 

/usr/local/lib/python3.5/dist-packages/numpy/linalg/linalg.py in _assertRankAtLeast2(*arrays)
    202         if a.ndim < 2:
    203             raise LinAlgError('%d-dimensional array given. Array must be '
--> 204                     'at least two-dimensional' % a.ndim)
    205 
    206 def _assertSquareness(*arrays):

LinAlgError: 0-dimensional array given. Array must be at least two-dimensional
scottgigante commented 5 years ago

Hi @surgebiswas , I've added a line of code that should fix this. Do you mind installing from dev and letting me know if it works?

pip install --user git+git://github.com/KrishnaswamyLab/MAGIC.git@dev#subdirectory=python