prolint2.metrics.base#
- Authors:
Daniel P. Ramirez & Besian I. Sejdiu
- Year:
2022
- Copyright:
MIT License
- class prolint2.metrics.base.BaseContactStore(ts, contact_frames, norm_factor: float = 1.0)[source]#
Base class for storing contact.
- apply_function(func: Callable, target_lipid_name=None)[source]#
Apply the given function to the contacts for the given lipid name.
- compute(metric: str, target_lipid_name=None)[source]#
Compute a pre-defined metric for all lipids or a specific lipid.
- Parameters:
metric (str) – The metric to compute. Must be one of ‘max’, ‘sum’, ‘mean’.
target_lipid_name (str, optional) – The name of the lipid to compute the metric for. If None, the metric will be computed for all lipids.
- Returns:
A dictionary of computed metrics for all lipids.
- Return type:
Dict[str, Dict[str, Dict[int, float]]]
Examples
>>> cd = AproxContacts(...) >>> cd.run() >>> cd.compute('max') >>> cd.compute('sum', 'DOPC') >>> cd.compute('median') # raises ValueError. Use `apply_function` instead.
- compute_metric(metric: str, target_lipid_name=None)[source]#
Compute the given metric for the given lipid name.
- property contacts#
Get the computed contacts all pooled together.
- property results#
Get the computed contacts per lipid id.
- class prolint2.metrics.base.BaseMetric[source]#
Base class for all metrics classes that act on single frame contact Iterables.
- class prolint2.metrics.base.FittingFunctionMeta(name, bases, dct)[source]#
Metaclass for fitting functions.
- class prolint2.metrics.base.Metric(contacts, metrics, output_format: ~prolint2.metrics.formatters.OutputFormat = <prolint2.metrics.formatters.DefaultOutputFormat object>, lipid_type=None, clear=True)[source]#
Base class for metric calculation.
prolint2.metrics.aprox_contacts#
- Authors:
Daniel P. Ramirez & Besian I. Sejdiu
- Year:
2022
- Copyright:
MIT License
- class prolint2.metrics.aprox_contacts.AproxContacts(ts, contact_frames, norm_factor: float = 1.0)[source]#
Compute the duration of lipid contacts. This class is used to compute the duration of lipid contacts.
- apply_function(func: Callable, target_lipid_name=None)[source]#
Apply a function to all lipids or a specific lipid.
- Parameters:
func (Callable) – The function to apply to the lipid contact durations.
target_lipid_name (str, optional) – The name of the lipid to apply the function to. If None, the function will be applied to all lipids.
conversion_func (Callable, optional) – The function to convert the contact array before calling func. If None, no conversion will be applied.
- Returns:
A dictionary of computed metrics for all lipids.
- Return type:
Dict[str, Dict[str, Dict[int, float]]]
Example
>>> cd = AproxContacts(...) >>> cd.run() >>> cd.apply_function(np.mean) >>> cd.apply_function(np.max, target_lipid_name='DOPC') >>> cd.apply_function(lambda x: np.mean(x) / np.max(x), target_lipid_name='DOPC')
- compute_metric(metric: str, target_lipid_name=None)[source]#
Compute a pre-defined metric for all lipids or a specific lipid.
- Parameters:
metric (str) – The metric to compute. Must be one of ‘max’, ‘sum’, ‘mean’.
target_lipid_name (str, optional) – The name of the lipid to compute the metric for. If None, the metric will be computed for all lipids.
- Returns:
A dictionary of computed metrics for all lipids.
- Return type:
Dict[str, Dict[str, Dict[int, float]]]
- pooled_results(target_lipid_name: Optional[str] = None) Dict[str, ndarray][source]#
Get the duration of lipid contacts for all lipid types pooled together.
- Parameters:
target_lipid_name (str, optional) – A list of lipid residue names to compute durations for. If None, durations will be computed for all lipid types.
- Returns:
A dictionary of lipid contact durations for all lipid types.
- Return type:
Dict[str, np.ndarray]
- run(lipid_resnames: Optional[Union[str, List]] = None) Dict[str, ndarray][source]#
Compute the duration of lipid contacts for all lipid types.
- Parameters:
lipid_resnames (str, optional) – A list of lipid residue names to compute durations for. If None, durations will be computed for all lipid types.
- Returns:
A dictionary of lipid contact durations for all lipid types.
- Return type:
Dict[str, np.ndarray]
prolint2.metrics.exact_contacts#
- Authors:
Daniel P. Ramirez & Besian I. Sejdiu
- Year:
2022
- Copyright:
MIT License
- class prolint2.metrics.exact_contacts.ExactContacts(ts, contact_frames, norm_factor: float = 1.0)[source]#
Compute the duration of lipid contacts. This class is used to compute the duration of lipid contacts.
- apply_function(func: Callable, target_lipid_name=None)[source]#
Apply a function to all lipids or a specific lipid.
- Parameters:
func (Callable) – The function to apply to the lipid contact durations.
target_lipid_name (str, optional) – The name of the lipid to apply the function to. If None, the function will be applied to all lipids.
- Returns:
A dictionary of computed metrics for all lipids.
- Return type:
Dict[str, Dict[str, Dict[int, float]]]
Example
>>> cd = ExactContacts(...) >>> cd.run() >>> cd.apply_function(np.mean) >>> cd.apply_function(np.max, target_lipid_name='DOPC') >>> cd.apply_function(lambda x: np.mean(x) / np.max(x), target_lipid_name='DOPC')
- compute_lipid_durations(contact_frame: Dict[int, List[int]], lipid_resname: str) ndarray[source]#
Compute the duration of lipid contacts.
- Parameters:
contact_frame (Dict[int, List[int]]) – A dictionary of contact frames.
lipid_resname (str) – The residue name of the lipid to compute durations for.
- Returns:
An array of lipid contact durations.
- Return type:
np.ndarray
- compute_metric(metric: str, target_lipid_name=None)[source]#
Compute a pre-defined metric for all lipids or a specific lipid.
- Parameters:
metric (str) – The metric to compute. Must be one of ‘max’, ‘sum’, ‘mean’.
target_lipid_name (str, optional) – The name of the lipid to compute the metric for. If None, the metric will be computed for all lipids.
- Returns:
A dictionary of computed metrics for all lipids.
- Return type:
Dict[str, Dict[str, Dict[int, float]]]
- pooled_results(target_lipid_name=None)[source]#
Pool results for all lipids.
- Parameters:
target_lipid_name (str, optional) – The name of the lipid to compute pooled results for. If None, pooled results will be computed for all lipids.
- Returns:
A dictionary of pooled results for all lipids.
- Return type:
Dict[str, Dict[str, List[float]]]
- run(lipid_resnames: Optional[Union[str, List]] = None) Dict[str, ndarray][source]#
Compute the duration of lipid contacts for all lipid types.
- Parameters:
lipid_resnames (str, optional) – A list of lipid residue names to compute durations for. If None, durations will be computed for all lipid types.
- Returns:
A dictionary of lipid contact durations for all lipid types. The output is stored in the self._contacts attribute.
- Return type:
Dict[str, np.ndarray]
prolint2.metrics.metrics#
- Authors:
Daniel P. Ramirez & Besian I. Sejdiu
- Year:
2022
- Copyright:
MIT License
- class prolint2.metrics.metrics.MaxMetric[source]#
A metric to compute the maximum contact value.
- Variables:
name (str) – The name of the metric (set to ‘max’).
Examples
>>> max_metric = MaxMetric() >>> result = max_metric.compute_metric(contact_array)
- compute_metric(contact_array)[source]#
Compute the maximum contact value for a given contact array.
- Parameters:
contact_array (Iterable[int]) – An iterable representing contact data.
- Returns:
The maximum contact value.
- Return type:
int
Examples
>>> result = max_metric.compute_metric(contact_array)
- class prolint2.metrics.metrics.MeanMetric[source]#
A metric to compute the mean of contact values.
- Variables:
name (str) – The name of the metric (set to ‘mean’).
- compute_metric(contact_array)[source]#
Compute the mean of contact values for a given contact array.
Examples
>>> mean_metric = MeanMetric() >>> result = mean_metric.compute_metric(contact_array)
- compute_metric(contact_array)[source]#
Compute the mean of contact values for a given contact array.
- Parameters:
contact_array (Iterable[int]) – An iterable representing contact data.
- Returns:
The computed mean value.
- Return type:
float
Examples
>>> result = mean_metric.compute_metric(contact_array)
- class prolint2.metrics.metrics.SumMetric[source]#
A metric to compute the sum of contact values.
- Variables:
name (str) – The name of the metric (set to ‘sum’).
Examples
>>> sum_metric = SumMetric() >>> result = sum_metric.compute_metric(contact_array)
- compute_metric(contact_array)[source]#
Compute the sum of contact values for a given contact array.
- Parameters:
contact_array (Iterable[int]) – An iterable representing contact data.
- Returns:
The computed sum of contact values.
- Return type:
int
Examples
>>> result = sum_metric.compute_metric(contact_array)
- class prolint2.metrics.metrics.UserDefinedMetric(custom_function: Callable[[Iterable[int]], float])[source]#
A user-defined metric class.
- Parameters:
custom_function (Callable[[Iterable[int]], float]) – A custom function to compute the metric.
- Variables:
name (str) – The name of the metric (set to ‘custom’).
Examples
>>> custom_metric = UserDefinedMetric(my_custom_function) >>> result = custom_metric.compute_metric(contact_array)
- prolint2.metrics.metrics.create_metric(contacts, metrics, output_format=None, custom_function: Optional[Callable] = None, metric_registry: Optional[MetricRegistry] = None, lipid_type=None, **kwargs)[source]#
Create and configure a metric computation task.
This function creates a metric computation task based on user-defined parameters. It returns a Metric object that can be used to compute metrics on contact data.
- Parameters:
contacts (ContactData) – The contact data to analyze.
metrics (list) – A list of metrics to compute, including ‘max’, ‘sum’, ‘mean’, or ‘custom’.
output_format (str, optional) – The output format for the computed metrics. Supported values include ‘default’, ‘custom’, ‘single’, or ‘dashboard’.
custom_function (Callable, optional) – A custom function to use when the ‘custom’ metric is selected.
metric_registry (MetricRegistry, optional) – A registry containing metric classes.
lipid_type (str, optional) – The type of lipid to consider in the metric computation.
**kwargs – Additional keyword arguments for output format classes.
- Returns:
A Metric object configured with the specified parameters.
- Return type:
- Raises:
ValueError – If an invalid output format is specified or if ‘single’ format is used with more than one metric.
Examples
>>> metrics = ['max', 'mean'] >>> metric = create_metric(contacts, metrics, output_format='default') >>> metric.run() >>> results = metric.compute('max') >>> results = metric.compute('sum', lipid_type='DOPC') >>> metric.compute('median') # Raises ValueError. Use `apply_function` instead.