API Reference

Track

Functions:

Arcs(file_, *args, **kwargs)

Compose BEDPE, Pairs track automatically based on type of file extension.(.bedpe, .pairs)

HiCMat(file, *args, **kwargs)

Compose DotHic or Cool track automatically based on tpye of file extension (.cool, .mcool, .hic)

Hist(file, *args, **kwargs)

Compose BigWig, BedGraph, SNP, BAMCov track automatically based on type of file extension.(.bw, .bigwig, .snp, .vcf, .bedgraph, .bam, .sam)

Classes:

ArcsBase(*args, **kwargs)

Arcs(link) track.

BAM(*args, **kwargs)

BAM alignment track for plotting reads.

BAMCov(*args, **kwargs)

Alignment reads coverage track.

BED(*args, **kwargs)

Bed Track for plotting 1d intervals data from .bed file.

BEDPE(*args, **kwargs)

Arcs track from .bedpe file.

BedBase(*args, **kwargs)

BED Base track.

BedGraph(*args, **kwargs)

BedGraph track.

BigWig(*args, **kwargs)

BigWig track

ChromName(*args, **kwargs)

Track for show chromosome name.

Cool(*args, **kwargs)

Cool track from .cool, .mcool file.

DiScore(*args, **kwargs)

Directionnality index track.

DotHiC(*args, **kwargs)

HicMat track from .hic file.

GTF(*args, **kwargs)

GTF gene annotation track.

HLine(*args, **kwargs)

Horizontal line track.

HiCDiff(*args, **kwargs)

Track for express the comparison between two HiC Track.

HiCPeaks(*args, **kwargs)

Hi-C Peaks(Loops) from .bedpe file.

HicMatBase(*args, **kwargs)

HicMatBase class for all track plotting matrix-like data.

HistBase(*args, **kwargs)

HistBase track class

Ideogram(*args, **kwargs)

The chromosome ideograme track.

InsuScore(*args, **kwargs)

Insulation score track.

Pairs(*args, **kwargs)

Arcs track from .pairs file.

SNP(*args, **kwargs)

Track for show SNPs Manhattan plot.

Selfish(*args, **kwargs)

Differential chromatin interaction.

Spacer(*args, **kwargs)

The spacer track Does not have any real content, just used to split two tracks.

TAD(*args, **kwargs)

Tad tack from bed file

Track(*args, **kwargs)

Track base class.

Virtual4C(*args, **kwargs)

Track for view virtual 4C related to a certain genome position, and a HiC Track (include Cool and DotHiC).

XAxis(*args, **kwargs)

The x axis track.

coolbox.core.track.Arcs(file_, *args, **kwargs)coolbox.core.track.arcs.base.ArcsBase

Compose BEDPE, Pairs track automatically based on type of file extension.(.bedpe, .pairs)

class coolbox.core.track.ArcsBase(*args, **kwargs)

Arcs(link) track.

Parameters
stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

has_prop

plot_contacts

plot_label

Methods:

fetch_plot_data(gr, **kwargs)

Parameters

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
intervalspandas.core.frame.DataFrame

Can be two types: 1: with columns: [‘pos1’, ‘pos2’, ‘score’] ‘score’ is optional 2: with columns: [‘start1’, ‘end1’, ‘start2’, ‘end2’, ‘score’] ‘score’ is optional

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.BAM(*args, **kwargs)

BAM alignment track for plotting reads.

Parameters
filestr

Path to .bam .sam file.

length_ratio_threshfloat

Length ratio threshold of show alignments. (Default 0.01)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

fetch_intervals

has_prop

plot_align

plot_label

Methods:

fetch_data(gr, **kwargs)

Parameters

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
intervalspandas.core.frame.DataFrame

Sam interval table. The DataFrame table should has columns like:

columns = [“qname”, “flag”, “rname”, “pos”, “mapq”, “cigar”,

“rnext”, “pnext”, “tlen”, “seq”, “qual”, “options”]

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.BAMCov(*args, **kwargs)

Alignment reads coverage track.

Parameters
file: str

File path of bam file.

num_bins: int, optional

Number of bins to plot hist fig.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

fetch_coverage

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)Union[Tuple[numpy.ndarray, numpy.ndarray], pandas.core.frame.DataFrame, numpy.ndarray]

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.BED(*args, **kwargs)

Bed Track for plotting 1d intervals data from .bed file. The input bed file can be bed3/bed6/bed9/bed12

Parameters
gene_style: {‘flybase’, ‘normal’}
display{‘stacked’, ‘interlaced’, ‘collapsed’}, optional

Display mode. (Default: ‘stacked’)

fontsizeint, optional

Font size. (Default: BED.DEFAULT_FONTSIZE)

labels{True, False, ‘auto’}, optional

Draw bed name or not. ‘auto’ for automate decision according to density. (Default: ‘auto’)

interval_heightint, optional

The height of the interval. (Default: 100)

num_rowsint, optional

Set the max interval rows. (Default: unlimited interval rows)

row_heightfloat

Height of a row. default 0.5

file: str

The file path of .bed file.

colorstr, optional

Track color, ‘bed_rgb’ for auto specify color according to bed record. (Default: ‘bed_rgb’)

border_colorstr, optional

Border_color of gene. (Default: ‘black’)

max_valuefloat, optional

Max score. (Default: inf)

min_valuefloat, optional

Min score. (Default: -inf)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

draw_gene_simple(ax, bed, ypos, rgb, edgecolor)

draws an interval with direction (if given)

draw_gene_with_introns(ax, bed, ypos, rgb, …)

draws a gene like in flybase gbrowse.

draw_gene_with_introns_flybase_style(ax, …)

draws a gene using different styles

fetch_data(gr, **kwargs)

Parameters

fetch_intervals(bgz_file, gr)

Fetch intervals within input chromosome range.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

get_y_pos(free_row)

The y_pos is set such that regions to be plotted do not overlap (stacked).

intervals2dataframe(intervals, bed_type)

Convert intervals list to pandas.DataFrame

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

set_colormap(df)

As min_score and max_score change every plot, we compute them for every plot

draw_arrow

get_rgb_and_edge_color

get_track_height

has_prop

infer_bed_type

init_colormap

load_range

plot_genes

plot_label

Methods:

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.BEDPE(*args, **kwargs)

Arcs track from .bedpe file.

Parameters
file: str

Path of .bedpe file

posstr, optional

Method for choosing arch anchor for bedpe data: ‘start’, ‘end’, ‘mid’, default ‘mid’

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

fetch_intervals

has_prop

plot_contacts

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
intervalspandas.core.frame.DataFrame

Can be two types: 1: with columns: [‘pos1’, ‘pos2’, ‘score’] ‘score’ is optional 2: with columns: [‘start1’, ‘end1’, ‘start2’, ‘end2’, ‘score’] ‘score’ is optional

class coolbox.core.track.BedBase(*args, **kwargs)

BED Base track.

Parameters
file: str

The file path of .bed file.

colorstr, optional

Track color, ‘bed_rgb’ for auto specify color according to bed record. (Default: ‘bed_rgb’)

border_colorstr, optional

Border_color of gene. (Default: ‘black’)

max_valuefloat, optional

Max score. (Default: inf)

min_valuefloat, optional

Min score. (Default: -inf)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

set_colormap(df)

As min_score and max_score change every plot, we compute them for every plot

get_rgb_and_edge_color

has_prop

infer_bed_type

init_colormap

plot_label

Methods:

fetch_data(gr, **kwargs)

Parameters

set_colormap(df)

As min_score and max_score change every plot, we compute them for every plot

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
intervalspandas.core.frame.DataFrame

BED interval table. The table should be in format like:

bed_fields = [‘chromosome’, ‘start’, ‘end’,

‘name’, ‘score’, ‘strand’, ‘thick_start’, ‘thick_end’, ‘rgb’, ‘block_count’, ‘block_sizes’, ‘block_starts’]

The table can be in bed6/bed9/bed12 format and the trailing columns can be omited.

set_colormap(df)

As min_score and max_score change every plot, we compute them for every plot

class coolbox.core.track.BedGraph(*args, **kwargs)

BedGraph track.

Parameters
filestr

File path of bedgraph file.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

has_prop

load

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
hist_data: Union[Tuple[np.ndarray, np.ndarray], pd.DataFrame, np.ndarray]

data used for plotting.

class coolbox.core.track.BigWig(*args, **kwargs)

BigWig track

Parameters
filestr

File path of bigwig file.

num_binsint, optional

Number of bins to plot the hist in current range, default 700.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_plot_data(gr, **kwargs)

Parameters

fetch_scores(genome_range, num_bins[, …])

Fetch bins scores within input chromosome range.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

check_chrom_name

get_num_bins

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Parameters

fetch_plot_data(gr, **kwargs)

Parameters

fetch_scores(genome_range, num_bins[, …])

Fetch bins scores within input chromosome range.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)
Parameters
grGenomeRange
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
hist_data: Union[Tuple[np.ndarray, np.ndarray], pd.DataFrame, np.ndarray]

data used for plotting.

fetch_scores(genome_range, num_bins, max_try_nums=5)

Fetch bins scores within input chromosome range.

class coolbox.core.track.ChromName(*args, **kwargs)

Track for show chromosome name.

Parameters
fontsizefloat

Font name to show.

offsetfloat

Offset ratio to the start position.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.Cool(*args, **kwargs)

Cool track from .cool, .mcool file.

Parameters
file: str

The file path of .cool, .mcool file

balance: bool

If use the balanced contact matrix.

style{‘triangular’, ‘window’, ‘matrix’}, optional

Matrix style, default ‘window’.

cmapstr, optional

Color map of hic matrix, default “JuiceBoxLike”.

color_bar{‘vertical’, ‘horizontal’, ‘no’}, optional

Color bar style. default ‘vertical’.

depth_ratiofloat, optional

Depth ratio of triangular matrix, use ‘full’ for full depth. default ‘full’.

max_value{float, ‘auto’}, optional

Max value of hic matrix, use ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of hic matrix, use ‘auto’ for specify min value automatically, default ‘auto’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

resolution{int, ‘auto’}, optional

Matrix resolution, default ‘auto’.

transform{str, bool}, optional

Transform for matrix, like ‘log2’, ‘log10’, default False.

normalize{‘zscore’, ‘expect’, ‘total’, False}

Normalization method, default False.

norm: {‘log’, ‘no’}

Method used when normalizing. default ‘no’

gaussian_sigma{float, False}, optional

Do gaussian filter(with sigma, for example 1.0) on matrix if specified. default False.

process_func{callable, str, False}, optional

Process matrix with a user-defined function(receive a matrix, return a processed matrix). default False.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr[, gr2])

Fetch the raw matrix should be plotted.

fetch_pixels(gr[, gr2])

Fetch the pixels table of upper triangle of the original contact matrix(not processed).

fetch_plot_data(gr[, gr2])

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

get_track_height(frame_width, *args)

calculate track height dynamically.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr[, gr2])

Plot matrix

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

JuiceBoxLikeColor

JuiceBoxLikeColor2

adjust_figure

diagonal_mean

diagonal_mean_std

