Plots¶
hicstuff.view turns sparse maps into dense arrays (sparse_to_dense) and
draws them (plot_matrix), as hicstuff view does. See
Working with matrices.
hicstuff.view ¶
Hi-C visualization
Functions to draw contact maps with matplotlib, and to look at the contigs of a genome assembly.
sparse_to_dense ¶
Converts a sparse square matrix into a full dense matrix. Removes the diagonal by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
M
|
coo_matrix
|
A sparse representation of the matrix. |
required |
remove_diag
|
bool
|
Whether the diagonal |
True
|
Returns:
| Type | Description |
|---|---|
numpy.array :
|
The matrix in dense format. |
Example
>>> import numpy as np
>>> from scipy.sparse import coo_matrix
>>> row, col = np.array([1, 2, 3]), np.array([3, 2, 1])
>>> data = np.array([4, 5, 6])
>>> S = coo_matrix((data, (row, col)))
>>> M = sparse_to_dense(S, remove_diag=True)
>>> for u in M:
... print(u)
[0 0 0 0]
[ 0 0 0 10]
[0 0 0 0]
[ 0 10 0 0]
Source code in src/hicstuff/view.py
plot_matrix ¶
plot_matrix(array, ax=None, filename=None, vmin=0, vmax=None, title=None, dpi=500, cmap='Reds', chrom_starts=None)
A function that performs all the tedious matplotlib magic to draw a 2D array with as few parameters and as little whitespace as possible.
Adjusted from https://github.com/koszullab/metaTOR
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
array
|
The input (dense) matrix that must be plotted. |
required |
ax
|
AxesSubplot
|
An optional axis on which to draw the plot. Useful for multipanel images. |
None
|
filename
|
str
|
The filename where the image should be stored. If None, the image is shown interactively. |
None
|
vmin
|
int
|
The minimum value on the colorscale. |
0
|
vmax
|
int or None
|
The maximum value on the colorscale. If None, the 99th percentile is taken. |
None
|
title
|
str
|
The string to display as figure title. |
None
|
dpi
|
int
|
The DPI (i.e. resolution in dots per inch) of the output image. |
500
|
cmap
|
str
|
The name of the matplotlib colormap to use when plotting the matrix. |
'Reds'
|
chrom_starts
|
array
|
Array of bin positions where to draw chromosome starts as dotted lines. |
None
|
Source code in src/hicstuff/view.py
normalize ¶
scaffold_distribution ¶
Visualize scaffold size distribution
Compute (and optionally display) scaffold size distribution for a genome in fasta format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genome
|
(str, file or Path)
|
The genome scaffold file (or file handle) |
required |
threshold
|
int
|
The size below which scaffolds are discarded, by default 1000000 |
100
|
plot
|
bool
|
Whether to plot the results |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
The list of scaffold sizes in decreasing order. |
Source code in src/hicstuff/view.py
reorder_fasta ¶
Reorder and trim a fasta file
Sort a fasta file by record lengths, optionally trimming the smallest ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genome
|
(str, file or Path)
|
The genome scaffold file (or file handle) |
required |
output
|
(str, file or Path)
|
The output file to write to |
required |
threshold
|
int
|
The size below which scaffolds are discarded, by default 100000 |
100000
|