GangCaoLab / CoolBox

Jupyter notebook based genomic data visualization toolkit.
https://gangcaolab.github.io/CoolBox/index.html
GNU General Public License v3.0
224 stars 37 forks source link

Missing arcs when plotting BEDPE file format #73

Open eafyounian opened 2 years ago

eafyounian commented 2 years ago

Hi! When plotting arcs for BEDPE file format, if the first coordinate comes after the second coordinate (i.e. start_x > start_y), the arc is not drawn. I have fixed this issue by swapping the first coordinate with the second coordinate (see figure where the first track after the gene track shows some features, the second track is how it looks after my fix, and the third track is before the fix where some arcs are missing). image Is there some other more elegant fixes?

By the way, I am using coolbox version 0.3.3. I quickly checked the source of the latest version (i.e. 0.3.8) but I did not immediately find any indication that this is addressed in the latest version (but of course I may have missed it 🙂).

Thank you in advance for your consideration and response! 🙂

Nanguage commented 2 years ago

I have reproduced this behavior, the Arc track fetched the non-upper-triangular record(start_x > start_y) but it's not drawn.

image

After I checked, this bug is caused by the following code:

https://github.com/GangCaoLab/CoolBox/blob/36a86b20e032c6200d6f4077a5b241c0dbda2a78/coolbox/core/track/arcs/plot.py#L101

When drawing, the diameter of arc is determined by pos2 - pos1 and becomes negative when plot the non-upper-triangular record(start_x > start_y).

A more elegant solution is to add a judgment to fetch_plot_data that converts all records to the upper-triangular form(start_x < start_y). fetch_plot_data is this function:

https://github.com/GangCaoLab/CoolBox/blob/36a86b20e032c6200d6f4077a5b241c0dbda2a78/coolbox/core/track/arcs/bedpe.py#L56-L78