abidlabs / contrastive

Contrastive PCA
MIT License
199 stars 47 forks source link

TypeError: 'numpy.float64' object cannot be interpreted as an integer #7

Closed edifice1989 closed 6 years ago

edifice1989 commented 6 years ago

Hi guys,

I encountered an issue when running:

contrastive/experiments/Single-Cell RNA-seq (Figure 3).ipynb

The error started from the code :   

dataset = SingleCell(itemgetter(*active_file_idx)(fnames), [fnames[6]])

My best guess this is an issue with Scipy new release?

================ERROR message================

TypeError                                 Traceback (most recent call last)
<ipython-input-34-9d882ec2e7eb> in <module>()
      2 
      3 active_file_idx = [1,2]
----> 4 dataset = SingleCell(itemgetter(*active_file_idx)(fnames), [fnames[6]])

<ipython-input-22-c169daba19a1> in __init__(self, active_files, background_file, N_GENES, to_standardize, verbose)
      5 
      6     def __init__(self, active_files, background_file, N_GENES = 500, to_standardize=True, verbose=True):
----> 7         self.active = vstack([self.file_to_features(fname) for fname in active_files])
      8         self.bg = vstack([self.file_to_features(fname) for fname in background_file])
      9         self.reduce_features(N_GENES)

<ipython-input-22-c169daba19a1> in <listcomp>(.0)
      5 
      6     def __init__(self, active_files, background_file, N_GENES = 500, to_standardize=True, verbose=True):
----> 7         self.active = vstack([self.file_to_features(fname) for fname in active_files])
      8         self.bg = vstack([self.file_to_features(fname) for fname in background_file])
      9         self.reduce_features(N_GENES)

<ipython-input-22-c169daba19a1> in file_to_features(self, fname)
     28         col = data[:,0]-1 #1-indexed
     29         values = data[:,2]
---> 30         c = csc_matrix((values, (row, col)), shape=(row.max()+1, col.max()+1))
     31         return c
     32 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/sparse/compressed.py in __init__(self, arg1, shape, dtype, copy)
     49                     # (data, ij) format
     50                     from .coo import coo_matrix
---> 51                     other = self.__class__(coo_matrix(arg1, shape=shape))
     52                     self._set_self(other)
     53                 elif len(arg1) == 3:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/sparse/coo.py in __init__(self, arg1, shape, dtype, copy)
    152                     # Use 2 steps to ensure shape has length 2.
    153                     M, N = shape
--> 154                     self._shape = check_shape((M, N))
    155 
    156                 idx_dtype = get_index_dtype(maxval=max(self.shape))

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/sparse/sputils.py in check_shape(args, current_shape)
    279             new_shape = tuple(operator.index(arg) for arg in shape_iter)
    280     else:
--> 281         new_shape = tuple(operator.index(arg) for arg in args)
    282 
    283     if current_shape is None:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/sparse/sputils.py in <genexpr>(.0)
    279             new_shape = tuple(operator.index(arg) for arg in shape_iter)
    280     else:
--> 281         new_shape = tuple(operator.index(arg) for arg in args)
    282 
    283     if current_shape is None:

TypeError: 'numpy.float64' object cannot be interpreted as an integer`
abidlabs commented 6 years ago

It looks like the shape that's being passed into the sparse matrix is not a tuple of integers like it's supposed to be. Can you try seeing what row.max()+1, col.max() evaluate to in line 30 of def file_to_features()? If the values make sense but are floats instead of integers, then you can try casting them.