vaquerizaslab/fanc

fancplot / -region parameter : KeyError

matteozoia4 opened this issue · 8 comments

Dear FAN-C providers,

I am encountering an issue while trying to plot my .cool file via fancplot.
As I understood in the latest FAN-C version, .cool files can be employed as inputs.
I unfortunately find a mismatch/error while setting the chr:start-end region format syntax.

Here I share the insulation and .cool files download, coupled to the error details.

Many thanks for your help!

Ps: Let me know whether the link works properly.

fancplot -o /../LB_insulation.png chr3:65.1mb-68.6mb \
-p triangular /../LB_5kb.cool -m 3500000 -vmin 0 -vmax 0.05 \
-p scores /../LB_5kb.insulation
2023-04-22 14:04:06,489 INFO Using non-interactive backend
2023-04-22 14:04:09,298 INFO Found 1 regions
/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/bin/fancplot:187: UserWarning: There was an error with plot 0, region chr3:65099999-68600000 (Traceback (most recent call last):
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3652, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
**KeyError: 'chr3'**

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/cooler/util.py", line 164, in parse_region
    clen = chromsizes[chrom] if chromsizes is not None else None
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/pandas/core/series.py", line 1012, in __getitem__
    return self._get_value(key)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/pandas/core/series.py", line 1121, in _get_value
    loc = self.index.get_loc(label)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3654, in get_loc
    raise KeyError(key) from err
KeyError: 'chr3'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/compatibility/cooler.py", line 355, in _region_subset
    df = self.bins().fetch(query)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/cooler/core/_selectors.py", line 115, in fetch
    lo, hi = self._fetch(*args, **kwargs)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/cooler/api.py", line 268, in _fetch
    parse_region(region, self._chromsizes),
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/venv/lib/python3.9/site-packages/cooler/util.py", line 166, in parse_region
    raise ValueError(f"Unknown sequence label: {chrom}") from e
ValueError: Unknown sequence label: chr3

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/bin/fancplot", line 170, in __init__
    fig, axes = gf.plot(plot_region)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/plotter.py", line 211, in plot
    p.plot(r)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/base_plotter.py", line 292, in plot
    plot_output = self._plot(region)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/hic_plotter.py", line 509, in _plot
    self._refresh(region)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/hic_plotter.py", line 556, in _refresh
    x_, y_, hm = self._mesh_data(region)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/hic_plotter.py", line 528, in _mesh_data
    hm = self.hic_buffer.get_matrix(region, region)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/hic_plotter.py", line 143, in get_matrix
    self._BUFFERING_STRATEGIES[self.buffering_strategy](self, *regions)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/plotting/hic_plotter.py", line 183, in _buffer_relative
    self.buffered_matrix = self.data.matrix(tuple(self.buffered_region),
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/matrix.py", line 1023, in matrix
    row_regions, col_regions, matrix_entries = self.regions_and_matrix_entries(key,
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/matrix.py", line 963, in regions_and_matrix_entries
    row_regions, col_regions, edges_iter = self.regions_and_edges(key, *args, **kwargs)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/matrix.py", line 869, in regions_and_edges
    row_regions = list(row_regions)
  File "/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/fanc/compatibility/cooler.py", line 358, in _region_subset
    chromosome_end = self.chromosome_lengths[region.chromosome]
KeyError: 'chr3'
)
  warnings.warn("There was an error with plot {}, region {}:{}-{} ({})".format(i, region.chromosome,
2023-04-22 14:04:09,592 WARNING 'chr3'
Closing remaining open files:/data/projects/p616_Cis-regulatory_landscapes_in_heart_development/hdf5-build/hdf5-1.8.23/fanc/LB_5kb.insulation...done

Hi, I did not yet receive a link to the files - did you send it to me elsewhere?

Please also have a look here for Cooler syntax in FAN-C: https://fan-c.readthedocs.io/en/latest/fanc-executable/compatibility.html

There are still no files - my best guess is that it is 3 and not chr3.

There was also no email attachment

Answering to the message by mail (not directly on the GitHub interface) I was able to attach the files but afterwards are not visible here indeed, my bad.
I answer directly on the GitHub window now hoping with this link it will be possible.

https://we.tl/t-AGovLIH7TD

Many thanks for your time!

It is as I wrote above, the chromosome name in the file is 3, not chr3:

fancplot 3:65.1mb-68.6mb -p triangular LB_5kb.cool -vmin 0 -vmax 0.01

Screenshot 2023-04-25 at 09 57 43