aertslab / scenicplus

SCENIC+ is a python package to build gene regulatory networks (GRNs) using combined or separate single-cell gene expression (scRNA-seq) and single-cell chromatin accessibility (scATAC-seq) data.
Other
162 stars 27 forks source link

Length mismatch: Expected axis has 0 elements, new values have 3 elements #374

Closed XiaoKaixuan12333 closed 2 months ago

XiaoKaixuan12333 commented 2 months ago

Describe the bug Hi, i want to run pycistarget,accroding the tutorial, when i run "region_sets = {key: pr.PyRanges(region_names_to_coordinates(binarized_topic_region[key].index.tolist())) for key in binarized_topic_region.keys()}" I meet the error :


ValueError Traceback (most recent call last) Cell In[96], line 4 2 import pyranges as pr 3 from pycistarget.utils import * ----> 4 region_sets = {key: pr.PyRanges(region_names_to_coordinates(region_bin_topics_top_3k[key].index.tolist())) for key in region_bin_topics_top_3k.keys()}

Cell In[96], line 4, in (.0) 2 import pyranges as pr 3 from pycistarget.utils import * ----> 4 region_sets = {key: pr.PyRanges(region_names_to_coordinates(region_bin_topics_top_3k[key].index.tolist())) for key in region_bin_topics_top_3k.keys()}

File ~/anaconda3/envs/scenicplus/lib/python3.11/site-packages/pycistarget/utils.py:35, in region_names_to_coordinates(region_names) 33 regiondf=pd.concat([chrom, start, end], axis=1, sort=False) 34 regiondf.index=[i for i in region_names if ':' in i] ---> 35 regiondf.columns=['Chromosome', 'Start', 'End'] 36 return(regiondf)

File ~/anaconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/generic.py:5920, in NDFrame.setattr(self, name, value) 5918 try: 5919 object.getattribute(self, name) -> 5920 return object.setattr(self, name, value) 5921 except AttributeError: 5922 pass

File ~/anaconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/_libs/properties.pyx:69, in pandas._libs.properties.AxisProperty.set()

File ~/anaconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/generic.py:822, in NDFrame._set_axis(self, axis, labels) 820 def _set_axis(self, axis: int, labels: AnyArrayLike | list) -> None: 821 labels = ensure_index(labels) --> 822 self._mgr.set_axis(axis, labels) 823 self._clear_item_cache()

File ~/anaconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/internals/managers.py:228, in BaseBlockManager.set_axis(self, axis, new_labels) 226 def set_axis(self, axis: int, new_labels: Index) -> None: 227 # Caller is responsible for ensuring we have an Index object. --> 228 self._validate_set_axis(axis, new_labels) 229 self.axes[axis] = new_labels

File ~/anaconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/internals/base.py:70, in DataManager._validate_set_axis(self, axis, new_labels) 67 pass 69 elif new_len != old_len: ---> 70 raise ValueError( 71 f"Length mismatch: Expected axis has {old_len} elements, new " 72 f"values have {new_len} elements" 73 )

ValueError: Length mismatch: Expected axis has 0 elements, new values have 3 elements

I have check the https://github.com/aertslab/scenicplus/issues/87 mentioned

for DAR in markers_dict.keys():
    regions = markers_dict[DAR].index[markers_dict[DAR].index.str.startswith('chr')] #only keep regions on known chromosomes
    if len(regions) > 0:
        region_sets['DARs'][DAR] = pr.PyRanges(region_names_to_coordinates(regions))

but i still have this error. I don not know what wrong with it. please help me.

XiaoKaixuan12333 commented 2 months ago

I have checked the code in pycistarget utils.py package. I've found the code require region name must"chrX: start-end" but my region name is " chrX-strat-end". After i change my region name, i've solve this problem.