draw_colorbar

fetch_window_genome_range

fill_zero_nan

gaussian_matrix

has_prop

infer_binsize

normalize_cis

normalize_matrix

normalize_trans

plot_colorbar

plot_label

plot_matrix

process_matrix

transform_matrix

Methods:

fetch_data(gr[, gr2])

Fetch the raw matrix should be plotted.

fetch_pixels(gr[, gr2])

Fetch the pixels table of upper triangle of the original contact matrix(not processed).

fetch_data(gr: coolbox.utilities.genome.GenomeRange, gr2=None, **kwargs)numpy.ndarray

Fetch the raw matrix should be plotted. Normally it’s a matrix with raw contacts

Parameters
gr2GenomeRange, optional, keyword argument
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
matrixnp.array

Hi-C raw contact matrix.

fetch_pixels(gr: coolbox.utilities.genome.GenomeRange, gr2=None, **kwargs)

Fetch the pixels table of upper triangle of the original contact matrix(not processed).

Parameters
gr2GenomeRange, optional.
balancebool, optional

balance matrix or not, default self.is_balance.

resolution{‘auto’, int}

resolution of the data. for example 5000. ‘auto’ for calculate resolution automatically. default ‘auto’

joinbool

whether to expand the bin ID columns into (chrom, start, end). default True

Returns
pixelspandas.core.frame.DataFrame

Hi-C pixels table. The pixel table contains the non-zero upper triangle entries of the contact map.

class coolbox.core.track.DiScore(*args, **kwargs)

Directionnality index track.

Parameters
hicmat: {str, HicMatBase}

The input hicmat file or HicMatBase object used to calculate di score.

window_size: int, optional

Width of the diamond region along the matrix used to calculate di. default: 40

method: {‘standard’, ‘adaptive’}, optional

Method used for calculating di. default: ‘adaptive’

args_hicdict, optional

Key words arguments used to create Cool/DotHic tack when the input hicmat is a file path

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

di_methods

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)numpy.ndarray

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.DotHiC(*args, **kwargs)

HicMat track from .hic file.

Parameters
file: str

The file path of .hic file.

balance{bool, ‘KR’, ‘VC’, ‘VC_SQRT’}, optional

Matrix balance method, default True(‘KR’ balance)

style{‘triangular’, ‘window’, ‘matrix’}, optional

Matrix style, default ‘window’.

cmapstr, optional

Color map of hic matrix, default “JuiceBoxLike”.

color_bar{‘vertical’, ‘horizontal’, ‘no’}, optional

Color bar style. default ‘vertical’.

depth_ratiofloat, optional

Depth ratio of triangular matrix, use ‘full’ for full depth. default ‘full’.

max_value{float, ‘auto’}, optional

Max value of hic matrix, use ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of hic matrix, use ‘auto’ for specify min value automatically, default ‘auto’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

resolution{int, ‘auto’}, optional

Matrix resolution, default ‘auto’.

transform{str, bool}, optional

Transform for matrix, like ‘log2’, ‘log10’, default False.

normalize{‘zscore’, ‘expect’, ‘total’, False}

Normalization method, default False.

norm: {‘log’, ‘no’}

Method used when normalizing. default ‘no’

gaussian_sigma{float, False}, optional

Do gaussian filter(with sigma, for example 1.0) on matrix if specified. default False.

process_func{callable, str, False}, optional

Process matrix with a user-defined function(receive a matrix, return a processed matrix). default False.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr[, gr2])

Fetch the raw matrix should be plotted.

fetch_pixels(gr[, gr2, balance])

Parameters

fetch_plot_data(gr[, gr2])

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

get_track_height(frame_width, *args)

calculate track height dynamically.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr[, gr2])

Plot matrix

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

JuiceBoxLikeColor

JuiceBoxLikeColor2

adjust_figure

diagonal_mean

diagonal_mean_std

draw_colorbar

fetch_window_genome_range

fill_zero_nan

gaussian_matrix

has_prop

infer_binsize

normalize_cis

normalize_matrix

normalize_trans

plot_colorbar

plot_label

plot_matrix

process_matrix

transform_matrix

Methods:

fetch_data(gr[, gr2])

Fetch the raw matrix should be plotted.

fetch_pixels(gr[, gr2, balance])

Parameters

fetch_data(gr, gr2=None, **kwargs)numpy.ndarray

Fetch the raw matrix should be plotted. Normally it’s a matrix with raw contacts

Parameters
gr2GenomeRange, optional, keyword argument
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
matrixnp.array

Hi-C raw contact matrix.

fetch_pixels(gr, gr2=None, balance=None, **kwargs)
Parameters
gr{str, GenomeRange}

Intervals within input chromosome range.

gr2{str, GenomeRange}

Intervals within input chromsome range2.

balance{bool, ‘KR’, ‘VC’, ‘VC_SQRT’}, optional

matrix balance method, default self.balance.

resolution{‘auto’, int}

resolution of the data. for example 5000. ‘auto’ for calculate resolution automatically. default ‘auto’

Returns
pixelspandas.core.frame.DataFrame

Hi-C pixels table. The pixel table contains the non-zero upper triangle entries of the contact map.

class coolbox.core.track.GTF(*args, **kwargs)

GTF gene annotation track.

Parameters
filestr

Path to .gtf(or .gtf.bgz) file.

row_filterstr, optional

Row filter expression, only keep the rows for draw. (Default ‘feature == “gene”’)

length_ratio_threshfloat

Length ratio threshold of features, (Default 0.01)

color{str, ‘random’}, optional

When the color is random, color for each gene will be randomly selected.

name_attr{‘auto’, ‘gene_name’, ‘gene_id’, str}, optional

Use which attribute to show feature’s name. Default use ‘auto’(try ‘gene_name’ -> ‘gene_id’ -> ‘position_string’)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_intervals(gr)

Parameters

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

plot_label

Methods:

fetch_data(gr, **kwargs)

Parameters

fetch_intervals(gr)

Parameters

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)
Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
df: pandas.DataFrame

should be with the format like:

columns = [‘seqname’, ‘source’, ‘feature’, ‘start’, ‘end’,

‘score’, ‘strand’, ‘frame’, ‘attribute’, ‘feature_name’]

fetch_intervals(gr: coolbox.utilities.genome.GenomeRange)
Parameters
gr{str, GenomeRange}
Returns
intervalspandas.core.frame.DataFrame

Annotation interval table.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.HLine(*args, **kwargs)

Horizontal line track. Used for add a horizontal line between two tracks.

Parameters
line_widthfloat, optional

(Default: HLine.DEFAULT_LINE_WIDTH)

line_stylestr, optional

(Default: HLine.DEFAULT_LINE_STYLE)

colorstr, optional

(Default: HLine.DEFAULT_COLOR)

alphafloat, optional

(Default: HLine.DEFAULT_ALPHA)

heightfloat, optional

The height of Spacer track. (Default: HLine.DEFAULT_HEIGHT)

namestr, optional

Track’s name.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

titlestr, optional

Title of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.HiCDiff(*args, **kwargs)

Track for express the comparison between two HiC Track.

Parameters
hic1coolbox.api.track.Cool

First HiC Track or hic file path(.cool, .mcool, .hic).

hic2coolbox.api.track.Cool

Second HiC Track or hic file path(.cool, .mcool, .hic).

args_hic: dict

Key word arguments send to create Cool/DoctHic instance if the input hic1/hic2 is file.

diff_methodstr

Difference method (‘diff’, ‘log2fc’), default ‘diff’

style{‘triangular’, ‘window’, ‘matrix’}, optional

Matrix style, default ‘window’.

cmapstr, optional

Color map of hic matrix, default “JuiceBoxLike”.

color_bar{‘vertical’, ‘horizontal’, ‘no’}, optional

Color bar style. default ‘vertical’.

depth_ratiofloat, optional

Depth ratio of triangular matrix, use ‘full’ for full depth. default ‘full’.

max_value{float, ‘auto’}, optional

Max value of hic matrix, use ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of hic matrix, use ‘auto’ for specify min value automatically, default ‘auto’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

resolution{int, ‘auto’}, optional

Matrix resolution, default ‘auto’.

transform{str, bool}, optional

Transform for matrix, like ‘log2’, ‘log10’, default False.

normalize{‘zscore’, ‘expect’, ‘total’, False}

Normalization method, default False.

norm: {‘log’, ‘no’}

Method used when normalizing. default ‘no’

gaussian_sigma{float, False}, optional

Do gaussian filter(with sigma, for example 1.0) on matrix if specified. default False.

process_func{callable, str, False}, optional

Process matrix with a user-defined function(receive a matrix, return a processed matrix). default False.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw matrix should be plotted.

fetch_plot_data(gr[, gr2])

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

get_track_height(frame_width, *args)

calculate track height dynamically.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr[, gr2])

Plot matrix

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

JuiceBoxLikeColor

JuiceBoxLikeColor2

adjust_figure

diagonal_mean

diagonal_mean_std

diff_matrix

draw_colorbar

fetch_pixels

fetch_window_genome_range

fill_zero_nan

gaussian_matrix

has_prop

infer_binsize

normalize_cis

normalize_matrix

normalize_trans

plot_colorbar

plot_label

plot_matrix

process_matrix

transform_matrix

Methods:

fetch_data(gr, **kwargs)

Fetch the raw matrix should be plotted.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)numpy.ndarray

Fetch the raw matrix should be plotted. Normally it’s a matrix with raw contacts

Parameters
gr2GenomeRange, optional, keyword argument
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
matrixnp.array

Hi-C raw contact matrix.

coolbox.core.track.HiCMat(file: Union[str, coolbox.core.track.hicmat.base.HicMatBase], *args, **kwargs)coolbox.core.track.hicmat.base.HicMatBase

Compose DotHic or Cool track automatically based on tpye of file extension (.cool, .mcool, .hic)

class coolbox.core.track.HiCPeaks(*args, **kwargs)

Hi-C Peaks(Loops) from .bedpe file. Used to show the peaks on the Hi-C interaction map.

Parameters
file: str

Path of .bedpe file

posstr, optional

Method for choosing arch anchor for bedpe data: ‘start’, ‘end’, ‘mid’, default ‘mid’

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

fetch_intervals

has_prop

plot_contacts

plot_label

class coolbox.core.track.HicMatBase(*args, **kwargs)

HicMatBase class for all track plotting matrix-like data.

Parameters
style{‘triangular’, ‘window’, ‘matrix’}, optional

Matrix style, default ‘window’.

cmapstr, optional

Color map of hic matrix, default “JuiceBoxLike”.

color_bar{‘vertical’, ‘horizontal’, ‘no’}, optional

Color bar style. default ‘vertical’.

depth_ratiofloat, optional

Depth ratio of triangular matrix, use ‘full’ for full depth. default ‘full’.

max_value{float, ‘auto’}, optional

Max value of hic matrix, use ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of hic matrix, use ‘auto’ for specify min value automatically, default ‘auto’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

resolution{int, ‘auto’}, optional

Matrix resolution, default ‘auto’.

transform{str, bool}, optional

Transform for matrix, like ‘log2’, ‘log10’, default False.

