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

BEDPE plotting #46

Closed
jessakay opened this issue Feb 23, 2021 · 2 comments
Closed

BEDPE plotting #46

jessakay opened this issue Feb 23, 2021 · 2 comments

Comments

@jessakay
Copy link

Hello!

I'm interested in visualizing interactions (BEDPE files) with fancplot or through the Python API. It seems that it's currently possible to overlay them as circles on top of contact maps using HicPeakPlot. But I'm wondering if there are ways to plot them as curved lines between anchors on a separate panel (e.g., using matplotlib.patches.Arc as pyGenomeTracks have done). Optionally, it'd be great to have to ability to vary the opacity/thickness of lines based on some "score" column.

Would this be of interest to implement as a new plot class? Or perhaps there is a simpler way of adding them on top of existing panels through matplotlib directly? I tried looking into the latter option but had a hard time figuring out where to start.

Any pointers would be appreciated

@kaukrise
Copy link
Collaborator

Hi,

the FAN-C plotting classes all use standard matplotlib axes for plotting. Here is an example to get you started:

import fanc
import fanc.plotting as fancplot
import matplotlib.pyplot as plt
from matplotlib.patches import Arc

# we use the Bonev et al. (2017) data, which you can find in the FAN-C example data
hic = fanc.load("examples/architecture/other-hic/bonev2017_esc_10kb.chr1.hic")

# Set up the figure with two panels that share an x axis
fig, axes = plt.subplots(2, 1, sharex=True)
# plot the Hi-C matrix (don't show the colorbar as otherwise the axes won't be aligned - you can also use more complicated layouts and put the colorbar in a separate panel using the "cax" argument)
p = fancplot.TriangularMatrixPlot(hic, ax=axes[0], show_colorbar=False)
p.plot('chr1:30.5mb-31.5mb')
# generate an arc
a = Arc((30960000, 0), 380000, 1, theta1=0, theta2=180, edgecolor='blue')
# add arc to the bottom panel
axes[1].add_patch(a)

# show the figure
plt.show()

Screenshot 2021-02-23 at 11 02 11

Obviously to do this automatically for BEDPE files you would have to calculate the midpoint between the two anchors for xy and their distance as width. You could also set something like 1-FDR as the arc height, so loops with higher scores get higher arcs.

If you end up writing a class for this (you can use the HicPeakPlot as a blueprint), feel free to submit a pull request!

Cheers,
Kai

@kaukrise
Copy link
Collaborator

Closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants