helpers.pipeline

A dataclass that allows for an object oriented pipeline.

class lta.helpers.pipeline.Pipeline(file: pathlib.Path, output: pathlib.Path, n_rows_metadata: int, level: str, control: str, compartment: str, mode: str, sample_id: str, thresh: float, n: int)

The Lipid Traffic Analysis pipeline.

file

The path to the combined data input file.

Type

Path

output

Where to save the results.

Type

Path

n_rows_metadata

The number of rows to treat as column metadata. As Python is 0-indexed, passing 11 will read in rows 0-10.

Type

int

level

Metadata location of experimental conditions.

Type

str

control

Value within self.level that represents the control condition.

Type

str

compartment

Metadata location of sample tissue compartment.

Type

str

mode

Metadata location of lipidomics mode.

Type

str

sample_id

Metadata location of sample IDs.

Type

str

thresh

The fraction of samples that are 0 above which a lipid will be called 0 for a compartment.

Type

float

n

Number of bootstrap replicates.

Type

int

_calculate_enfc() Dict[str, Dict[str, pandas.core.frame.DataFrame]]

Calculate error-normalised fold change.

Calculates the ENFC for each compartment across modes. For fold change to be meaningful, order must be specified. This will report fold-change as condition / self.control for all conditions except control within self.value.

Returns

Top level key is the experimental condition, mapped to a dictionary of modes and ENFC results

Return type

Dict[str, Dict[str, pd.DataFrame]]

_get_a_lipids() Dict[str, pandas.core.frame.DataFrame]

Extract A-lipids from the dataset.

Any compartment where more than self.thresh of the samples are 0 is considered a total 0 for that lipid. Lipids that are non-0 for all compartments in any Phenotype are considered A-lipids.

Returns

Key is mode, value is table of A-lipids

Return type

Dict[str, pd.DataFrame]

_get_b_lipids(picky: bool = True) Dict[str, pandas.core.frame.DataFrame]

Extract B-lipids from the dataset.

Any compartment where more than self.thresh of the samples are 0 is considered a total 0 for that lipid. Lipids that are non-0 for any pair of compartments within any Phenotype are considered B-lipids.

Notes

By definition, all A-lipids will also be B-lipids for every pair of compartments. These are referred to as B-consistent, or Bc for short. Those B-lipids that are not A-lipids are also known as B-picky, or Bp for short. Which set is calculated is controlled by the boolean flag picky.

Parameters

picky (bool) – default=True If true, do not consider lipids that are also A-lipids

Returns

Keys are the compartment pair and mode. Values are the table of B-lipids for that grouping.

Return type

Dict[str, pd.DataFrame]

Raises

AttributeError – If A-lipids have not been previously calculated

_get_n_lipids(n: int) Dict[str, pandas.core.frame.DataFrame]

Extract N-lipids from the dataset.

Any compartment where more than self.thresh of the samples are 0 is considered a total 0 for that lipid. Lipids that are non-0 for n compartments in any Phenotype are considered N-lipids.

Notes

For historical consistency, N1-lipids (ie those found in only 1 compartment) are called U-lipids as they are Unique. Also N2-lipids are not the same as B-lipids. A B-lipid could occur in multiple pairs of compartment, while N2-lipids must only occur in 1.

Parameters

n (int) – The number of compartments to limit the search to

Returns

Keys are the compartment group and mode. Values are the table of N-lipids for that grouping.

Return type

Dict[str, pd.DataFrame]

_jaccard(data: Dict[str, pandas.core.frame.DataFrame], group: str) Dict[str, Dict[str, pandas.core.frame.DataFrame]]

Calculate jaccard similarity and p-values.

This takes a dictionary of data. As the output of each group of lipids will be structured as such, it should be called per lipid group.

Notes

The P-values are calculated using a bootstrap approach on a centered Jaccard similarity.

Parameters
  • data (Dict[str, pd.DataFrame]) – A dictionary of modes and lipid data

  • group (str) – Which lipids are being checke. This is used by logging only.

Returns

Keys are the compartment group and mode. Values are the table of Jaccard similarity and p-values.

Return type

Dict[str, Dict[str, pd.DataFrame]]

run() None

Run the full LTA pipeline.

This:

  1. Calculates error-normalised fold change for all conditions relatve to control

  2. Finds A-lipids and Jaccard distances.

  3. Finds U-lipids and Jaccard distances.

  4. Finds B-lipids (both picky and consistent) and Jaccard distances.

  5. Finds N2-lipids and Jaccard distances.

  6. Writes combined results.