scverse / scanpy_usage

Scanpy use cases.
BSD 3-Clause "New" or "Revised" License
75 stars 59 forks source link

Problem with sc.pp.highly_variable_genes() #12

Closed Leprechaun777 closed 5 years ago

Leprechaun777 commented 5 years ago

I'm going through the https://scanpy-tutorials.readthedocs.io/en/latest/pbmc3k.html#Finding-marker-genes tutorial. I'm using my own 10x data. Using scanpy 1.37 and now I tried the same with 1.4.

I'm at the line "sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5)"

I'm getting:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-32-ea8d9dc47463> in <module>
----> 1 sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5)

~/anaconda3/lib/python3.6/site-packages/scanpy/preprocessing/highly_variable_genes.py in highly_variable_genes(adata, min_disp, max_disp, min_mean, max_mean, n_top_genes, n_bins, flavor, subset, inplace)
    115         # a normalized disperion of 1
    116         one_gene_per_bin = disp_std_bin.isnull()
--> 117         gen_indices = np.where(one_gene_per_bin[df['mean_bin']])[0].tolist()
    118         if len(gen_indices) > 0:
    119             logg.msg(

~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in __getitem__(self, key)
    909             key = check_bool_indexer(self.index, key)
    910 
--> 911         return self._get_with(key)
    912 
    913     def _get_with(self, key):

~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in _get_with(self, key)
    951                 return self.loc[key]
    952 
--> 953             return self.reindex(key)
    954         except Exception:
    955             # [slice(0, 5, None)] will break if you convert to ndarray,

~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in reindex(self, index, **kwargs)
   3732     @Appender(generic.NDFrame.reindex.__doc__)
   3733     def reindex(self, index=None, **kwargs):
-> 3734         return super(Series, self).reindex(index=index, **kwargs)
   3735 
   3736     def drop(self, labels=None, axis=0, index=None, columns=None,

~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in reindex(self, *args, **kwargs)
   4344         # perform the reindex on the axes
   4345         return self._reindex_axes(axes, level, limit, tolerance, method,
-> 4346                                   fill_value, copy).__finalize__(self)
   4347 
   4348     def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,

~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
   4357             ax = self._get_axis(a)
   4358             new_index, indexer = ax.reindex(labels, level=level, limit=limit,
-> 4359                                             tolerance=tolerance, method=method)
   4360 
   4361             axis = self._get_axis_number(a)

~/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/category.py in reindex(self, target, method, level, limit, tolerance)
    501         else:
    502             if not target.is_unique:
--> 503                 raise ValueError("cannot reindex with a non-unique indexer")
    504 
    505             indexer, missing = self.get_indexer_non_unique(np.array(target))

ValueError: cannot reindex with a non-unique indexer

I'm not sure where the non-unique problem is coming from, my guess was from the gene list. I ran "adata.var_names_make_unique() " as outlined in the tutorial. So I'm guessing it's something else.

Thank you.

Leprechaun777 commented 5 years ago

Nevermind, I guess this wasn't working in 1.37 but now it seems to work in 1.4. I just didn't restart my python after updating to 1.4.