OpenMS / pyopenms-docs

pyOpenMS readthedocs documentation, additional utilities, addons, scripts, and examples.
https://pyopenms.readthedocs.io
Other
42 stars 52 forks source link

Document how direct infusion data is handled inFeatureFindingMetabo #266

Closed bpben closed 1 year ago

bpben commented 2 years ago

Hi, I'm using the tutorial example for [untargeted metabolomics[(https://pyopenms.readthedocs.io/en/latest/feature_detection.html?highlight=FeatureFindingMetabo#metabolomics-untargeted). When I use quant_method "median" in the MassTraceDetection step I get an error when running FeatureFindingMetabo.run: RuntimeError: this method has not been implemented yet. Feel free to complain about it!

My code is below. If I change quant_method to "area", it works fine. I'm assuming that quant_method "median" hasn't been implemented in the FeatureFindingMetabo algorithms, but I wanted to check. If it hasn't been implemented, is it possible to point me to some way I could make a workaround? I'm not familiar with C++, so not sure if I could implement it.

Just as a note - median is suggested as a method for direct injection, which is the source data I'm using at the moment.

# mass trace
mass_traces = []
mtd = MassTraceDetection()
mtd_params = mtd.getDefaults()
mtd_params.setValue("quant_method", 'median') 
mtd.setParameters(mtd_params)
mtd.run(exp, mass_traces, 0)

# elution peak
mass_traces_split = []
mass_traces_final = []
epd = ElutionPeakDetection()
epd_params = epd.getDefaults()
epd.setParameters(epd_params)
epd.detectPeaks(mass_traces, mass_traces_split)
mass_traces_final = mass_traces_split

# feature map
fm = FeatureMap()
feat_chrom = []
ffm = FeatureFindingMetabo()
ffm_params = ffm.getDefaults()
ffm_params.setValue("isotope_filtering_model", "none")
ffm_params.setValue("remove_single_traces", "false") # set false to keep features with only one mass trace
ffm_params.setValue("mz_scoring_by_elements", "false")
ffm_params.setValue("report_convex_hulls", "true")
ffm.setParameters(ffm_params)
ffm.run(mass_traces_final, fm, feat_chrom)
timosachsenberg commented 2 years ago

I think the behavior is probably the same on C++ and python side. e.g., median gets registered here: https://github.com/OpenMS/OpenMS/blob/develop/src/openms/source/FILTERING/DATAREDUCTION/MassTraceDetection.cpp#L53-L54 So maybe it is a combination of parameters that is not supported. @cbielow you have been using FFM quite frequently in the past for direct infusion. Do you see some obvious problem here?

jpfeuffer commented 2 years ago

the problem is here: https://github.com/OpenMS/OpenMS/blob/bf46a11720e76a406addbaafdddaff9f6a48515f/src/openms/source/KERNEL/MassTrace.cpp#L355

timosachsenberg commented 2 years ago

so problem is the smoothing?
can you set the smoothing parameter in FFM to false and try if it works? https://github.com/OpenMS/OpenMS/blob/bf46a11720e76a406addbaafdddaff9f6a48515f/src/openms/source/FILTERING/DATAREDUCTION/FeatureFindingMetabo.cpp#L289 to false

jpfeuffer commented 2 years ago

I don't think it is the smoothing. I think in general nothing is implemented to get the median quantity of a mass trace. It is the getIntensity function

timosachsenberg commented 2 years ago

it is: https://github.com/OpenMS/OpenMS/blob/bf46a11720e76a406addbaafdddaff9f6a48515f/src/openms/source/KERNEL/MassTrace.cpp#L370 but only if not smoothed

jpfeuffer commented 2 years ago

Ah thanks. Correct.

bpben commented 2 years ago

Thanks for the quick responses, appreciate this! If I change the use_smoothed_intensities parameter to "false", it works! That seems to solve it, though haven't looked into the smoothing approach - is it the case that taking the median means the smoothing isn't required?

timosachsenberg commented 2 years ago

I think the error message means that smoothing doesn't make sense for direct infusion data. I will repurpose this issue to a documentation task.

tapaswenipathak commented 2 years ago

What is the documentation todo here?

timosachsenberg commented 2 years ago

might need domain knowledge. @axelwalter may I assign you here?

axelwalter commented 1 year ago

Fixed here. The median quantification method will now be used with smoothing enabled and disabled. It was already documented that the median method should be used for direct infusion data.