Skip to content

Commit

Permalink
Add chromatogram extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasscheid committed Sep 12, 2024
1 parent 722343b commit d176037
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v2.6.1dev

### `Added`

- Added `PYOPENMS_CHROMATOGRAMEXTRACTOR` extracting MS1 Chromatograms and visualize them in multiQC report [#329](https://github.com/nf-core/mhcquant/pull/329)

## v2.6.0 - nfcore/mhcquant "Mr Bob" - 2024/06/17

### `Added`
Expand Down
42 changes: 39 additions & 3 deletions assets/multiqc_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ custom_logo_url: https://github.com/nf-core/mhcquant
custom_logo_title: "nf-core/mhcquant"

report_comment: >
This report has been generated by the <a href="https://github.com/nf-core/mhcquant/releases/tag/2.6.0" target="_blank">nf-core/mhcquant</a>
This report has been generated by the <a href="https://github.com/nf-core/mhcquant/tree/dev" target="_blank">nf-core/mhcquant</a>
analysis pipeline. For information about how to interpret these results, please see the
<a href="https://nf-co.re/mhcquant/2.6.0/docs/output" target="_blank">documentation</a>.
<a href="https://nf-co.re/mhcquant/dev/docs/output" target="_blank">documentation</a>.
report_section_order:
"nf-core-mhcquant-methods-description":
order: -1000
Expand All @@ -15,5 +15,41 @@ report_section_order:
order: -1002

export_plots: true

disable_version_detection: true

# Modules to run
run_modules:
- custom_content

# Custom tables and plots
custom_data:
# Summary of chromatogram plot
chromatogram:
plot_type: "linegraph"
file_format: "csv"
section_name: "MS1 Chromatogram"
description: |
An MS1 chromatogram is a plot of the intensity of precursor ions (MS1) detected over time,
typically with retention time (RT) on the x-axis and ion intensity on the y-axis.
It represents the total ion current (TIC) from the MS1 scan,
which is useful for monitoring the overall elution profile of compounds during a chromatographic separation.
pconfig:
id: "chromatogram"
title: "MS1 Chromatograms"
xlab: "Retention time [min]"
xmin: 0
ylab: "Intensity"
logswitch: true
logswitch_active: true

sp:
chromatogram:
fn: "*_chrom.csv"
## Define the order of sections
#module_order:
# - custom_content
#
## Set the order of custom code plots and tables
#custom_content:
# order:
# - chromatogram
45 changes: 45 additions & 0 deletions bin/chromatogram_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# Written by Jonas Scheid under the MIT license

import logging
import csv
import argparse
import matplotlib.pyplot as plt

import pyopenms as oms

# Setup logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")


def parse_arguments():
parser = argparse.ArgumentParser(description='Exctract TICs of MS1 Spectra')
parser.add_argument('-in','--input', type=str, help='Path to the spectrum file')
parser.add_argument('-out', '--output', type=str, help='Path to the output CSV file containing RT and TIC of Precursors')
return parser.parse_args()

def main():
args = parse_arguments()
input_file = args.input
output_file = args.output

# Load the mzML file
logging.info(f'Loading file: {input_file}')
exp = oms.MSExperiment()
mzml_file = oms.MzMLFile()
mzml_file.load(input_file, exp)

# Get RT and Spectrum TIC of MS1 Spectra
chromatogram = [(spectrum.getRT() / 60, spectrum.calculateTIC()) for spectrum in exp.getSpectra() if spectrum.getMSLevel() == 1]
logging.info(f'Found {len(chromatogram)} MS1 Spectra')
logging.info(f'RT range: {round(chromatogram[0][0],2)} - {round(chromatogram[-1][0],2)} [min]')
# Add (0,0) to start and end of chromatogram
chromatogram = [(0, 0)] + chromatogram + [(chromatogram[-1][0], 0)]

# Write to csv
with open(output_file, 'w') as f:
writer = csv.writer(f)
writer.writerows(chromatogram)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"multiqc": {
"branch": "master",
"git_sha": "b7ebe95761cd389603f9cc0e0dc384c0f663815a",
"git_sha": "06c8865e36741e05ad32ef70ab3fac127486af48",
"installed_by": ["modules"]
},
"openms/decoydatabase": {
Expand Down
4 changes: 1 addition & 3 deletions modules/nf-core/multiqc/environment.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions modules/nf-core/multiqc/main.nf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions modules/nf-core/multiqc/meta.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions modules/nf-core/multiqc/tests/main.nf.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions modules/nf-core/multiqc/tests/main.nf.test.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ manifest {
description = """Identify and quantify peptides from mass spectrometry raw data"""
mainScript = 'main.nf'
nextflowVersion = '!>=23.04.0'
version = '2.6.0'
version = '2.6.1dev'
doi = '10.1021/acs.jproteome.9b00313'
}

Expand Down
28 changes: 18 additions & 10 deletions workflows/mhcquant.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
// MODULE: Loaded from modules/local/
//

include { OPENMS_FILEFILTER } from '../modules/local/openms_filefilter'
include { OPENMS_COMETADAPTER } from '../modules/local/openms_cometadapter'
include { OPENMS_PEPTIDEINDEXER } from '../modules/local/openms_peptideindexer'
include { MS2RESCORE } from '../modules/local/ms2rescore'
include { OPENMS_PSMFEATUREEXTRACTOR } from '../modules/local/openms_psmfeatureextractor'
include { OPENMS_PERCOLATORADAPTER } from '../modules/local/openms_percolatoradapter'
include { PYOPENMS_IONANNOTATOR } from '../modules/local/pyopenms_ionannotator'
include { OPENMS_TEXTEXPORTER } from '../modules/local/openms_textexporter'
include { OPENMS_MZTABEXPORTER } from '../modules/local/openms_mztabexporter'
include { OPENMS_FILEFILTER } from '../modules/local/openms_filefilter'
include { PYOPENMS_CHROMATOGRAMEXTRACTOR } from '../modules/local/pyopenms_chromatogramextractor'
include { OPENMS_COMETADAPTER } from '../modules/local/openms_cometadapter'
include { OPENMS_PEPTIDEINDEXER } from '../modules/local/openms_peptideindexer'
include { MS2RESCORE } from '../modules/local/ms2rescore'
include { OPENMS_PSMFEATUREEXTRACTOR } from '../modules/local/openms_psmfeatureextractor'
include { OPENMS_PERCOLATORADAPTER } from '../modules/local/openms_percolatoradapter'
include { PYOPENMS_IONANNOTATOR } from '../modules/local/pyopenms_ionannotator'
include { OPENMS_TEXTEXPORTER } from '../modules/local/openms_textexporter'
include { OPENMS_MZTABEXPORTER } from '../modules/local/openms_mztabexporter'

//
// SUBWORKFLOW: Loaded from subworkflows/local/
Expand Down Expand Up @@ -83,6 +84,11 @@ workflow MHCQUANT {
ch_clean_mzml_file = PREPARE_SPECTRA.out.mzml
}

// Compute MS1 TICs for QC
PYOPENMS_CHROMATOGRAMEXTRACTOR(ch_clean_mzml_file)
ch_versions = ch_versions.mix(PYOPENMS_CHROMATOGRAMEXTRACTOR.out.versions)
ch_multiqc_files = ch_multiqc_files.mix(PYOPENMS_CHROMATOGRAMEXTRACTOR.out.csv.map{ meta, mzml -> mzml })

// Run comet database search
OPENMS_COMETADAPTER(ch_clean_mzml_file.combine(ch_decoy_db))
ch_versions = ch_versions.mix(OPENMS_COMETADAPTER.out.versions)
Expand Down Expand Up @@ -223,7 +229,9 @@ workflow MHCQUANT {
ch_multiqc_files.collect(),
ch_multiqc_config.toList(),
ch_multiqc_custom_config.toList(),
ch_multiqc_logo.toList()
ch_multiqc_logo.toList(),
[],
[]
)

emit:
Expand Down

0 comments on commit d176037

Please sign in to comment.