Error with sc.pp.highly_variable_genes, pp.highly_variable_genes` expects an `AnnData` argument

Hello,

I am following the scvi tutorial, and I am getting the following error:

adata = sc.pp.highly_variable_genes(
adata,
flavor=“seurat_v3”,
n_top_genes=2000,
batch_key=“orig.ident”,
subset=True
)

ValueError Traceback (most recent call last)
Input In [6], in <cell line: 2>()
1 adata.raw = adata # keep full dimension safe
----> 2 var = sc.pp.highly_variable_genes(
3 adata,
4 flavor=“seurat_v3”,
5 n_top_genes=2000,
6 batch_key=“orig.ident”,
7 subset=True,
8 inplace=False
9 )

File ~/.local/lib/python3.9/site-packages/scanpy/preprocessing/_highly_variable_genes.py:422, in highly_variable_genes(adata, layer, n_top_genes, min_disp, max_disp, min_mean, max_mean, span, n_bins, flavor, subset, inplace, batch_key, check_values)
416 raise ValueError(
417 'pp.highly_variable_genes expects an AnnData argument, ’
418 ‘pass inplace=False if you want to return a pd.DataFrame.’
419 )
421 if flavor == ‘seurat_v3’:
→ 422 return _highly_variable_genes_seurat_v3(
423 adata,
424 layer=layer,
425 n_top_genes=n_top_genes,
426 batch_key=batch_key,
427 check_values=check_values,
428 span=span,
429 subset=subset,
430 inplace=inplace,
431 )
433 if batch_key is None:
434 df = _highly_variable_genes_single_batch(
435 adata,
436 layer=layer,
(…)
443 flavor=flavor,
444 )

File ~/.local/lib/python3.9/site-packages/scanpy/preprocessing/_highly_variable_genes.py:85, in _highly_variable_genes_seurat_v3(adata, layer, n_top_genes, batch_key, check_values, span, subset, inplace)
83 x = np.log10(mean[not_const])
84 model = loess(x, y, span=span, degree=2)
—> 85 model.fit()
86 estimat_var[not_const] = model.outputs.fitted_values
87 reg_std = np.sqrt(10**estimat_var)

File _loess.pyx:899, in _loess.loess.fit()

ValueError: b’reciprocal condition number 5.0015e-16\n’

Digging around I found suggestions this might be due to several genes with 0 counts, which I expect, so I tried filtering. But

adata=sc.pp.filter_genes(adata, min_cells=1)

results in


TypeError Traceback (most recent call last)
Input In [4], in <cell line: 3>()
1 adata.raw = adata # keep full dimension safe
2 adata=sc.pp.filter_cells(adata, min_genes=200)
----> 3 adata=sc.pp.filter_genes(adata, min_cells=1)
4 var = sc.pp.highly_variable_genes(
5 adata,
6 flavor=“seurat_v3”,
(…)
10 inplace=False
11 )

File ~/.local/lib/python3.9/site-packages/scanpy/preprocessing/_simple.py:259, in filter_genes(data, min_counts, min_cells, max_counts, max_cells, inplace, copy)
256 min_number = min_counts if min_cells is None else min_cells
257 max_number = max_counts if max_cells is None else max_cells
258 number_per_gene = np.sum(
→ 259 X if min_cells is None and max_cells is None else X > 0, axis=0
260 )
261 if issparse(X):
262 number_per_gene = number_per_gene.A1

TypeError: ‘>’ not supported between instances of ‘NoneType’ and ‘int’
TypeError: ‘>’ not supported between instances of ‘NoneType’ and ‘int’

Not sure what could be causing it. I would like to avoid re-filtering, since I am combining preprocessed data.

Thanks!