RIAssigner.data =============== .. py:module:: RIAssigner.data Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/RIAssigner/data/Data/index /autoapi/RIAssigner/data/MatchMSData/index /autoapi/RIAssigner/data/PandasData/index /autoapi/RIAssigner/data/SimpleData/index /autoapi/RIAssigner/data/ValidateSimpleData/index Classes ------- .. autoapisummary:: RIAssigner.data.Data RIAssigner.data.PandasData RIAssigner.data.MatchMSData RIAssigner.data.SimpleData RIAssigner.data.ValidateSimpleData Package Contents ---------------- .. py:class:: Data(filename: str, filetype: str, rt_unit: str) Bases: :py:obj:`abc.ABC` Base class for data managers. .. py:attribute:: RetentionTimeType .. py:attribute:: RetentionIndexType .. py:attribute:: CommentFieldType .. py:attribute:: URegistry .. py:attribute:: _keys_conversions .. py:attribute:: _rt_possible_keys .. py:attribute:: _ri_possible_keys .. py:method:: is_valid(value: Union[RetentionTimeType, RetentionIndexType]) -> bool :staticmethod: Determine whether a retention time value is valid :param rt: Value to check for validity. :type rt: RetentionTimeType :returns: State of validity (True/False). :rtype: bool .. py:method:: can_be_float(rt: Union[pint.Quantity, float, int]) -> bool :staticmethod: Determine whether a value can be converted to a float. This function checks if the provided input is an instance of either Quantity, float, or int. :param rt: Value to check for float conversion. :type rt: Union[Quantity, float, int] :returns: True if the input is an instance of Quantity, float, or int, False otherwise. :rtype: bool .. py:method:: add_possible_rt_keys(keys: List[str]) -> None :classmethod: A method that adds new identifiers to get retention time information. :param keys: A list of new identifiers (keys) to be added to the `_rt_possible_keys`. :type keys: List[str] :returns: None .. py:method:: add_possible_ri_keys(keys: List[str]) -> None :classmethod: A method that adds new identifiers to get retention index information. :param keys: A list of new identifiers (keys) to be added to the `_ri_possible_keys`. :type keys: List[str] :returns: None .. py:method:: get_possible_rt_keys() -> List[str] :classmethod: A method that returns the possible keys to get retention times. :returns: A list of possible keys to get retention times. :rtype: List[str] .. py:method:: get_possible_ri_keys() -> List[str] :classmethod: A method that returns the possible keys to get retention indices. :returns: A list of possible keys to get retention indices. :rtype: List[str] .. py:attribute:: _filename .. py:attribute:: _filetype .. py:attribute:: _rt_unit .. py:attribute:: _unit .. py:method:: write(filename: str) -> None :abstractmethod: Store current content to disk. :param filename: Path to output filename. :type filename: str .. py:property:: filename :type: str Getter for filename property. :returns: Filename of originally loaded data. :rtype: str .. py:property:: retention_times :type: Iterable[RetentionTimeType] :abstractmethod: Getter for `retention_times` property. :returns: RT values contained in data. :rtype: Iterable[RetentionTimeType] .. py:property:: retention_indices :type: Iterable[RetentionIndexType] :abstractmethod: Getter for `retention_indices` property. :returns: RI values stored in data. :rtype: Iterable[RetentionIndexType] .. py:method:: has_retention_indices() -> bool Check if all retention indices in the spectra exist. This method iterates over the retention indices in the spectra. If it encounters a value that is None, it immediately returns False. If it iterates over all retention indices without finding a None value, it returns True. :returns: True if all retention indices exist, False otherwise. :rtype: bool .. py:method:: has_retention_times() -> bool Check if all retention times in the spectra exist. This method iterates over the retention times in the spectra. If it encounters a value that is None, it immediately returns False. If it iterates over all retention times without finding a None value, it returns True. :returns: True if all retention times exist, False otherwise. :rtype: bool .. py:property:: comment :type: Iterable[CommentFieldType] :abstractmethod: Getter for `comment` property. :returns: Comment field values stored in data. :rtype: Iterable[CommentFieldType] .. py:method:: init_ri_from_comment(ri_source: str) -> None Extract RI from comment field. Extracts the RI from the comment field of the data file. The RI is expected to be in the format 'ri_source=RI_value'. The function extracts the RI value and sets it on the retention_index property. :param content_comment: Comment field of the data file. :param ri_source: String that is expected to be in the comment field before the RI value. .. py:class:: PandasData(filename: str, filetype: str, rt_unit: str) Bases: :py:obj:`RIAssigner.data.Data.Data` Class to handle data from filetypes which can be imported into a pandas dataframe. .. py:attribute:: _carbon_number_column_names .. py:attribute:: _rt_key :value: 'rt' .. py:method:: _read() Load content from file into PandasData object. .. py:method:: _read_into_dataframe() -> None Read the data from file into dataframe. .. py:method:: write(filename: str) -> None Write data on disk. Supports 'csv', 'tsv', 'tabular' and 'parquet' formats. .. py:method:: _init_carbon_number_index() -> None Find key of carbon number column and store it. .. py:method:: _init_rt_column_info() -> None Find key of retention time column and store it. .. py:method:: _init_ri_column_info() -> None Initialize retention index column name and set its position next to the retention time column. .. py:method:: _init_ri_indices() -> None Initialize retention indices to a factor of 100 of carbon numbers or None if carbon numbers are not present. .. py:method:: _sort_by_rt() -> None Sort peaks by their retention times. .. py:method:: _replace_nans_with_0s() -> None Replace NaN values (including blank strings and invalid values) with 0s. .. py:method:: __eq__(o: object) -> bool Comparison operator `==`. :param o: Object to compare with. :type o: object :returns: State of equality. :rtype: bool .. py:property:: retention_times :type: Iterable[RIAssigner.data.Data.Data.RetentionTimeType] Get retention times in seconds. .. py:property:: retention_indices :type: Iterable[RIAssigner.data.Data.Data.RetentionIndexType] Get retention indices from data or computed from carbon numbers. .. py:method:: _ri_from_carbon_numbers() -> Iterable[int] Returns the RI of compound based on carbon number. .. py:property:: comment :type: Iterable[RIAssigner.data.Data.Data.CommentFieldType] Get comments. :returns: Comments. :rtype: Iterable[Data.CommentFieldType] .. py:class:: MatchMSData(filename: str, filetype: str, rt_unit: str) Bases: :py:obj:`RIAssigner.data.Data.Data` Class to handle data from filetypes which can be imported using 'matchms'. .. py:method:: _read() Load data into object and initialize properties. .. py:method:: write(filename: str) -> None Write data to back to the spectra file :param filename: Path to filename under which to store the data. :type filename: str .. py:method:: _write_RIs_to_spectra() -> None Write the RI values stored in the object to the spectra metadata. .. py:method:: _read_retention_times() -> None Read retention times from spectrum metadata. .. py:method:: _read_retention_indices() -> None Read retention indices from spectrum metadata. .. py:method:: _sort_spectra_by_rt() -> None Sort objects (peaks) in spectra list by their retention times. .. py:method:: __eq__(o: object) -> bool Comparison operator `==`. :param o: Object to compare with. :type o: object :returns: State of equality. :rtype: bool .. py:property:: retention_times :type: Iterable[RIAssigner.data.Data.Data.RetentionTimeType] Get retention times in seconds. .. py:property:: retention_indices :type: Iterable[RIAssigner.data.Data.Data.RetentionIndexType] Get retention indices. .. py:property:: comment :type: Iterable[RIAssigner.data.Data.Data.CommentFieldType] Get comments. .. py:property:: spectra_metadata :type: Tuple[numpy.array, List[str]] .. py:class:: SimpleData(retention_times: Iterable[float], rt_unit: str, retention_indices: Iterable[float] = None) Bases: :py:obj:`RIAssigner.data.Data.Data` Class to handle data from numpy arrays .. py:method:: _read(retention_times, retention_indices) .. py:method:: write() :abstractmethod: Store current content to disk. :param filename: Path to output filename. :type filename: str .. py:property:: retention_indices :type: Iterable[RIAssigner.data.Data.Data.RetentionIndexType] Getter for `retention_indices` property. :returns: RI values stored in data. :rtype: Iterable[RetentionIndexType] .. py:property:: retention_times :type: Iterable[RIAssigner.data.Data.Data.RetentionTimeType] Getter for `retention_times` property. :returns: RT values contained in data. :rtype: Iterable[RetentionTimeType] .. py:property:: comment :type: Iterable[Optional[str]] Getter for `comment` property. :returns: Comment field values stored in data. :rtype: Iterable[CommentFieldType] .. py:class:: ValidateSimpleData(retention_times: Iterable[float], rt_unit: str, retention_indices: Iterable[float] = None) Bases: :py:obj:`RIAssigner.data.SimpleData.SimpleData` Class to handle data from numpy arrays .. py:method:: _validate_input(retention_times, retention_indices)