corems.molecular_id.factory.spectrum_search_results
1class SpectrumSearchResults: 2 """Class for storing Search Results for a single Spectrum Query 3 4 Parameters 5 ---------- 6 query_spectrum : MassSpectrum 7 The queried mass spectrum 8 precursor_mz : float, optional 9 The queried precursor_mz. None is interpreted as an open query, i.e. no precursor_mz 10 spectral_similarity_search_results : dict 11 The search results for the queried spectrum, which will be unpacked into attributes 12 13 Attributes 14 ---------- 15 query_spectrum : MassSpectrum 16 The queried mass spectrum 17 query_spectrum_id : int 18 The id of the queried spectrum (the scan number within an MassSpectra object) 19 precursor_mz : float 20 The precursor m/z of the queried spectrum 21 22 Other Possible Attributes 23 ------------------------- 24 ref_mol_id : str 25 The id of the molecule associated with the query spectrum in reference database 26 ref_ms_id : str 27 The id of the query spectrum in reference database 28 ref_precursor_mz : float 29 The precursor mass of the query spectrum 30 precursor_mz_error_ppm : float 31 The ppm error between the query spectrum and the reference spectrum 32 entropy_similarity : float 33 The entropy similarity between the query spectrum and the reference spectrum 34 ref_ion_type : str 35 The ion type of the reference spectrum, i.e. [M+H]+, [M+Na]+, etc. 36 query_mz_in_ref_n : list 37 The number of query m/z peaks that are in the reference spectrum 38 query_mz_in_ref_fract : float 39 The fraction of query m/z peaks that are in the reference spectrum 40 query_frag_types : list 41 The fragment types of the query spectrum that are in the reference spectrum, 42 i.e. LSF (lipid species fragments) or MSF (molecular species fragments), 43 generally used for only for lipidomics 44 ref_mz_in_query_n : list 45 The number of reference m/z peaks that are in the query spectrum 46 ref_mz_in_query_fract : float 47 The fraction of reference m/z peaks that are in the query spectrum 48 ref_frag_types : list 49 The fragment types of the reference spectrum, 50 i.e. LSF (lipid species fragments) or MSF (molecular species fragments), 51 generally used for only for lipidomics 52 53 Methods 54 ------- 55 *to_dataframe(). 56 Convert the SpectrumSearchResults to a pandas DataFrame 57 58 """ 59 60 def __init__( 61 self, query_spectrum, precursor_mz, spectral_similarity_search_results 62 ): 63 self.query_spectrum = query_spectrum 64 self.precursor_mz = precursor_mz 65 if query_spectrum is not None: 66 if query_spectrum.scan_number is not None: 67 self.query_spectrum_id = query_spectrum.scan_number 68 attribute_keys = [ 69 "ref_mol_id", 70 "ref_ms_id", 71 "ref_precursor_mz", 72 "precursor_mz_error_ppm", 73 "ref_ion_type", 74 "entropy_similarity", 75 "query_mz_in_ref_n", 76 "query_mz_in_ref_fract", 77 "query_frag_types", 78 "ref_mz_in_query_n", 79 "ref_mz_in_query_fract", 80 "ref_frag_types", 81 ] 82 for key in spectral_similarity_search_results.keys(): 83 if key in attribute_keys: 84 setattr(self, key, spectral_similarity_search_results[key]) 85 86 def to_dataframe(self, cols_to_drop=None): 87 """Convert the SpectrumSearchResults to a pandas DataFrame 88 89 Parameters 90 ---------- 91 cols_to_drop : list, optional 92 A list of columns to drop from the DataFrame. Default is None. 93 94 Returns 95 ------- 96 pandas.DataFrame 97 A DataFrame with the SpectrumSearchResults attributes as columns 98 99 """ 100 import pandas as pd 101 102 # get initial dict 103 df = pd.DataFrame.from_dict(self.__dict__).copy() 104 105 # remove ms2_spectrum column 106 df = df.drop(columns=["query_spectrum"]) 107 108 # drop additional columns 109 if cols_to_drop is not None: 110 df = df.drop(columns=cols_to_drop) 111 112 # reorder to high to low entropy similarity 113 df = df.sort_values(by=["entropy_similarity"], ascending=False) 114 115 # rename id to query_scan_number 116 return pd.DataFrame(df)
2class SpectrumSearchResults: 3 """Class for storing Search Results for a single Spectrum Query 4 5 Parameters 6 ---------- 7 query_spectrum : MassSpectrum 8 The queried mass spectrum 9 precursor_mz : float, optional 10 The queried precursor_mz. None is interpreted as an open query, i.e. no precursor_mz 11 spectral_similarity_search_results : dict 12 The search results for the queried spectrum, which will be unpacked into attributes 13 14 Attributes 15 ---------- 16 query_spectrum : MassSpectrum 17 The queried mass spectrum 18 query_spectrum_id : int 19 The id of the queried spectrum (the scan number within an MassSpectra object) 20 precursor_mz : float 21 The precursor m/z of the queried spectrum 22 23 Other Possible Attributes 24 ------------------------- 25 ref_mol_id : str 26 The id of the molecule associated with the query spectrum in reference database 27 ref_ms_id : str 28 The id of the query spectrum in reference database 29 ref_precursor_mz : float 30 The precursor mass of the query spectrum 31 precursor_mz_error_ppm : float 32 The ppm error between the query spectrum and the reference spectrum 33 entropy_similarity : float 34 The entropy similarity between the query spectrum and the reference spectrum 35 ref_ion_type : str 36 The ion type of the reference spectrum, i.e. [M+H]+, [M+Na]+, etc. 37 query_mz_in_ref_n : list 38 The number of query m/z peaks that are in the reference spectrum 39 query_mz_in_ref_fract : float 40 The fraction of query m/z peaks that are in the reference spectrum 41 query_frag_types : list 42 The fragment types of the query spectrum that are in the reference spectrum, 43 i.e. LSF (lipid species fragments) or MSF (molecular species fragments), 44 generally used for only for lipidomics 45 ref_mz_in_query_n : list 46 The number of reference m/z peaks that are in the query spectrum 47 ref_mz_in_query_fract : float 48 The fraction of reference m/z peaks that are in the query spectrum 49 ref_frag_types : list 50 The fragment types of the reference spectrum, 51 i.e. LSF (lipid species fragments) or MSF (molecular species fragments), 52 generally used for only for lipidomics 53 54 Methods 55 ------- 56 *to_dataframe(). 57 Convert the SpectrumSearchResults to a pandas DataFrame 58 59 """ 60 61 def __init__( 62 self, query_spectrum, precursor_mz, spectral_similarity_search_results 63 ): 64 self.query_spectrum = query_spectrum 65 self.precursor_mz = precursor_mz 66 if query_spectrum is not None: 67 if query_spectrum.scan_number is not None: 68 self.query_spectrum_id = query_spectrum.scan_number 69 attribute_keys = [ 70 "ref_mol_id", 71 "ref_ms_id", 72 "ref_precursor_mz", 73 "precursor_mz_error_ppm", 74 "ref_ion_type", 75 "entropy_similarity", 76 "query_mz_in_ref_n", 77 "query_mz_in_ref_fract", 78 "query_frag_types", 79 "ref_mz_in_query_n", 80 "ref_mz_in_query_fract", 81 "ref_frag_types", 82 ] 83 for key in spectral_similarity_search_results.keys(): 84 if key in attribute_keys: 85 setattr(self, key, spectral_similarity_search_results[key]) 86 87 def to_dataframe(self, cols_to_drop=None): 88 """Convert the SpectrumSearchResults to a pandas DataFrame 89 90 Parameters 91 ---------- 92 cols_to_drop : list, optional 93 A list of columns to drop from the DataFrame. Default is None. 94 95 Returns 96 ------- 97 pandas.DataFrame 98 A DataFrame with the SpectrumSearchResults attributes as columns 99 100 """ 101 import pandas as pd 102 103 # get initial dict 104 df = pd.DataFrame.from_dict(self.__dict__).copy() 105 106 # remove ms2_spectrum column 107 df = df.drop(columns=["query_spectrum"]) 108 109 # drop additional columns 110 if cols_to_drop is not None: 111 df = df.drop(columns=cols_to_drop) 112 113 # reorder to high to low entropy similarity 114 df = df.sort_values(by=["entropy_similarity"], ascending=False) 115 116 # rename id to query_scan_number 117 return pd.DataFrame(df)
Class for storing Search Results for a single Spectrum Query
Parameters
- query_spectrum (MassSpectrum): The queried mass spectrum
- precursor_mz (float, optional): The queried precursor_mz. None is interpreted as an open query, i.e. no precursor_mz
- spectral_similarity_search_results (dict): The search results for the queried spectrum, which will be unpacked into attributes
Attributes
- query_spectrum (MassSpectrum): The queried mass spectrum
- query_spectrum_id (int): The id of the queried spectrum (the scan number within an MassSpectra object)
- precursor_mz (float): The precursor m/z of the queried spectrum
Other Possible Attributes
ref_mol_id : str The id of the molecule associated with the query spectrum in reference database ref_ms_id : str The id of the query spectrum in reference database ref_precursor_mz : float The precursor mass of the query spectrum precursor_mz_error_ppm : float The ppm error between the query spectrum and the reference spectrum entropy_similarity : float The entropy similarity between the query spectrum and the reference spectrum ref_ion_type : str The ion type of the reference spectrum, i.e. [M+H]+, [M+Na]+, etc. query_mz_in_ref_n : list The number of query m/z peaks that are in the reference spectrum query_mz_in_ref_fract : float The fraction of query m/z peaks that are in the reference spectrum query_frag_types : list The fragment types of the query spectrum that are in the reference spectrum, i.e. LSF (lipid species fragments) or MSF (molecular species fragments), generally used for only for lipidomics ref_mz_in_query_n : list The number of reference m/z peaks that are in the query spectrum ref_mz_in_query_fract : float The fraction of reference m/z peaks that are in the query spectrum ref_frag_types : list The fragment types of the reference spectrum, i.e. LSF (lipid species fragments) or MSF (molecular species fragments), generally used for only for lipidomics
Methods
*to_dataframe(). Convert the SpectrumSearchResults to a pandas DataFrame
61 def __init__( 62 self, query_spectrum, precursor_mz, spectral_similarity_search_results 63 ): 64 self.query_spectrum = query_spectrum 65 self.precursor_mz = precursor_mz 66 if query_spectrum is not None: 67 if query_spectrum.scan_number is not None: 68 self.query_spectrum_id = query_spectrum.scan_number 69 attribute_keys = [ 70 "ref_mol_id", 71 "ref_ms_id", 72 "ref_precursor_mz", 73 "precursor_mz_error_ppm", 74 "ref_ion_type", 75 "entropy_similarity", 76 "query_mz_in_ref_n", 77 "query_mz_in_ref_fract", 78 "query_frag_types", 79 "ref_mz_in_query_n", 80 "ref_mz_in_query_fract", 81 "ref_frag_types", 82 ] 83 for key in spectral_similarity_search_results.keys(): 84 if key in attribute_keys: 85 setattr(self, key, spectral_similarity_search_results[key])
87 def to_dataframe(self, cols_to_drop=None): 88 """Convert the SpectrumSearchResults to a pandas DataFrame 89 90 Parameters 91 ---------- 92 cols_to_drop : list, optional 93 A list of columns to drop from the DataFrame. Default is None. 94 95 Returns 96 ------- 97 pandas.DataFrame 98 A DataFrame with the SpectrumSearchResults attributes as columns 99 100 """ 101 import pandas as pd 102 103 # get initial dict 104 df = pd.DataFrame.from_dict(self.__dict__).copy() 105 106 # remove ms2_spectrum column 107 df = df.drop(columns=["query_spectrum"]) 108 109 # drop additional columns 110 if cols_to_drop is not None: 111 df = df.drop(columns=cols_to_drop) 112 113 # reorder to high to low entropy similarity 114 df = df.sort_values(by=["entropy_similarity"], ascending=False) 115 116 # rename id to query_scan_number 117 return pd.DataFrame(df)
Convert the SpectrumSearchResults to a pandas DataFrame
Parameters
- cols_to_drop (list, optional): A list of columns to drop from the DataFrame. Default is None.
Returns
- pandas.DataFrame: A DataFrame with the SpectrumSearchResults attributes as columns