Skip to content

contribs_bw throws ValueError when using --debug-chr flag #229

@mfansler

Description

@mfansler

Using the --debug-chr argument in the contribs_bw command can lead to errors like:

Saving 'counts' scores
Traceback (most recent call last):
  File "/work/aaa/miniforge3/envs/chrombpnet_0_1_7/bin/chrombpnet", line 8, in <module>
    sys.exit(main())
  File "/work/aaa/miniforge3/envs/chrombpnet_0_1_7/lib/python3.10/site-packages/chrombpnet/CHROMBPNET.py", line 69, in main
    importance_hdf5_to_bigwig.main(args_copy)
  File "/work/aaa/miniforge3/envs/chrombpnet_0_1_7/lib/python3.10/site-packages/chrombpnet/evaluation/make_bigwigs/importance_hdf5_to_bigwig.py", line 33, in main
    bigwig_helper.write_bigwig(d.sum(1),
  File "/work/aaa/miniforge3/envs/chrombpnet_0_1_7/lib/python3.10/site-packages/chrombpnet/evaluation/make_bigwigs/bigwig_helper.py", line 115, in write_bigwig
    all_entries = np.hstack(all_entries)
  File "<__array_function__ internals>", line 180, in hstack
  File "/work/aaa/miniforge3/envs/chrombpnet_0_1_7/lib/python3.10/site-packages/numpy/core/shape_base.py", line 345, in hstack
    return _nx.concatenate(arrs, 1)
  File "<__array_function__ internals>", line 180, in concatenate
ValueError: need at least one array to concatenate

This can occur under a couple circumstances:

  1. Including multiple debug chromosomes.
  2. Using a chromosome with fewer regions than the number of chrom.sizes entries.

This appears due to the following code:

for itr in iterator:
# subset to chromosome (debugging)
if debug_chr and regions[i][0]!=debug_chr:
continue
i = order_of_regs[itr]
i_chr, i_start, i_end, i_mid = regions[i]

which under either (1) or (2) will always enter the continue branch and lead to all_entries being left empty. Case (1) fails because equality is checked instead of membership; case (2) fails because i is not initialized and is still holding its enumeration value from iterating the chrom.sizes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions