aertslab / pycisTopic

pycisTopic is a Python module to simultaneously identify cell states and cis-regulatory topics from single cell epigenomics data.
Other
58 stars 12 forks source link

consensus_peaks.to_bed #139

Closed TingTingShao closed 6 months ago

TingTingShao commented 6 months ago

Hi,

I ran into unexpected error never met before with the established pipeline, not sure why

rule get_consensus_peaks:
    input:
        narrow_peaks_pkl=os.path.join(config['work_dir'], "030results_cistopic/010consensus_peak_calling/MACS/narrow_peaks_dict.pkl"),
    output:
        consensus_regions=os.path.join(config['work_dir'], "030results_cistopic/010consensus_peak_calling/consensus_regions.bed")
    run:
        narrow_peaks_dict=pickle.load(open(input.narrow_peaks_pkl, 'rb'))
        print("-------narrow-peaks-dict--------")
        print(narrow_peaks_dict)
        consensus_peaks=get_consensus_peaks(narrow_peaks_dict, config['peak_half_width'], chromsizes=chromsizes, path_to_blacklist=config['path_to_blacklist'])
        print("-------consensus-peaks--------")
        print(consensus_peaks)
        if isinstance(consensus_peaks, set):
            consensus_peaks=list(consensus_peaks.tolist)
        consensus_peaks.to_bed(
            path = output.consensus_regions,
            keep=True,
            compression='infer',
            chain=False)   

error:

-------consensus-peaks--------
+--------------+-----------+-----------+-------+
| Chromosome   | Start     | End       | +2    |
| (category)   | (int64)   | (int32)   | ...   |
|--------------+-----------+-----------+-------|
| chr1         | 807568    | 808068    | ...   |
| chr1         | 819547    | 820047    | ...   |
| chr1         | 858607    | 859107    | ...   |
| chr1         | 897235    | 897735    | ...   |
| ...          | ...       | ...       | ...   |
| chrY         | 3003914   | 3004414   | ...   |
| chrY         | 8567191   | 8567691   | ...   |
| chrY         | 14525148  | 14525648  | ...   |
| chrY         | 14525960  | 14526460  | ...   |
+--------------+-----------+-----------+-------+
Unstranded PyRanges object has 1,269,742 rows and 5 columns from 24 chromosomes.
For printing, the PyRanges was sorted on Chromosome.
2 hidden columns: Name, Score
2024-05-05 18:58:19,755 snakemake.logging ERROR    RuleException:
TypeError in file /vsc-hard-mounts/leuven-data/351/vsc35107/master_thesis/snap2_pipeline/Snakefile01, line 74:
Passing a set as an indexer is not supported. Use a list instead.
  File "/vsc-hard-mounts/leuven-data/351/vsc35107/master_thesis/snap2_pipeline/Snakefile01", line 74, in __rule_get_consensus_peaks
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pyranges/pyranges.py", line 4894, in to_bed
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pyranges/out.py", line 129, in _to_bed
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pyranges/out.py", line 129, in <listcomp>
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pyranges/out.py", line 37, in _bed
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/generic.py", line 4578, in get
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/frame.py", line 4051, in __getitem__
  File "/data/leuven/351/vsc35107/miniconda3/envs/scenicplus/lib/python3.11/site-packages/pandas/core/indexing.py", line 2774, in check_dict_or_set_indexers

Thanks, tingting

TingTingShao commented 6 months ago

I re-create a new env, it solved the problem.

Thanks, tingting