Skip to main content

A python package for drawing some bioinformatic pictures.

Project description

bioplotz: A package for plotting images for bioinformatics

Latest PyPI version Downloads

Dependencies

Python modules:

  • numpy
  • matplotlib
  • pandas

Installation

Install via pip

pip install bioplotz

Install from source code

pip install git+https://github.com/sc-zhang/bioplotz.git --user

Usage

Manhattan Plot

import bioplotz as bp

fig, ax = bp.manhattan(data, threshold=0, color=['orange', 'green'], threshold_line_color='blue', log_base=0,
                       reverse=False, xtick_labels=True, ytick_labels=True, ax=None, marker='.', s=1, **kwargs)
parameter value type explain
data dict
list
dict key: block name
    value: [[x1,x2,...,xn], [y1,y2,...,yn]]
list is a list like: [[x1,y1], [x2, y2], ..., [xn, yn]]
threshold value
list
value if only one threshold line to plot, Notice: if log_base was set, threshold values should be calculated with same log_base manunally, if reverse is True, threshold values should be set to its opposite number
list if more than one threshold line need to plot, a list can be used for different lines, like: [threshold_value1, threshol_value2]
color list color is a list used for blocks, if the count of block greater than color count, it will be used circularly
threshold_line_color value
list
value if threshold is a single value
list if threshold is a list
threshold_line_width value value the line width of threshold lines
block_line_width value value if there are only one color, the block line will display as border, the width is set by this parameter
log_base value log_base = 0 means not calucate value with log
log_base != 0 means log base for log values with it
reverse Boolean if all data lower than 0, you may use it to show opposite values
other parameters value same with parameters used in pyplot.scatter

Chromosome Plot

import matplotlib.pyplot as plt
import bioplotz as bp

fig, ax, mapper = bp.chromosome(chr_len_db, chr_order, bed_data, centro_pos, value_type="numeric", orientation="vertical", **kwargs)
plt.colorbar(mapper, ax=ax, shrink=0.5)
parameter value type Optional Default explain
chr_len_db dict No - key: chromosome name
value: chromosome length
chr_order list Yes None list: the custom chromosome order, like: ["Chr1", "Chr3", "Chr2"]
must same with keys in chr_len
bed_data list Yes None list: two dimension list, like: [[chrome name, start pos, end pos, value/color]]
centro_pos dict Yes None key: chromosome name
value: middle position of centromere
value_type str Yes numeric numeric: the 4th column of bed_data should be value
color: the 4th column of bed_data is color
marker: different with other two types, it need 5 columns, the 4th column of bed_data is marker, the 5th column is color (marker is same with the parameter which be used in pyplot.scatter)
orientation str Yes vertical "vertical" or "horizontal"
cmap str Yes gist_rainbow cmap for colorbar
cmap_parts int Yes 100 how many parts for splitting cmap
s float or array-like, shape(n,) Yes None same with parameter s use in pyplot.scatter
fig_ratio float Yes None if plot with subplots, use this parameter to keep the arcs of chromosomes correct, for "vertical", this parameter should be fig_width/fig_height, otherwise, fig_height/fig_width
other parameters value Yes None same with parameters used in pyplot.plot
  • If value_type is numeric, the return value will be a mapper, else None

Gene Cluster Plot

import bioplotz as bp

fig, ax = bp.genecluster(gene_list)
parameter value type Optional Default explain
gene_list list No - list: 2-dimension list, like [[gene name, start pos, end pos, direct(+/-), color], ..., [gene name, start pos, end pos, direct(+/-), color]]
edgecolor list
str
Yes None list: same length with gene_list, like: ["green", "blue", ..., "red"]
str: common edge color for all genes
edgewidth int Yes 1 edge width for all genes
lw int Yes 3 line width to show the genome backbone

Notice, the best figsize should be (gene count, 1), for example: plt.figure(figsize=(16, 1)), and the bbox_inches parameter which in savefig should be 'tight'.

Multi Alignment Plot

import bioplotz as bp

fig, ax = bp.multialign(data)
parameter value type Optional Default explain
data dict No - key: gene name
value: alignment sequence
match_color str Yes blue color of matched bases
match_background_color str Yes None background color of matched bases
mismatch_color str Yes red color of mismatched bases
mismatch_background_color str Yes None background color of mismatched bases
base_per_line int Yes 80 base count to display for each line
highlight_positions list Yes None positions for highlighting, 0-base
highlight_color str Yes green color of highlighting positions in highlight_positions
highlight_background_color str Yes None background color of highlighting positions in highlight_positions
**kwargs any Yes - same with which use in ax.text

Notice, the figsize should be (base_per_line/10, x) where x=align_length/base_per_line*gene_count/5, and the font must be monospaced, like "Courier New", that sometimes user need add codes as following.

import matplotlib as mpl
import bioplotz as bp

basefont = mpl.font_manager.FontProperties(fname="/path/to/font.ttf")
fig, ax = bp.multialign(data, fontproperties=basefont)

or

plt.rcParams['font.sans-serif'] = 'Courier New'

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

bioplotz-0.1.0.dev15.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bioplotz-0.1.0.dev15-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file bioplotz-0.1.0.dev15.tar.gz.

File metadata

  • Download URL: bioplotz-0.1.0.dev15.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for bioplotz-0.1.0.dev15.tar.gz
Algorithm Hash digest
SHA256 bc60fadc06c0e523c80be1f2923ae9660917bde661c83305fc16fcb10bc726bd
MD5 c2c33b31d77b1154e92ae7cd20eded55
BLAKE2b-256 9dc6dbb11d5af48944be2cf629391c858a2d27fc080d46a7928e86682eb73db3

See more details on using hashes here.

File details

Details for the file bioplotz-0.1.0.dev15-py3-none-any.whl.

File metadata

  • Download URL: bioplotz-0.1.0.dev15-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for bioplotz-0.1.0.dev15-py3-none-any.whl
Algorithm Hash digest
SHA256 b5f31d5952ed53ab470b220c54cfa3f8312c08d9d78268d000b6ae318f6ee1a5
MD5 99911d89e11a6e80e8bd3b59d6f44fcb
BLAKE2b-256 87d97552f74cb2d5382f91e89df0aaffa717f8b90813bb085ca76350ce6bb6b6

See more details on using hashes here.

Supported by

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