You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am getting this error while adding a new column for MT genes.
What is that I am doing wrong?
adata=sc.read_10x_h5(dir_path+'filtered_feature_bc_matrix.h5')
adata.var_names_make_unique()
print(adata.X)
print(adata.obs['sample'].value_counts())
print(adata.obs['sample'].value_counts())
print(f'Number of cells before filter: {adata.n_obs}')
# Quality control - calculate QC covariatesadata.obs['n_counts'] =adata.X.sum(1)
adata.obs['log_counts'] =np.log(adata.obs['n_counts'])
adata.obs['n_genes'] = (adata.X>0).sum(1)
mt_gene_mask= [gene.startswith('MT-') forgeneinadata.var_names]
adata.obs['mt_frac'] =adata.X[:, mt_gene_mask].sum(1)/adata.obs['n_counts']
AV_24 571
Name: sample, dtype: int64
Number of cells before filter: 571
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-26-5e7c1a502972> in <module>
1112 mt_gene_mask = [gene.startswith('MT-') for gene in adata.var_names]
---> 13 adata.obs['mt_frac'] = adata.X[:, mt_gene_mask].sum(1)/adata.obs['n_counts']
~/my_virtualenv/lib/python3.7/site-packages/pandas/core/series.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
634# for binary ops, use our custom dunder methods635 result = ops.maybe_dispatch_ufunc_to_dunder_op(
--> 636 self, ufunc, method, *inputs, **kwargs
637 )
638if result isnotNotImplemented:
pandas/_libs/ops_dispatch.pyx in pandas._libs.ops_dispatch.maybe_dispatch_ufunc_to_dunder_op()
~/my_virtualenv/lib/python3.7/site-packages/pandas/core/ops/common.py in new_method(self, other)
62 other = item_from_zerodim(other)
63
---> 64 return method(self, other)
6566return new_method
~/my_virtualenv/lib/python3.7/site-packages/pandas/core/ops/__init__.py in wrapper(left, right)
503 result = arithmetic_op(lvalues, rvalues, op, str_rep)
504
--> 505 return _construct_result(left, result, index=left.index, name=res_name)
506507 wrapper.__name__= op_name
~/my_virtualenv/lib/python3.7/site-packages/pandas/core/ops/__init__.py in _construct_result(left, result, index, name)
476# We do not pass dtype to ensure that the Series constructor477# does inference in the case where `result` has object-dtype.
--> 478 out = left._constructor(result, index=index)
479 out = out.__finalize__(left)
480
~/my_virtualenv/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
303 data = data.copy()
304else:
--> 305 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
306307 data = SingleBlockManager(data, index, fastpath=True)
~/my_virtualenv/lib/python3.7/site-packages/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
480elif subarr.ndim >1:
481ifisinstance(data, np.ndarray):
--> 482 raise Exception("Data must be 1-dimensional")
483else:
484 subarr = com.asarray_tuplesafe(data, dtype=dtype)
Exception: Data must be 1-dimensional
The text was updated successfully, but these errors were encountered:
Hi,
I am getting this error while adding a new column for MT genes.
What is that I am doing wrong?
The text was updated successfully, but these errors were encountered: