MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / algorithm

Function algorithm

src/pyOpenMS/pyTOPP/MRMMapper.py:11–60  ·  view source on GitHub ↗
(chromatogram_map, targeted, precursor_tolerance, product_tolerance, allow_unmapped=True, allow_double_mappings=False)

Source from the content-addressed store, hash-verified

9"""
10
11def algorithm(chromatogram_map, targeted, precursor_tolerance, product_tolerance, allow_unmapped=True, allow_double_mappings=False):
12
13 output = copy.copy(chromatogram_map)
14 output.clear(False);
15 empty_chromats = []
16 output.setChromatograms(empty_chromats);
17
18 notmapped = 0
19 for chrom in chromatogram_map.getChromatograms():
20 mapped_already = False
21 for transition in targeted.getTransitions():
22 if (abs(chrom.getPrecursor().getMZ() - transition.getPrecursorMZ()) < precursor_tolerance and
23 abs(chrom.getProduct().getMZ() - transition.getProductMZ()) < product_tolerance):
24 if mapped_already:
25 this_peptide = targeted.getPeptideByRef(transition.getPeptideRef() ).sequence
26 other_peptide = chrom.getPrecursor().getMetaValue("peptide_sequence")
27 print "Found mapping of", chrom.getPrecursor().getMZ(), "/", chrom.getProduct().getMZ(), "to", transition.getPrecursorMZ(), "/",transition.getProductMZ()
28 print "Of peptide", this_peptide
29 print "But the chromatogram is already mapped to", other_peptide
30 if not allow_double_mappings: raise Exception("Cannot map twice")
31 mapped_already = True
32 precursor = chrom.getPrecursor();
33 peptide = targeted.getPeptideByRef(transition.getPeptideRef() )
34 precursor.setMetaValue("peptide_sequence", peptide.sequence)
35 chrom.setPrecursor(precursor)
36 chrom.setNativeID(transition.getNativeID())
37 if not mapped_already:
38 notmapped += 1
39 print "Did not find a mapping for chromatogram", chrom.getNativeID()
40 if not allow_unmapped: raise Exception("No mapping")
41 else:
42 output.addChromatogram(chrom)
43
44 if notmapped > 0:
45 print "Could not find mapping for", notmapped, "chromatogram(s)"
46
47
48 dp = pyopenms.DataProcessing()
49 # dp.setProcessingActions(ProcessingAction:::FORMAT_CONVERSION)
50 pa = pyopenms.DataProcessing().ProcessingAction().FORMAT_CONVERSION
51 dp.setProcessingActions(set([pa]))
52
53 chromatograms = output.getChromatograms();
54 for chrom in chromatograms:
55 this_dp = chrom.getDataProcessing()
56 this_dp.append(dp)
57 chrom.setDataProcessing(this_dp)
58
59 output.setChromatograms(chromatograms);
60 return output
61
62def main(options):
63 precursor_tolerance = options.precursor_tolerance

Callers 1

mainFunction · 0.70

Calls 15

setProcessingActionsMethod · 0.95
ExceptionClass · 0.85
setChromatogramsMethod · 0.80
getChromatogramsMethod · 0.80
getPeptideRefMethod · 0.80
getMetaValueMethod · 0.80
getNativeIDMethod · 0.80
DataProcessingMethod · 0.80
copyMethod · 0.45
clearMethod · 0.45
getMZMethod · 0.45
getPrecursorMZMethod · 0.45

Tested by

no test coverage detected