### Download Example mzML Data - Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/identification_accurate_mass.rst Downloads example mzML files and associated database files from a specified URL if the example directory does not already exist. This is a prerequisite for running the example workflow. ```python if not os.path.isdir(os.path.join(os.getcwd(), "IdByMz_Example")): os.mkdir(os.path.join(os.getcwd(), "IdByMz_Example")) base = "https://abibuilder.cs.uni-tuebingen.de/archive/openms/Tutorials/Example_Data/Metabolomics/" urls = [ "datasets/2012_02_03_PStd_050_1.mzML", "datasets/2012_02_03_PStd_050_2.mzML", "datasets/2012_02_03_PStd_050_3.mzML", "databases/PositiveAdducts.tsv", "databases/NegativeAdducts.tsv", "databases/HMDBMappingFile.tsv", "databases/HMDB2StructMapping.tsv", ] for url in urls: request = requests.get(base + url, allow_redirects=True) open(os.path.join(files, os.path.basename(url)), "wb").write( request.content ) ``` -------------------------------- ### Download Example mzML File with pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/mzml_files.rst Downloads a small example mzML file ('tiny.mzML') from a GitHub repository using urlretrieve. This is the first step to analyze mzML file content. ```python import pyopenms as oms from urllib.request import urlretrieve gh = "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master" urlretrieve(gh + "/src/data/tiny.mzML", "test.mzML") ``` -------------------------------- ### Install pyOpenMS Documentation Dependencies Source: https://github.com/openms/pyopenms-docs/blob/master/docs/README.md Installs all required Python packages for building the pyOpenMS documentation. This command should be run after activating the virtual environment and navigating to the documentation directory. ```bash cd /docs pip install -r requirements.txt python install_pyopenms.py ``` -------------------------------- ### Get Help on ExperimentalSettings Class in pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Demonstrates using the help() function to get information about the ExperimentalSettings class in pyOpenMS, which is a base class for MSExperiment and contains metadata related to experimental settings. ```python help(oms.ExperimentalSettings) ``` -------------------------------- ### Download Example Data for GNPS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/export_files_GNPS.rst Downloads example mzML and consensusXML files required for GNPS analysis using pyOpenMS. These files serve as input for subsequent processing steps. ```python from urllib.request import urlretrieve gh = "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master" urlretrieve( gh + "/src/data/Metabolomics_1_aligned.mzML", "Metabolomics_1_aligned.mzML" ) urlretrieve( gh + "/src/data/Metabolomics_2_aligned.mzML", "Metabolomics_2_aligned.mzML" ) urlretrieve( gh + "/src/data/UntargetedMetabolomics.consensusXML", "UntargetedMetabolomics.consensusXML", ) ``` -------------------------------- ### Download Example mzML Files using Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/untargeted_metabolomics_preprocessing.rst Downloads two example mzML files from a GitHub repository using Python's urlretrieve function. These files are necessary for the subsequent pre-processing steps. ```python from urllib.request import urlretrieve gh = "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master" urlretrieve(gh + "/src/data/Metabolomics_1.mzML", "Metabolomics_1.mzML") urlretrieve(gh + "/src/data/Metabolomics_2.mzML", "Metabolomics_2.mzML") ``` -------------------------------- ### Download Example Feature Data using Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/map_alignment.rst This Python snippet demonstrates how to download example featureXML files from a GitHub repository using `urllib.request.urlretrieve`. It then loads these files into `pyopenms.FeatureMap` objects and stores them in a list. This is useful for testing map alignment algorithms. ```python import pyopenms as oms from urllib.request import urlretrieve base_url = ( "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master/src/data/" ) # we use featureXML files which already contain PSMs (as obtained by oms.IDMapper()) # ... so we can use all aligners pyOpenMS has to offer feature_files = [ "BSA1_F1_idmapped.featureXML", "BSA2_F1_idmapped.featureXML", "BSA3_F1_idmapped.featureXML", ] feature_maps = [] # download the feature files and store feature maps in list (feature_maps) for feature_file in feature_files: urlretrieve(base_url + feature_file, feature_file) feature_map = oms.FeatureMap() oms.FeatureXMLFile().load(feature_file, feature_map) feature_maps.append(feature_map) ``` -------------------------------- ### Download Example Data for Feature Linking (Python) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/feature_linking.rst Downloads example featureXML files from a specified URL and loads them into pyOpenMS FeatureMap objects. This is a prerequisite for performing feature linking. ```python import pyopenms as oms from urllib.request import urlretrieve base_url = ( "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master/src/data/" ) feature_files = [ "BSA1_F1.featureXML", "BSA2_F1.featureXML", "BSA3_F1.featureXML", ] feature_maps = [] # download the feature files and store feature maps in list (feature_maps) for feature_file in feature_files: urlretrieve(base_url + feature_file, feature_file) feature_map = oms.FeatureMap() oms.FeatureXMLFile().load(feature_file, feature_map) feature_maps.append(feature_map) ``` -------------------------------- ### Download Example Data for Feature Map Annotation Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/PSM_to_features.rst Downloads necessary example data files (featureXML and idXML) from a GitHub repository using urlretrieve. This step is crucial for running the subsequent annotation process. ```python import pyopenms as oms from urllib.request import urlretrieve base_url = ( "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master/src/data/" ) feature_file = "BSA1_F1.featureXML" urlretrieve(base_url + feature_file, feature_file) idxml_file = "BSA1_F1.idXML" urlretrieve(base_url + idxml_file, idxml_file) ``` -------------------------------- ### Install pyOpenMS using pip Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/installation.rst Install pyOpenMS and its dependency numpy using pip. This method uses pre-compiled binary wheels available on PyPI for OSX, Linux, and Windows (64-bit only). Ensure you have a compatible Python version (3.9-3.13) and the 64-bit release for Windows. ```bash pip install numpy pip install pyopenms ``` -------------------------------- ### Build pyOpenMS Documentation with Sphinx Source: https://github.com/openms/pyopenms-docs/blob/master/docs/README.md Builds the pyOpenMS documentation in HTML format using Sphinx. This command should be executed from the `/docs` directory after installing dependencies. ```bash make html ``` -------------------------------- ### Check pyOpenMS Version and Build Information (Python) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/support.rst This Python snippet demonstrates how to import the pyOpenMS library and print detailed version and build information. This is useful for troubleshooting and reporting issues, as it provides essential context about the installed pyOpenMS environment. It requires the pyOpenMS library to be installed. ```python import pyopenms as oms print("Version: " + oms.VersionInfo.getVersion()) print("OpenMP: " + str(oms.OpenMSBuildInfo.isOpenMPEnabled())) print("Build type: " + oms.OpenMSBuildInfo.getBuildType()) print("Architecture: " + oms.OpenMSOSInfo.getBinaryArchitecture()) ``` -------------------------------- ### Applying GaussFilter to MSExperiment in Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/algorithms.rst Shows a practical example of using the GaussFilter in pyOpenMS. It includes loading data from an mzML file into an MSExperiment object and then applying the GaussFilter to it. This demonstrates a common workflow for data processing. ```python import pyopenms as oms from urllib.request import urlretrieve gh = "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master" urlretrieve(gh + "/src/data/tiny.mzML", "test.mzML") gf = oms.GaussFilter() exp = oms.MSExperiment() om.MzMLFile().load("test.mzML", exp) gf.filterExperiment(exp) # oms.MzMLFile().store("test.filtered.mzML", exp) ``` -------------------------------- ### Complex STL Container Wrapping (SequestInfile.pyx) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Example from SequestInfile.pyx demonstrating the return of a complex STL container: a map from String to a vector of Strings. ```Cython # Example from SequestInfile.pyx # map< String, vector > to get returned ``` -------------------------------- ### Get Help on MSExperiment Class in pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Illustrates how to use Python's built-in help() function to inspect the MSExperiment class in pyOpenMS. This provides information about the class's purpose, inheritance, and methods. ```python help(oms.MSExperiment) ``` -------------------------------- ### Perform K-Fold Cross-Validation Setup (Python) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/interfacing_ml_libraries.rst Sets up the necessary components for k-fold cross-validation using `ShuffleSplit` from scikit-learn. It initializes an empty DataFrame and list to store performance metrics during the cross-validation process. ```python # Performing k-fold cross validation X = np.arange(10) ss = ShuffleSplit(n_splits=5, test_size=0.25, random_state=0) performance_df = pd.DataFrame() performance_list = [] counter = 0 for train_index, test_index in ss.split(X_train, Y_train): counter += 1 X_train_Kfold, X_test_Kfold = ( ``` -------------------------------- ### Complex STL Container Wrapping (IDRipper.pyx) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Example from IDRipper.pyx demonstrating the wrapping of complex STL constructs, specifically a map from String to a pair of vectors. ```Cython # Example from IDRipper.pyx # map< String, pair, vector<> > > ``` -------------------------------- ### Complex STL Container Wrapping (MSQuantifications.pyx) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Examples from MSQuantifications.pyx showing input and output of complex STL containers, including a vector of vectors of pairs and a map of Strings to Ratios. ```Cython # Example from MSQuantifications.pyx # vector< vector< pair > > as input # map< String, Ratio> as return ``` -------------------------------- ### Complex STL Container Wrapping (QcMLFile.pyx) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Example from QcMLFile.pyx illustrating the wrapping of a nested map structure, specifically a map from String to another map of Strings to Strings. ```Cython # Example from QcMLFile.pyx # map< String, map< String,String> > as input ``` -------------------------------- ### Manual Wrapping with Addons Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Procedure for manually wrapping C++ code that cannot be handled by autowrap. This involves creating .pyx files in an 'addons' folder with the same name as the .pxd file, starting with two empty lines and using 4-space indentation. ```Cython # Additional wrapper functions here # add wrap-ignore to the pxd file ``` -------------------------------- ### Install pyOpenMS Nightly Builds using pip Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/installation.rst Install the latest nightly builds of pyOpenMS, which include the newest features. This command uses a specific index URL for nightly wheels. Ensure you have a compatible Python version installed. ```bash pip install --index-url https://pypi.cs.uni-tuebingen.de/simple/ pyopenms ``` -------------------------------- ### Install reticulate R Package Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/pyopenms_in_r.rst Installs the 'reticulate' R package, which is necessary for using pyOpenMS functionalities in R. Ensure pyOpenMS is installed in the Python environment R will use. ```R install.packages("reticulate") ``` -------------------------------- ### Example INI File Structure for Parameter Restrictions Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/parameter_handling.rst This is an example of an INI file generated by pyOpenMS, showing how parameter restrictions are represented. The 'restrictions' attribute indicates the valid range or set of values for a parameter. For example, '0.0:' signifies a lower bound of 0.0 with no upper bound. ```xml ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/openms/pyopenms-docs/blob/master/docs/README.md Demonstrates how to create a Python virtual environment using the `venv` module and activate it on Linux and Windows systems. This isolates project dependencies. ```bash python -m venv /path/to/myenv # Linux: source /bin/activate # Windows: c:\path\to\myenv\Scripts\activate.bat ``` -------------------------------- ### Create and Store mzML File with pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Shows how to create an empty MSExperiment object and store it as an mzML file using pyOpenMS. This involves importing the library and using the MzMLFile class. ```python import pyopenms as oms exp = oms.MSExperiment() oms.MzMLFile().store("testfile.mzML", exp) ``` -------------------------------- ### Param Object Initialization and Manipulation in pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/parameter_handling.rst Demonstrates how to create a Param object, set values with descriptions, access values, modify them, and retrieve string lists. It also shows how to check for parameter existence and retrieve descriptions. ```python import pyopenms as oms p = oms.Param() p.setValue("param1", 4.0, "This is value 1") p.setValue("param2", 5.0, "This is value 2") p.setValue( "param3", [b"H:+:0.6", b"Na:+:0.2", b"K:+:0.2"], "This is value 3 (StringList)", ) print(p[b"param1"]) p[b"param1"] += 3 # add three to the parameter value print(p[b"param1"]) print(p[b"param3"]) ``` -------------------------------- ### Install ML Libraries with pip Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/interfacing_ml_libraries.rst Installs necessary machine learning libraries, specifically seaborn and xgboost, using pip. These libraries are essential for data visualization and gradient boosting, respectively. ```ipython3 !pip install seaborn !pip install xgboost ``` -------------------------------- ### Basic Algorithm Execution in OpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/algorithms.rst Demonstrates the fundamental pattern for executing OpenMS algorithms. This involves instantiating an algorithm, populating an MSExperiment object, and then running the algorithm on the experiment. This pattern is common for many filtering and processing algorithms. ```output algorithm = NameOfTheAlgorithmClass() exp = MSExperiment() # populate exp, for example load from file # ... # run the algorithm on data algorithm.filterExperiment(exp) ``` -------------------------------- ### Autowrap Hints for Classes Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Hints to control how autowrap processes C++ classes. These hints are added to .pxd files to guide the wrapping behavior, such as ignoring classes, specifying instance wrapping, defining hash functions, or indicating manual memory management. ```Cython cdef class MyClass: # wrap-ignore # wrap-instances: # wrap-hash: # wrap-manual-memory: ``` -------------------------------- ### Plotting Merged MS2 Spectra in Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/spectrum_merging.rst This code visualizes MS2 spectra before and after merging. It plots up to four examples, showing the input spectra in the upper rows and the merged spectrum in the bottom row for each example. Dependencies include matplotlib and pyopenms. ```python # plot the merged and merging MS2 spectra fig, axs = plt.subplots(3, min(4, len(merged_spectra))) fig.set_figheight(7) fig.set_figwidth(14) plt.subplots_adjust(hspace=1) for index, item in enumerate(merged_spectra.items()): if index == 4: # show 4 examples break specs = item[1] for i in range(0, 3): s = specs[i] if i < 2 else spectraMerged_ms2[item[0]] axs[i, index].bar(s.get_peaks()[0], s.get_peaks()[1], width=1) axs[i, index].set_yscale("log") axs[i, index].set_ylim(1e3, 1e5) axs[i, index].set_xlim(0, 1200) axs[i, index].title.set_text( "Input MS2 spectrum" if i < 2 else "Merged MS2 spectrum" ) plt.show() ``` -------------------------------- ### Download and Load mzML File with pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Provides a Python code snippet to download a sample mzML file ('tiny.mzML') from a GitHub repository using urlretrieve and then load it into an MSExperiment object using pyOpenMS. ```python from urllib.request import urlretrieve # download small example file gh = "https://raw.githubusercontent.com/OpenMS/pyopenms-docs/master" urlretrieve(gh + "/src/data/tiny.mzML", "tiny.mzML") exp = oms.MSExperiment() # load example file oms.MzMLFile().load("tiny.mzML", exp) ``` -------------------------------- ### Create and Analyze RNA Oligonucleotides with pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/oligonucleotides_rna.rst Demonstrates creating an RNA oligonucleotide from a string, extracting prefixes and suffixes, calculating molecular weight and formula, and generating isotope distributions. Requires pyopenms. ```python import pyopenms as oms oligo = oms.NASequence.fromString("AAUGCAAUGG") prefix = oligo.getPrefix(4) suffix = oligo.getSuffix(4) print(oligo) print(prefix) print(suffix) print() print("Oligo length", oligo.size()) print("Total precursor mass", oligo.getMonoWeight()) print( "y1+ ion mass of", str(prefix), ":", prefix.getMonoWeight(oms.NASequence.NASFragmentType.YIon, 1), ) print() seq_formula = oligo.getFormula() print("RNA Oligo", oligo, "has molecular formula", seq_formula) print("=" * 35) print() isotopes = seq_formula.getIsotopeDistribution(oms.CoarseIsotopePatternGenerator(6)) for iso in isotopes.getContainer(): print("Isotope", iso.getMZ(), ":", iso.getIntensity()) ``` -------------------------------- ### Import pyOpenMS Package Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Demonstrates how to import the pyOpenMS package in Python. This is the first step after installation to access the library's functionalities. ```python import pyopenms ``` -------------------------------- ### Load Protein Sequences from FASTA File (Python) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/peptides_proteins.rst This snippet demonstrates how to load protein sequences from an existing FASTA file ('example.fasta') into a list of FASTA entries using pyOpenMS. It prints the number of entries and the identifier and sequence of each entry. It requires the 'pyopenms' library and the 'example.fasta' file to exist. ```python import openms as oms entries = [] f = oms.FASTAFile() f.load("example.fasta", entries) print(len(entries)) for e in entries: print(e.identifier, e.sequence) ``` -------------------------------- ### Inspect Loaded MSExperiment Object in pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Shows how to use the help() function to inspect the properties and methods of an MSExperiment object after loading data from an mzML file. ```python help(exp) ``` -------------------------------- ### Get Available RNase Enzymes Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/digestion.rst Retrieves a list of all available RNase enzyme names from the RNaseDB. This helps in identifying which enzymes can be used for oligonucleotide digestion. ```python import pyopenms as oms db = oms.RNaseDB() names = [] db.getAllNames(names) print(names) # Will print out all available enzymes: ['RNase_U2', 'RNase_T1', 'RNase_H', 'unspecific cleavage', 'no cleavage', 'RNase_MC1', 'RNase_A', 'cusativin'] e = db.getEnzyme("RNase_T1") print(e.getRegEx()) print(e.getThreePrimeGain()) ``` -------------------------------- ### Get Available Protease Enzymes Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/digestion.rst Retrieves a list of all available protease enzyme names from the ProteaseDB. This is useful for understanding which enzymes can be used for protein digestion. ```python import pyopenms as oms names = [] oms.ProteaseDB().getAllNames(names) print(len(names)) # at least 25 by default e = oms.ProteaseDB().getEnzyme("Lys-C") print(e.getRegExDescription()) print(e.getRegEx()) ``` -------------------------------- ### Plot Isotopic Distribution in Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/chemistry.rst Provides Python code to plot the isotopic distribution of methanol using a predefined plotDistribution function and matplotlib. This is a visualization example. ```python plt.figure(figsize=(10, 7)) plt.subplot(1, 2, 1) plt.title("Isotopic distribution of methanol") plotDistribution(methanol_isoDist) plt.xlabel("Atomic mass (u)") ``` -------------------------------- ### Complex STL Container Wrapping (Attachment.pyx) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Example from Attachment.pyx showing the return of a nested vector structure: a vector of vectors of Strings. ```Cython # Example from Attachment.pyx # vector< vector > to get returned ``` -------------------------------- ### Get Molecular Formula from AASequence in Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/peptides_proteins.rst Illustrates how to obtain the molecular formula of a peptide sequence by combining the AASequence object with the EmpiricalFormula functionality in OpenMS. ```python seq = oms.AASequence.fromString("DFPIANGER") seq_formula = seq.getFormula() print("Peptide", seq, "has molecular formula", seq_formula) ``` -------------------------------- ### Iterate Through Spectra and Get MS Level Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Shows how to iterate through all spectra in an MSExperiment object and print the MS level for each spectrum. This is a fundamental operation for processing spectral data. ```python for spec in exp: print("MS Level:", spec.getMSLevel()) ``` -------------------------------- ### Load mzML File and Access Spectrum Peaks with pyOpenMS Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/mzml_files.rst Loads an mzML file ('test.mzML') into an MSExperiment object using pyOpenMS and then accesses and prints the first array of peaks (m/z values) from the second spectrum in the experiment. ```python exp = oms.MSExperiment() olds.MzMLFile().load("test.mzML", exp) print(exp.getSpectrum(1).get_peaks()[0]) ``` -------------------------------- ### Accessing Chemical Constants in Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/chemistry.rst Demonstrates how to import and access built-in chemical and physical constants from the pyopenms.Constants module. It shows an example of retrieving Avogadro's number. ```python import pyopenms.Constants help(pyopenms.Constants) print("Avogadro's number is", pyopenms.Constants.AVOGADRO) ``` -------------------------------- ### Load TraML Transition Data in Python Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/other_ms_data_formats.rst Shows how to load transition data from a TraML file using pyOpenMS. This example downloads a sample TraML file and initializes a TargetedExperiment object to hold the loaded transition information. Storing TraML data is not demonstrated in this snippet. ```python from urllib.request import urlretrieve gh = "https://raw.githubusercontent.com/OpenMS/pyopenms-extra/master" urlretrieve(gh + "/src/data/ConvertTSVToTraML_output.TraML", "test.TraML") targeted_exp = oms.TargetedExperiment() # Loading the data into targeted_exp would typically follow here, e.g.: # oms.TraMLFile().load("test.TraML", targeted_exp) ``` -------------------------------- ### Abstract Base Class Handling (ChromatogramExtractorAlgorithm.pxd) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/community/wrapping_workflows_new_classes.rst Illustrates how to handle abstract base classes like ISpectrumAccess in autowrap. The solution involves copy-pasting the function for each possible implementation of the abstract base class. ```Cython # Example from ChromatogramExtractorAlgorithm.pxd # abstract base class (ISpectrumAccess) # solved by copy-pasting the function multiple times for each possible implementation ``` -------------------------------- ### Get Number of Spectra and Chromatograms in MSExperiment Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/first_steps.rst Demonstrates how to retrieve the total number of spectra and chromatograms stored within an MSExperiment object. This is useful for understanding the scale of the loaded data. ```python print(exp.getNrSpectra()) print(exp.getNrChromatograms()) ``` -------------------------------- ### Store Protein Sequences in FASTA File (Python) Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/peptides_proteins.rst This snippet shows how to create FASTA entries with identifier, sequence, and description, and then store them in a FASTA file using pyOpenMS. It requires the 'pyopenms' library and creates a file named 'example.fasta'. ```python import openms as oms bsa = oms.FASTAEntry() bsa.sequence = "MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGE" bsa.description = "BSA Bovine Albumin (partial sequence)" bsa.identifier = "BSA" alb = oms.FASTAEntry() alb.sequence = "MKWVTFISLLFLFSSAYSRGVFRRDAHKSEVAHRFKDLGE" alb.description = "ALB Human Albumin (partial sequence)" alb.identifier = "ALB" entries = [bsa, alb] f = oms.FASTAFile() f.store("example.fasta", entries) ``` -------------------------------- ### Get pyOpenMS Help in R Source: https://github.com/openms/pyopenms-docs/blob/master/docs/source/user_guide/pyopenms_in_r.rst Retrieves help information for pyOpenMS objects within R using the 'py_help' function from the 'reticulate' package. This is useful for understanding function signatures and parameters. ```R library(reticulate) ropenms=import("pyopenms", convert = FALSE) idXML=ropenms$IdXMLFile py_help(idXML) ``` -------------------------------- ### Generate Theoretical Fragment Spectra with pyopenms Source: https://context7.com/openms/pyopenms-docs/llms.txt This example shows how to generate theoretical fragment ion spectra (y-ions, full spectrum) for a given peptide sequence using pyopenms. It demonstrates setting parameters for ion types and charge states, and storing the results to an mzML file. ```python import pyopenms as oms tsg = oms.TheoreticalSpectrumGenerator() peptide = oms.AASequence.fromString("DFPIANGER") # Generate y-ions only spec_y = oms.MSSpectrum() p = oms.Param() p.setValue("add_b_ions", "false") p.setValue("add_metainfo", "true") tsg.setParameters(p) tsg.getSpectrum(spec_y, peptide, 1, 1) # charge range 1:1 print(f"Y-ion spectrum has {spec_y.size()} peaks") for ion, peak in zip(spec_y.getStringDataArrays()[0], spec_y): print(f"{ion.decode()} at m/z {peak.getMZ():.4f}") # Generate full spectrum with all ion types spec_full = oms.MSSpectrum() p2 = oms.Param() p2.setValue("add_a_ions", "true") p2.setValue("add_b_ions", "true") p2.setValue("add_first_prefix_ion", "true") p2.setValue("add_precursor_peaks", "true") p2.setValue("add_losses", "true") p2.setValue("add_metainfo", "true") tsg.setParameters(p2) tsg.getSpectrum(spec_full, peptide, 1, 2) # charge range 1:2 print(f"Full spectrum has {spec_full.size()} peaks") # Store spectra to mzML exp = oms.MSExperiment() exp.addSpectrum(spec_y) exp.addSpectrum(spec_full) om.MzMLFile().store("theoretical_spectra.mzML", exp) ```