pyGenomeViz

repository·main·Indexed 19 days ago

https://github.com/moshi4/pygenomeviz

A Python package for comparative genomics visualization based on matplotlib. It enables plotting of genomic features and sequence similarity links between multiple genomes, supporting Genbank and GFF formats. The library provides tools for visualizing exon features, parsing genomic files, and integrating alignment results from BLAST, MUMmer, MMseqs, and progressiveMauve. It supports various output formats including SVG, PDF, and interactive HTML, and offers a web-based GUI via streamlit.

Tokens
22.8K
Snippets
72
Records
95
Agent score
63%

What's inside pygenomeviz

  1. Use the HTML Viewer for interactive visualization

    main

    pyGenomeViz supports interactive HTML viewer output, allowing for features like pan/zoom, tooltips, object color changes, and text changes.

    • In the API: Use the savefig_html method to generate an HTML file.
    • In the CLI: Select the HTML file output option during command execution.
  2. Add and plot data on subtracks

    main

    Subtracks allow you to plot custom graphs (like GC content or GC skew) directly below feature tracks.

    1. Create a track and call track.add_subtrack(name="NAME", ylim=(min, max)).
    2. Retrieve the subtrack using track.get_subtrack("NAME").
    3. Use the subtrack's matplotlib Axes (subtrack.ax) to plot data.
    4. Crucial: When plotting data that corresponds to genomic coordinates, use segment.transform_coord(x) to convert genomic coordinates to the track-level coordinate system used by the matplotlib axes.
    # 1. Add subtrack
    track.add_subtrack(name="GCcontent", ylim=(0, 100))
    
    # 2. Get subtrack and plot
    subtrack = track.get_subtrack("GCcontent")
    for segment in track.segments:
        # x contains genomic coordinates
        x, gc_content = gbk.calc_gc_content(window_size=1000, step_size=500, seq=seq)
        
        # 3. Transform coordinates for matplotlib
        x_transformed = segment.transform_coord(x)
        
        # 4. Plot using the subtrack's axes
        subtrack.ax.fill_between(x_transformed, gc_content, color="grey")
  3. Install pgv-pmauve

    main

    pgv-pmauve is a CLI workflow in pyGenomeViz for visualizing genome alignment results using progressiveMauve. It is used to visualize commonly conserved regions between multiple genomes.

    Installation Options

    Conda

    Install via conda-forge and bioconda:

    conda install -c conda-forge -c bioconda pygenomeviz progressivemauve

    Pip

    Install pyGenomeViz via pip, but note that progressiveMauve must be installed separately. On Ubuntu, you can use apt:

    pip install pygenomeviz
    sudo apt install progressivemauve

    Docker

    Run the workflow using the official Docker image:

    docker run -it --rm -p 8501:8501 ghcr.io/moshi4/pygenomeviz:latest pgv-pmauve -h
    conda install -c conda-forge -c bioconda pygenomeviz progressivemauve
  4. Install pgv-mmseqs

    main

    The pgv-mmseqs CLI workflow requires both pygenomeviz and the mmseqs2 tool. You can install them using Conda, Pip, or Docker.

    Install both packages from conda-forge and bioconda:

    conda install -c conda-forge -c bioconda pygenomeviz mmseqs2

    Pip

    Install pygenomeviz via pip, but you must install mmseqs2 separately. On Ubuntu 22.04 or later, you can use apt:

    pip install pygenomeviz
    sudo apt install mmseqs2

    Docker

    Run the workflow using the official container:

    docker run -it --rm -p 8501:8501 ghcr.io/moshi4/pygenomeviz:latest pgv-mmseqs -h
    conda install -c conda-forge -c bioconda pygenomeviz mmseqs2
  5. Use the pgv-mummer CLI for genome alignment visualization

    main

    The pgv-mummer command visualizes genome alignments using MUMmer tools (nucmer or promer).

    Basic Syntax: pgv-mummer [options] seq1.gbk seq2.gbk seq3.gbk -o outdir

    Key Arguments:

    • seqs: Positional arguments for input GenBank files.
    • -o, --outdir: The output directory for the generated figures.
    • --seqtype: Determines the alignment tool used:
      • --seqtype nucleotide (default): Uses nucmer.
      • --seqtype protein: Uses promer.
    pgv-mummer seq1.gbk seq2.gbk -o output_directory
  6. Install pgv-gui

    main

    The pgv-gui command launches the pyGenomeViz Web Application (built with Streamlit) for visualizing Genbank files and genome comparison results.

    To use the GUI, you must install streamlit. For genome comparison functionality, you must also have BLAST, MUMmer, or MMseqs installed on your system.

    Conda

    Install pyGenomeViz, Streamlit, and required bioinformatics tools via Conda:

    conda install -c conda-forge -c bioconda pygenomeviz streamlit blast mummer mmseqs2

    Pip

    Install pyGenomeViz with the [gui] extra to include Streamlit:

    pip install pygenomeviz[gui]

    Note: On Ubuntu 22.04 or later, you can install the required bioinformatics tools using sudo apt install ncbi-blast+ mummer mmseqs2.

    Docker

    Run the application in a containerized environment:

    docker run -it --rm -p 8501:8501 ghcr.io/moshi4/pygenomeviz:latest pgv-gui
    pip install pygenomeviz[gui]
  7. Use the pgv-pmauve CLI

    main

    The pgv-pmauve command visualizes genome alignments from Genbank or FASTA files.

    Usage Syntax

    pgv-pmauve [options] seq1.gbk seq2.gbk seq3.gbk -o outdir

    Important Constraints

    • Multi-Contig Input: progressiveMauve cannot align multiple contigs directly. If your input contains multiple contigs, the tool will use a concatenated sequence of those contigs as the input.
    • Colormaps: The --block_cmap option accepts any colormap type available in matplotlib.
    pgv-pmauve NC_000913.gbk.gz NC_002695.gbk.gz NC_011751.gbk.gz NC_011750.gbk.gz -o pgv-pmauve_example1 --show_scale_bar
  8. Use the dark theme

    main

    Set the theme argument to "dark" when initializing the GenomeViz object to switch from the default light theme to a dark theme.

    from pygenomeviz import GenomeViz
    
    gv = GenomeViz(fig_track_height=0.7, theme="dark")
  9. Install pyGenomeViz

    main

    pyGenomeViz requires Python 3.10 or later. You can install it via PyPI, Conda, or run it using Docker for the web application interface.

    # Install via PyPI
    pip install pygenomeviz
    
    # Install via conda-forge
    conda install -c conda-forge pygenomeviz
    
    # Use Docker for the GUI
    docker run -it --rm -p 8501:8501 ghcr.io/moshi4/pygenomeviz:latest pgv-gui -h
  10. Install pgv-mummer via Conda, Pip, or Docker

    main

    You can install the pgv-mummer CLI workflow using several methods. Note that pgv-mummer requires the MUMmer toolset to be installed on your system. If using Pip, you must install MUMmer separately (e.g., via sudo apt install mummer on Ubuntu).

    ### Conda
    ```bash
    conda install -c conda-forge -c bioconda pygenomeviz mummer

    Pip

    pip install pygenomeviz
    # Note: You must also install MUMmer manually, e.g.:
    # sudo apt install mummer

    Docker

    docker run -it --rm -p 8501:8501 ghcr.io/moshi4/pygenomeviz:latest pgv-mummer -h
  11. Install pgv-blast

    main

    The pgv-blast CLI workflow requires both pygenomeviz and the blast software. You can install it using Conda, Pip, or Docker.

    Conda

    conda install -c conda-forge -c bioconda pygenomeviz blast

    Pip Install pygenomeviz via pip, but you must manually install BLAST. On Ubuntu, use:

    pip install pygenomeviz
    sudo apt install ncbi-blast+

    Docker Run the tool using the official container:

    docker run -it --rm -p 8501:8501 ghcr.io/moshi4/pygenomeviz:latest pgv-blast -h
    conda install -c conda-forge -c bioconda pygenomeviz blast
  12. Use the pgv-mmseqs CLI workflow

    main

    The pgv-mmseqs command visualizes homologous CDSs (Coding DNA Sequences) using the MMseqs Reciprocal Best-Hit (RBH) method between multiple genomes.

    Basic Syntax: pgv-mmseqs [options] seq1.gbk seq2.gbk seq3.gbk -o outdir

    Arguments:

    • seqs: Positional arguments for input GenBank files.
    • -o, --outdir: Output directory for the results.

    Key Options:

    • --formats: Output image format. Options: 'png' (default), 'jpg', 'svg', 'pdf', 'html'.
    pgv-mmseqs seq1.gbk seq2.gbk seq3.gbk -o outdir