API Reference¶
PyMassSpec extension for searching mass spectra using NIST’s Mass Spectrum Search Engine.
base
¶
Base class for other PyMassSpec NIST Search classes.
-
class
NISTBase
(name='', cas='---')[source]¶ Bases:
object
Base class for other PyMassSpec NIST Search classes.
- Parameters
Methods:
__eq__
(other)Return
self == other
.__str__
()Return
str(self)
.from_dict
(dictionary)Construct an object from a dictionary.
from_json
(json_data)Construct an object from json data.
from_pynist
(pynist_dict)Create an object from the raw data returned by the C extension.
to_dict
()Convert the object to a dictionary.
to_json
()Convert the object to json.
Attributes:
-
classmethod
from_json
(json_data)[source]¶ Construct an object from json data.
- Parameters
json_data (
str
)
-
classmethod
from_pynist
(pynist_dict)[source]¶ Create an object from the raw data returned by the C extension.
docker_engine
¶
Search engine for Linux and other platforms supporting Docker.
Classes:
|
Search engine for Linux and other platforms supporting Docker. |
Functions:
|
Parse json data into a list of SearchResult objects. |
|
Parse json data into a list of (SearchResult, ReferenceData) tuples. |
|
Decorator to ensure that functions do not run after the class has been uninitialised. |
-
class
Engine
(lib_path, lib_type=1, work_dir=None, debug=False)[source]¶ Bases:
object
Search engine for Linux and other platforms supporting Docker.
The first time the engine is initialized it will download the latest version of the docker image automatically. This can also be performed manually, such as to upgrade to the latest version, with the following command:
docker pull domdfcoding/pywine-pyms-nist
The engine must be uninitialized when no longer required to shut down the underlying docker container. This is achieved with the
uninit()
method. Alternatively, this class can be used as a contextmanager to automatically uninitialize the engine upon leaving thewith
block:with pyms_nist_search.Engine( FULL_PATH_TO_MAIN_LIBRARY, pyms_nist_search.NISTMS_MAIN_LIB, FULL_PATH_TO_WORK_DIR, ) as search: search.full_spectrum_search(ms, n_hits=5)
Changed in version 0.6.0: Added context manager support.
Methods:
full_search_with_ref_data
(mass_spec[, n_hits])Perform a Full Spectrum Search of the mass spectral library, including reference data.
full_spectrum_search
(mass_spec[, n_hits])Perform a Full Spectrum Search of the mass spectral library.
get_reference_data
(spec_loc)Get reference data from the library for the compound at the given location.
spectrum_search
(mass_spec[, n_hits])Perform a Quick Spectrum Search of the mass spectral library.
uninit
()Uninitialize the Search Engine.
-
full_search_with_ref_data
(mass_spec, n_hits=5)[source]¶ Perform a Full Spectrum Search of the mass spectral library, including reference data.
- Parameters
mass_spec (
MassSpectrum
) – The mass spectrum to search against the library.n_hits (
int
) – The number of hits to return. Default5
.
- Return type
- Returns
List of tuples containing possible identities for the mass spectrum, and the reference data.
-
full_spectrum_search
(mass_spec, n_hits=5)[source]¶ Perform a Full Spectrum Search of the mass spectral library.
- Parameters
mass_spec (
MassSpectrum
) – The mass spectrum to search against the library.n_hits (
int
) – The number of hits to return. Default5
.
- Return type
- Returns
List of possible identities for the mass spectrum.
-
get_reference_data
(spec_loc)[source]¶ Get reference data from the library for the compound at the given location.
- Parameters
spec_loc (
int
)- Return type
-
spectrum_search
(mass_spec, n_hits=5)[source]¶ Perform a Quick Spectrum Search of the mass spectral library.
- Parameters
mass_spec (
MassSpectrum
) – The mass spectrum to search against the library.n_hits (
int
) – The number of hits to return. Default5
.
- Return type
- Returns
List of possible identities for the mass spectrum.
-
-
hit_list_from_json
(json_data)[source]¶ Parse json data into a list of SearchResult objects.
- Parameters
json_data (
str
) – str- Return type
reference_data
¶
Class to store reference data from NIST MS Search.
-
class
ReferenceData
(name='', cas='---', nist_no=0, id='', mw=0.0, formula='', contributor='', mass_spec=None, synonyms=None, exact_mass=None)[source]¶ Bases:
NISTBase
Class to store reference data from NIST MS Search.
- Parameters
name (
str
) – The name of the compound. Default''
.cas (
Union
[str
,int
]) – The CAS number of the compound. Default'---'
.formula (
str
) – The formula of the compound. Default''
.contributor (
str
) – The contributor to the library. Default''
.mass_spec (
Optional
[MassSpectrum
]) – The reference mass spectrum. DefaultNone
.synonyms (
Optional
[Sequence
[str
]]) – List of synonyms for the compound. DefaultNone
.
Methods:
__repr__
()Return a string representation of the
ReferenceData
.from_jcamp
(file_name[, ignore_warnings])Create a ReferenceData object from a JCAMP-DX file.
from_json
(json_data)Construct an object from JSON data.
from_mona_dict
(mona_data)Construct an object from Massbank of North America json data that has been loaded into a dictionary.
from_pynist
(pynist_dict)Create a
ReferenceData
object from the raw data returned by the C extension.to_dict
()Convert the object to a dictionary.
to_json
()Convert the object to JSON.
to_msp
()Returns the ReferenceData object as an MSP file similar to that produced by NIST MS Search’s export function.
Attributes:
The name of the contributor to the library.
The exact mass of the compound.
The formula of the compound.
The ID of the compound.
The mass spectrum of the compound.
The molecular weight of the compound.
The NIST number of the compund.
A list of synonyms for the compound.
-
__repr__
()[source]¶ Return a string representation of the
ReferenceData
.- Return type
-
classmethod
from_jcamp
(file_name, ignore_warnings=True)[source]¶ Create a ReferenceData object from a JCAMP-DX file.
-
classmethod
from_json
(json_data)[source]¶ Construct an object from JSON data.
- Parameters
json_data (
str
)- Return type
-
classmethod
from_mona_dict
(mona_data)[source]¶ Construct an object from Massbank of North America json data that has been loaded into a dictionary.
- Parameters
mona_data (
Dict
) – dict- Return type
-
classmethod
from_pynist
(pynist_dict)[source]¶ Create a
ReferenceData
object from the raw data returned by the C extension.- Parameters
- Return type
-
property
mass_spec
¶ The mass spectrum of the compound.
- Return type
search_result
¶
Class to store search results from NIST MS Search.
-
class
SearchResult
(name='', cas='---', match_factor=0, reverse_match_factor=0, hit_prob=0.0, spec_loc=0)[source]¶ Bases:
NISTBase
Class to store search results from NIST MS Search.
- Parameters
name (
str
) – The name of the compound. Default''
.cas (
Union
[str
,int
]) – The CAS number of the compound. Default'---'
.match_factor (
float
) – Default0
.reverse_match_factor (
float
) – Default0
.hit_prob (
float
) – Default0.0
.spec_loc (
float
) – The location of the reference spectrum in the library. Default0
.
Methods:
from_pynist
(pynist_dict)Create a
SearchResult
object from the raw data returned by the C extension.to_dict
()Convert the object to a dictionary.
Attributes:
Returns the probability of the hit being the compound responsible for the mass spectrum.
Returns a score (out of 1000) representing the similarity of the searched mass spectrum to the search result.
A score (out of 1000) representing the similarity of the searched mass spectrum to the search result, but ignoring any peaks that are in the searched mass spectrum but not in the library spectrum.
The location of the reference spectrum in the library.
-
classmethod
from_pynist
(pynist_dict)[source]¶ Create a
SearchResult
object from the raw data returned by the C extension.- Parameters
- Return type
-
property
hit_prob
¶ Returns the probability of the hit being the compound responsible for the mass spectrum.
- Return type
-
property
match_factor
¶ Returns a score (out of 1000) representing the similarity of the searched mass spectrum to the search result.
- Return type
-
property
reverse_match_factor
¶ A score (out of 1000) representing the similarity of the searched mass spectrum to the search result, but ignoring any peaks that are in the searched mass spectrum but not in the library spectrum.
- Return type
-
property
spec_loc
¶ The location of the reference spectrum in the library.
This can then be searched using the
get_reference_data()
method of the search engine to obtain the reference data.- Return type
utils
¶
General utilities.
Functions:
|
Convert a pyms.Spectrum.MassSpectrum object into a string. |
|
Takes a list of Unicode character codes and converts them to characters, taking into account the special codes used by the NIST DLL. |
-
pack
(mass_spec, top=20)[source]¶ Convert a pyms.Spectrum.MassSpectrum object into a string.
Adapted from https://sourceforge.net/projects/mzapi-live/
- Parameters
mass_spec (
MassSpectrum
)top (
int
) – The number of largest peaks to identify. Default20
.
- Return type
win_engine
¶
Search engine for Windows systems.
-
class
Engine
(lib_path, lib_type=1, work_dir=None, debug=False)[source]¶ Bases:
object
Search engine for Windows systems.
- Parameters
Methods:
full_search_with_ref_data
(mass_spec[, n_hits])Perform a Full Spectrum Search of the mass spectral library, including reference data.
full_spectrum_search
(mass_spec[, n_hits])Perform a Full Spectrum Search of the mass spectral library.
get_reference_data
(spec_loc)Get reference data from the library for the compound at the given location.
spectrum_search
(mass_spec[, n_hits])Perform a Quick Spectrum Search of the mass spectral library.
uninit
()Uninitialize the Search Engine.
-
full_search_with_ref_data
(mass_spec, n_hits=5)[source]¶ Perform a Full Spectrum Search of the mass spectral library, including reference data.
- Parameters
mass_spec (
MassSpectrum
) – The mass spectrum to search against the library.n_hits (
int
) – The number of hits to return. Default5
.
- Return type
- Returns
List of tuples containing possible identities for the mass spectrum, and the reference data
-
static
full_spectrum_search
(mass_spec, n_hits=5)[source]¶ Perform a Full Spectrum Search of the mass spectral library.
- Parameters
mass_spec (
MassSpectrum
) – The mass spectrum to search against the library.n_hits (
int
) – The number of hits to return. Default5
.
- Return type
- Returns
List of possible identities for the mass spectrum.
-
static
get_reference_data
(spec_loc)[source]¶ Get reference data from the library for the compound at the given location.
- Parameters
spec_loc (
int
)- Return type
-
static
spectrum_search
(mass_spec, n_hits=5)[source]¶ Perform a Quick Spectrum Search of the mass spectral library.
- Parameters
mass_spec (
MassSpectrum
) – The mass spectrum to search against the library.n_hits (
int
) – The number of hits to return. Default5
.
- Return type
- Returns
List of possible identities for the mass spectrum.