/// Create the mapping void doMap(OpenSwath::SpectrumAccessPtr input, TargetedExpType& transition_exp) { for (Size i = 0; i < input->getNrChromatograms(); i++) { chromatogram_map[input->getChromatogramNativeID(i)] = boost::numeric_cast<int>(i); } for (Size i = 0; i < transition_exp.getPeptides().size(); i++) { assay_peptide_map[transition_exp.getPeptides()[i].id] = boost::numeric_cast<int>(i); } for (Size i = 0; i < transition_exp.getTransitions().size(); i++) { assay_map[transition_exp.getTransitions()[i].getPeptideRef()].push_back(&transition_exp.getTransitions()[i]); } }
/// Fill up transition group with paired Transitions and Chromatograms void getTransitionGroup(OpenSwath::SpectrumAccessPtr input, MRMTransitionGroupType& transition_group, String id) { transition_group.setTransitionGroupID(id); // Go through all transitions for (Size i = 0; i < assay_map[id].size(); i++) { // Check first whether we have a mapping (e.g. see -force option) const TransitionType* transition = assay_map[id][i]; if (chromatogram_map.find(transition->getNativeID()) == chromatogram_map.end()) { LOG_DEBUG << "Found no matching chromatogram for id " << transition->getNativeID() << std::endl; continue; } OpenSwath::ChromatogramPtr cptr = input->getChromatogramById(chromatogram_map[transition->getNativeID()]); MSChromatogram chromatogram; OpenSwathDataAccessHelper::convertToOpenMSChromatogram(cptr, chromatogram); chromatogram.setMetaValue("product_mz", transition->getProductMZ()); chromatogram.setMetaValue("precursor_mz", transition->getPrecursorMZ()); chromatogram.setNativeID(transition->getNativeID()); // Now add the transition and the chromatogram to the group transition_group.addTransition(*transition, transition->getNativeID()); transition_group.addChromatogram(chromatogram, chromatogram.getNativeID()); } }
OpenSwath::SpectrumPtr OpenSwathScoring::getAddedSpectra_(OpenSwath::SpectrumAccessPtr swath_map, double RT, int nr_spectra_to_add) { std::vector<std::size_t> indices = swath_map->getSpectraByRT(RT, 0.0); if (indices.empty() ) { OpenSwath::SpectrumPtr sptr(new OpenSwath::Spectrum); return sptr; } int closest_idx = boost::numeric_cast<int>(indices[0]); if (indices[0] != 0 && std::fabs(swath_map->getSpectrumMetaById(boost::numeric_cast<int>(indices[0]) - 1).RT - RT) < std::fabs(swath_map->getSpectrumMetaById(boost::numeric_cast<int>(indices[0])).RT - RT)) { closest_idx--; } if (nr_spectra_to_add == 1) { OpenSwath::SpectrumPtr spectrum_ = swath_map->getSpectrumById(closest_idx); return spectrum_; } else { std::vector<OpenSwath::SpectrumPtr> all_spectra; // always add the spectrum 0, then add those right and left all_spectra.push_back(swath_map->getSpectrumById(closest_idx)); for (int i = 1; i <= nr_spectra_to_add / 2; i++) // cast to int is intended! { if (closest_idx - i >= 0) { all_spectra.push_back(swath_map->getSpectrumById(closest_idx - i)); } if (closest_idx + i < (int)swath_map->getNrSpectra()) { all_spectra.push_back(swath_map->getSpectrumById(closest_idx + i)); } } OpenSwath::SpectrumPtr spectrum_ = SpectrumAddition::addUpSpectra(all_spectra, spacing_for_spectra_resampling_, true); return spectrum_; } }
void OpenSwathScoring::calculateDIAScores(OpenSwath::IMRMFeature* imrmfeature, const std::vector<TransitionType> & transitions, OpenSwath::SpectrumAccessPtr swath_map, OpenSwath::SpectrumAccessPtr ms1_map, OpenMS::DIAScoring & diascoring, const PeptideType& pep, OpenSwath_Scores & scores) { OPENMS_PRECONDITION(transitions.size() > 0, "There needs to be at least one transition."); std::vector<double> normalized_library_intensity; getNormalized_library_intensities_(transitions, normalized_library_intensity); // parameters int by_charge_state = 1; // for which charge states should we check b/y series double precursor_mz = transitions[0].precursor_mz; // find spectrum that is closest to the apex of the peak using binary search OpenSwath::SpectrumPtr spectrum_ = getAddedSpectra_(swath_map, imrmfeature->getRT(), add_up_spectra_); OpenSwath::SpectrumPtr* spectrum = &spectrum_; // Isotope correlation / overlap score: Is this peak part of an // isotopic pattern or is it the monoisotopic peak in an isotopic // pattern? diascoring.dia_isotope_scores(transitions, (*spectrum), imrmfeature, scores.isotope_correlation, scores.isotope_overlap); // Mass deviation score diascoring.dia_massdiff_score(transitions, (*spectrum), normalized_library_intensity, scores.massdev_score, scores.weighted_massdev_score); // Presence of b/y series score OpenMS::AASequence aas; OpenSwathDataAccessHelper::convertPeptideToAASequence(pep, aas); diascoring.dia_by_ion_score((*spectrum), aas, by_charge_state, scores.bseries_score, scores.yseries_score); // FEATURE we should not punish so much when one transition is missing! scores.massdev_score = scores.massdev_score / transitions.size(); // DIA dotproduct and manhattan score diascoring.score_with_isotopes((*spectrum), transitions, scores.dotprod_score_dia, scores.manhatt_score_dia); // MS1 ppm score : check that the map is not NULL and contains spectra if (ms1_map && ms1_map->getNrSpectra() > 0) { OpenSwath::SpectrumPtr ms1_spectrum = getAddedSpectra_(ms1_map, imrmfeature->getRT(), add_up_spectra_); diascoring.dia_ms1_massdiff_score(precursor_mz, ms1_spectrum, scores.ms1_ppm_score); diascoring.dia_ms1_isotope_scores(precursor_mz, ms1_spectrum, pep.getChargeState(), scores.ms1_isotope_correlation, scores.ms1_isotope_overlap); } }
void ChromatogramExtractorAlgorithm::extractChromatograms(const OpenSwath::SpectrumAccessPtr input, std::vector< OpenSwath::ChromatogramPtr >& output, std::vector<ExtractionCoordinates> extraction_coordinates, double mz_extraction_window, bool ppm, String filter) { Size input_size = input->getNrSpectra(); if (input_size < 1) { return; } if (output.size() != extraction_coordinates.size()) { throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Output and extraction coordinates need to have the same size"); } int used_filter = getFilterNr_(filter); // assert that they are sorted! if (std::adjacent_find(extraction_coordinates.begin(), extraction_coordinates.end(), ExtractionCoordinates::SortExtractionCoordinatesReverseByMZ) != extraction_coordinates.end()) { throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Input to extractChromatogram needs to be sorted by m/z"); } //go through all spectra startProgress(0, input_size, "Extracting chromatograms"); for (Size scan_idx = 0; scan_idx < input_size; ++scan_idx) { setProgress(scan_idx); OpenSwath::SpectrumPtr sptr = input->getSpectrumById(scan_idx); OpenSwath::SpectrumMeta s_meta = input->getSpectrumMetaById(scan_idx); OpenSwath::BinaryDataArrayPtr mz_arr = sptr->getMZArray(); OpenSwath::BinaryDataArrayPtr int_arr = sptr->getIntensityArray(); std::vector<double>::const_iterator mz_start = mz_arr->data.begin(); std::vector<double>::const_iterator mz_end = mz_arr->data.end(); std::vector<double>::const_iterator mz_it = mz_arr->data.begin(); std::vector<double>::const_iterator int_it = int_arr->data.begin(); if (sptr->getMZArray()->data.size() == 0) continue; // go through all transitions / chromatograms which are sorted by // ProductMZ. We can use this to step through the spectrum and at the // same time step through the transitions. We increase the peak counter // until we hit the next transition and then extract the signal. for (Size k = 0; k < extraction_coordinates.size(); ++k) { double integrated_intensity = 0; double current_rt = s_meta.RT; if (extraction_coordinates[k].rt_end - extraction_coordinates[k].rt_start > 0 && (current_rt < extraction_coordinates[k].rt_start || current_rt > extraction_coordinates[k].rt_end) ) { continue; } if (used_filter == 1) { extract_value_tophat( mz_start, mz_it, mz_end, int_it, extraction_coordinates[k].mz, integrated_intensity, mz_extraction_window, ppm); } else if (used_filter == 2) { throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__); } // Time is first, intensity is second output[k]->binaryDataArrayPtrs[0]->data.push_back(current_rt); output[k]->binaryDataArrayPtrs[1]->data.push_back(integrated_intensity); } } endProgress(); }