void ConsensusMapNormalizerAlgorithmQuantile::extractIntensityVectors(const ConsensusMap& map, vector<vector<double> >& out_intensities) { //reserve space for out_intensities (unequal vector lengths, 0-features omitted) Size number_of_maps = map.getColumnHeaders().size(); out_intensities.clear(); out_intensities.resize(number_of_maps); for (UInt i = 0; i < number_of_maps; i++) { ConsensusMap::ColumnHeaders::const_iterator it = map.getColumnHeaders().find(i); if (it == map.getColumnHeaders().end()) throw Exception::ElementNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, String(i)); out_intensities[i].reserve(it->second.size); } //fill out_intensities ConsensusMap::ConstIterator cf_it; for (cf_it = map.begin(); cf_it != map.end(); ++cf_it) { ConsensusFeature::HandleSetType::const_iterator f_it; for (f_it = cf_it->getFeatures().begin(); f_it != cf_it->getFeatures().end(); ++f_it) { out_intensities[f_it->getMapIndex()].push_back(f_it->getIntensity()); } } }
void ConsensusMapNormalizerAlgorithmQuantile::setNormalizedIntensityValues(const vector<vector<double> >& feature_ints, ConsensusMap& map) { //assumes the input map and feature_ints are in the same order as in the beginning, //although feature_ints has normalized values now (but the same ranks as before) Size number_of_maps = map.getColumnHeaders().size(); ConsensusMap::ConstIterator cf_it; vector<Size> progress_indices(number_of_maps); for (cf_it = map.begin(); cf_it != map.end(); ++cf_it) { ConsensusFeature::HandleSetType::const_iterator f_it; for (f_it = cf_it->getFeatures().begin(); f_it != cf_it->getFeatures().end(); ++f_it) { Size map_idx = f_it->getMapIndex(); double intensity = feature_ints[map_idx][progress_indices[map_idx]++]; f_it->asMutable().setIntensity(intensity); } } }
Param p; p.setValue("rt_estimate","false"); p.setValue("rt_pair_dist",0.4); p.setValue("rt_dev_low",1.0); p.setValue("rt_dev_high",2.0); p.setValue("mz_pair_dists",ListUtils::create<double>(4.0)); p.setValue("mz_dev",0.6); pm.setParameters(p); ConsensusMap output; TEST_EXCEPTION(Exception::IllegalArgument,pm.run(vector<ConsensusMap>(),output)); vector<ConsensusMap> input(1); MapConversion::convert(5,features,input[0]); output.getColumnHeaders()[5].label = "light"; output.getColumnHeaders()[5].filename = "filename"; output.getColumnHeaders()[8] = output.getColumnHeaders()[5]; output.getColumnHeaders()[8].label = "heavy"; pm.run(input,output); TEST_EQUAL(output.size(),1); ABORT_IF(output.size()!=1) TEST_REAL_SIMILAR(output[0].begin()->getMZ(),1.0f); TEST_REAL_SIMILAR(output[0].begin()->getRT(),1.0f); TEST_REAL_SIMILAR(output[0].rbegin()->getMZ(),5.0f); TEST_REAL_SIMILAR(output[0].rbegin()->getRT(),1.5f); TEST_REAL_SIMILAR(output[0].getQuality(),0.959346); TEST_EQUAL(output[0].getCharge(),1); //test automated RT parameter estimation LabeledPairFinder pm2;
ExitCodes main_(int, const char **) override { FeatureGroupingAlgorithmUnlabeled * algorithm = new FeatureGroupingAlgorithmUnlabeled(); //------------------------------------------------------------- // parameter handling //------------------------------------------------------------- StringList ins; ins = getStringList_("in"); String out = getStringOption_("out"); //------------------------------------------------------------- // check for valid input //------------------------------------------------------------- // check if all input files have the correct type FileTypes::Type file_type = FileHandler::getType(ins[0]); for (Size i = 0; i < ins.size(); ++i) { if (FileHandler::getType(ins[i]) != file_type) { writeLog_("Error: All input files must be of the same type!"); return ILLEGAL_PARAMETERS; } } //------------------------------------------------------------- // set up algorithm //------------------------------------------------------------- Param algorithm_param = getParam_().copy("algorithm:", true); writeDebug_("Used algorithm parameters", algorithm_param, 3); algorithm->setParameters(algorithm_param); Size reference_index(0); //------------------------------------------------------------- // perform grouping //------------------------------------------------------------- // load input ConsensusMap out_map; StringList ms_run_locations; if (file_type == FileTypes::FEATUREXML) { // use map with highest number of features as reference: Size max_count(0); FeatureXMLFile f; for (Size i = 0; i < ins.size(); ++i) { Size s = f.loadSize(ins[i]); if (s > max_count) { max_count = s; reference_index = i; } } // Load reference map and input it to the algorithm UInt64 ref_id; Size ref_size; std::vector<PeptideIdentification> ref_pepids; std::vector<ProteinIdentification> ref_protids; { FeatureMap map_ref; FeatureXMLFile f_fxml_tmp; f_fxml_tmp.getOptions().setLoadConvexHull(false); f_fxml_tmp.getOptions().setLoadSubordinates(false); f_fxml_tmp.load(ins[reference_index], map_ref); algorithm->setReference(reference_index, map_ref); ref_id = map_ref.getUniqueId(); ref_size = map_ref.size(); ref_pepids = map_ref.getUnassignedPeptideIdentifications(); ref_protids = map_ref.getProteinIdentifications(); } ConsensusMap dummy; // go through all input files and add them to the result one by one for (Size i = 0; i < ins.size(); ++i) { FeatureXMLFile f_fxml_tmp; FeatureMap tmp_map; f_fxml_tmp.getOptions().setLoadConvexHull(false); f_fxml_tmp.getOptions().setLoadSubordinates(false); f_fxml_tmp.load(ins[i], tmp_map); // copy over information on the primary MS run StringList ms_runs; tmp_map.getPrimaryMSRunPath(ms_runs); ms_run_locations.insert(ms_run_locations.end(), ms_runs.begin(), ms_runs.end()); if (i != reference_index) { algorithm->addToGroup(i, tmp_map); // store some meta-data about the maps in the "dummy" object -> try to // keep the same order as they were given in the input independent of // which map is the reference. dummy.getColumnHeaders()[i].filename = ins[i]; dummy.getColumnHeaders()[i].size = tmp_map.size(); dummy.getColumnHeaders()[i].unique_id = tmp_map.getUniqueId(); // add protein identifications to result map dummy.getProteinIdentifications().insert( dummy.getProteinIdentifications().end(), tmp_map.getProteinIdentifications().begin(), tmp_map.getProteinIdentifications().end()); // add unassigned peptide identifications to result map dummy.getUnassignedPeptideIdentifications().insert( dummy.getUnassignedPeptideIdentifications().end(), tmp_map.getUnassignedPeptideIdentifications().begin(), tmp_map.getUnassignedPeptideIdentifications().end()); } else { // copy the meta-data from the refernce map dummy.getColumnHeaders()[i].filename = ins[i]; dummy.getColumnHeaders()[i].size = ref_size; dummy.getColumnHeaders()[i].unique_id = ref_id; // add protein identifications to result map dummy.getProteinIdentifications().insert( dummy.getProteinIdentifications().end(), ref_protids.begin(), ref_protids.end()); // add unassigned peptide identifications to result map dummy.getUnassignedPeptideIdentifications().insert( dummy.getUnassignedPeptideIdentifications().end(), ref_pepids.begin(), ref_pepids.end()); } } // get the resulting map out_map = algorithm->getResultMap(); // // Copy back meta-data (Protein / Peptide ids / File descriptions) // // add protein identifications to result map out_map.getProteinIdentifications().insert( out_map.getProteinIdentifications().end(), dummy.getProteinIdentifications().begin(), dummy.getProteinIdentifications().end()); // add unassigned peptide identifications to result map out_map.getUnassignedPeptideIdentifications().insert( out_map.getUnassignedPeptideIdentifications().end(), dummy.getUnassignedPeptideIdentifications().begin(), dummy.getUnassignedPeptideIdentifications().end()); out_map.setColumnHeaders(dummy.getColumnHeaders()); // canonical ordering for checking the results, and the ids have no real meaning anyway // the way this was done in DelaunayPairFinder and StablePairFinder // -> the same ordering as FeatureGroupingAlgorithmUnlabeled::group applies! out_map.sortByMZ(); out_map.updateRanges(); } else { vector<ConsensusMap> maps(ins.size()); ConsensusXMLFile f; for (Size i = 0; i < ins.size(); ++i) { f.load(ins[i], maps[i]); StringList ms_runs; maps[i].getPrimaryMSRunPath(ms_runs); ms_run_locations.insert(ms_run_locations.end(), ms_runs.begin(), ms_runs.end()); } // group algorithm->FeatureGroupingAlgorithm::group(maps, out_map); // set file descriptions: bool keep_subelements = getFlag_("keep_subelements"); if (!keep_subelements) { for (Size i = 0; i < ins.size(); ++i) { out_map.getColumnHeaders()[i].filename = ins[i]; out_map.getColumnHeaders()[i].size = maps[i].size(); out_map.getColumnHeaders()[i].unique_id = maps[i].getUniqueId(); } } else { // components of the output map are not the input maps themselves, but // the components of the input maps: algorithm->transferSubelements(maps, out_map); } } // assign unique ids out_map.applyMemberFunction(&UniqueIdInterface::setUniqueId); // annotate output with data processing info addDataProcessing_(out_map, getProcessingInfo_(DataProcessing::FEATURE_GROUPING)); out_map.setPrimaryMSRunPath(ms_run_locations); // write output ConsensusXMLFile().store(out, out_map); // some statistics map<Size, UInt> num_consfeat_of_size; for (ConsensusMap::const_iterator cmit = out_map.begin(); cmit != out_map.end(); ++cmit) { ++num_consfeat_of_size[cmit->size()]; } LOG_INFO << "Number of consensus features:" << endl; for (map<Size, UInt>::reverse_iterator i = num_consfeat_of_size.rbegin(); i != num_consfeat_of_size.rend(); ++i) { LOG_INFO << " of size " << setw(2) << i->first << ": " << setw(6) << i->second << endl; } LOG_INFO << " total: " << setw(6) << out_map.size() << endl; delete algorithm; return EXECUTION_OK; }
void group(const vector< FeatureMap >&, ConsensusMap& map) override { map.getColumnHeaders()[0].filename = "bla"; map.getColumnHeaders()[0].size = 5; }
FGA* nullPointer = nullptr; START_SECTION((FeatureGroupingAlgorithm())) ptr = new FGA(); TEST_NOT_EQUAL(ptr, nullPointer) END_SECTION START_SECTION((virtual ~FeatureGroupingAlgorithm())) delete ptr; END_SECTION START_SECTION((virtual void group(const vector< FeatureMap > &maps, ConsensusMap &out)=0)) FGA fga; vector< FeatureMap > in; ConsensusMap map; fga.group(in,map); TEST_EQUAL(map.getColumnHeaders()[0].filename, "bla") END_SECTION START_SECTION((static void registerChildren())) { TEST_STRING_EQUAL(Factory<FeatureGroupingAlgorithm>::registeredProducts()[0],FeatureGroupingAlgorithmLabeled::getProductName()); TEST_STRING_EQUAL(Factory<FeatureGroupingAlgorithm>::registeredProducts()[1],FeatureGroupingAlgorithmUnlabeled::getProductName()); TEST_EQUAL(Factory<FeatureGroupingAlgorithm>::registeredProducts().size(), 4) } END_SECTION START_SECTION((void transferSubelements(const vector<ConsensusMap>& maps, ConsensusMap& out) const)) { vector<ConsensusMap> maps(2); maps[0].getColumnHeaders()[0].filename = "file1"; maps[0].getColumnHeaders()[0].size = 1;
Param p; p.setValue("rt_estimate","false"); p.setValue("rt_pair_dist",0.4); p.setValue("rt_dev_low",1.0); p.setValue("rt_dev_high",2.0); p.setValue("mz_pair_dists",ListUtils::create<double>(4.0)); p.setValue("mz_dev",0.6); fga.setParameters(p); //test exception (no file name set in out) TEST_EXCEPTION(Exception::IllegalArgument, fga.group(in,out)); out.getColumnHeaders()[5].label = "light"; out.getColumnHeaders()[5].filename = "filename"; out.getColumnHeaders()[8] = out.getColumnHeaders()[5]; out.getColumnHeaders()[8].label = "heavy"; fga.group(in,out); TEST_EQUAL(out.size(),1) TEST_REAL_SIMILAR(out[0].getQuality(),0.959346); TEST_EQUAL(out[0].size(),2) ConsensusFeature::HandleSetType::const_iterator it = out[0].begin(); TEST_REAL_SIMILAR(it->getMZ(),1.0f); TEST_REAL_SIMILAR(it->getRT(),1.0f); ++it; TEST_REAL_SIMILAR(it->getMZ(),5.0f); TEST_REAL_SIMILAR(it->getRT(),1.5f); END_SECTION