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
584 stars 90 forks source link

Plotting a region reversed #22

Closed MrTomRod closed 4 years ago

MrTomRod commented 4 years ago

It would be nice to be able to plot a genomic region in reverse. I'm writing a script that allows me to compare the loci around the same genes in different species. Sometimes, the locus of interest is on the leading and sometimes on the lagging strand. I'd like to correct for this by discerning the orientation of the gene of interest and then to plot the region in reverse order if necessary.

Example: Regular plot:

ax, _ = graphic_record.plot(figure_width=12)

test_custom_colors

Reversed plot:

graphic_record.reverse()  # new hypothetical function
ax, _ = graphic_record.plot(figure_width=12)

test_custom_colors_reverse

I'd be very happy if you could implement this.

Zulko commented 4 years ago

Got it. Not sure how easy it will be. A short term solution is to reverse your original Biopython record using record.reverse_complement() before you translate it to a graphic record. You would obtain the second figure, with the difference that the ruler's indices would be different, they would be relative to the (-) strand.

Zulko commented 4 years ago

Have you tried this? I haven't tried it but it could work:

ax, _ = graphic_record.plot(figure_width=12)
x_start, x_end = ax.get_xlim()
ax.set_xlim(x_end, x_start)
MrTomRod commented 4 years ago

It works! The function name is slightly different, get_xlim instead of get_xlims:

ax, _ = graphic_record.plot(figure_width=12)
x_start, x_end = ax.get_xlim()
ax.set_xlim(x_end, x_start)

This solves the issue for me. Thanks a lot!

Zulko commented 4 years ago

Yay! Matplotlib saved the day. Thanks for the use case suggestion, I'll add this to the documentation.