Edinburgh-Genome-Foundry / DnaFeaturesViewer

:eye: Python library to plot DNA sequence features (e.g. from Genbank files)
https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/
MIT License
604 stars 92 forks source link

Overlaping arrows #42

Open ghutinet opened 4 years ago

ghutinet commented 4 years ago

Great tool!

The only thing I couldn't figure is if you want all your gene arrows on the same line with overlapping arrows. I didn't find any option that would allow me to do so. Is there any? If yes would it draw the tip of the arrow on top the next gene arrow or on the bottom?

Thank you

FruityPerdix commented 4 years ago

Hey, I was having the same issue. In the end I used illustrator to align the arrows to the line. This kind of defeats the point. I'm posting this to emphasize that there is more interest for this option.

Other than that I enjoy the library!

Zulko commented 4 years ago

@ghutinet @FruityPerdix there may be a trick to do that I am not 100% sure I understand what the expected result is, do you have a screenshot/schema?

FruityPerdix commented 4 years ago

This is what would be ideal:

overlapping_arrows

Zulko commented 4 years ago

This can be done by setting the record's feature_level_height to 0, which can be done at record creation of afterwards. Here is a minimal example:

from dna_features_viewer import GraphicFeature, GraphicRecord
import numpy as np

record = GraphicRecord(sequence_length=1000, features=[
    GraphicFeature(
        start=50 * i + np.random.randint(-20, 20),
        end=50 * i + np.random.randint(30, 70),
        strand= [-1, 1][i % 2],
        color=["limegreen", "yellow", "cyan"][i % 3],
    )
    for i in range(20)
])
record.feature_level_height = 0  # <=====
ax, _ = record.plot(figure_width=10);

Selection_641 Selection_642

ghutinet commented 4 years ago

Thanks, that works to align the arrows! However the annotation heights are not updated and stay at weird places: phiST

avery-r commented 3 years ago

I'm curious to know if there was ever a fix for this issue. I had to mess around with the label font size and labels_spacing settings to find a combination of values that resulted in all labels being attached to lines.

veghp commented 3 years ago

This problem is a bit complicated and may need refactoring, but redefining the below function before plotting at least connects the boxes until a proper solution is implemented:

def new_determine_annotation_height(levels):
    return 1
record.determine_annotation_height = new_determine_annotation_height

example

ZongzhiWu commented 1 year ago

How about circular genomes?