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 database_name : str 53 The name of the associated database, i.e. "LipidBlast" or "GNPS" 54 55 Methods 56 ------- 57 *to_dataframe(). 58 Convert the SpectrumSearchResults to a pandas DataFrame 59 60 """ 61 62 def __init__( 63 self, query_spectrum, precursor_mz, spectral_similarity_search_results 64 ): 65 self.query_spectrum = query_spectrum 66 self.precursor_mz = precursor_mz 67 if query_spectrum is not None: 68 if query_spectrum.scan_number is not None: 69 self.query_spectrum_id = query_spectrum.scan_number 70 attribute_keys = [ 71 "ref_mol_id", 72 "ref_ms_id", 73 "ref_precursor_mz", 74 "precursor_mz_error_ppm", 75 "ref_ion_type", 76 "entropy_similarity", 77 "query_mz_in_ref_n", 78 "query_mz_in_ref_fract", 79 "query_frag_types", 80 "ref_mz_in_query_n", 81 "ref_mz_in_query_fract", 82 "ref_frag_types", 83 "database_name", 84 ] 85 for key in spectral_similarity_search_results.keys(): 86 if key in attribute_keys: 87 setattr(self, key, spectral_similarity_search_results[key]) 88 89 def to_dataframe(self, cols_to_drop=None): 90 """Convert the SpectrumSearchResults to a pandas DataFrame 91 92 Parameters 93 ---------- 94 cols_to_drop : list, optional 95 A list of columns to drop from the DataFrame. Default is None. 96 97 Returns 98 ------- 99 pandas.DataFrame 100 A DataFrame with the SpectrumSearchResults attributes as columns 101 102 """ 103 import pandas as pd 104 105 # get initial dict 106 df = pd.DataFrame.from_dict(self.__dict__).copy() 107 108 # remove ms2_spectrum column 109 df = df.drop(columns=["query_spectrum"]) 110 111 # drop additional columns 112 if cols_to_drop is not None: 113 df = df.drop(columns=cols_to_drop) 114 115 # reorder to high to low entropy similarity 116 df = df.sort_values(by=["entropy_similarity"], ascending=False) 117 118 # rename id to query_scan_number 119 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 database_name : str 54 The name of the associated database, i.e. "LipidBlast" or "GNPS" 55 56 Methods 57 ------- 58 *to_dataframe(). 59 Convert the SpectrumSearchResults to a pandas DataFrame 60 61 """ 62 63 def __init__( 64 self, query_spectrum, precursor_mz, spectral_similarity_search_results 65 ): 66 self.query_spectrum = query_spectrum 67 self.precursor_mz = precursor_mz 68 if query_spectrum is not None: 69 if query_spectrum.scan_number is not None: 70 self.query_spectrum_id = query_spectrum.scan_number 71 attribute_keys = [ 72 "ref_mol_id", 73 "ref_ms_id", 74 "ref_precursor_mz", 75 "precursor_mz_error_ppm", 76 "ref_ion_type", 77 "entropy_similarity", 78 "query_mz_in_ref_n", 79 "query_mz_in_ref_fract", 80 "query_frag_types", 81 "ref_mz_in_query_n", 82 "ref_mz_in_query_fract", 83 "ref_frag_types", 84 "database_name", 85 ] 86 for key in spectral_similarity_search_results.keys(): 87 if key in attribute_keys: 88 setattr(self, key, spectral_similarity_search_results[key]) 89 90 def to_dataframe(self, cols_to_drop=None): 91 """Convert the SpectrumSearchResults to a pandas DataFrame 92 93 Parameters 94 ---------- 95 cols_to_drop : list, optional 96 A list of columns to drop from the DataFrame. Default is None. 97 98 Returns 99 ------- 100 pandas.DataFrame 101 A DataFrame with the SpectrumSearchResults attributes as columns 102 103 """ 104 import pandas as pd 105 106 # get initial dict 107 df = pd.DataFrame.from_dict(self.__dict__).copy() 108 109 # remove ms2_spectrum column 110 df = df.drop(columns=["query_spectrum"]) 111 112 # drop additional columns 113 if cols_to_drop is not None: 114 df = df.drop(columns=cols_to_drop) 115 116 # reorder to high to low entropy similarity 117 df = df.sort_values(by=["entropy_similarity"], ascending=False) 118 119 # rename id to query_scan_number 120 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 database_name : str The name of the associated database, i.e. "LipidBlast" or "GNPS"
Methods
*to_dataframe(). Convert the SpectrumSearchResults to a pandas DataFrame
63 def __init__( 64 self, query_spectrum, precursor_mz, spectral_similarity_search_results 65 ): 66 self.query_spectrum = query_spectrum 67 self.precursor_mz = precursor_mz 68 if query_spectrum is not None: 69 if query_spectrum.scan_number is not None: 70 self.query_spectrum_id = query_spectrum.scan_number 71 attribute_keys = [ 72 "ref_mol_id", 73 "ref_ms_id", 74 "ref_precursor_mz", 75 "precursor_mz_error_ppm", 76 "ref_ion_type", 77 "entropy_similarity", 78 "query_mz_in_ref_n", 79 "query_mz_in_ref_fract", 80 "query_frag_types", 81 "ref_mz_in_query_n", 82 "ref_mz_in_query_fract", 83 "ref_frag_types", 84 "database_name", 85 ] 86 for key in spectral_similarity_search_results.keys(): 87 if key in attribute_keys: 88 setattr(self, key, spectral_similarity_search_results[key])
90 def to_dataframe(self, cols_to_drop=None): 91 """Convert the SpectrumSearchResults to a pandas DataFrame 92 93 Parameters 94 ---------- 95 cols_to_drop : list, optional 96 A list of columns to drop from the DataFrame. Default is None. 97 98 Returns 99 ------- 100 pandas.DataFrame 101 A DataFrame with the SpectrumSearchResults attributes as columns 102 103 """ 104 import pandas as pd 105 106 # get initial dict 107 df = pd.DataFrame.from_dict(self.__dict__).copy() 108 109 # remove ms2_spectrum column 110 df = df.drop(columns=["query_spectrum"]) 111 112 # drop additional columns 113 if cols_to_drop is not None: 114 df = df.drop(columns=cols_to_drop) 115 116 # reorder to high to low entropy similarity 117 df = df.sort_values(by=["entropy_similarity"], ascending=False) 118 119 # rename id to query_scan_number 120 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