normalize{‘zscore’, ‘expect’, ‘total’, False}

Normalization method, default False.

norm: {‘log’, ‘no’}

Method used when normalizing. default ‘no’

gaussian_sigma{float, False}, optional

Do gaussian filter(with sigma, for example 1.0) on matrix if specified. default False.

process_func{callable, str, False}, optional

Process matrix with a user-defined function(receive a matrix, return a processed matrix). default False.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr[, gr2])

Fetch the raw matrix should be plotted.

fetch_plot_data(gr[, gr2])

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

get_track_height(frame_width, *args)

calculate track height dynamically.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr[, gr2])

Plot matrix

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

JuiceBoxLikeColor

JuiceBoxLikeColor2

adjust_figure

diagonal_mean

diagonal_mean_std

draw_colorbar

fetch_pixels

fetch_window_genome_range

fill_zero_nan

gaussian_matrix

has_prop

infer_binsize

normalize_cis

normalize_matrix

normalize_trans

plot_colorbar

plot_label

plot_matrix

process_matrix

transform_matrix

Methods:

fetch_data(gr[, gr2])

Fetch the raw matrix should be plotted.

fetch_plot_data(gr[, gr2])

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

plot(ax, gr[, gr2])

Plot matrix

fetch_data(gr: coolbox.utilities.genome.GenomeRange, gr2=None, **kwargs)numpy.ndarray

Fetch the raw matrix should be plotted. Normally it’s a matrix with raw contacts

Parameters
gr2GenomeRange, optional, keyword argument
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
matrixnp.array

Hi-C raw contact matrix.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, gr2=None, **kwargs)numpy.ndarray

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

Parameters
gr2GenomeRange, optional
gr_updated: bool, optional

If the input GenomeRange has been updated. default False Default False means that the input gr will be expanded in window mode

gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
matrixnp.array

Processed hic matrix used for plotting.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, gr2=None, **kwargs)

Plot matrix

Parameters
ax
gr2GenomeRange, optional
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

coolbox.core.track.Hist(file, *args, **kwargs)coolbox.core.track.hist.base.HistBase

Compose BigWig, BedGraph, SNP, BAMCov track automatically based on type of file extension.(.bw, .bigwig, .snp, .vcf, .bedgraph, .bam, .sam)

class coolbox.core.track.HistBase(*args, **kwargs)

HistBase track class

Parameters
stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)Union[Tuple[numpy.ndarray, numpy.ndarray], pandas.core.frame.DataFrame, numpy.ndarray]

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)Union[Tuple[numpy.ndarray, numpy.ndarray], pandas.core.frame.DataFrame, numpy.ndarray]
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
hist_data: Union[Tuple[np.ndarray, np.ndarray], pd.DataFrame, np.ndarray]

data used for plotting.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.Ideogram(*args, **kwargs)

The chromosome ideograme track.

Parameters
file_str

Path to chromosome ideogram txt file, ideogram file is download from the UCSC Table Browser CytoBandIdeo table (in “all table” group). see: http://genome.ucsc.edu/cgi-bin/hgTables?hgta_group=allTables&hgta_table=cytoBandIdeo

color_schemedict, optional

Color scheme of ideogram, default: Ideogram.DEFAULT_COLOR_SCHEME

show_band_namebool, optional

Show band name or not. default True.

font_sizeint, optional

Band name font size.

border_colorstr, optional

Border color. default: ‘#000000’

border_widthfloat, optional

Border width. default: 1.2

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

lookup_band_color

plot_label

plot_text

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.InsuScore(*args, **kwargs)

Insulation score track.

Parameters
hicmat: {str, HicMatBase}

The input hicmat file or HicMatBase object used to calculate di score.

window_size: {int, str}, optional

Width of the diamond region along the matrix used to calculate di. default: 20 window_size can also be a str with format like “20-40” representing a range of window_sizes.

normalize: bool, optional

Weather to log-nomalize the insulation score array. default: true

method: {‘standard’, ‘adaptive’}, optional

Method used for calculating di. default: ‘adaptive’

args_hicdict, optional

Key words arguments used to create Cool/DotHic tack when the input hicmat is a file path

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)numpy.ndarray

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.Pairs(*args, **kwargs)

Arcs track from .pairs file.

Parameters
file: str

Path of .pairs file

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

fetch_intervals

has_prop

plot_contacts

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.SNP(*args, **kwargs)

Track for show SNPs Manhattan plot.

Input file is a tab-split file contains SNP’s chrom, position, pvalue information. You should specify it’s column indexes by col_chrom, col_pos, col_pval arguments.

Parameters
filestr

Path to input .snp/.vcf file.

col_chromint

Column index of seqname(chromosome).

col_posint

Column index of snp position.

col_pvalint

Column index of snp p-value.

pval_transform{‘-log2’, ‘-log10’}

Transform the p value. Default ‘-log10’.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

has_prop

load_range

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

transform_fn

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
hist_data: Union[Tuple[np.ndarray, np.ndarray], pd.DataFrame, np.ndarray]

data used for plotting.

class coolbox.core.track.Selfish(*args, **kwargs)

Differential chromatin interaction.

Parameters
hic1coolbox.api.track.Cool

First HiC Track or hic file path(.cool, .mcool, .hic).

hic2coolbox.api.track.Cool

Second HiC Track or hic file path(.cool, .mcool, .hic).

hic_argsdict, optional

Argument to create Hi-C instance, only in use when first or second argument is a path.

sigma0float, optional

Initial sigma, parameter of SELFISH method. Default: 1.6

sint, optional

Iteration count parameter of SELFISH method. Default: 10

style{‘triangular’, ‘window’, ‘matrix’}, optional

Matrix style, default ‘window’.

cmapstr, optional

Color map of hic matrix, default “JuiceBoxLike”.

color_bar{‘vertical’, ‘horizontal’, ‘no’}, optional

Color bar style. default ‘vertical’.

depth_ratiofloat, optional

Depth ratio of triangular matrix, use ‘full’ for full depth. default ‘full’.

max_value{float, ‘auto’}, optional

Max value of hic matrix, use ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of hic matrix, use ‘auto’ for specify min value automatically, default ‘auto’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

resolution{int, ‘auto’}, optional

Matrix resolution, default ‘auto’.

transform{str, bool}, optional

Transform for matrix, like ‘log2’, ‘log10’, default False.

normalize{‘zscore’, ‘expect’, ‘total’, False}

Normalization method, default False.

norm: {‘log’, ‘no’}

Method used when normalizing. default ‘no’

gaussian_sigma{float, False}, optional

Do gaussian filter(with sigma, for example 1.0) on matrix if specified. default False.

process_func{callable, str, False}, optional

Process matrix with a user-defined function(receive a matrix, return a processed matrix). default False.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

References

Abbas Roayaei Ardakany, Ferhat Ay, Stefano Lonardi, Selfish: discovery of differential chromatin interactions via a self-similarity measure, Bioinformatics, Volume 35, Issue 14, July 2019, Pages i145–i153, https://doi.org/10.1093/bioinformatics/btz362

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw matrix should be plotted.

fetch_plot_data(gr[, gr2])

Fetch 2d contact matrix, the matrix may be processed in case ‘transform’, ‘normalize’, ‘gaussian_sigma’, ‘process_func’ exits in properties.

get_track_height(frame_width, *args)

calculate track height dynamically.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr[, gr2])

Plot matrix

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

JuiceBoxLikeColor

JuiceBoxLikeColor2

adjust_figure

diagonal_mean

diagonal_mean_std

diff_matrix

draw_colorbar

fetch_pixels

fetch_window_genome_range

fill_zero_nan

gaussian_matrix

has_prop

infer_binsize

normalize_cis

normalize_matrix

normalize_trans

plot_colorbar

plot_label

plot_matrix

process_matrix

transform_matrix

Methods:

fetch_data(gr, **kwargs)

Fetch the raw matrix should be plotted.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)numpy.ndarray

Fetch the raw matrix should be plotted. Normally it’s a matrix with raw contacts

Parameters
gr2GenomeRange, optional, keyword argument
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
matrixnp.array

Hi-C raw contact matrix.

class coolbox.core.track.Spacer(*args, **kwargs)

The spacer track Does not have any real content, just used to split two tracks.

Parameters
heightfloat, optional

The height of Spacer track. (Default: Spacer.DEFAULT_HEIGHT)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.TAD(*args, **kwargs)

Tad tack from bed file

Parameters
border_style: str, optional

Border style of tad. (Default: ‘solid’)

border_width: int, optional

Border width of tad. (Default: ‘2.0’)

show_scorebool

Show bed score or not. default False.

score_font_size{‘auto’, int}

Score text font size. default ‘auto’

score_font_colorstr

Score text color. default ‘#000000’

score_height_ratiofloat

(text tag height) / (TAD height). used for adjust the position of Score text. default 0.5

border_onlybool

Only show border, default False

depth_ratio{float, ‘auto’, ‘full’}

Depth ratio of triangular, use ‘full’ for full depth, use ‘auto’ for calculate depth by current genome_range. default ‘auto’.

orientation{‘normal’, ‘inverted’}

Invert y-axis or not, default ‘normal’

file: str

The file path of .bed file.

colorstr, optional

Track color, ‘bed_rgb’ for auto specify color according to bed record. (Default: ‘bed_rgb’)

border_colorstr, optional

Border_color of gene. (Default: ‘black’)

max_valuefloat, optional

Max score. (Default: inf)

min_valuefloat, optional

Min score. (Default: -inf)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_intervals(bgz_file, gr)

Fetch intervals within input chromosome range.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

intervals2dataframe(intervals, bed_type)

Convert intervals list to pandas.DataFrame

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_tads(ax, gr, tads)

Plots the boundaries as triangles in the given ax.

plot_triangular(ax, gr, region, ymax, depth)

/ / / _____________________

set_colormap(df)

As min_score and max_score change every plot, we compute them for every plot

get_depth_ratio

get_rgb_and_edge_color

get_track_height

has_prop

infer_bed_type

init_colormap

load_range

plot_box

plot_label

plot_score

Methods:

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.Track(*args, **kwargs)

Track base class.

Parameters
properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

plot_label

Methods:

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

append_coverage(coverage, pos='top')

Append coverage to this track.

Parameters
coveragecoolbox.api.coverage.Coverage

Coverage object to be piled.

pos{‘top’, ‘bottom’}, optional

Add coverages to top or bottom. (Default: ‘top’)

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the plot data for the given GenomeRange. The returned data would be used in plot function, the default implementation directly return fetch_data.

Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

pile_coverages(coverages, pos='top')

Pile a stack of coverages with self’s coverages

Parameters
coverageslist of coolbox.api.coverage.Coverage or coolbox.api.coverage.CoverageStack

Coverage objects to be piled.

pos{‘top’, ‘bottom’}, optional

Add coverages to top or bottom. (Default: ‘top’)

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

plot_coverages(ax, gr: coolbox.utilities.genome.GenomeRange, gr2: coolbox.utilities.genome.GenomeRange)

Plot all coverages on given axes.

Parameters
grGenomeRange

First genome range.

