lib5c.operators.base module¶
-
class
lib5c.operators.base.
InteractionMatrixOperator
[source]¶ Bases:
object
Abstract base class for objects that operate on single InteractionMatrix objects.
Subclasses should implement an
apply_inplace()
function that takes in an InteractionMatrix object and returns an InteractionMatrix object but is allowed to operate in-place. Additional parameters requried by theapply_inplace()
function can be either passed to the function as**kwargs
or stored in properties of the InteractionMatrixOperator subclass.-
apply
(target, **kwargs)[source]¶ Apply this operator to a target InteractionMatrix, returning a copy.
Parameters: - target (InteractionMatrix) – The InteractionMatrix object to operate on.
- kwargs (other keyword arguments) – To be utilized by subclasses.
Returns: The result of applying the operation.
Return type:
-
apply_by_region
(target, **kwargs)[source]¶ Apply this operator independently to each region of a target InteractionMatrix.
Parameters: - target (InteractionMatrix) – The InteractionMatrix object to operate on.
- kwargs (other keyword arguments) – To be utilized by subclasses.
Returns: The result of applying the operation.
Return type: Notes
To support logging, we used the following pattern:
- Log on the target object to indicate regional application
- Maintain a list of results of the application
- Instantiate
- Get the first result from the list and copy its log to the instance
- Log on the result object to indicate end of regional application
- Return the instance
If you see
'applying by region'
with no closing'done applying by region'
, that indictates that you are looking at a target object for an apply-by-region operation that was not done in-place. Such a log line can be ignored.If you see
'applying by region'
with a closing'done applying by region'
, that indicates that you are looking at a result object for an apply-by-region operation that was not done in-place. The lines in the block show the log for only the first region, but each region was processed identically.
-
apply_inplace
(target, **kwargs)[source]¶ Apply this operator to a target InteractionMatrix in-place.
Parameters: - target (InteractionMatrix) – The InteractionMatrix object to operate on.
- kwargs (other keyword arguments) – To be utilized by subclasses.
Returns: The result of applying the operation.
Return type:
-
-
class
lib5c.operators.base.
MultiInteractionMatrixOperator
[source]¶ Bases:
object
Abstract base class for objects that operate on multiple InteractionMatrix objects.
Subclasses should implement an
apply_inplace()
function that takes in an list of InteractionMatrix objects and returns a list of InteractionMatrix objects but is allowed to operate in-place. Additional parameters requried by theapply_inplace()
function can be either passed to the function as**kwargs
or stored in properties of the MultiInteractionMatrixOperator subclass.-
apply
(targets, **kwargs)[source]¶ Apply this operator to a list of target InteractionMatrix objects.
Parameters: - targets (list of InteractionMatrix) – The list of InteractionMatrix objects to operate on simultaneously.
- kwargs (other keyword arguments) – To be utilized by subclasses.
Returns: The result of applying the operation.
Return type: list of InteractionMatrix
-
apply_by_region
(targets, **kwargs)[source]¶ Apply this operator independently to each region of the target InteractionMatrix objects.
Parameters: - targets (list of InteractionMatrix) – The list of InteractionMatrix objects to operate on simultaneously.
- kwargs (other keyword arguments) – To be utilized by subclasses.
Returns: The result of applying the operation.
Return type: list of InteractionMatrix
Notes
To support logging, we used the following pattern:
- Log on all target objects to indicate regional application
- Maintain a dict of list of results of the application
- Instantiate the results
- Get the first region of the first result from the dict of lists and copy its log to each instance
- Log on all result objects to indicate end of regional application
- Return the instances
If you see
'applying by region'
with no closing'done applying by region'
, that indictates that you are looking at a target object for an apply-by-region operation that was not done in-place. Such a log line can be ignored.If you see
'applying by region'
with a closing'done applying by region'
, that indicates that you are looking at a result object for an apply-by-region operation that was not done in-place. The lines in the block show the log for only the first region, but each region was processed identically.
-
apply_inplace
(targets, **kwargs)[source]¶ Apply this operator to a target InteractionMatrix in-place.
Parameters: - targets (list of InteractionMatrix) – The list of InteractionMatrix objects to operate on simultaneously.
- kwargs (other keyword arguments) – To be utilized by subclasses.
Returns: The result of applying the operation.
Return type: list of InteractionMatrix
-