Skip to content

reader

Reader functions for various file formats

read_dynamx(filepath_or_buffer, time_conversion=('min', 's'))

Reads DynamX .csv files and returns the resulting peptide table as a pandas DataFrame.

Parameters:

Name Type Description Default
filepath_or_buffer Union[Path[str], str, IO]

File path of the .csv file or :class:~io.StringIO object.

required
time_conversion Optional[tuple[Literal['h', 'min', 's'], Literal['h', 'min', 's']]]

How to convert the time unit of the field 'exposure'. Format is ('', <'to'>). Unit options are 'h', 'min' or 's'.

('min', 's')

Returns:

Type Description
DataFrame

Peptide table as a pandas DataFrame.

Source code in hdxms_datasets/reader.py
13
14
15
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
def read_dynamx(
    filepath_or_buffer: Union[Path[str], str, IO],
    time_conversion: Optional[tuple[Literal["h", "min", "s"], Literal["h", "min", "s"]]] = (
        "min",
        "s",
    ),
) -> pd.DataFrame:
    """
    Reads DynamX .csv files and returns the resulting peptide table as a pandas DataFrame.

    Args:
        filepath_or_buffer: File path of the .csv file or :class:`~io.StringIO` object.
        time_conversion: How to convert the time unit of the field 'exposure'. Format is ('<from>', <'to'>).
            Unit options are 'h', 'min' or 's'.

    Returns:
        Peptide table as a pandas DataFrame.
    """

    df = pd.read_csv(filepath_or_buffer)
    df.columns = df.columns.str.replace(" ", "_").str.lower()

    df.insert(df.columns.get_loc("end") + 1, "stop", df["end"] + 1)

    if time_conversion is not None:
        time_lut = {"h": 3600, "min": 60, "s": 1}
        time_factor = time_lut[time_conversion[0]] / time_lut[time_conversion[1]]
        df["exposure"] *= time_factor

    return df