lib5c.operators.standardization module

class lib5c.operators.standardization.Standardizer(propagate_nan=True)[source]

Bases: lib5c.operators.base.MultiInteractionMatrixOperator

Operator for standardizing InteractionMatrix objects. This process reduces all InteractionMatrix objects passed to the lowest common denominator of loci. In other words, loci that are not present in every InteractionMatrix object will be discarded from all InteractionMatrix objects.

propagate_nan

If True, nan values will be propagated across InteractionMatrix objects.

Type

bool

Notes

The InteractionMatrix objects supplied must have locusmap attributes.

apply_inplace(targets, **kwargs)[source]

Apply the standardization operation to the target InteractionMatrix objects.

Parameters
  • targets (list of InteractionMatrix) – The InteractionMatrix objects to standardize.

  • kwargs (other keyword arguments) – To be utilized by subclasses.

Returns

The standardized InteractionMatrix objects.

Return type

list of InteractionMatrix

Examples

>>> import numpy as np
>>> from lib5c.core.interactions import InteractionMatrix
>>> from lib5c.core.loci import Locus, LocusMap
>>> from lib5c.operators.standardization import Standardizer
>>> s = Standardizer()
>>> lm = LocusMap([
...     Locus('chr3', 34109023, 34113109),
...     Locus('chr3', 34113147, 34116141),
...     Locus('chr3', 87282063, 87285636),
...     Locus('chr3', 87285637, 87295935)
... ])
...
>>> im1 = InteractionMatrix([[  0.,   5.,  10.,  15.],
...                          [  5.,  10.,  15.,  20.],
...                          [ 10.,  15.,  20.,  25.],
...                          [ 15.,  20.,  25.,  30.]], locusmap=lm)
...
>>> im2 = InteractionMatrix([[    1., np.nan,    11.],
...                          [np.nan,    11.,    16.],
...                          [   11.,    16.,    21.]], locusmap=lm[:3])
...
>>> results = s.apply([im1, im2])
>>> print(results[0])
InteractionMatrix of size 3
[[ 0. nan 10.]
 [nan 10. 15.]
 [10. 15. 20.]]
Associated LocusMap:
LocusMap comprising 3 loci
    Range: chr3:34109023-34113109 to chr3:87282063-87285636
>>> print(results[1])
InteractionMatrix of size 3
[[ 1. nan 11.]
 [nan 11. 16.]
 [11. 16. 21.]]
Associated LocusMap:
LocusMap comprising 3 loci
    Range: chr3:34109023-34113109 to chr3:87282063-87285636
>>> results[0].print_log()
InteractionMatrix created
standardized with propagate_nan=True
deleted locus at index 3