gr2GenomeRange

Second genome range.

class coolbox.core.track.Virtual4C(*args, **kwargs)

Track for view virtual 4C related to a certain genome position, and a HiC Track (include Cool and DotHiC).

Parameters
hicmat{str, Cool, DotHiC}

Related hic track or Hi-C file path.

genome_positionstr

related genome position, like: ‘chr1:2000000-2000000’

bin_widthint, optional

How many bin used for calculate the mean value. default 3

args_hicdict, optional

Argument for create hic track, needed only if first argument is a path.

hicmat: {str, HicMatBase}

The input hicmat file or HicMatBase object used to calculate di score.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)numpy.ndarray

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.track.XAxis(*args, **kwargs)

The x axis track.

Parameters
heightfloat, optional

Height of Spacer track. (Default: XAxis.DEFAULT_HEIGHT)

fontsizeint, optional

Font size of XAxis. (Default: XAxis.DEFAULT_FONTSIZE)

where{‘top’, ‘bottom’}, optional

The position of tick labels relative to the axis. (Default: ‘bottom’)

name (str, optional):

Track’s name.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

has_prop

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Coverage

Functions:

Arcs(file_, *args, **kwargs)

Compose BEDPE, Pairs track automatically based on type of file extension.(.bedpe, .pairs)

Hist(file, *args, **kwargs)

Compose BigWig, BedGraph, SNP, BAMCov track automatically based on type of file extension.(.bw, .bigwig, .snp, .vcf, .bedgraph, .bam, .sam)

Classes:

ArcsCoverage(*args, **kwargs)

Compose BEDPE, Pairs track automatically based on type of file extension.(.bedpe, .pairs)

BEDPE(*args, **kwargs)

Arcs track from .bedpe file.

BEDPECoverage(*args, **kwargs)

Arcs track from .bedpe file.

BedGraph(*args, **kwargs)

BedGraph track.

BedGraphCoverage(*args, **kwargs)

BedGraph track.

BigWig(*args, **kwargs)

BigWig track

BigWigCoverage(*args, **kwargs)

BigWig track

HLines(*args, **kwargs)

Horizontal line coverage, for show threshold.

HiCPeaks(*args, **kwargs)

Hi-C Peaks(Loops) from .bedpe file.

HiCPeaksCoverage(*args, **kwargs)

Hi-C Peaks(Loops) from .bedpe file.

HighLights(*args, **kwargs)

High light region.

HighLightsFromFile(*args, **kwargs)

High light regions coverage, read the regions from the file.

HistCoverage(*args, **kwargs)

Compose BigWig, BedGraph, SNP, BAMCov track automatically based on type of file extension.(.bw, .bigwig, .snp, .vcf, .bedgraph, .bam, .sam)

Pairs(*args, **kwargs)

Arcs track from .pairs file.

PairsCoverage(*args, **kwargs)

Arcs track from .pairs file.

TAD(*args, **kwargs)

Tad tack from bed file

TADCoverage(*args, **kwargs)

Tad tack from bed file

Vlines(*args, **kwargs)

Vertical lines.

VlinesFromFile(*args, **kwargs)

Vertical lines from the file.

coolbox.core.coverage.Arcs(file_, *args, **kwargs)coolbox.core.track.arcs.base.ArcsBase

Compose BEDPE, Pairs track automatically based on type of file extension.(.bedpe, .pairs)

class coolbox.core.coverage.ArcsCoverage(*args, **kwargs)

Compose BEDPE, Pairs track automatically based on type of file extension.(.bedpe, .pairs)

Attributes
name

Methods

check_track_type

plot

class coolbox.core.coverage.BEDPE(*args, **kwargs)

Arcs track from .bedpe file.

Parameters
file: str

Path of .bedpe file

posstr, optional

Method for choosing arch anchor for bedpe data: ‘start’, ‘end’, ‘mid’, default ‘mid’

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

fetch_intervals

has_prop

plot_contacts

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
intervalspandas.core.frame.DataFrame

Can be two types: 1: with columns: [‘pos1’, ‘pos2’, ‘score’] ‘score’ is optional 2: with columns: [‘start1’, ‘end1’, ‘start2’, ‘end2’, ‘score’] ‘score’ is optional

class coolbox.core.coverage.BEDPECoverage(*args, **kwargs)

Arcs track from .bedpe file.

Parameters
file: str

Path of .bedpe file

posstr, optional

Method for choosing arch anchor for bedpe data: ‘start’, ‘end’, ‘mid’, default ‘mid’

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

check_track_type

plot

class coolbox.core.coverage.BedGraph(*args, **kwargs)

BedGraph track.

Parameters
filestr

File path of bedgraph file.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

has_prop

load

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)pandas.core.frame.DataFrame
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
hist_data: Union[Tuple[np.ndarray, np.ndarray], pd.DataFrame, np.ndarray]

data used for plotting.

class coolbox.core.coverage.BedGraphCoverage(*args, **kwargs)

BedGraph track.

Parameters
filestr

File path of bedgraph file.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

check_track_type

plot

class coolbox.core.coverage.BigWig(*args, **kwargs)

BigWig track

Parameters
filestr

File path of bigwig file.

num_binsint, optional

Number of bins to plot the hist in current range, default 700.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_plot_data(gr, **kwargs)

Parameters

fetch_scores(genome_range, num_bins[, …])

Fetch bins scores within input chromosome range.

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_yaxis_range(plot_axis, y_ax)

Plot the scale of the y axis with respect to the plot_axis

adjust_plot

check_chrom_name

get_num_bins

has_prop

plot_data_range

plot_fill

plot_heatmap

plot_hist

plot_label

plot_line

plot_scatter

plot_stairs

plot_text_range

Methods:

fetch_data(gr, **kwargs)

Parameters

fetch_plot_data(gr, **kwargs)

Parameters

fetch_scores(genome_range, num_bins[, …])

Fetch bins scores within input chromosome range.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)
Parameters
grGenomeRange
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

fetch_plot_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)
Parameters
gr: GenomeRange

GenomeRange is an object with properties of [chrom, start, end].

kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

Returns
hist_data: Union[Tuple[np.ndarray, np.ndarray], pd.DataFrame, np.ndarray]

data used for plotting.

fetch_scores(genome_range, num_bins, max_try_nums=5)

Fetch bins scores within input chromosome range.

class coolbox.core.coverage.BigWigCoverage(*args, **kwargs)

BigWig track

Parameters
filestr

File path of bigwig file.

num_binsint, optional

Number of bins to plot the hist in current range, default 700.

stylestr, optional

Track graph type, format {‘line’, ‘fill’, ‘heatmap’, ‘scatter’}

fmtstr, optional

Line styles used when the plot style is line, will be passed as fmt parameter in matplotlib.pyplot.plot

line_widthint, optional

Value used when the plot style is line, will be passed as linewidth parameter in matplotlib.pyplot.plot

sizeint, optional

Value used when the plot style is scatter, will be passed as s parameter in matplotlib.pyplot.scatter

colorstr, optional

Main color

threshold_colorstr, optional

Track’s color for values greater than specified threshold.

thresholdfloat, optional

Threshold used when the plot style is line or scatter, values greater than this thresh will be plotted with color = threshold_color

cmap: str, optional

Cmap used when the plot type is heatmap, will be passed as cmap paramerter in matplotlib.pyplot.matshow

alphafloat, optional

Alpha value of plot, default 1.0

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot.

data_range_style{bool, ‘text’, ‘y-axis’}, optional

Show_data_range or not, default True.

max_value{float, ‘auto’}, optional

Max value of track. ‘auto’ for specify max value automatically, default ‘auto’.

min_value{float, ‘auto’}, optional

Min value of track. ‘auto’ for specify max value automatically, default ‘auto’.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

check_track_type

plot

class coolbox.core.coverage.HLines(*args, **kwargs)

Horizontal line coverage, for show threshold.

Parameters
valuesfloat

Y position. A list of y value or a single value.

percent_modebool

If in percent mode, y position will equal to ymin + (ymax - ymin) * val.

colorstr, optional

Line color, default ‘#1e1e1e’.

alphafloat, optional

Line alpha value, default 0.8.

line_stylestr, optional

Line style, default ‘dashed’.

line_widthfloat, optional

Line width, default 0.5.

namestr, optional

The name of thr Coverage.

Attributes
name

Methods

check_track_type

plot

class coolbox.core.coverage.HiCPeaks(*args, **kwargs)

Hi-C Peaks(Loops) from .bedpe file. Used to show the peaks on the Hi-C interaction map.

Parameters
file: str

Path of .bedpe file

posstr, optional

Method for choosing arch anchor for bedpe data: ‘start’, ‘end’, ‘mid’, default ‘mid’

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

fetch_intervals

has_prop

plot_contacts

plot_label

class coolbox.core.coverage.HiCPeaksCoverage(*args, **kwargs)

Hi-C Peaks(Loops) from .bedpe file. Used to show the peaks on the Hi-C interaction map.

Parameters
file: str

Path of .bedpe file

posstr, optional

Method for choosing arch anchor for bedpe data: ‘start’, ‘end’, ‘mid’, default ‘mid’

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

check_track_type

plot

class coolbox.core.coverage.HighLights(*args, **kwargs)

High light region.

Parameters
highlight_regionslist of {str, tuple}

A list of regions for highlights, region can be expressed as a tuple or string. region tuple like: [(‘chr1’, 100000, 120000), (‘chr2’, 130000, 150000)] region string format: chr:start-end like: [‘chr1:100000-120000’, ‘chr2:130000-150000’].

colorstr, optional

High light region color, default HighLights.DEFAULT_COLOR.

alphafloat, optional

High light region alpha value, default 0.5

border_linebool, optional

Plot border line or not, default True.

border_line_stylestr, optional

Border line style, default ‘dashed’

border_line_widthfloat, optional

Border line width, default 1.0

border_line_colorstr, optional

Border line color, default ‘#000000’

border_line_alphafloat, optional

Border line alpha value, default 0.8

namestr, optional

The name of thr Coverage.

Attributes
name

Methods

check_track_type

fetch_data

plot

class coolbox.core.coverage.HighLightsFromFile(*args, **kwargs)

High light regions coverage, read the regions from the file.

Parameters
file_str

Path to the file.

colorstr, optional

High light region color, use ‘bed_rgb’ for specify color from the file, default ‘bed_rgb’.

alphafloat, optional

High light region alpha value, default 0.1.

border_linebool, optional

Plot border line or not, default True.

border_line_stylestr, optional

Border line style, default ‘dashed’.

border_line_widthfloat, optional

Border line width, default 1.0.

border_line_colorstr, optional

Border line color, default ‘#000000’

border_line_alphafloat, optional

Border line alpha value, default 0.8

namestr, optional

The name of thr Coverage.

Attributes
name

Methods

check_track_type

fetch_data

plot

coolbox.core.coverage.Hist(file, *args, **kwargs)coolbox.core.track.hist.base.HistBase

Compose BigWig, BedGraph, SNP, BAMCov track automatically based on type of file extension.(.bw, .bigwig, .snp, .vcf, .bedgraph, .bam, .sam)

