Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mcool files with hic_matrix_square #404

Closed
mxw010 opened this issue Jul 7, 2022 · 6 comments
Closed

Support for mcool files with hic_matrix_square #404

mxw010 opened this issue Jul 7, 2022 · 6 comments
Labels
bug PR opened A PR has been opened to address this issue

Comments

@mxw010
Copy link

mxw010 commented Jul 7, 2022

Welcome to the pyGenomeTracks GitHub repository! Before opening the issue please check
that the following requirements are met :

  • [ x ] Search whether this issue (or a similar issue) has been solved before
    using the search tab above. Link the previous issue if appropriate below.

  • [ x ] Paste your pyGenomeTracks version (pyGenomeTracks --version) and your python
    version (python --version) below.

pyGenomeTracks --version
pyGenomeTracks 3.7

python --version
Python 3.9.12

Pretty sure this is due to the lack of support for .mcool file for some reason, because when I have

[hic matrix]
file = path-to-mcool.mcool::/resolutions/50000

in the .ini file I get

Traceback (most recent call last):
  File "~/.conda/envs/hicexplorer/lib/python3.9/site-packages/pygenometracks/tracksClass.py", line 677, in check_file_exists
    open(file_name_to_check, 'r').close()
FileNotFoundError: [Errno 2] No such file or directory: '~/path-to-file.mcool::/resolutions/50000'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/.conda/envs/hicexplorer/lib/python3.9/site-packages/pygenometracks/tracksClass.py", line 685, in check_file_exists
    open(name_with_tracks_path_to_check, 'r').close()
FileNotFoundError: [Errno 2] No such file or directory: '/~/path-to-file.mcool::/resolutions/50000'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/.conda/envs/hicexplorer/bin/pyGenomeTracks", line 11, in <module>
    main(args)
  File "~/.conda/envs/hicexplorer/lib/python3.9/site-packages/pygenometracks/plotTracks.py", line 274, in main
    trp = PlotTracks(args.tracks.name, args.width, fig_height=args.height,
  File "~/.conda/envs/hicexplorer/lib/python3.9/site-packages/pygenometracks/tracksClass.py", line 80, in __init__
    self.parse_tracks(tracks_file, plot_regions=plot_regions)
  File "~/.conda/envs/hicexplorer/lib/python3.9/site-packages/pygenometracks/tracksClass.py", line 604, in parse_tracks
    track_options = self.check_file_exists(track_options,
  File "~/.conda/envs/hicexplorer/lib/python3.9/site-packages/pygenometracks/tracksClass.py", line 688, in check_file_exists
    raise InputError(f"File in section [{track_dict['section_name']}] "
pygenometracks.utilities.InputError: File in section [3. [hic matrix]] not found:
~/path-to-file.mcool::/resolutions/50000

If I just feed the path to mcool, of course cooler complains that I didn't specify a group.

but when i change the file path to a .cool file, it plots nicely. hic_matrix already supports .mcool file so I would assume the code is already in place somewhere.

@lldelisle
Copy link
Collaborator

Hi,
I am sorry. When I implemented the squared matrix I forgot to change this line:

track_options['file_type'] == 'hic_matrix')

I'll make a PR which corrects it later today.

@mxw010
Copy link
Author

mxw010 commented Jul 8, 2022

Thanks! I Appreciate the quick response.

@lldelisle
Copy link
Collaborator

I nearly forgot you. The PR is ready. I need to check with my colleagues if we do a quick bug fix release.

@lldelisle lldelisle added bug PR opened A PR has been opened to address this issue labels Jul 8, 2022
@lldelisle lldelisle mentioned this issue Dec 7, 2022
@TincaSubic
Copy link

Hi,

I came here from the documentation on 3.8 release.
I have pyGenomeTracks 3.8 and Python 3.8.16 and I am encountering the same issue as already mentioned in this thread. If I specify the group, I get an error that the file cannot be found. On the other hand if I do not specify a group, I get an error from cooler that I did not specify a group.

@lldelisle
Copy link
Collaborator

Hi,
This is really strange because we have a test for this:

def test_plot_tracks_with_mcool():
outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=False)
args = "--tracks {0} --region X:2500000-3500000 "\
"--trackLabelFraction 0.23 --width 38 " \
"--dpi 130 --outFileName {1}" \
"".format(os.path.join(ROOT,
'mcool_hic_matrix_square.ini'),
outfile.name).split()
pygenometracks.plotTracks.main(args)
res = compare_images(os.path.join(ROOT,
'master_mcool_hic_matrix_square.png'),
outfile.name, tolerance)
assert res is None, res
os.remove(outfile.name)

The ini file is here:
browser_tracks_with_mcool = """
[x-axis]
[mcool1]
file = matrix.mcool::/0
depth = 1000000
file_type = hic_matrix_square
[mcool2]
file = matrix.mcool::/1
depth = 1000000
file_type = hic_matrix_square
[mcool3]
file = matrix.mcool::/2
depth = 1000000
file_type = hic_matrix_square
[mcool4]
file = matrix.mcool::/4
depth = 1000000
file_type = hic_matrix_square
"""
with open(os.path.join(ROOT, "mcool_hic_matrix_square.ini"), 'w') as fh:
fh.write(browser_tracks_with_mcool)

And it passes.
Could you try to repeat this on your mcool file to be sure the way you specify the resolution is the good one?

$ cooler info matrix.mcool
Traceback (most recent call last):
  File "/home/ldelisle/.conda/envs/lastVersion/bin/cooler", line 10, in <module>
    sys.exit(cli())
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/cooler/cli/_util.py", line 203, in decorated
    func(*args, **kwargs)
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/cooler/cli/info.py", line 41, in info
    c = Cooler(cool_uri)
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/cooler/api.py", line 85, in __init__
    self._refresh()
  File "/home/ldelisle/.conda/envs/lastVersion/lib/python3.9/site-packages/cooler/api.py", line 106, in _refresh
    raise KeyError(err_msg) from None
KeyError: "No cooler found at: matrix.mcool. Coolers found in ['/0', '/1', '/2', '/3', '/4']. Use '::' to specify a group path"
$ cooler info matrix.mcool::/0
{
    "bin-size": 640000,
    "bin-type": "fixed",
    "creation-date": "2018-02-14T15:11:28.401416",
    "format": "HDF5::Cooler",
    "format-url": "https://github.com/mirnylab/cooler",
    "format-version": 2,
    "generated-by": "cooler-0.7.6",
    "genome-assembly": "unknown",
    "nbins": 209,
    "nchroms": 5,
    "nnz": 21798,
    "sum": 2329145
}

@lldelisle lldelisle reopened this Jun 22, 2023
@TincaSubic
Copy link

TincaSubic commented Jun 23, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug PR opened A PR has been opened to address this issue
Projects
None yet
Development

No branches or pull requests

3 participants