Skip to content

plot

find_wrap(peptides, margin=4, step=5, wrap_limit=200)

Find the minimum wrap value for a given list of intervals.

Parameters:

Name Type Description Default
peptides DataFrame

Dataframe with columns 'start' and 'end' representing intervals.

required
margin int

The margin applied to the wrap value. Defaults to 4.

4
step int

The increment step for the wrap value. Defaults to 5.

5
wrap_limit int

The maximum allowed wrap value. Defaults to 200.

200

Returns:

Name Type Description
int int

The minimum wrap value that does not overlap with any intervals.

Source code in hdxms_datasets/plot.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def find_wrap(
    peptides: pl.DataFrame,
    margin: int = 4,
    step: int = 5,
    wrap_limit: int = 200,
) -> int:
    """
    Find the minimum wrap value for a given list of intervals.

    Args:
        peptides: Dataframe with columns 'start' and 'end' representing intervals.
        margin: The margin applied to the wrap value. Defaults to 4.
        step: The increment step for the wrap value. Defaults to 5.
        wrap_limit: The maximum allowed wrap value. Defaults to 200.

    Returns:
        int: The minimum wrap value that does not overlap with any intervals.
    """
    wrap = step

    while True:
        peptides_y = peptides.with_columns(
            (pl.int_range(pl.len(), dtype=pl.UInt32).alias("y") % wrap)
        )

        no_overlaps = True
        for name, df in peptides_y.group_by("y", maintain_order=True):
            overlaps = (np.array(df["end"]) + 1 + margin)[:-1] >= np.array(df["start"])[1:]
            if np.any(overlaps):
                no_overlaps = False
                break
                # return wrap

        wrap += step
        if wrap > wrap_limit:
            return wrap_limit  # Return the maximum wrap limit if no valid wrap found
        elif no_overlaps:
            return wrap

unique_peptides(df)

Checks if all peptides in the DataFrame are unique.

Source code in hdxms_datasets/plot.py
 8
 9
10
11
12
13
def unique_peptides(df: pl.DataFrame) -> bool:
    """
    Checks if all peptides in the DataFrame are unique.
    """

    return len(df) == len(df.unique(subset=["start", "end"]))