Distance law¶
hicstuff.distance_law computes the distance law from a pairs file
(get_distance_law), reads and writes its tables (import_distance_law,
export_distance_law), normalises and averages the curves
(normalize_distance_law, average_distance_law) and plots them with their
slope (plot_ps_slope). See The distance law.
hicstuff.distance_law ¶
export_distance_law ¶
Export the x(s) and p(s) from two list of numpy.ndarrays to a table in txt file with three columns separated by a tabulation. The first column contains the x(s), the second the p(s) and the third the name of the arm or chromosome. The file is created in the directory given by outdir or the current file if no file is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list of numpy.ndarray
|
The list of the start position of logbins of each p(s) in base pairs. |
required |
ps
|
list of numpy.ndarray
|
The list of p(s). |
required |
names
|
list of string
|
List containing the names of the chromosomes/arms/conditions of the p(s) values given. |
required |
out_file
|
str or None
|
Path where output file should be written. ./distance_law.txt by default. |
None
|
Return
txt file: File with three columns separated by a tabulation. The first column contains the x(s), the second the p(s) and the third the name of the arm or chromosome. The file is creates in the output file given or the default one if none given.
Source code in src/hicstuff/distance_law.py
import_distance_law ¶
Import the table created by export_distance_law and return the list of x(s) and p(s) in the order of the chromosomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance_law_file
|
string
|
Path to the file containing three columns : the x(s), the p(s), and the chromosome/arm name. |
required |
Returns:
| Type | Description |
|---|---|
list of numpy.ndarray :
|
The start coordinate of each bin one array per chromosome or arm. |
list of numpy.ndarray :
|
The distance law probabilities corresponding of the bins of the previous list. |
list of numpy.ndarray :
|
The names of the arms/chromosomes corresponding to the previous list. |
Source code in src/hicstuff/distance_law.py
get_distance_law ¶
get_distance_law(pairs_reads_file, fragments_file=None, centro_file=None, base=1.1, out_file=None, circular=False, rm_centro=0)
Compute distance law as a function of the genomic coordinate aka P(s). Bin length increases exponentially with distance. Works on pairs file format from 4D Nucleome Omics Data Standards Working Group. If the genome is composed of several chromosomes and you want to compute the arms separately, provide a file with the positions of centromers. Create a file with three coulumns separated by a tabulation. The first column contains the xs, the second the ps and the third the name of the arm or chromosome. The file is create in the directory given in outdir or in the current directory if no directory given.
When fragments_file is not provided, chromosome sizes are read from the
#chromsize: lines of the pairs header and distances are computed
directly as abs(pos2 - pos1). This mode is compatible with plain 4DN
standard pairs files (with or without frag columns) and with
gzip-compressed files. Centromere splitting is not supported in this mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs_reads_file
|
string
|
Path of a pairs file format from 4D Nucleome Omics Data Standards
Working Group. When |
required |
fragments_file
|
path or None
|
Path of a table containing in the first column the ID of the fragment, in the second the names of the chromosome in the third and fourth the start position and the end position of the fragment. The file have no header. (File like the 'fragments_list.txt' from hicstuff). When None, chromosome information is inferred from the pairs header and distances are computed from read positions directly. |
None
|
centro_file
|
None or str
|
None or path to a file with the genomic positions of the centromers
sorted as the chromosomes separated by a space. The file have only one
line. Requires |
None
|
base
|
float
|
Base use to construct the logspace of the bins - 1.1 by default. |
1.1
|
out_file
|
None or str
|
Path of the output file. If no path given, the output is returned. |
None
|
circular
|
bool
|
If True, calculate the distance as the chromosome is circular. Default value is False. Cannot be True if centro_file is not None |
False
|
rm_centro
|
int
|
If a value is given, will remove the contacts close the centromeres. It will remove as many kb as the argument given. Default is None. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
xs |
list of numpy.ndarray
|
Basepair coordinates of log bins used to compute distance law. |
ps |
list of numpy.ndarray
|
Contacts value, in arbitrary units, at increasingly long genomic ranges given by xs. |
names |
list of strings
|
Names of chromosomes that are plotted |
Source code in src/hicstuff/distance_law.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
normalize_distance_law ¶
Normalize the distance in order to have the sum of the ps values between 'inf' (default value is 3kb) until the end of the array equal to one and limit the effect of coverage between two conditions/chromosomes/arms when you compare them together. If we have a list of ps, it will normalize until the length of the shorter object or the value of sup, whichever is smaller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list of numpy.ndarray
|
list of logbins corresponding to the ps. |
required |
ps
|
list of numpy.ndarray
|
Average ps or list of ps of the chromosomes/arms. xs and ps have to have the same shape. |
required |
inf
|
integer
|
Inferior value of the interval on which, the normalization is applied. |
3000
|
sup
|
integer
|
Superior value of the interval on which, the normalization is applied. |
None
|
Returns:
| Type | Description |
|---|---|
list of numpy.ndarray :
|
List of ps each normalized separately. |
Source code in src/hicstuff/distance_law.py
average_distance_law ¶
Compute the average distance law between the file the different distance law of the chromosomes/arms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list of numpy.ndarray
|
The list of logbins. |
required |
ps
|
list of lists of floats
|
The list of numpy.ndarray. |
required |
sup
|
int
|
Value given to set the minimum size of the chromosomes/arms to make the average. |
required |
big_arm_only
|
bool
|
By default False. If True, will only take into account the arms/chromosomes longer than the value of sup. Sup mandatory if set. |
False
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray :
|
List of the xs with the max length. |
numpy.ndarray :
|
List of the average_ps. |
Source code in src/hicstuff/distance_law.py
slope_distance_law ¶
Compute the slope of the loglog curve of the ps as the [log(ps(n+1)) - log(ps(n))] / [log(n+1) - log(n)]. Compute only list of ps, not list of array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list of numpy.ndarray
|
The list of logbins. |
required |
ps
|
list of numpy.ndarray
|
The list of ps. |
required |
Returns:
| Type | Description |
|---|---|
list of numpy.ndarray :
|
The slope of the distance law. It will be shorter of one value than the ps given initially. |
Source code in src/hicstuff/distance_law.py
get_ylim ¶
Compute the max and the min of the list of list between the inferior (inf) and superior (sup) bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list of numpy.ndarray
|
The list of the logbins starting position in basepair. |
required |
curve
|
list of numpy.ndarray
|
A list of numpy.ndarray from which you want to extract minimum and maximum values in a given interval. |
required |
inf
|
int
|
Inferior limit of the interval in basepair. |
required |
sup
|
int
|
Superior limit of the interval in basepair. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
min_tot |
float
|
Minimum value of the list of list in this interval. |
max_tot |
float
|
Maximum value of the list of list in this interval. |
Examples:
>>> get_ylim([np.array([1, 4, 15]), np.array([1, 4, 15, 40])],
... [np.array([5.5, 3.2, 17.10]), np.array([24, 32, 1.111, 18.5])],
... 2,
... 15
... )
(1.111, 32.0)
Source code in src/hicstuff/distance_law.py
plot_ps_slope ¶
Compute two plots, one with the different distance law of each arm/chromosome in loglog scale and one with the slope (derivative) of these curves. Generate a svg file with savefig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list of numpy.ndarray
|
The list of the logbins of each ps. |
required |
ps
|
list of numpy.ndarray
|
The list of ps. |
required |
labels
|
list of strings
|
Names of the different curves in the order in which they are given. |
required |
fig_path
|
str
|
Path where the figure will be created. If None (default), the plot is shown in an interactive window. |
None
|
inf
|
int
|
Value of the mimimum x of the window of the plot. Have to be strictly positive. By default 3000. |
3000
|
sup
|
int
|
Value of the maximum x of the window of the plot. By default None. |
None
|