void IDMapper::getIDDetails_(const PeptideIdentification & id, DoubleReal & rt_pep, DoubleList & mz_values, IntList & charges, bool use_avg_mass) const { mz_values.clear(); charges.clear(); rt_pep = id.getMetaValue("RT"); // collect m/z values of pepId if (param_.getValue("mz_reference") == "precursor") // use precursor m/z of pepId { mz_values.push_back(id.getMetaValue("MZ")); } for (vector<PeptideHit>::const_iterator hit_it = id.getHits().begin(); hit_it != id.getHits().end(); ++hit_it) { Int charge = hit_it->getCharge(); charges.push_back(charge); if (param_.getValue("mz_reference") == "peptide") // use mass of each pepHit (assuming H+ adducts) { DoubleReal mass = use_avg_mass ? hit_it->getSequence().getAverageWeight(Residue::Full, charge) : hit_it->getSequence().getMonoWeight(Residue::Full, charge); mz_values.push_back( mass / (DoubleReal) charge); } } }
SS DFStatement::buildSS( const StringList &inVarNameList, const DoubleList &inCoefList, const StringList &outVarNameList, const DoubleList &outCoefList ) { // // FIRST, BUILD THE FILTER EQUATION // StringList::const_iterator inVarNameItr = inVarNameList.begin(); DoubleList::const_iterator inCoefItr = inCoefList.begin(); StringList::const_iterator outVarNameItr = outVarNameList.begin(); DoubleList::const_iterator outCoefItr = outCoefList.begin(); BE be( 0, "+", BE( *inCoefItr, "*", *inVarNameItr ) ); while( ++inVarNameItr != inVarNameList.end() ) { (void)++inCoefItr; be = BE( be, "+", BE( *inCoefItr, "*", *inVarNameItr ) ); } while( ++outVarNameItr != outVarNameList.end() ) { (void)++outCoefItr; be = BE( be, "-", BE( *outCoefItr, "*", *outVarNameItr ) ); } be = BE( be, "/", outCoefList.front() ); be = BE( outVarNameList.front(), "=", be ); // // SHIFT THE VARIABLES // SS ss( IE( 1 ), be ); (void)--inVarNameItr; while( inVarNameItr != inVarNameList.begin() ) { StringList::const_iterator nxtInVarNameItr = inVarNameItr; (void)--nxtInVarNameItr; ss = SS( ss, BE( *inVarNameItr, "=", *nxtInVarNameItr ) ); inVarNameItr = nxtInVarNameItr; } (void)--outVarNameItr; while( outVarNameItr != outVarNameList.begin() ) { StringList::const_iterator nxtOutVarNameItr = outVarNameItr; (void)--nxtOutVarNameItr; ss = SS( ss, BE( *outVarNameItr, "=", *nxtOutVarNameItr ) ); outVarNameItr = nxtOutVarNameItr; } return ss; }
void ProteinResolver::computeIntensityOfMSD_(vector<MSDGroup> & msd_groups) { // iteriert ueber alles msd gruppe for (vector<MSDGroup>::iterator group = msd_groups.begin(); group != msd_groups.end(); ++group) { DoubleList intensities; // iterierere ueber peptide entry (peptide identification), intensitaet (summe der einzelintensitaeten) for (list<PeptideEntry *>::iterator pep = group->peptides.begin(); pep != group->peptides.end(); ++pep) { intensities.push_back((*pep)->intensity); } // median von der list ist itensity der msd group group->intensity = Math::median(intensities.begin(), intensities.end()); } }
int main() { int position; int click; Data dt; DoubleList dlist; while(1) { cout << "Push data (press 1)\n"; cout << "Pop data (press 2)\n"; cout << "View data (press 3)\n"; cout << "Clean data (press 4)\n"; cout << "Is list empty? (press 5)\n"; cout << "Exit (press 0)"; cin >> click; if( click == 1) { system("cls"); dt = dataInput(dt); position = positionInput(position); dlist.push(dt, position); } if( click == 2) { system("cls"); dt = dataInput(dt); position = positionInput(position); dlist.pop(position); } if( click == 3) { system("cls"); dlist.view(); } if( click == 4) { system("cls"); dlist.clean(); } if( click == 5) { system("cls"); dlist.isEmpty(); } if( click == 0) { system("cls"); exit(0); } } return 0; }
void XQuestResultXMLFile::writeXQuestXML(String out_file, String base_name, const std::vector< PeptideIdentification >& peptide_ids, const std::vector< std::vector< OPXLDataStructs::CrossLinkSpectrumMatch > >& all_top_csms, const PeakMap& spectra, String precursor_mass_tolerance_unit, String fragment_mass_tolerance_unit, double precursor_mass_tolerance, double fragment_mass_tolerance, double fragment_mass_tolerance_xlinks, String cross_link_name, double cross_link_mass_light, DoubleList cross_link_mass_mono_link, String in_fasta, String in_decoy_fasta, StringList cross_link_residue1, StringList cross_link_residue2, double cross_link_mass_iso_shift, String enzyme_name, Size missed_cleavages) { String spec_xml_name = base_name + "_matched"; std::cout << "Writing xquest.xml to " << out_file << std::endl; std::ofstream xml_file; xml_file.open(out_file.c_str(), std::ios::trunc); // XML Header xml_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; xml_file << "<?xml-stylesheet type=\"text/xsl\" href=\"\"?>" << std::endl; DateTime time= DateTime::now(); String timestring = time.getDate() + " " + time.getTime(); String mono_masses; if (cross_link_mass_mono_link.size() > 1) { for (Size k = 0; k < cross_link_mass_mono_link.size()-1; ++k) { mono_masses += String(cross_link_mass_mono_link[k]) + ", "; } mono_masses += cross_link_mass_mono_link[cross_link_mass_mono_link.size()-1]; } String aarequired1, aarequired2; for (Size k= 0; k < cross_link_residue1.size()-1; ++k) { aarequired1 += cross_link_residue1[k] + ","; } aarequired1 += cross_link_residue1[cross_link_residue1.size()-1]; for (Size k= 0; k < cross_link_residue2.size()-1; ++k) { aarequired2 += cross_link_residue2[k] + ","; } aarequired2 += cross_link_residue2[cross_link_residue2.size()-1]; xml_file << "<xquest_results xquest_version=\"OpenPepXL 1.0\" date=\"" << timestring << "\" author=\"Eugen Netz, Timo Sachsenberg\" tolerancemeasure_ms1=\"" << precursor_mass_tolerance_unit << "\" tolerancemeasure_ms2=\"" << fragment_mass_tolerance_unit << "\" ms1tolerance=\"" << precursor_mass_tolerance << "\" ms2tolerance=\"" << fragment_mass_tolerance << "\" xlink_ms2tolerance=\"" << fragment_mass_tolerance_xlinks << "\" crosslinkername=\"" << cross_link_name << "\" xlinkermw=\"" << cross_link_mass_light << "\" monolinkmw=\"" << mono_masses << "\" database=\"" << in_fasta << "\" database_dc=\"" << in_decoy_fasta << "\" xlinktypes=\"1111\" AArequired1=\"" << aarequired1 << "\" AArequired2=\"" << aarequired2 << "\" cp_isotopediff=\"" << cross_link_mass_iso_shift << "\" enzyme_name=\"" << enzyme_name << "\" outputpath=\"" << spec_xml_name << "\" Iontag_charges_for_index=\"1\" missed_cleavages=\"" << missed_cleavages << "\" ntermxlinkable=\"0\" CID_match2ndisotope=\"1" << "\" variable_mod=\"TODO\" nocutatxlink=\"1\" xcorrdelay=\"5\" >" << std::endl; for (std::vector< std::vector< OPXLDataStructs::CrossLinkSpectrumMatch > >::const_iterator top_csms_spectrum = all_top_csms.begin(); top_csms_spectrum != all_top_csms.end(); ++top_csms_spectrum) { std::vector< OPXLDataStructs::CrossLinkSpectrumMatch > top_vector = (*top_csms_spectrum); if (top_vector.empty()) { continue; } // Spectrum Data, for each spectrum Size scan_index_light = top_vector[0].scan_index_light; Size scan_index_heavy = scan_index_light; if (cross_link_mass_iso_shift > 0) { scan_index_heavy = top_vector[0].scan_index_heavy; } const PeakSpectrum& spectrum_light = spectra[scan_index_light]; double precursor_charge = spectrum_light.getPrecursors()[0].getCharge(); double precursor_mz = spectrum_light.getPrecursors()[0].getMZ(); double precursor_rt = spectrum_light.getRT(); double precursor_mass = precursor_mz * static_cast<double>(precursor_charge) - static_cast<double>(precursor_charge) * Constants::PROTON_MASS_U; double precursor_mz_heavy = spectra[scan_index_heavy].getPrecursors()[0].getMZ(); double precursor_rt_heavy = spectra[scan_index_heavy].getRT(); // print information about new peak to file (starts with <spectrum_search..., ends with </spectrum_search> String spectrum_light_name = base_name + ".light." + scan_index_light; String spectrum_heavy_name = base_name + ".heavy." + scan_index_heavy; String spectrum_name = spectrum_light_name + String("_") + spectrum_heavy_name; String rt_scans = String(precursor_rt) + ":" + String(precursor_rt_heavy); String mz_scans = String(precursor_mz) + ":" + String(precursor_mz_heavy); // Mean ion intensity (light spectrum, TODO add heavy spectrum?) double mean_intensity= 0; if (cross_link_mass_iso_shift > 0) { for (SignedSize j = 0; j < static_cast<SignedSize>(spectrum_light.size()); ++j) mean_intensity += spectrum_light[j].getIntensity(); for (SignedSize j = 0; j < static_cast<SignedSize>(spectra[scan_index_heavy].size()); ++j) mean_intensity += spectra[scan_index_heavy][j].getIntensity(); mean_intensity = mean_intensity / (spectrum_light.size() + spectra[scan_index_heavy].size()); } else { for (SignedSize j = 0; j < static_cast<SignedSize>(spectrum_light.size()); ++j) mean_intensity += spectrum_light[j].getIntensity(); mean_intensity = mean_intensity / spectrum_light.size(); } xml_file << "<spectrum_search spectrum=\"" << spectrum_name << "\" mean_ionintensity=\"" << mean_intensity << "\" ionintensity_stdev=\"" << "TODO" << "\" addedMass=\"" << "TODO" << "\" iontag_ncandidates=\"" << "TODO" << "\" apriori_pmatch_common=\"" << "TODO" << "\" apriori_pmatch_xlink=\"" << "TODO" << "\" ncommonions=\"" << "TODO" << "\" nxlinkions=\"" << "TODO" << "\" mz_precursor=\"" << precursor_mz << "\" scantype=\"" << "light_heavy" << "\" charge_precursor=\"" << precursor_charge << "\" Mr_precursor=\"" << precursor_mass << "\" rtsecscans=\"" << rt_scans << "\" mzscans=\"" << mz_scans << "\" >" << std::endl; for (std::vector< OPXLDataStructs::CrossLinkSpectrumMatch>::const_iterator top_csm = top_csms_spectrum->begin(); top_csm != top_csms_spectrum->end(); ++top_csm) { String xltype = "monolink"; String structure = top_csm->cross_link.alpha.toUnmodifiedString(); String letter_first = structure.substr(top_csm->cross_link.cross_link_position.first, 1); double weight = top_csm->cross_link.alpha.getMonoWeight() + top_csm->cross_link.cross_linker_mass; int alpha_pos = top_csm->cross_link.cross_link_position.first + 1; int beta_pos = top_csm->cross_link.cross_link_position.second + 1; String topology = String("a") + alpha_pos; String id = structure + String("-") + letter_first + alpha_pos + String("-") + static_cast<int>(top_csm->cross_link.cross_linker_mass); if (top_csm->cross_link.getType() == OPXLDataStructs::CROSS) { xltype = "xlink"; structure += "-" + top_csm->cross_link.beta.toUnmodifiedString(); topology += String("-b") + beta_pos; weight += top_csm->cross_link.beta.getMonoWeight(); id = structure + "-" + topology; } else if (top_csm->cross_link.getType() == OPXLDataStructs::LOOP) { xltype = "intralink"; topology += String("-b") + beta_pos; String letter_second = structure.substr(top_csm->cross_link.cross_link_position.second, 1); id = structure + String("-") + letter_first + alpha_pos + String("-") + letter_second + beta_pos; } // Error calculation double cl_mz = (weight + (static_cast<double>(precursor_charge) * Constants::PROTON_MASS_U)) / static_cast<double>(precursor_charge); double error = precursor_mz - cl_mz; double rel_error = (error / cl_mz) / 1e-6; PeptideIdentification pep_id = peptide_ids[top_csm->peptide_id_index]; std::vector< PeptideHit > pep_hits = pep_id.getHits(); String prot_alpha = pep_hits[0].getPeptideEvidences()[0].getProteinAccession(); if (pep_hits[0].getPeptideEvidences().size() > 1) { for (Size i = 1; i < pep_hits[0].getPeptideEvidences().size(); ++i) { prot_alpha = prot_alpha + "," + pep_hits[0].getPeptideEvidences()[i].getProteinAccession(); } } String prot_beta = ""; if (pep_hits.size() > 1) { prot_beta= pep_hits[1].getPeptideEvidences()[0].getProteinAccession(); if (pep_hits[1].getPeptideEvidences().size() > 1) { for (Size i = 1; i < pep_hits[1].getPeptideEvidences().size(); ++i) { prot_alpha = prot_alpha + "," + pep_hits[1].getPeptideEvidences()[i].getProteinAccession(); } } } // Hit Data, for each cross-link to Spectrum Hit (e.g. top 5 per spectrum) xml_file << "<search_hit search_hit_rank=\"" <<top_csm->rank << "\" id=\"" << id << "\" type=\"" << xltype << "\" structure=\"" << structure << "\" seq1=\"" << top_csm->cross_link.alpha.toUnmodifiedString() << "\" seq2=\"" << top_csm->cross_link.beta.toUnmodifiedString() << "\" prot1=\"" << prot_alpha << "\" prot2=\"" << prot_beta << "\" topology=\"" << topology << "\" xlinkposition=\"" << (top_csm->cross_link.cross_link_position.first+1) << "," << (top_csm->cross_link.cross_link_position.second+1) << "\" Mr=\"" << weight << "\" mz=\"" << cl_mz << "\" charge=\"" << precursor_charge << "\" xlinkermass=\"" << top_csm->cross_link.cross_linker_mass << "\" measured_mass=\"" << precursor_mass << "\" error=\"" << error << "\" error_rel=\"" << rel_error << "\" xlinkions_matched=\"" << (top_csm->matched_xlink_alpha + top_csm->matched_xlink_beta) << "\" backboneions_matched=\"" << (top_csm->matched_common_alpha + top_csm->matched_common_beta) << "\" weighted_matchodds_mean=\"" << "TODO" << "\" weighted_matchodds_sum=\"" << "TODO" << "\" match_error_mean=\"" << "TODO" << "\" match_error_stdev=\"" << "TODO" << "\" xcorrx=\"" << top_csm->xcorrx_max << "\" xcorrb=\"" << top_csm->xcorrc_max << "\" match_odds=\"" <<top_csm->match_odds << "\" prescore=\"" << top_csm->pre_score << "\" prescore_alpha=\"" << "TODO" << "\" prescore_beta=\"" << "TODO" << "\" match_odds_alphacommon=\"" << "TODO" << "\" match_odds_betacommon=\"" << "TODO" << "\" match_odds_alphaxlink=\"" << "TODO" << "\" match_odds_betaxlink=\"" << "TODO" << "\" num_of_matched_ions_alpha=\"" << (top_csm->matched_common_alpha + top_csm->matched_xlink_alpha) << "\" num_of_matched_ions_beta=\"" << (top_csm->matched_common_beta + top_csm->matched_xlink_beta) << "\" num_of_matched_common_ions_alpha=\"" << top_csm->matched_common_alpha << "\" num_of_matched_common_ions_beta=\"" << top_csm->matched_common_beta << "\" num_of_matched_xlink_ions_alpha=\"" << top_csm->matched_xlink_alpha << "\" num_of_matched_xlink_ions_beta=\"" << top_csm->matched_xlink_beta << "\" xcorrall=\"" << "TODO" << "\" TIC=\"" << top_csm->percTIC << "\" TIC_alpha=\"" << "TODO" << "\" TIC_beta=\"" << "TODO" << "\" wTIC=\"" << top_csm->wTIC << "\" intsum=\"" << top_csm->int_sum * 100 << "\" apriori_match_probs=\"" << "TODO" << "\" apriori_match_probs_log=\"" << "TODO" << "\" HyperCommon=\"" << top_csm->HyperCommon << "\" HyperXLink=\"" << top_csm->HyperXlink << "\" HyperAlpha=\"" << top_csm->HyperAlpha << "\" HyperBeta=\"" << top_csm->HyperBeta << "\" HyperBoth=\"" << top_csm->HyperBoth << "\" PScoreCommon=\"" << top_csm->PScoreCommon << "\" PScoreXLink=\"" << top_csm->PScoreXlink << "\" PScoreAlpha=\"" << top_csm->PScoreAlpha << "\" PScoreBeta=\"" << top_csm->PScoreBeta << "\" PScoreBoth=\"" << top_csm->PScoreBoth << "\" series_score_mean=\"" << "TODO" << "\" annotated_spec=\"" << "" << "\" score=\"" << top_csm->score << "\" >" << std::endl; xml_file << "</search_hit>" << std::endl; } // Closing tag for Spectrum xml_file << "</spectrum_search>" << std::endl; } // Closing tag for results (end of file) xml_file << "</xquest_results>" << std::endl; xml_file.close(); return; }
bool Pattern::Match(const DoubleTimeList::const_iterator& current, const DoubleTimeList::const_iterator& end) const { DoubleTimeList points; size_t positionCount = Size(); auto cit = current; size_t i = 0; while(i < positionCount && cit != end) { points.push_back(DoubleTimePoint((*cit).value, i++)); cit++; } if (i < positionCount) { // points not enough for matching return false; } // sort the points by value struct PointCompare { bool operator() (DoubleTimePoint p1,DoubleTimePoint p2) { return p1.value < p2.value; } } compareObj; std::sort(points.begin(), points.end(), compareObj); // check each groups auto gcit = groups_.begin(); auto pcit = points.begin(); double max_in_last_group = -DBL_MAX; while(gcit != groups_.end() && pcit != points.end()) { PointsGroup group = *gcit; DoubleList values; // check fixed delta double delta = std::fabs(((*pcit).value - max_in_last_group) / ((*pcit).value + max_in_last_group)); if (delta < fixed_delta_) return false; // make sure points in the group size_t i = 0; size_t group_size = group.Size(); while (i < group_size && pcit != points.end()) { if (!group.In((int)(*pcit).position)) return false; values.push_back((*pcit).value); pcit++; i++; } // check adjacent for AdjacentGroup if (group.IsAdjacentGroup()) { if (!group.CheckAdjacence(&values)) return false; } max_in_last_group = values[values.size() - 1]; gcit++; } return true; }
int main() { LinkedList list; list.insertHead(45); list.insertHead(23); list.print(); list.insertTail(456); list.insertTail(234); list.insertTail(34); list.print(); cout << list.remove(456) << endl; list.print(); list.removeHead(); list.removeTail(); list.print(); cout << endl; DoubleList dlist; dlist.push_back(45); dlist.push_back(3456); dlist.push_front(12); dlist.push_front(2); cout << dlist.front() << ' ' << dlist.back() << endl; dlist.print(); dlist.pop_back(); dlist.pop_front(); dlist.print(); return 0; }
using namespace OpenMS::Math; ///////////////////////////////////////////////////////////// START_TEST( StatisticFunctions, "$Id$" ); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// START_SECTION([EXTRA](template <typename IteratorType> static DoubleReal sum(IteratorType begin, IteratorType end))) { int x[] = {-1, 0, 1, 2, 3}; TEST_EQUAL(int(Math::sum(x, x + 5)), 5); TEST_EQUAL(int(Math::sum(x, x)), 0); DoubleList y; y << -1.0 << -0.5 << 0.0 << 0.5 << 1.0 << 1.5 << 2.0; TEST_REAL_SIMILAR(Math::sum(y.begin(), y.end()), 3.5); } END_SECTION START_SECTION([EXTRA](template <typename IteratorType> static DoubleReal mean(IteratorType begin, IteratorType end))) { int x[] = {-1, 0, 1, 2, 3}; TEST_EQUAL(Math::mean(x, x + 5), 1); TEST_EXCEPTION(Exception::InvalidRange, Math::mean(x, x)); DoubleList y; y << -1.0 << -0.5 << 0.0 << 0.5 << 1.0 << 1.5 << 2.0; TEST_REAL_SIMILAR(Math::mean(y.begin(), y.end()), 0.5); }
TEST_EQUAL(intlist.size(),3); TEST_EQUAL(intlist[0], 1) TEST_EQUAL(intlist[1], 22) TEST_EQUAL(intlist[2], 333) TEST_EQUAL(p2.getValue("intlist2").valueType(),DataValue::INT_LIST) intlist = p2.getValue("intlist2"); TEST_EQUAL(intlist.size(),0) TEST_EQUAL(p2.getValue("intlist3").valueType(),DataValue::INT_LIST) intlist = p2.getValue("intlist3"); TEST_EQUAL(intlist.size(),1) TEST_EQUAL(intlist[0],1) TEST_EQUAL(p2.getValue("doublelist").valueType(), DataValue::DOUBLE_LIST) DoubleList doublelist = p2.getValue("doublelist"); TEST_EQUAL(doublelist.size(),3); TEST_EQUAL(doublelist[0], 1.22) TEST_EQUAL(doublelist[1], 2.33) TEST_EQUAL(doublelist[2], 4.55) TEST_EQUAL(p2.getValue("doublelist2").valueType(),DataValue::DOUBLE_LIST) doublelist = p2.getValue("doublelist2"); TEST_EQUAL(doublelist.size(),0) TEST_EQUAL(p2.getValue("doublelist3").valueType(),DataValue::DOUBLE_LIST) doublelist = p2.getValue("doublelist3"); TEST_EQUAL(doublelist.size(),1) TEST_EQUAL(doublelist[0],1.4) END_SECTION
TEST(settings_types, DoubleList) { DoubleList l; { ASSERT_TRUE(l.set_default("0.0,1.1,2.2,3.3,4.4,5.5")); ASSERT_TRUE(l.is_default()); ASSERT_EQ(6, l.size()); for (int i = 0; i < l.size(); ++i) { ASSERT_EQ(double(i)+double(i)/10., l.values()[i]); } ASSERT_STREQ("0.0,1.1,2.2,3.3,4.4,5.5", l.get_value()); } { ASSERT_TRUE(l.set_value("0.01234567891011, 666.6")); ASSERT_FALSE(l.is_default()); ASSERT_EQ(2, l.size()); ASSERT_DOUBLE_EQ(0.01234567891011, l.values()[0]); ASSERT_EQ(666.6, l.values()[1]); // FIXME(BM) string printing to not enough decimal places! EXPECT_STREQ("0.01234567891011,666.6", l.get_value()); } }
int main() { DoubleList<int> list; for(int i=0;i<20;i++){ list.Insert(i*3,i); } cout<<"the Length of the list is "<<list.Length()<<endl; list.Print(); for(int j=0;j<5;j++){ list.Insert(3,j*3); } cout<<"the Length of the list is "<<list.Length()<<endl; list.Print(); list.Remove(5); cout<<"the Length of the list is "<<list.Length()<<endl; list.Print(); cout<<list.FindData(54)->GetData()<<endl; cout<<"The third element is "<<list.Get(3)<<endl; list.MakeEmpty(); cout<<"the Length of the list is "<<list.Length()<<endl; list.Print(); return 0; }