jlakkis / CarDEC

Other
19 stars 4 forks source link

Initializing CarDEC class failing #3

Closed bapoorva closed 4 years ago

bapoorva commented 4 years ago

Hi, I attempted to run Cardec on my own test data set but its failing at the very step when i run

CarDEC = CarDEC_API(adata, weights_dir = "weights_dir/CarDEC_LVG Weights", batch_key = "sample", n_high_var = 2000, LVG = True)

I get this error

Trying to set attribute `.var` of view, copying.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/CarDEC/CarDEC_API.py", line 36, in __init__
    self.dataset = normalize_scanpy(adata, *self.norm_args)
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/CarDEC/CarDEC_utils.py", line 60, in normalize_scanpy
    n_bins = 20, n_top_genes = n_high_var, batch_key = batch_key)
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/scanpy/preprocessing/_highly_variable_genes.py", line 244, in highly_variable_genes
    batches = adata.obs[batch_key].cat.categories
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 5270, in __getattr__
    return object.__getattribute__(self, name)
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/pandas/core/accessor.py", line 187, in __get__
    accessor_obj = self._accessor(obj)
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/pandas/core/arrays/categorical.py", line 2512, in __init__
    self._validate(data)
  File "/Users/bapoorva/opt/miniconda3/lib/python3.7/site-packages/pandas/core/arrays/categorical.py", line 2521, in _validate
    raise AttributeError("Can only use .cat accessor with a 'category' dtype")
AttributeError: Can only use .cat accessor with a 'category' dtype

So I get that my input is not of the right datatype. I analyzed my data using Seurat and I ran SCT on it. So my input has 2 assays. But it is set to "RNA" assay by default. I'm not entirely sure what part of my input data is generating this error. Any suggestions ?

Apoorva

bapoorva commented 4 years ago

Turns out my sample column was an integer instead of a category. That solved it