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

Can this align multiple chromosomes ? #12

Closed
gunjanpandey opened this issue Jan 18, 2023 · 7 comments
Closed

Can this align multiple chromosomes ? #12

gunjanpandey opened this issue Jan 18, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@gunjanpandey
Copy link

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

image

@moshi4
Copy link
Owner

moshi4 commented Jan 18, 2023

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.

@RyloByte
Copy link

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!

@gunjanpandey
Copy link
Author

@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?

@RyloByte
Copy link

@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 :)

@moshi4
Copy link
Owner

moshi4 commented Jan 29, 2023

@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

@Dx-wmc

This comment was marked as off-topic.

@moshi4 moshi4 added the enhancement New feature or request label May 2, 2024
@moshi4
Copy link
Owner

moshi4 commented May 18, 2024

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 moshi4 closed this as completed May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants