ms2pip.search_space
Define and build the search space for in silico spectral library generation.
This module defines the search space for in silico spectral library generation as a
ProteomeSearchSpace object. Variable and fixed modifications can be configured
as ModificationConfig objects.
The peptide search space can be built from a protein FASTA file and a set of parameters, which can
then be converted to a psm_utils.PSMList object for use in ms2pip. All
parameters are listed below at ProteomeSearchSpace and can be passed as a
dictionary, a JSON file, or as a ProteomeSearchSpace object. For example:
{
"fasta_file": "test.fasta",
"min_length": 8,
"max_length": 30,
"cleavage_rule": "trypsin",
"missed_cleavages": 2,
"semi_specific": false,
"add_decoys": true,
"modifications": [
{
"label": "UNIMOD:Oxidation",
"amino_acid": "M"
},
{
"label": "UNIMOD:Carbamidomethyl",
"amino_acid": "C",
"fixed": true
}
],
"max_variable_modifications": 3,
"charges": [2, 3]
}
For an unspecific protein digestion, the cleavage rule can be set to unspecific. This will
result in a cleavage rule that allows cleavage after any amino acid with an unlimited number of
allowed missed cleavages.
To disable protein digestion when the FASTA file contains peptides, set the cleavage rule to
-. This will treat each line in the FASTA file as a separate peptide sequence, but still
allow for modifications and charges to be added.
Examples
>>> from ms2pip.search_space import ProteomeSearchSpace, ModificationConfig
>>> search_space = ProteomeSearchSpace(
... fasta_file="tests/data/test_proteins.fasta",
... min_length=8,
... max_length=30,
... cleavage_rule="trypsin",
... missed_cleavages=2,
... semi_specific=False,
... modifications=[
... ModificationConfig(label="UNIMOD:Oxidation", amino_acid="M"),
... ModificationConfig(label="UNIMOD:Carbamidomethyl", amino_acid="C", fixed=True),
... ],
... charges=[2, 3],
... )
>>> psm_list = search_space.into_psm_list()
>>> from ms2pip.search_space import ProteomeSearchSpace
>>> search_space = ProteomeSearchSpace.from_any("tests/data/test_search_space.json")
>>> psm_list = search_space.into_psm_list()
- class ms2pip.search_space.ModificationConfig(*, label, amino_acid=None, peptide_n_term=False, protein_n_term=False, peptide_c_term=False, protein_c_term=False, fixed=False)[source]
Bases:
BaseModelCreate a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ms2pip.search_space.ProteomeSearchSpace(*, fasta_file, min_length=8, max_length=30, min_precursor_mz=0, max_precursor_mz=inf, cleavage_rule='trypsin', missed_cleavages=2, semi_specific=False, add_decoys=False, modifications=[ModificationConfig(label='UNIMOD:Oxidation', amino_acid='M', peptide_n_term=False, protein_n_term=False, peptide_c_term=False, protein_c_term=False, fixed=False), ModificationConfig(label='UNIMOD:Carbamidomethyl', amino_acid='C', peptide_n_term=False, protein_n_term=False, peptide_c_term=False, protein_c_term=False, fixed=True)], max_variable_modifications=3, charges=[2, 3])[source]
Bases:
BaseModelCreate a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- classmethod from_any(_input)[source]
Create ProteomeSearchSpace from various input types.
- Parameters:
_input (dict | str | Path | ProteomeSearchSpace) – Search space parameters as a dictionary, a path to a JSON file, an existing
ProteomeSearchSpaceobject.- Return type:
- build(processes=None)[source]
Build peptide search space from FASTA file.
- Parameters:
processes (int | None) – Number of processes to use for parallelization. Uses all available CPU cores by default.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self (BaseModel) – The BaseModel instance.
context (Any) – The context.
- Return type:
None