class coolbox.core.coverage.HistCoverage(*args, **kwargs)

Compose BigWig, BedGraph, SNP, BAMCov track automatically based on type of file extension.(.bw, .bigwig, .snp, .vcf, .bedgraph, .bam, .sam)

Attributes
name

Methods

check_track_type

plot

class coolbox.core.coverage.Pairs(*args, **kwargs)

Arcs track from .pairs file.

Parameters
file: str

Path of .pairs file

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_plot_data(gr, **kwargs)

Parameters

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot arc connecting two positions on a linear scale representing interactions between bins.

plot_arcs(ax, gr, gr2, intervals)

Parameters

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_hicpeaks(ax, gr, gr2, intervals)

plot hic peaks uppon a HicMatBase track.

fetch_intervals

has_prop

plot_contacts

plot_label

Methods:

fetch_data(gr, **kwargs)

Fetch the raw data for the given GenomeRange.

fetch_data(gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Fetch the raw data for the given GenomeRange.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.coverage.PairsCoverage(*args, **kwargs)

Arcs track from .pairs file.

Parameters
file: str

Path of .pairs file

stylestr, optional

Style of arcs plot: ‘arcs’, ‘hicpeaks’, default ‘arcs’

score_to_widthstr, optional

Mapping function of score to width, default: ‘0.5 + math.sqrt(score)’

line_widthfloat, optional

Width of arc line.

open_regionbool, optional

If specified to True, will fetch the contacts on side in the region, default True

diameter_to_heightstr, optional

Mapping function of arc diameter(interval end - start) to height. You can specify to ‘max_diameter’ let all arcs has same height. default ‘max_height * diameter / max_diameter’.

orientationstr, optional

Track orientation, use ‘inverted’ for inverted track plot. default None

line_stylestr, optional

Border line style, default ‘solid’

fillbool, optional

Fill center or not, default False.

fill_colorstr, optional

Fill color, use ‘bed_rgb’ for specify color in file, default ‘bed_rgb’.

fill_alphafloat, optional

Alpha value of fill region. default 0.2

side{‘upper’, ‘lower’, ‘both’}

Plot peak in which side of the matrix. NOTE: This parameters is useful only if the Cool track in matrix format.

alphafloat, optional

Alpha value of track, default 0.8.

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

colorstr, optional;

Color of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

check_track_type

plot

class coolbox.core.coverage.TAD(*args, **kwargs)

Tad tack from bed file

Parameters
border_style: str, optional

Border style of tad. (Default: ‘solid’)

border_width: int, optional

Border width of tad. (Default: ‘2.0’)

show_scorebool

Show bed score or not. default False.

score_font_size{‘auto’, int}

Score text font size. default ‘auto’

score_font_colorstr

Score text color. default ‘#000000’

score_height_ratiofloat

(text tag height) / (TAD height). used for adjust the position of Score text. default 0.5

border_onlybool

Only show border, default False

depth_ratio{float, ‘auto’, ‘full’}

Depth ratio of triangular, use ‘full’ for full depth, use ‘auto’ for calculate depth by current genome_range. default ‘auto’.

orientation{‘normal’, ‘inverted’}

Invert y-axis or not, default ‘normal’

file: str

The file path of .bed file.

colorstr, optional

Track color, ‘bed_rgb’ for auto specify color according to bed record. (Default: ‘bed_rgb’)

border_colorstr, optional

Border_color of gene. (Default: ‘black’)

max_valuefloat, optional

Max score. (Default: inf)

min_valuefloat, optional

Min score. (Default: -inf)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

append_coverage(coverage[, pos])

Append coverage to this track.

fetch_data(gr, **kwargs)

Parameters

fetch_intervals(bgz_file, gr)

Fetch intervals within input chromosome range.

fetch_plot_data(gr, **kwargs)

Fetch the plot data for the given GenomeRange.

intervals2dataframe(intervals, bed_type)

Convert intervals list to pandas.DataFrame

pile_coverages(coverages[, pos])

Pile a stack of coverages with self’s coverages

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot_coverages(ax, gr, gr2)

Plot all coverages on given axes.

plot_tads(ax, gr, tads)

Plots the boundaries as triangles in the given ax.

plot_triangular(ax, gr, region, ymax, depth)

/ / / _____________________

set_colormap(df)

As min_score and max_score change every plot, we compute them for every plot

get_depth_ratio

get_rgb_and_edge_color

get_track_height

has_prop

infer_bed_type

init_colormap

load_range

plot_box

plot_label

plot_score

Methods:

plot(ax, gr, **kwargs)

Plot figure based on data returned by fetch_plot_data.

plot(ax, gr: coolbox.utilities.genome.GenomeRange, **kwargs)

Plot figure based on data returned by fetch_plot_data.

Parameters
gr: GenomeRange
kwargs: dict

Other optional parameters including gr2, resolution for some tracks.

class coolbox.core.coverage.TADCoverage(*args, **kwargs)

Tad tack from bed file

Parameters
border_style: str, optional

Border style of tad. (Default: ‘solid’)

border_width: int, optional

Border width of tad. (Default: ‘2.0’)

show_scorebool

Show bed score or not. default False.

score_font_size{‘auto’, int}

Score text font size. default ‘auto’

score_font_colorstr

Score text color. default ‘#000000’

score_height_ratiofloat

(text tag height) / (TAD height). used for adjust the position of Score text. default 0.5

border_onlybool

Only show border, default False

depth_ratio{float, ‘auto’, ‘full’}

Depth ratio of triangular, use ‘full’ for full depth, use ‘auto’ for calculate depth by current genome_range. default ‘auto’.

orientation{‘normal’, ‘inverted’}

Invert y-axis or not, default ‘normal’

file: str

The file path of .bed file.

colorstr, optional

Track color, ‘bed_rgb’ for auto specify color according to bed record. (Default: ‘bed_rgb’)

border_colorstr, optional

Border_color of gene. (Default: ‘black’)

max_valuefloat, optional

Max score. (Default: inf)

min_valuefloat, optional

Min score. (Default: -inf)

properties_dictdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr, optional

The name of Track. (Default: “{self.__class__.__name__}.{self.__class__._counts}”)

titlestr, optional

Title of ax

heightint, optional

Height of ax

Attributes
propertiesdict

The properties(features) of this track. For example ‘height’, ‘color’…

namestr

The name of Track.

coverageslist of coolbox.api.coverage.Coverage

Coverages on this Track.

Methods

check_track_type

plot

class coolbox.core.coverage.Vlines(*args, **kwargs)

Vertical lines.

Parameters
vlineslist of {int, str}

A list of vline positions. position can be expressed as a tuple like: [(‘chr1’, 10000), (‘chr2’, 50000)] or a genome range string like: [‘chr1:10000-10000’, ‘chr2:50000-50000’]

colorstr, optional

Line color, default ‘#1e1e1e’.

alphafloat, optional

Line alpha value, default 0.8.

line_stylestr, optional

Line style, default ‘dashed’.

line_widthfloat, optional

Line width, default 0.5.

namestr, optional

The name of thr Coverage.

Attributes
name

Methods

check_track_type

fetch_data

plot

class coolbox.core.coverage.VlinesFromFile(*args, **kwargs)

Vertical lines from the file.

Parameters
file_str

Path to file.

colorstr, optional

Line color, default ‘#1e1e1e’.

alphafloat, optional

Line alpha value, default 0.8.

line_stylestr, optional

Line style, default ‘dashed’.

line_widthfloat, optional

Line width, default 0.5.

namestr, optional

The name of thr Coverage.

Attributes
name

Methods

check_track_type

fetch_data

plot

Feature

Classes:

Color(value)

Track color.

ColorMap(value)

Track color map.

CoolStyle([style])

Control Cool track’s style.

DepthRatio(depth_ratio)

Control Cool track’s depth ratio.

Feature(**kwargs)

Feature base class.

FrameFeature(**kwargs)

FrameFeature base class.

FrameTitle(value)

Frame title.

HistStyle([style, fmt, size, line_width])

Style of BigWig or BedGraph.

Inverted()

Invert the orientation of track.

MaxValue(value)

Max value of track.

MinValue(value)

Min value of track.

ShowColorBar([show])

Show color bar or not.

ShowDataRange([data_range_style])

Show data range or not.

Title(value)

Track title.

TrackHeight(value)

Track height.

class coolbox.core.feature.Color(value)

Track color.

class coolbox.core.feature.ColorMap(value)

Track color map.

class coolbox.core.feature.CoolStyle(style='triangular')

Control Cool track’s style.

class coolbox.core.feature.DepthRatio(depth_ratio)

Control Cool track’s depth ratio.

class coolbox.core.feature.Feature(**kwargs)

Feature base class.

class coolbox.core.feature.FrameFeature(**kwargs)

FrameFeature base class.

class coolbox.core.feature.FrameTitle(value)

Frame title.

class coolbox.core.feature.HistStyle(style='fill', fmt='-', size=10, line_width=2.0)

Style of BigWig or BedGraph.

class coolbox.core.feature.Inverted

Invert the orientation of track.

class coolbox.core.feature.MaxValue(value)

Max value of track.

class coolbox.core.feature.MinValue(value)

Min value of track.

class coolbox.core.feature.ShowColorBar(show=True)

Show color bar or not.

class coolbox.core.feature.ShowDataRange(data_range_style='y-axis')

Show data range or not.

class coolbox.core.feature.Title(value)

Track title.

class coolbox.core.feature.TrackHeight(value)

Track height.

Frame

JointView

Browser

Classes:

Browser(frame[, reference_genome, …])

Browser base class.

WidgetsPanel([type, reference_genome])

Widgets container.

class coolbox.core.browser.Browser(frame, reference_genome='hg19', init_range=None, widgets_box='simple', dpi=None, img_format='svg')

Browser base class.

Attributes
center
tracks
window_size

Methods

clear_fig_cache()

Clear the fig cache.

get_init_range([chrom])

Generate an initial range within a chromosome.

preload_imgs(directions)

Preloading images to self.fig_cache.

refresh([hard])

Refresh the image display.

save(path[, dpi])

Save current frame’s image to file.

show(*args, **kwargs)

Show widgets and frame.

fetch_data

go_left

go_right

goto

zoom_in

zoom_out

Methods:

clear_fig_cache()

Clear the fig cache.

get_init_range([chrom])

Generate an initial range within a chromosome.

preload_imgs(directions)

Preloading images to self.fig_cache.

refresh([hard])

Refresh the image display.

save(path[, dpi])

Save current frame’s image to file.

show(*args, **kwargs)

Show widgets and frame.

clear_fig_cache()

Clear the fig cache.

get_init_range(chrom=None)

Generate an initial range within a chromosome.

Args:

chrom (str, optional): initial choromosome.

Return:

(GenomeRange)

preload_imgs(directions)

Preloading images to self.fig_cache.

Can load image in one of 4 directions:

left, right, zoom-in, zoom-out

or load all directions.

refresh(hard=False)

Refresh the image display.

save(path, dpi=None)

Save current frame’s image to file. The suffix of the path will changing the saving format. For example: bsr.save(“fig.png”) will save file to ‘png’ format.

show(*args, **kwargs)

Show widgets and frame.

class coolbox.core.browser.WidgetsPanel(type='simple', reference_genome='hg19')

Widgets container.

Parameters
type{‘simple’, ‘full’}, optional

Widgets type ‘simple’ or ‘full’, default ‘simple’

reference_genomestr, optional

Reference genome, built-in references:(‘hg19’, ‘hg38’, ‘mm9’, ‘mm10’) if you want use other genome, you can specify the “chromosome length file”, that is a tab splited file, first column is the chromosomes, and second column is the length of correspond chromosome. default ‘hg19’

Utilities

Classes:

GenomeLength(length_file[, genome_name])

Methods

GenomeRange(*args)

Express a range on the genome.

Interval(begin, end[, data])

Attributes

IntervalTree([intervals])

A binary lookup tree of intervals.

ReadBed(file_handle)

Reads a bed file.

deque

deque([iterable[, maxlen]]) –> deque object

partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

refGeneRec(bin, name, chrom, strand, …)

Attributes

Functions:

abspath(path)

Return an absolute path.

change_chrom_names(chrom)

Changes UCSC chromosome names to ensembl chromosome names and vice versa.

cm2inch(*tupl)

convert length unit from cm to inch.

correspond_track(track_or_name)

Search track by it’s name.

dirname(p)

Returns the directory component of a pathname

fig2bytes(fig[, encode, dpi])

Convert matplotlib.figure.Figure/IPython.display.SVG object to image bytes.

file_to_intervaltree(file_name)

converts a BED like file into a bx python interval tree

format_properties(properties)

Convert bool value to ‘yes’ or ‘no’, for compatible with pyGenomeTracks Convert string to float if possible

get_size(obj[, seen])

Recursively finds size of objects

get_tmp_dir([name])

Return the path to coolbox temporary directory.

get_uniq_tmp_file([prefix, suffix, dirname])

Return the path to a unique(not exists) temporary file.

hex2rgb(color_hex)

Convert hex color code to rgb tuple.

inch2cm(*tupl)

convert length unit from inch to cm.

join(a, *p)

Join two or more pathname components, inserting ‘/’ as needed.

op_err_msg(a, b[, op])

Generate the error message of error operand type.

opener(filename)

Determines if a file is compressed or not

query_bed(filename, chrom, start, end, *[, …])

Call tabix and generate an array of strings for each line it returns.

rgb2hex(r, g, b)

Convert rgb color to hex format.

shiftedColorMap(cmap[, start, midpoint, …])

This function is from: https://stackoverflow.com/a/20528097/8500469

split_genome_range(genome_range)

Little helper func.

tabix_index(filename[, preset])

Call tabix to create an index for a bgzip-compressed file.

tabix_query(filename, chrom, start, end[, split])

Call tabix and generate an array of strings for each line it returns.

to_bytes(s)

Like toString, to bytes.

to_gr(obj)

Convert object to GenomeRange.

to_string(s)

Convert bytes, bytes list to string, string list.

class coolbox.utilities.GenomeLength(length_file, genome_name='')

Methods

bound_range(genome_range)

Bound a genome range within reference.

check_range(genome_range)

Check a genome range is valid or not.

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If key is not found, default is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

parse_file

Methods:

bound_range(genome_range)

Bound a genome range within reference.

check_range(genome_range)

Check a genome range is valid or not.

bound_range(genome_range)

Bound a genome range within reference.

(both start and end position is one based.)

check_range(genome_range)

Check a genome range is valid or not.

(both start and end position is one based.)

class coolbox.utilities.GenomeRange(*args)

Express a range on the genome.

Attributes
chromstr

chromosome

startint

start position

endint

end position

Methods

change_chrom_names()

>>> range1 = GenomeRange("chr1", 1000, 2000)

parse_region_string(region_string)

splits a region string into a (chrom, start, end) tuple

Methods:

change_chrom_names()

>>> range1 = GenomeRange("chr1", 1000, 2000)

parse_region_string(region_string)

splits a region string into a (chrom, start, end) tuple

Attributes:

length

>>> range1 = GenomeRange("chr1", 0, 1000)

change_chrom_names()
>>> range1 = GenomeRange("chr1", 1000, 2000)
>>> range1.chrom
'chr1'
>>> range1.change_chrom_names()
>>> range1.chrom
'1'
>>> range1.change_chrom_names()
>>> range1.chrom
'chr1'
property length
>>> range1 = GenomeRange("chr1", 0, 1000)
>>> range1.length
1000
static parse_region_string(region_string)

splits a region string into a (chrom, start, end) tuple

Parameters
region_stringstr

Region string to be parsed, like: “chr:start-end”

class coolbox.utilities.Interval(begin, end, data=None)
Attributes
begin

Alias for field number 0

data

Alias for field number 2

end

Alias for field number 1

Methods

contains_interval(other)

Whether other is contained in this Interval.

contains_point(p)

Whether the Interval contains p.

copy()

Shallow copy.

count(value, /)

Return number of occurrences of value.

distance_to(other)

Returns the size of the gap between intervals, or 0 if they touch or overlap.

ge(other)

Greater than or overlaps.

gt(other)

Strictly greater than.

index(value[, start, stop])

Return first index of value.

is_null()

Whether this equals the null interval.

le(other)

Less than or overlaps.

length()

The distance covered by this Interval.

lt(other)

Strictly less than.

overlap_size(begin[, end])

Return the overlap size between two intervals or a point :param begin: beginning point of the range, or the point, or an Interval :param end: end point of the range.

overlaps(begin[, end])

Whether the interval overlaps the given point, range or Interval.

range_matches(other)

Whether the begins equal and the ends equal.

Methods:

contains_interval(other)

Whether other is contained in this Interval.

contains_point(p)

Whether the Interval contains p.

copy()

Shallow copy.

distance_to(other)

Returns the size of the gap between intervals, or 0 if they touch or overlap.

ge(other)

Greater than or overlaps.

gt(other)

Strictly greater than.

is_null()

Whether this equals the null interval.

le(other)

Less than or overlaps.

length()

The distance covered by this Interval.

lt(other)

Strictly less than.

overlap_size(begin[, end])

Return the overlap size between two intervals or a point :param begin: beginning point of the range, or the point, or an Interval :param end: end point of the range.

overlaps(begin[, end])

Whether the interval overlaps the given point, range or Interval.

range_matches(other)

Whether the begins equal and the ends equal.

contains_interval(other)

Whether other is contained in this Interval. :param other: Interval :return: True or False :rtype: bool

contains_point(p)

Whether the Interval contains p. :param p: a point :return: True or False :rtype: bool

copy()

Shallow copy. :return: copy of self :rtype: Interval

distance_to(other)

Returns the size of the gap between intervals, or 0 if they touch or overlap. :param other: Interval or point :return: distance :rtype: Number

ge(other)

Greater than or overlaps. Returns True if no part of this Interval extends lower than other. :raises ValueError: if either self or other is a null Interval :param other: Interval or point :return: True or False :rtype: bool

gt(other)

Strictly greater than. Returns True if no part of this Interval extends lower than or into other. :raises ValueError: if either self or other is a null Interval :param other: Interval or point :return: True or False :rtype: bool

is_null()

Whether this equals the null interval. :return: True if end <= begin else False :rtype: bool

le(other)

Less than or overlaps. Returns True if no part of this Interval extends higher than other. :raises ValueError: if either self or other is a null Interval :param other: Interval or point :return: True or False :rtype: bool

length()

The distance covered by this Interval. :return: length :type: Number

lt(other)

Strictly less than. Returns True if no part of this Interval extends higher than or into other. :raises ValueError: if either self or other is a null Interval :param other: Interval or point :return: True or False :rtype: bool

overlap_size(begin, end=None)

Return the overlap size between two intervals or a point :param begin: beginning point of the range, or the point, or an Interval :param end: end point of the range. Optional if not testing ranges. :return: Return the overlap size, None if not overlap is found :rtype: depends on the given input (e.g., int will be returned for int interval and timedelta for datetime intervals)

overlaps(begin, end=None)

Whether the interval overlaps the given point, range or Interval. :param begin: beginning point of the range, or the point, or an Interval :param end: end point of the range. Optional if not testing ranges. :return: True or False :rtype: bool

range_matches(other)

Whether the begins equal and the ends equal. Compare __eq__(). :param other: Interval :return: True or False :rtype: bool

class coolbox.utilities.IntervalTree(intervals=None)

A binary lookup tree of intervals. The intervals contained in the tree are represented using Interval(a, b, data) objects. Each such object represents a half-open interval [a, b) with optional data.

Methods

add(interval)

Adds an interval to the tree, if not already present.

addi(begin, end[, data])

Shortcut for add(Interval(begin, end, data)).

append(interval)

Adds an interval to the tree, if not already present.

appendi(begin, end[, data])

Shortcut for add(Interval(begin, end, data)).

at(p)

Returns the set of all intervals that contain p.

begin()

Returns the lower bound of the first interval in the tree.

chop(begin, end[, datafunc])

Like remove_envelop(), but trims back Intervals hanging into the chopped area so that nothing overlaps.

clear()

Empties the tree.

containsi(begin, end[, data])

Shortcut for (Interval(begin, end, data) in tree).

copy()

Construct a new IntervalTree using shallow copies of the intervals in the source tree.

difference(other)

Returns a new tree, comprising all intervals in self but not in other.

difference_update(other)

Removes all intervals in other from self.

discard(interval)

Removes an interval from the tree, if present.

discardi(begin, end[, data])

Shortcut for discard(Interval(begin, end, data)).

end()

Returns the upper bound of the last interval in the tree.

envelop(begin[, end])

Returns the set of all intervals fully contained in the range [begin, end).

find_nested()

Returns a dictionary mapping parent intervals to sets of intervals overlapped by and contained in the parent.

from_tuples(tups)

Create a new IntervalTree from an iterable of 2- or 3-tuples,

intersection(other)

Returns a new tree of all intervals common to both self and other.

intersection_update(other)

Removes intervals from self unless they also exist in other.

is_empty()

Returns whether the tree is empty.

isdisjoint(other)

Return True if two sets have a null intersection.

items()

Constructs and returns a set of all intervals in the tree.

iter()

Returns an iterator over all the intervals in the tree.

merge_equals([data_reducer, data_initializer])

Finds all intervals with equal ranges and merges them into a single interval.

merge_overlaps([data_reducer, …])

Finds all intervals with overlapping ranges and merges them into a single interval.

overlap(begin[, end])

Returns a set of all intervals overlapping the given range.

overlaps(begin[, end])

Returns whether some interval in the tree overlaps the given point or range.

overlaps_point(p)

Returns whether some interval in the tree overlaps p.

overlaps_range(begin, end)

Returns whether some interval in the tree overlaps the given range.

pop()

Return the popped value.

print_structure([tostring])

## FOR DEBUGGING ONLY ## Pretty-prints the structure of the tree.

range()

Returns a minimum-spanning Interval that encloses all the members of this IntervalTree.

remove(interval)

Removes an interval from the tree, if present.

remove_envelop(begin, end)

Removes all intervals completely enveloped in the given range.

remove_overlap(begin[, end])

Removes all intervals overlapping the given point or range.

removei(begin, end[, data])

Shortcut for remove(Interval(begin, end, data)).

score([full_report])

Returns a number between 0 and 1, indicating how suboptimal the tree is.

slice(point[, datafunc])

Split Intervals that overlap point into two new Intervals.

span()

Returns the length of the minimum-spanning Interval that encloses all the members of this IntervalTree.

split_overlaps()

Finds all intervals with overlapping ranges and splits them along the range boundaries.

symmetric_difference(other)

Return a tree with elements only in self or other but not both.

symmetric_difference_update(other)

Throws out all intervals except those only in self or other, not both.

union(other)

Returns a new tree, comprising all intervals from self and other.

update(intervals)

Given an iterable of intervals, add them to the tree.

verify()

## FOR DEBUGGING ONLY ## Checks the table to ensure that the invariants are held.

Methods:

add(interval)

Adds an interval to the tree, if not already present.

addi(begin, end[, data])

Shortcut for add(Interval(begin, end, data)).

append(interval)

Adds an interval to the tree, if not already present.

appendi(begin, end[, data])

Shortcut for add(Interval(begin, end, data)).

at(p)

Returns the set of all intervals that contain p.

begin()

Returns the lower bound of the first interval in the tree.

chop(begin, end[, datafunc])

Like remove_envelop(), but trims back Intervals hanging into the chopped area so that nothing overlaps.

clear()

Empties the tree.

containsi(begin, end[, data])

Shortcut for (Interval(begin, end, data) in tree).

copy()

Construct a new IntervalTree using shallow copies of the intervals in the source tree.

difference(other)

Returns a new tree, comprising all intervals in self but not in other.

difference_update(other)

Removes all intervals in other from self.

discard(interval)

Removes an interval from the tree, if present.

discardi(begin, end[, data])

Shortcut for discard(Interval(begin, end, data)).

end()

Returns the upper bound of the last interval in the tree.

envelop(begin[, end])

Returns the set of all intervals fully contained in the range [begin, end).

find_nested()

Returns a dictionary mapping parent intervals to sets of intervals overlapped by and contained in the parent.

from_tuples(tups)

Create a new IntervalTree from an iterable of 2- or 3-tuples,

intersection(other)

Returns a new tree of all intervals common to both self and other.

intersection_update(other)

Removes intervals from self unless they also exist in other.

is_empty()

Returns whether the tree is empty.

items()

Constructs and returns a set of all intervals in the tree.

iter()

Returns an iterator over all the intervals in the tree.

merge_equals([data_reducer, data_initializer])

Finds all intervals with equal ranges and merges them into a single interval.

merge_overlaps([data_reducer, …])

Finds all intervals with overlapping ranges and merges them into a single interval.

overlap(begin[, end])

Returns a set of all intervals overlapping the given range.

overlaps(begin[, end])

Returns whether some interval in the tree overlaps the given point or range.

overlaps_point(p)

Returns whether some interval in the tree overlaps p.

overlaps_range(begin, end)

Returns whether some interval in the tree overlaps the given range.

print_structure([tostring])

## FOR DEBUGGING ONLY ## Pretty-prints the structure of the tree.

range()

Returns a minimum-spanning Interval that encloses all the members of this IntervalTree.

remove(interval)

Removes an interval from the tree, if present.

remove_envelop(begin, end)

Removes all intervals completely enveloped in the given range.

remove_overlap(begin[, end])

Removes all intervals overlapping the given point or range.

removei(begin, end[, data])

Shortcut for remove(Interval(begin, end, data)).

score([full_report])

Returns a number between 0 and 1, indicating how suboptimal the tree is.

slice(point[, datafunc])

Split Intervals that overlap point into two new Intervals.

span()

Returns the length of the minimum-spanning Interval that encloses all the members of this IntervalTree.

split_overlaps()

Finds all intervals with overlapping ranges and splits them along the range boundaries.

symmetric_difference(other)

Return a tree with elements only in self or other but not both.

symmetric_difference_update(other)

Throws out all intervals except those only in self or other, not both.

union(other)

Returns a new tree, comprising all intervals from self and other.

update(intervals)

Given an iterable of intervals, add them to the tree.

verify()

## FOR DEBUGGING ONLY ## Checks the table to ensure that the invariants are held.

add(interval)

Adds an interval to the tree, if not already present.

Completes in O(log n) time.

addi(begin, end, data=None)

Shortcut for add(Interval(begin, end, data)).

Completes in O(log n) time.

append(interval)

Adds an interval to the tree, if not already present.

Completes in O(log n) time.

appendi(begin, end, data=None)

Shortcut for add(Interval(begin, end, data)).

Completes in O(log n) time.

at(p)

Returns the set of all intervals that contain p.

Completes in O(m + log n) time, where:
  • n = size of the tree

  • m = number of matches

Return type

set of Interval

begin()

Returns the lower bound of the first interval in the tree.

Completes in O(1) time.

chop(begin, end, datafunc=None)

Like remove_envelop(), but trims back Intervals hanging into the chopped area so that nothing overlaps.

clear()

Empties the tree.

Completes in O(1) tine.

containsi(begin, end, data=None)

Shortcut for (Interval(begin, end, data) in tree).

Completes in O(1) time. :rtype: bool

copy()

Construct a new IntervalTree using shallow copies of the intervals in the source tree.

Completes in O(n*log n) time. :rtype: IntervalTree

difference(other)

Returns a new tree, comprising all intervals in self but not in other.

difference_update(other)

Removes all intervals in other from self.

discard(interval)

Removes an interval from the tree, if present. If not, does nothing.

Completes in O(log n) time.

discardi(begin, end, data=None)

Shortcut for discard(Interval(begin, end, data)).

Completes in O(log n) time.

end()

Returns the upper bound of the last interval in the tree.

Completes in O(1) time.

envelop(begin, end=None)

Returns the set of all intervals fully contained in the range [begin, end).

Completes in O(m + k*log n) time, where:
  • n = size of the tree

  • m = number of matches

  • k = size of the search range

Return type

set of Interval

find_nested()

Returns a dictionary mapping parent intervals to sets of intervals overlapped by and contained in the parent.

Completes in O(n^2) time. :rtype: dict of [Interval, set of Interval]

classmethod from_tuples(tups)
Create a new IntervalTree from an iterable of 2- or 3-tuples,

where the tuple lists begin, end, and optionally data.

intersection(other)

Returns a new tree of all intervals common to both self and other.

intersection_update(other)

Removes intervals from self unless they also exist in other.

is_empty()

Returns whether the tree is empty.

Completes in O(1) time. :rtype: bool

items()

Constructs and returns a set of all intervals in the tree.

Completes in O(n) time. :rtype: set of Interval

iter()

Returns an iterator over all the intervals in the tree.

Completes in O(1) time. :rtype: collections.Iterable[Interval]

merge_equals(data_reducer=None, data_initializer=None)

Finds all intervals with equal ranges and merges them into a single interval. If provided, uses data_reducer and data_initializer with similar semantics to Python’s built-in reduce(reducer_func[, initializer]), as follows:

If data_reducer is set to a function, combines the data fields of the Intervals with

current_reduced_data = data_reducer(current_reduced_data, new_data)

If data_reducer is None, the merged Interval’s data field will be set to None, ignoring all the data fields of the merged Intervals.

On encountering the first Interval to merge, if data_initializer is None (default), uses the first Interval’s data field as the first value for current_reduced_data. If data_initializer is not None, current_reduced_data is set to a shallow copy of data_initiazer created with

copy.copy(data_initializer).

Completes in O(n*logn).

merge_overlaps(data_reducer=None, data_initializer=None, strict=True)

Finds all intervals with overlapping ranges and merges them into a single interval. If provided, uses data_reducer and data_initializer with similar semantics to Python’s built-in reduce(reducer_func[, initializer]), as follows:

If data_reducer is set to a function, combines the data fields of the Intervals with

current_reduced_data = data_reducer(current_reduced_data, new_data)

If data_reducer is None, the merged Interval’s data field will be set to None, ignoring all the data fields of the merged Intervals.

On encountering the first Interval to merge, if data_initializer is None (default), uses the first Interval’s data field as the first value for current_reduced_data. If data_initializer is not None, current_reduced_data is set to a shallow copy of data_initializer created with copy.copy(data_initializer).

If strict is True (default), intervals are only merged if their ranges actually overlap; adjacent, touching intervals will not be merged. If strict is False, intervals are merged even if they are only end-to-end adjacent.

Completes in O(n*logn).

overlap(begin, end=None)

Returns a set of all intervals overlapping the given range.

Completes in O(m + k*log n) time, where:
  • n = size of the tree

  • m = number of matches

  • k = size of the search range

Return type

set of Interval

overlaps(begin, end=None)

Returns whether some interval in the tree overlaps the given point or range.

Completes in O(r*log n) time, where r is the size of the search range. :rtype: bool

overlaps_point(p)

Returns whether some interval in the tree overlaps p.

Completes in O(log n) time. :rtype: bool

overlaps_range(begin, end)

Returns whether some interval in the tree overlaps the given range. Returns False if given a null interval over which to test.

Completes in O(r*log n) time, where r is the range length and n is the table size. :rtype: bool

print_structure(tostring=False)

## FOR DEBUGGING ONLY ## Pretty-prints the structure of the tree. If tostring is true, prints nothing and returns a string. :rtype: None or str

range()

Returns a minimum-spanning Interval that encloses all the members of this IntervalTree. If the tree is empty, returns null Interval. :rtype: Interval

remove(interval)

Removes an interval from the tree, if present. If not, raises ValueError.

Completes in O(log n) time.

remove_envelop(begin, end)

Removes all intervals completely enveloped in the given range.

Completes in O((r+m)*log n) time, where:
  • n = size of the tree

  • m = number of matches

  • r = size of the search range

remove_overlap(begin, end=None)

Removes all intervals overlapping the given point or range.

Completes in O((r+m)*log n) time, where:
  • n = size of the tree

  • m = number of matches

  • r = size of the search range (this is 1 for a point)

removei(begin, end, data=None)

Shortcut for remove(Interval(begin, end, data)).

Completes in O(log n) time.

score(full_report=False)

Returns a number between 0 and 1, indicating how suboptimal the tree is. The lower, the better. Roughly, this number represents the fraction of flawed Intervals in the tree. :rtype: float

slice(point, datafunc=None)

Split Intervals that overlap point into two new Intervals. if specified, uses datafunc(interval, islower=True/False) to set the data field of the new Intervals. :param point: where to slice :param datafunc(interval, isupper): callable returning a new value for the interval’s data field

span()

Returns the length of the minimum-spanning Interval that encloses all the members of this IntervalTree. If the tree is empty, return 0.

split_overlaps()

Finds all intervals with overlapping ranges and splits them along the range boundaries.

Completes in worst-case O(n^2*log n) time (many interval boundaries are inside many intervals), best-case O(n*log n) time (small number of overlaps << n per interval).

symmetric_difference(other)

Return a tree with elements only in self or other but not both.

symmetric_difference_update(other)

Throws out all intervals except those only in self or other, not both.

union(other)

Returns a new tree, comprising all intervals from self and other.

update(intervals)

Given an iterable of intervals, add them to the tree.

Completes in O(m*log(n+m), where m = number of intervals to add.

verify()

## FOR DEBUGGING ONLY ## Checks the table to ensure that the invariants are held.

class coolbox.utilities.ReadBed(file_handle)

Reads a bed file. Based on the number of fields it tries to guess the type of bed file used. Current options are bed3, bed6 and bed12

Example: bed = readBed(open(“file.bed”, ‘r’)) for interval in bed:

print(interval[‘start’])

Methods

get_bed_interval(bed_line)

Processes each bed line from a bed file, casts the values and returns a namedtuple object

get_no_comment_line([iter, count])

Skips comment lines starting with ‘#’ “track” or “browser” in the bed files

guess_file_type(file_iter)

try to guess type of bed file by counting the fields

next()

Methods:

get_bed_interval(bed_line)

Processes each bed line from a bed file, casts the values and returns a namedtuple object

get_no_comment_line([iter, count])

Skips comment lines starting with ‘#’ “track” or “browser” in the bed files

guess_file_type(file_iter)

try to guess type of bed file by counting the fields

next()

get_bed_interval(bed_line)

Processes each bed line from a bed file, casts the values and returns a namedtuple object

>>> bed_line="chr1\t0\t1000\tgene_1\t0.5\t-\t0\t1000\t0\t3\t10,20,100\t20,200,700"
>>> with open('/tmp/test.bed', 'w') as fh:
...     foo = fh.write(bed_line)
>>> bed_f = ReadBed(open('/tmp/test.bed','r'))
>>> bed = bed_f.get_bed_interval(bed_line)
>>> bed.chromosome
'chr1'
>>> bed.block_starts
[20, 200, 700]
>>> bed_line="chr2\t0\t1000\tgene_1\t0.5\t-\n"
>>> with open('/tmp/test.bed', 'w') as fh:
...     foo = fh.write(bed_line)
>>> bed_f = ReadBed(open('/tmp/test.bed','r'))
>>> bed_f.get_bed_interval(bed_line)
BedInterval(chromosome='chr2', start=0, end=1000, name='gene_1', score=0.5, strand='-')
get_no_comment_line(iter=None, count=True)

Skips comment lines starting with ‘#’ “track” or “browser” in the bed files

guess_file_type(file_iter)

try to guess type of bed file by counting the fields

next()
coolbox.utilities.abspath(path)

Return an absolute path.

coolbox.utilities.change_chrom_names(chrom)

Changes UCSC chromosome names to ensembl chromosome names and vice versa.

>>> change_chrom_names("chr1")
'1'
>>> change_chrom_names("1")
'chr1'
coolbox.utilities.cm2inch(*tupl)

convert length unit from cm to inch.

>>> cm2inch(10)
3.937007874015748
>>> cm2inch(2, 2)
(0.7874015748031495, 0.7874015748031495)
>>> cm2inch((1, 5))
(0.39370078740157477, 1.968503937007874)
coolbox.utilities.correspond_track(track_or_name: Union[Track, str])

Search track by it’s name. For mark corresponding track in a element definition, allow pass track name to find related object in CLI mode.

class coolbox.utilities.deque

deque([iterable[, maxlen]]) –> deque object

A list-like sequence optimized for data accesses near its endpoints.

Attributes
maxlen

maximum size of a deque or None if unbounded

Methods

append

Add an element to the right side of the deque.

appendleft

Add an element to the left side of the deque.

clear

Remove all elements from the deque.

copy

Return a shallow copy of a deque.

count(value)

extend

Extend the right side of the deque with elements from the iterable

extendleft

Extend the left side of the deque with elements from the iterable

index(value, [start, [stop]])

Raises ValueError if the value is not present.

insert

D.insert(index, object) – insert object before index

pop

Remove and return the rightmost element.

popleft

Remove and return the leftmost element.

remove

D.remove(value) – remove first occurrence of value.

reverse

D.reverse() – reverse IN PLACE

rotate

Rotate the deque n steps to the right (default n=1).

Methods:

append

Add an element to the right side of the deque.

appendleft

Add an element to the left side of the deque.

clear

Remove all elements from the deque.

copy

Return a shallow copy of a deque.

count(value)

extend

Extend the right side of the deque with elements from the iterable

extendleft

Extend the left side of the deque with elements from the iterable

index(value, [start, [stop]])

Raises ValueError if the value is not present.

insert

D.insert(index, object) – insert object before index

pop

Remove and return the rightmost element.

popleft

Remove and return the leftmost element.

remove

D.remove(value) – remove first occurrence of value.

reverse

D.reverse() – reverse IN PLACE

rotate

Rotate the deque n steps to the right (default n=1).

Attributes:

maxlen

maximum size of a deque or None if unbounded

append()

Add an element to the right side of the deque.

appendleft()

Add an element to the left side of the deque.

clear()

Remove all elements from the deque.

copy()

Return a shallow copy of a deque.

count(value)integer return number of occurrences of value
extend()

Extend the right side of the deque with elements from the iterable

extendleft()

Extend the left side of the deque with elements from the iterable

index(value[, start[, stop]])integer return first index of value.

Raises ValueError if the value is not present.

insert()

D.insert(index, object) – insert object before index

maxlen

maximum size of a deque or None if unbounded

pop()

Remove and return the rightmost element.

popleft()

Remove and return the leftmost element.

remove()

D.remove(value) – remove first occurrence of value.

reverse()

D.reverse() – reverse IN PLACE

rotate()

Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.

coolbox.utilities.dirname(p)

Returns the directory component of a pathname

coolbox.utilities.fig2bytes(fig, encode='svg', dpi=None)

Convert matplotlib.figure.Figure/IPython.display.SVG object to image bytes.

coolbox.utilities.file_to_intervaltree(file_name)

converts a BED like file into a bx python interval tree

Parameters
file_namestr

Path to file.

coolbox.utilities.format_properties(properties)

Convert bool value to ‘yes’ or ‘no’, for compatible with pyGenomeTracks Convert string to float if possible

coolbox.utilities.get_size(obj, seen=None)

Recursively finds size of objects

From:

https://stackoverflow.com/a/40880923/8500469

coolbox.utilities.get_tmp_dir(name='.coolbox')

Return the path to coolbox temporary directory. If the file not exists, will make it.

coolbox.utilities.get_uniq_tmp_file(prefix='', suffix='.svg', dirname='.coolbox')

Return the path to a unique(not exists) temporary file.

coolbox.utilities.hex2rgb(color_hex)

Convert hex color code to rgb tuple.

>>> hex2rgb('#819a46')
(129, 154, 70)
coolbox.utilities.inch2cm(*tupl)

convert length unit from inch to cm.

coolbox.utilities.join(a, *p)

Join two or more pathname components, inserting ‘/’ as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.

coolbox.utilities.op_err_msg(a, b, op='+')

Generate the error message of error operand type.

coolbox.utilities.opener(filename)

Determines if a file is compressed or not

>>> import gzip
>>> msg = "hello blablabla"
>>> tmp_f_raw  = open("/tmp/test_opener.txt", 'w')
>>> tmp_f_raw.write(msg)
15
>>> tmp_f_raw.close()
>>> tmp_f_gzip = gzip.open('/tmp/test_opener.txt.gz', 'wb')
>>> tmp_f_gzip.write(to_bytes(msg))
15
>>> tmp_f_gzip.close()
>>> test_raw = opener(tmp_f_raw.name)
>>> type(test_raw)
<class '_io.BufferedReader'>
>>> test_gzip = opener(tmp_f_gzip.name)
>>> type(test_gzip)
<class 'gzip.GzipFile'>
>>> test_raw.close()
>>> test_gzip.close()
>>> import os
>>> os.remove(test_raw.name)
>>> os.remove(test_gzip.name)
class coolbox.utilities.partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

Attributes
args

tuple of arguments to future partial calls

func

function object to use in future partial calls

keywords

dictionary of keyword arguments to future partial calls

Methods

__call__(*args, **kwargs)

Call self as a function.

Attributes:

args

tuple of arguments to future partial calls

func

function object to use in future partial calls

keywords

dictionary of keyword arguments to future partial calls

args

tuple of arguments to future partial calls

func

function object to use in future partial calls

keywords

dictionary of keyword arguments to future partial calls

coolbox.utilities.query_bed(filename, chrom, start, end, *, split=False)

Call tabix and generate an array of strings for each line it returns.

class coolbox.utilities.refGeneRec(bin, name, chrom, strand, txStart, txEnd, cdsStart, cdsEnd, exonCount, exonStart, exonEnds, score, name2, cdsStartStat, cdsEndStat, exonFrames)
Attributes
bin

Alias for field number 0

cdsEnd

Alias for field number 7

cdsEndStat

Alias for field number 14

cdsStart

Alias for field number 6

cdsStartStat

Alias for field number 13

chrom

Alias for field number 2

exonCount

Alias for field number 8

exonEnds

Alias for field number 10

exonFrames

Alias for field number 15

exonStart

Alias for field number 9

name

Alias for field number 1

name2

Alias for field number 12

score

Alias for field number 11

strand

Alias for field number 3

txEnd

Alias for field number 5

txStart

Alias for field number 4

Methods

count(value, /)

Return number of occurrences of value.

index(value[, start, stop])

Return first index of value.

get_exons_size

offset_zero

to_bed12_line

to_line

coolbox.utilities.rgb2hex(r, g, b)

Convert rgb color to hex format.

>>> rgb2hex(129, 154, 70)
'#819a46'
>>> rgb2hex(-10, 256, -1)
Traceback (most recent call last):
...
AssertionError: (r, g, b) value must within range 0 ~ 255.
coolbox.utilities.shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap')

This function is from: https://stackoverflow.com/a/20528097/8500469

Function to offset the “center” of a colormap. Useful for data with a negative min and positive max and you want the middle of the colormap’s dynamic range to be at zero

coolbox.utilities.split_genome_range(genome_range)

Little helper func. enforce gr is a GenomeRange object, and split gr to chrom, start, end

coolbox.utilities.tabix_index(filename, preset='gff')

Call tabix to create an index for a bgzip-compressed file.

coolbox.utilities.tabix_query(filename, chrom, start, end, split=True)

Call tabix and generate an array of strings for each line it returns.

coolbox.utilities.to_bytes(s)

Like toString, to bytes.

>>> to_bytes('hello')
b'hello'
>>> to_bytes(['hello', 'world'])
[b'hello', b'world']
coolbox.utilities.to_gr(obj)

Convert object to GenomeRange.

>>> gr = to_gr("chr1:0-1000")
>>> (gr.chrom, gr.start, gr.end)
("chr1", 0, 1000)
coolbox.utilities.to_string(s)

Convert bytes, bytes list to string, string list.

>>> to_string("hello")
'hello'
>>> to_string(b"hello")
'hello'
>>> to_string([b'hello', b'world'])
['hello', 'world']