Draw an ideogram of either HG38 or CHM13 contigs in a matplotlib axes object.
Project description
pyryotype
Table of Contents
Installation
pip install ideogram
Example usage
from pyryotype import GENOME, plot_ideogram
from matplotlib import pyplot as plt
fig, axes = plt.subplots(
ncols=1,
nrows=22,
figsize=(11, 11),
facecolor="white",
)
genome = GENOME.CHM13
for ax, contig_name in zip(axes, range(1, 23)):
chromosome = f"chr{contig_name}"
plot_ideogram(ax, target=chromosome, genome=genome)
fig.savefig("ideogram.png", dpi=300)
Will output:
Coverage plotting
Coverage plotting is designed to be used with the output of Mosdepth. The following example uses the output of mosdepth
to plot the coverage of chromosome 1. The region representing the first 100Mb of the chromosome is highlighted in black.
from pathlib import Path
from matplotlib import pyplot as plt
from matplotlib.ticker import EngFormatter
import pandas as pd
from pyryotype.coverage import plot_coverage
test_cov_file = Path(__file__).parent / "static" / "chr1_cov.regions.bed.gz"
fig, ax = plt.subplots(
ncols=1,
nrows=1,
figsize=(11, 2),
)
df = pd.read_csv(test_cov_file, sep="\t", names=["chromosome", "start", "end", "value"])
ax = plot_coverage(ax, df, "chr1", regions=[(0, 100000000)], ylabel="Coverage", color="black")
ax.set_xlabel("Genomic Position (bp)")
# ax.yaxis.set_visible(False)
ax.set_yticks([])
ax.set_yticklabels([])
for side in ("right", "top", "left"):
ax.spines[side].set_visible(False)
formatter = EngFormatter(unit='b', places=1)
# Set formatter for the x-axis
ax.xaxis.set_major_formatter(formatter)
fig.savefig("example_outputs/test_coverage.png", dpi=300, bbox_inches="tight")
Will output something like:
PAF plotting
Designed primarily to plot the alignment of assemblies to a reference genome. Must provide a valid PAF file.
from matplotlib import pyplot as plt
from readpaf import parse_paf
from pathlib import Path
from pyryotype.paf_plotting import PAFProtocol, PlotMode, plot_paf_alignments
test_paf = Path(__file__).parent / "static" / "test.paf"
fig, ax = plt.subplots(
ncols=1,
nrows=1,
figsize=(11, 1),
)
ax = plot_paf_alignments(
ax,
parse_paf(test_paf.open()),
target="chr1",
mapq_filter=0,
strict=PlotMode.STRICT,
contig_colours=PlotMode.UNIQUE_COLOURS,
)
ax.set_xlabel("")
# ax.yaxis.set_visible(False)
ax.set_yticks([])
ax.set_yticklabels([])
for side in ("right", "top", "left"):
ax.spines[side].set_visible(False)
fig.savefig("tests/test_paf_plotting.png", dpi=300, bbox_inches="tight")
Will output the following image: The colours assigned to each alignment can be changed to either be based on the Alignment Strand, or unique for each record. See the PlotMode docstring for the options that can be applied.
Multiple mappings on the same chromosome can be collapsed into a single line by setting strict=PlotMode.STRICT
.
This can be seen in the above mappings, where the large block is comprised of 3 separate alignments, from the same read. IF strict=PlotMode.CHILL
then each alignment will be plotted separately, even if these alignments are from the same read. This looks like:
License
pyryotype
is distributed under the terms of the MIT license.
Cytoband data
- HG38 - Nushell, will have to be adapted for bash
curl -L "https://hgdownload.cse.ucsc.edu/goldenpath/hg38/database/cytoBand.txt.gz" | gzip -d - | rg -Ne "^chr\\d+\t" | save cytoBand_HG38.tsv
- CHM13 - bash yay
curl -L http://t2t.gi.ucsc.edu/chm13/hub/t2t-chm13-v2.0/download/chm13v2.0_cytobands_allchrs.bed.gz | gzip -d - > cytobands_chm13.bed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyryotype-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a697d8d0dbb85409900b9cbd3eaa7c08444b42da18b5351054e126d0e77e786 |
|
MD5 | f6e723364cf8af0a422b5e5b9dc23b38 |
|
BLAKE2b-256 | 50b761a978c18ae9d88f91b9d0a1793da4f7a5de013223a01ed6e0a0040a07a1 |