pyprobound.rounds.BaseRound

class BaseRound(reference_round, train_depth=True, log_depth=0, library_concentration=-1, name='')

Bases: Transform, ABC

Base class for sequencing rounds.

reference_round

The previous round for cumulative enrichment.

Type:

BaseRound | None

log_depth

The sequencing depth \(\eta\) in log space.

Type:

Tensor

__init__(reference_round, train_depth=True, log_depth=0, library_concentration=-1, name='')

Initializes the round.

Parameters:
  • reference_round (BaseRound | None) – The previous round used in cumulative enrichment.

  • train_depth (bool) – Whether to train the sequencing depth \(\eta\).

  • log_depth (float) – The initial value of log_depth.

  • library_concentration (float) – The total library concentration, used for estimating the free protein concentration.

  • name (str) – A string used to describe the round.

Methods

cache(fun)

Decorator for a function to cache its output.

check_length_consistency()

Checks that input lengths of Binding components are consistent.

components()

Iterator of child components.

forward(seqs)

Predicts the log relative count.

freeze()

Turns off gradient calculation for all parameters.

log_aggregate(seqs)

Predicts the log aggregate \(\log Z_i\).

log_cumulative_enrichment(seqs)

Predicts the log cumulative enrichment.

log_enrichment(seqs)

Predicts the log enrichment ratio.

max_embedding_size()

The maximum number of bytes needed to encode a sequence.

optim_procedure([ancestry, current_order])

The sequential optimization procedure for all Binding components.

reload(checkpoint)

Loads the model from a checkpoint file.

reload_from_state_dict(state_dict)

Loads the model from a state dict.

save(checkpoint[, flank_lengths])

Saves the model to a file with "state_dict" and "metadata" fields.

unfreeze([parameter])

Turns on gradient calculation for the specified parameter.

Attributes

library_concentration

The total library concentration \([\text{library}]\).

unfreezable

alias of Literal['all', 'depth']

Non-Inherited Members

unfreezable

alias of Literal[‘all’, ‘depth’]

property library_concentration: float

The total library concentration \([\text{library}]\).

abstract components()

Iterator of child components.

Return type:

Iterator[Aggregate]

unfreeze(parameter='all')

Turns on gradient calculation for the specified parameter.

Parameters:

parameter (unfreezable) – Parameter to be unfrozen, defaults to all parameters.

Return type:

None

optim_procedure(ancestry=None, current_order=None)

The sequential optimization procedure for all Binding components.

The optimization procedure is generated recursively through iteration over the child components of each module. All Binding components with the same specification returned from key() are trained jointly.

Parameters:
  • ancestry (tuple[Component, ...] | None) – The parent components from the root for which the procedure is being generated to the current component.

  • current_order (dict[tuple[Spec, ...], BindingOptim] | None) – Mapping of Binding component specifications to the sequential optimization procedure for those Binding components.

Return type:

dict[tuple[Spec, ...], BindingOptim]

Returns:

The current_order updated with the optimization of the current component’s children.

abstract log_aggregate(seqs)

Predicts the log aggregate \(\log Z_i\).

Parameters:

seqs (Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{in_channels},\text{length})\).

Return type:

Tensor

Returns:

The log aggregate tensor of shape \((\text{minibatch},)\).

abstract log_enrichment(seqs)

Predicts the log enrichment ratio.

\[\log \frac{f_{i,r}}{f_{i,r-1}}\]
Parameters:

seqs (Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{in_channels},\text{length})\).

Return type:

Tensor

Returns:

The log enrichment ratio tensor of shape \((\text{minibatch},)\).

log_cumulative_enrichment(seqs)

Predicts the log cumulative enrichment.

\[\log \prod_r f_{i,r}\]
Parameters:

seqs (Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{in_channels},\text{length})\).

Return type:

Tensor

Returns:

The log enrichment ratio tensor of shape \((\text{minibatch},)\).

forward(seqs)

Predicts the log relative count.

\[\log \eta_{i,r} \prod_r f_{i,r}\]
Parameters:

seqs (Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{in_channels},\text{length})\).

Return type:

Tensor

Returns:

The log relative count tensor of shape \((\text{minibatch},)\).