Comments (1)
Hi @junxia97 👋
Can we obtain the retention time and ActivationType (e.g., HCD) from mgf files using the depthcharge package?
Yes, as long as they are specified in the MGF file itself. Under the hood, Depthcharge uses the MGF parser from Pyteomics, and you can access any available field using the custom_fields
parameter within the depthcharge parsers.
And how?
Here's a small example - we'll start by creating an example MGF file:
mgf_contents = """\
BEGIN IONS
PEPMASS=1000.0
CHARGE=3+
NCE=25.0
FOO=BAR
10.0 1234.5
20.0 6789.0
END IONS
"""
with open("example.mgf", "w+") as mgf_out:
mgf_out.write(mgf_contents)
We can then look a see how Pyteomics will parse the spectrum:
from pyteomics.mgf import MGF
with MGF("example.mgf") as mgf_in:
print(next(mgf_in))
# { 'charge array': masked_array(data=[--, --],
# mask=[ True, True],
# fill_value=0,
# dtype=int64),
# 'intensity array': array([1234.5, 6789. ]),
# 'm/z array': array([10., 20.]),
# 'params': { 'charge': [3],
# 'foo': 'BAR',
# 'nce': '25.0',
# 'pepmass': (1000.0, None)}}
If we want to parse the NCE and foo in this case, we now know that we need to access the nce
or foo
keys within the params
key in the spectrum dictionary. So if the spectrum is spec
, then we need spec["params"]["nce"]
and `spec["params"]["foo"]. Also note that all extra fields in MGF files are parsed as strings.
Now we can tell Depthcharge how we want to parse these as custom fields:
import pyarrow as pa
import depthcharge as dc
from depthcharge.data import CustomField
df = dc.data.spectra_to_df(
"example.mgf",
custom_fields=[
CustomField("NCE", lambda s: s["params"]["nce"], pa.string()),
CustomField("foo", lambda s: s["params"]["foo"], pa.string())
],
)
print(df)
#┌─────────────┬─────────┬──────────┬──────────────┬───┬───────────┬─────────────────┬──────┬─────┐
#│ peak_file ┆ scan_id ┆ ms_level ┆ precursor_mz ┆ … ┆ mz_array ┆ intensity_array ┆ NCE ┆ foo │
#│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
#│ str ┆ str ┆ u8 ┆ f64 ┆ ┆ list[f64] ┆ list[f64] ┆ str ┆ str │
#╞═════════════╪═════════╪══════════╪══════════════╪═══╪═══════════╪═════════════════╪══════╪═════╡
#│ example.mgf ┆ 0 ┆ 2 ┆ 1000.0 ┆ … ┆ [20.0] ┆ [1.0] ┆ 25.0 ┆ BAR │
#└─────────────┴─────────┴──────────┴──────────────┴───┴───────────┴─────────────────┴──────┴─────┘
Now you have df
which is a Polars DataFrame 🎉
from depthcharge.
Related Issues (17)
- Existing index doesn't know whether it's annotated HOT 2
- Provide tokenization function HOT 6
- Why there is a replacement from "I" to "L" in peptide sequence during the tokenize function of _PeptideTransformer in transformer.py? HOT 1
- [bug] m/z encoding is incorrect
- Update Peptide Transformer API
- Add detail to invalid spectra warning parsers.py HOT 1
- Example code to read .mgf file HOT 6
- Problem with AnnotatedSpectrumDataset and n_workers>0 HOT 5
- SpectrumDataset: is a IterableDataset,How to use shuffle in Dataloader? HOT 1
- Error in analyte decoder when tokens is None HOT 1
- Error in reversing peptides with PeptideTokenizer.detokenize
- Parser entry skipping based on custom fields
- Bump PyTorch dependency to >=1.9
- Best practices for spectrum data loading
- Scale to unit norm is wrong
- Dataset cache design
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from depthcharge.