Skip to main content

plot ideograms in matplotlib

Project description

pyideogram

Introduction

This is a python package to plot ideograms in matplotlib, as well as simple gene tracks. I made this primarily for myself, since I could not find any nice looking svg supporting ideogram package in python that works well with matplotlib. The general design idea is that the functions should be intuitive to use for someone familiar with matplotlib and give reasonably well looking output with minimal configuration, but should also have the flexibility of other matplotlib functions. So the underlying matplotlib functions can be manipulated directly by giving the correct kwargs.

Installation

You can easily install it via pip from pypi

pip install pyideogram

or install it manually:

git clone balthasar-eu/pyideogram
cd pyideogram
pip install .

Dependencies are python3.10, matplotlib and numpy

Usage

The package comes with integrated cytobands files for hg19 and hg38, as well as MANE transcripts (only positions, and orientation) for hg38. If you run any of the functions without providing annotation files, it will assume you want to use the stored ones.

The package currently has ideogramh and ideogramv which plot horizontal and vertical ideograms respectively, as well as a genetrack function, which can plot transcripts and exons from gtf files. full_ideogram iterates over all chromosomes and plots them with either ideogramh or ideogramv. Help is available for all functions int he docstring, which you can get with help().

Examples

import pyideogram
fig = pyideogram.full_ideogram()
fig.show()

Full ideogram of hg38

import pyideogram
from matplotlib import pyplot as plt

chrom = "chr6"

fig = plt.figure(figsize=(10, 4), dpi=150)

fig.suptitle("Chromsome 6")

gs = fig.add_gridspec(
    nrows=6,
    ncols=3,
    width_ratios=[2, 20, 2],
    height_ratios=[1, 1, 0.5, 1, 0.5, 1],
    hspace=0.01,
    left=0.01,
    right=0.99,
    top=0.94,
)

start = 29942000
end = 29946000

ax = fig.add_subplot(gs[0, :])

pyideogram.genetrack(
    f"{chrom}:{start}-{end}",
    ax=ax,
    textlane=True,
    transcriptstyle="arrowed",
    exonstyle="Box",
)

all_chrom = fig.add_subplot(gs[2, 1])
all_chrom.axis("off")
all_chrom.set_xticks([])

pyideogram.ideogramh(chrom, ax=all_chrom)
pyideogram.zoom(ax, all_chrom)

pyideogram.set_genome_xticks(ax)

start = 130000000
end = 135000000

ax = fig.add_subplot(gs[5, :])

pyideogram.genetrack(
    f"{chrom}:{start}-{end}",
    ax=ax,
    lanenum=5,
    trackkwargs={
        "color": "lightblue",
    },
    textlane=False,
    text_clip_width=True,
)

pyideogram.set_genome_xticks(ax)

ax = fig.add_subplot(gs[4, :], sharex=ax)

ax.set_xlim(start, end)
pyideogram.ideogramh(chrom, ax=ax, names=True)

pyideogram.zoom(ax, all_chrom)
plt.axis("off")
ax.tick_params(labelbottom=False)

Full ideogram of hg38

Citation

There is currently no publication attached to this package.

If you use the provided annotation for plotting genes, you might want to cite the MANE paper.

You might also want to cite matplotlib.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyideogram-0.0.2.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

pyideogram-0.0.2-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file pyideogram-0.0.2.tar.gz.

File metadata

  • Download URL: pyideogram-0.0.2.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for pyideogram-0.0.2.tar.gz
Algorithm Hash digest
SHA256 cde86aff66f4bdf3c931e084a1d52af1570838a6229379467aeab67b7ab9e60d
MD5 4c5808a96dfd9631762432fafe6c4872
BLAKE2b-256 f979147ac05b6b0729b6bd4fa05bd215eba3b030e8029d37a866074aa5b612d2

See more details on using hashes here.

File details

Details for the file pyideogram-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyideogram-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for pyideogram-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4b46816241dfbf72ac67916e3b7aa84b8326adabeea1328c088bbeffafa4e9
MD5 a0e98f64e5a1d0be9c9c212ecf55afd7
BLAKE2b-256 5252edfbfc8d06fe6236313f8d69de5c0f0059cad6312b08d2a34f4a2cd0f4be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page