void MapAlignmentTransformer::applyToFeature_(Feature & feature, const TransformationDescription & trafo) { applyToBaseFeature_(feature, trafo); // loop over all convex hulls vector<ConvexHull2D> & convex_hulls = feature.getConvexHulls(); for (vector<ConvexHull2D>::iterator chiter = convex_hulls.begin(); chiter != convex_hulls.end(); ++chiter) { // transform all hull point positions within convex hull ConvexHull2D::PointArrayType points = chiter->getHullPoints(); chiter->clear(); for (ConvexHull2D::PointArrayType::iterator points_iter = points.begin(); points_iter != points.end(); ++points_iter ) { DoubleReal rt = (*points_iter)[Feature::RT]; (*points_iter)[Feature::RT] = trafo.apply(rt); } chiter->setHullPoints(points); } // recurse into subordinates for (vector<Feature>::iterator subiter = feature.getSubordinates().begin(); subiter != feature.getSubordinates().end(); ++subiter) { applyToFeature_(*subiter, trafo); } }
END_SECTION START_SECTION( double elutionModelFit(ConvexHull2D::PointArrayType current_section, bool smooth_data) ) { // test a single feature double elution_model_fit_score; EmgScoring emgscore; MRMFeature feature = OpenSWATH_Test::createMockFeature(); Feature f = feature.getFeature("tr1"); elution_model_fit_score = emgscore.elutionModelFit(f.getConvexHulls()[0].getHullPoints() , false); TEST_REAL_SIMILAR(elution_model_fit_score, 0.981013417243958) }
bool overlaps_(const Feature& feature, const double rt, const double pc_mz, const double rt_tolerance) const { if (feature.getConvexHulls().empty()) { LOG_WARN << "HighResPrecursorMassCorrector warning: at least one feature has no convex hull - omitting feature for matching" << std::endl; } // get bounding box and extend by retention time tolerance DBoundingBox<2> box = feature.getConvexHull().getBoundingBox(); DPosition<2> extend_rt(rt_tolerance, 0.01); box.setMin(box.minPosition() - extend_rt); box.setMax(box.maxPosition() + extend_rt); DPosition<2> pc_pos(rt, pc_mz); if (box.encloses(pc_pos)) { return true; } else { return false; } }
ExitCodes main_(int, const char**) override { //------------------------------------------------------------- // parameter handling //------------------------------------------------------------- String in = getStringOption_("in"); String out = getStringOption_("out"); FileTypes::Type out_type = FileTypes::nameToType(getStringOption_("out_type")); if (out_type == FileTypes::UNKNOWN) { out_type = FileHandler().getTypeByFileName(out); } //------------------------------------------------------------- // loading input //------------------------------------------------------------- MzMLFile mz_data_file; mz_data_file.setLogType(log_type_); PeakMap ms_peakmap; std::vector<Int> ms_level(1, 1); (mz_data_file.getOptions()).setMSLevels(ms_level); mz_data_file.load(in, ms_peakmap); if (ms_peakmap.size() == 0) { LOG_WARN << "The given file does not contain any conventional peak data, but might" " contain chromatograms. This tool currently cannot handle them, sorry."; return INCOMPATIBLE_INPUT_DATA; } // make sure that the spectra are sorted by m/z ms_peakmap.sortSpectra(true); //------------------------------------------------------------- // get params for MTD and EPD algorithms //------------------------------------------------------------- Param com_param = getParam_().copy("algorithm:common:", true); writeDebug_("Common parameters passed to both sub-algorithms (mtd and epd)", com_param, 3); Param mtd_param = getParam_().copy("algorithm:mtd:", true); writeDebug_("Parameters passed to MassTraceDetection", mtd_param, 3); Param epd_param = getParam_().copy("algorithm:epd:", true); writeDebug_("Parameters passed to ElutionPeakDetection", epd_param, 3); //------------------------------------------------------------- // configure and run MTD //------------------------------------------------------------- MassTraceDetection mt_ext; mtd_param.insert("", com_param); mtd_param.remove("chrom_fwhm"); mt_ext.setParameters(mtd_param); vector<MassTrace> m_traces; mt_ext.run(ms_peakmap, m_traces); vector<MassTrace> m_traces_final; bool use_epd = epd_param.getValue("enabled").toBool(); if (!use_epd) { swap(m_traces_final, m_traces); } else { ElutionPeakDetection ep_det; epd_param.remove("enabled"); // artificially added above epd_param.insert("", com_param); ep_det.setParameters(epd_param); std::vector<MassTrace> split_mtraces; // note: this step will destroy any meta data annotation (e.g. FWHM_mz_avg) ep_det.detectPeaks(m_traces, split_mtraces); if (ep_det.getParameters().getValue("width_filtering") == "auto") { m_traces_final.clear(); ep_det.filterByPeakWidth(split_mtraces, m_traces_final); LOG_INFO << "Notice: " << split_mtraces.size() - m_traces_final.size() << " of total " << split_mtraces.size() << " were dropped because of too low peak width." << std::endl; } else { swap(m_traces_final, split_mtraces); } } //------------------------------------------------------------- // writing consensus map output //------------------------------------------------------------- if (out_type == FileTypes::CONSENSUSXML) { ConsensusMap consensus_map; StringList ms_runs; ms_peakmap.getPrimaryMSRunPath(ms_runs); consensus_map.setPrimaryMSRunPath(ms_runs); for (Size i = 0; i < m_traces_final.size(); ++i) { if (m_traces_final[i].getSize() == 0) continue; ConsensusFeature fcons; int k = 0; for (MassTrace::const_iterator it = m_traces_final[i].begin(); it != m_traces_final[i].end(); ++it) { FeatureHandle fhandle; fhandle.setRT(it->getRT()); fhandle.setMZ(it->getMZ()); fhandle.setIntensity(it->getIntensity()); fhandle.setUniqueId(++k); fcons.insert(fhandle); } fcons.setMetaValue(3, m_traces_final[i].getLabel()); fcons.setCharge(0); fcons.setWidth(m_traces_final[i].estimateFWHM(use_epd)); fcons.setQuality(1 - (1.0 / m_traces_final[i].getSize())); fcons.setRT(m_traces_final[i].getCentroidRT()); fcons.setMZ(m_traces_final[i].getCentroidMZ()); fcons.setIntensity(m_traces_final[i].getIntensity(false)); consensus_map.push_back(fcons); } consensus_map.applyMemberFunction(&UniqueIdInterface::setUniqueId); addDataProcessing_(consensus_map, getProcessingInfo_(DataProcessing::QUANTITATION)); consensus_map.setUniqueId(); ConsensusXMLFile().store(out, consensus_map); } else //(out_type == FileTypes::FEATUREXML) { //----------------------------------------------------------- // convert mass traces to features //----------------------------------------------------------- std::vector<double> stats_sd; FeatureMap ms_feat_map; StringList ms_runs; ms_peakmap.getPrimaryMSRunPath(ms_runs); ms_feat_map.setPrimaryMSRunPath(ms_runs); for (Size i = 0; i < m_traces_final.size(); ++i) { if (m_traces_final[i].getSize() == 0) continue; m_traces_final[i].updateMeanMZ(); m_traces_final[i].updateWeightedMZsd(); Feature f; f.setMetaValue(3, m_traces_final[i].getLabel()); f.setCharge(0); f.setMZ(m_traces_final[i].getCentroidMZ()); f.setIntensity(m_traces_final[i].getIntensity(false)); f.setRT(m_traces_final[i].getCentroidRT()); f.setWidth(m_traces_final[i].estimateFWHM(use_epd)); f.setOverallQuality(1 - (1.0 / m_traces_final[i].getSize())); f.getConvexHulls().push_back(m_traces_final[i].getConvexhull()); double sd = m_traces_final[i].getCentroidSD(); f.setMetaValue("SD", sd); f.setMetaValue("SD_ppm", sd / f.getMZ() * 1e6); if (m_traces_final[i].fwhm_mz_avg > 0) f.setMetaValue("FWHM_mz_avg", m_traces_final[i].fwhm_mz_avg); stats_sd.push_back(m_traces_final[i].getCentroidSD()); ms_feat_map.push_back(f); } // print some stats about standard deviation of mass traces if (stats_sd.size() > 0) { std::sort(stats_sd.begin(), stats_sd.end()); LOG_INFO << "Mass trace m/z s.d.\n" << " low quartile: " << stats_sd[stats_sd.size() * 1 / 4] << "\n" << " median: " << stats_sd[stats_sd.size() * 1 / 2] << "\n" << " upp quartile: " << stats_sd[stats_sd.size() * 3 / 4] << std::endl; } ms_feat_map.applyMemberFunction(&UniqueIdInterface::setUniqueId); //------------------------------------------------------------- // writing output //------------------------------------------------------------- // annotate output with data processing info TODO addDataProcessing_(ms_feat_map, getProcessingInfo_(DataProcessing::QUANTITATION)); //ms_feat_map.setUniqueId(); FeatureXMLFile().store(out, ms_feat_map); } return EXECUTION_OK; }
p.setQuality( 1, (QualityType)0.0); TEST_REAL_SIMILAR(p.getQuality(0), 0.0) TEST_REAL_SIMILAR(p.getQuality(1), 0.0) TEST_PRECONDITION_VIOLATED(p.setQuality( 10, (QualityType)1.0)) END_SECTION //do not change these datastructures, they are used in the following tests... std::vector< ConvexHull2D > hulls(2); hulls[0].addPoint(DPosition<2>(1.0,2.0)); hulls[0].addPoint(DPosition<2>(3.0,4.0)); hulls[1].addPoint(DPosition<2>(0.5,0.0)); hulls[1].addPoint(DPosition<2>(1.0,1.0)); START_SECTION((const vector<ConvexHull2D>& getConvexHulls() const)) Feature tmp; TEST_EQUAL(tmp.getConvexHulls().size(),0) END_SECTION START_SECTION((vector<ConvexHull2D>& getConvexHulls())) Feature tmp; tmp.setConvexHulls(hulls); TEST_EQUAL(tmp.getConvexHulls().size(),2) TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[0][0],1.0) TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[0][1],2.0) TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[1][0],3.0) TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[1][1],4.0) TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[0][0],0.5) TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[0][1],0.0) TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[1][0],1.0) TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[1][1],1.0) END_SECTION