pyGenomeViz icon indicating copy to clipboard operation
pyGenomeViz copied to clipboard

Can this align multiple chromosomes ?

Open gunjanpandey opened this issue 2 years ago • 6 comments

Can this align multiple chromosomes? something like this? If yes, please explain how.

image

gunjanpandey avatar Jan 18 '23 00:01 gunjanpandey

Currently, pyGenomeViz does not have the functionality to align and visualize multiple chromosomes. I plan to add the functionality to visualize multiple chromosome alignment results in the future.

I recommend that you check other tools such as GENESPACE and MCscan(jcvi), which enable you to align and visualize multiple chromosomes.

moshi4 avatar Jan 18 '23 09:01 moshi4

An additional question that might lead to another feature. I have aligning draft genomes, each with several contigs, and I'm wondering if there would be an easy way to assign a direction to contigs within the links table. In my case I am using gbk files as input, so trying to invert contigs within the input file itself could be difficult and time consuming. If there was a way to add a directionality of sorts that would be great. However, I know this would only really work if multiple chromosomes (or contigs) were first supported by your tool. Either way thanks a lot for the great tool!

RyloByte avatar Jan 27 '23 20:01 RyloByte

@RyloByte and @moshi4 . Agreed. I think it would be very useful have chromosome flip option.

@RyloByte - Meanwhile, could you please tell how did you invert a chromosome/contig?

gunjanpandey avatar Jan 28 '23 03:01 gunjanpandey

@gunjanpandey I don't have a method built just yet since I only recently started playing around with these plots. However, I am working on a solution currently. Not sure if anything will come of it though :)

RyloByte avatar Jan 28 '23 14:01 RyloByte

@RyloByte and @gunjanpandey

The following is an answer regarding the chromosome or contig inversion option. It may not be a complete answer, but it may be helpful.

Genbank reverse complement sequences can be easily obtained by using the reverse_complement method implemented in BioPython's SeqRecord. In pyGenomeViz, reverse complement genome sequences can be plotted by setting the reverse option of the Genbank parser class.

Below is an example code.

from pygenomeviz import Genbank, GenomeViz, load_dataset

gbk_files, _ = load_dataset("enterobacteria_phage")

gv = GenomeViz(fig_track_height=0.7)

# Normal direction
gbk = Genbank(gbk_files[0])
track1 = gv.add_feature_track(f"{gbk.name} (normal)", size=gbk.range_size)
track1.add_genbank_features(gbk)

# Reverse direction
gbk_reverse = Genbank(gbk_files[0], reverse=True)
track2 = gv.add_feature_track(f"{gbk_reverse.name} (reverse)", size=gbk_reverse.range_size)
track2.add_genbank_features(gbk_reverse, facecolor="skyblue")

gv.savefig("genbank_example_plot.png")

genbank_example_plot

moshi4 avatar Jan 29 '23 05:01 moshi4

@moshi4 The link is usually generated by blast alignment. How should we handle the situation when manually using reverse complementary sequences to blast against other sequences and generate links? The situation becomes even more complicated after using range in Genbank. xlims introduced in genoplotR can solve such problems, but pyGenomeviz has not considered this situation yet. This is also the problem I am currently facing.

Dx-wmc avatar Jul 10 '23 00:07 Dx-wmc

Close as the issue is resolved in major upgrade v1.0.0

Code Example

from pygenomeviz import GenomeViz
from pygenomeviz.align import MUMmer
from pygenomeviz.parser import Genbank
from pygenomeviz.utils import load_example_genbank_dataset, ColorCycler
ColorCycler.set_cmap("tab10")

gbk_files = load_example_genbank_dataset("saccharomyces")
gbk_list = list(map(Genbank, gbk_files))

gv = GenomeViz(feature_track_ratio=0.1)
gv.set_scale_bar(ymargin=2.0)

# Plot chromosomes
for gbk in gbk_list:
    color = ColorCycler()
    track = gv.add_feature_track(gbk.name, gbk.get_seqid2size(), space=0.01, label_kws=dict(color=color))
    for segment in track.segments:
        segment.add_feature(segment.start, segment.end, plotstyle="bigrbox", fc=color, lw=0.5)

# Run MUMmer alignment
align_coords = MUMmer(gbk_list).run()

# Plot MUMmer alignment links
if len(align_coords) > 0:
    for ac in align_coords:
        gv.add_link(ac.query_link, ac.ref_link, color="grey", inverted_color="red", curve=True, filter_length=1000)

gv.savefig("result.png")

result.png

chromosomes_visualization

moshi4 avatar May 18 '24 15:05 moshi4