35 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_ISOTOPEWAVELETTRANSFORM_H 36 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_ISOTOPEWAVELETTRANSFORM_H 49 #include <boost/math/special_functions/bessel.hpp> 58 #pragma clang diagnostic push 59 #pragma clang diagnostic ignored "-Wfloat-equal" 60 #pragma clang diagnostic ignored "-Wconversion" 61 #pragma clang diagnostic ignored "-Wshorten-64-to-32" 69 template <
typename PeakType>
89 typedef std::multimap<UInt, BoxElement>
Box;
103 reference_(NULL), trans_intens_(NULL)
109 reference_(reference)
111 trans_intens_ =
new std::vector<float>(reference_->size(), 0.0);
117 delete (trans_intens_);
122 delete (trans_intens_);
123 trans_intens_ = NULL;
131 return reference_->getRT();
137 return (*reference_)[i].getMZ();
143 return (*reference_)[i].getIntensity();
149 return (*trans_intens_)[i];
155 (*trans_intens_)[i] =
intens;
161 return trans_intens_->size();
178 inline typename MSSpectrum::const_iterator
MZBegin(
const double mz)
const 180 return reference_->MZBegin(mz);
185 inline typename MSSpectrum::const_iterator
MZEnd(
const double mz)
const 187 return reference_->MZEnd(mz);
192 inline typename MSSpectrum::const_iterator
end()
const 194 return reference_->end();
199 inline typename MSSpectrum::const_iterator
begin()
const 201 return reference_->begin();
256 const double ampl_cutoff,
const bool check_PPMs);
260 #ifdef OPENMS_HAS_CUDA 263 virtual int initializeScanCuda(
const MSSpectrum& scan,
const UInt c = 0);
266 virtual void finalizeScanCuda();
289 const double ampl_cutoff,
const bool check_PPMs);
304 const UInt RT_votes_cutoff,
const Int front_bound = -1,
const Int end_bound = -1);
325 inline double getLinearInterpolation(
const typename MSSpectrum::const_iterator& left_iter,
const double mz_pos,
const typename MSSpectrum::const_iterator& right_iter)
327 return left_iter->getIntensity() + (right_iter->getIntensity() - left_iter->getIntensity()) / (right_iter->getMZ() - left_iter->getMZ()) * (mz_pos - left_iter->getMZ());
336 inline double getLinearInterpolation(
const double mz_a,
const double intens_a,
const double mz_pos,
const double mz_b,
const double intens_b)
338 return intens_a + (intens_b - intens_a) / (mz_b - mz_a) * (mz_pos - mz_a);
381 const double seed_mz,
const UInt c,
const double ampl_cutoff);
390 const double seed_mz,
const UInt c,
const double ampl_cutoff);
401 const UInt c,
const UInt scan_index,
const bool check_PPMs,
const double transintens,
const double prev_score);
411 const UInt c,
const UInt scan_index,
const bool check_PPMs,
const double transintens,
const double prev_score);
455 const double intens,
const double rt,
const UInt MZ_begin,
const UInt MZ_end);
470 const UInt scan_index,
const UInt c,
const bool check_PPMs);
477 const UInt scan_index,
const UInt c,
const bool check_PPMs);
491 double old_frac_mass = c_mass - (
Int)(c_mass);
493 double new_frac_mass = new_mass - (
Int)(new_mass);
495 if (new_frac_mass - old_frac_mass > 0.5)
500 if (new_frac_mass - old_frac_mass < -0.5)
511 inline double getPPMs_(
const double mass_a,
const double mass_b)
const 513 return fabs(mass_a - mass_b) / (0.5 * (mass_a + mass_b)) * 1e6;
535 template <
typename PeakType>
541 template <
typename PeakType>
547 template <
typename PeakType>
553 template <
typename PeakType>
559 template <
typename PeakType>
562 tmp_boxes_ =
new std::vector<std::multimap<double, Box> >(1);
571 template <
typename PeakType>
578 tmp_boxes_ =
new std::vector<std::multimap<double, Box> >(max_charge);
579 if (max_scan_size <= 0)
590 psi_.reserve(to_reserve);
591 prod_.reserve(to_reserve);
592 xs_.reserve(to_reserve);
597 template <
typename PeakType>
603 template <
typename PeakType>
606 Int spec_size((
Int)c_ref.size());
610 double value, T_boundary_left, T_boundary_right, old, c_diff, current, old_pos, my_local_MZ, my_local_lambda, origin, c_mz;
612 for (
Int my_local_pos = 0; my_local_pos < spec_size; ++my_local_pos)
615 old = 0; old_pos = (my_local_pos -
from_max_to_left_ - 1 >= 0) ? c_ref[my_local_pos - from_max_to_left_ - 1].getMZ() : c_ref[0].getMZ() -
min_spacing_;
620 for (
Int current_conv_pos = std::max(0, my_local_pos - from_max_to_left_); c_diff < T_boundary_right; ++current_conv_pos)
622 if (current_conv_pos >= spec_size)
628 c_mz = c_ref[current_conv_pos].getMZ();
629 c_diff = c_mz + origin;
632 current = c_diff > T_boundary_left && c_diff <= T_boundary_right ?
IsotopeWavelet::getValueByLambda(my_local_lambda, c_diff * charge + 1.) * c_ref[current_conv_pos].getIntensity() : 0;
634 value += 0.5 * (current + old) * (c_mz - old_pos);
642 c_trans[my_local_pos].setIntensity(value);
646 template <
typename PeakType>
649 Int spec_size((
Int)c_ref.size());
653 double value, T_boundary_left, T_boundary_right, c_diff, current, my_local_MZ, my_local_lambda, origin, c_mz;
655 for (
Int my_local_pos = 0; my_local_pos < spec_size; ++my_local_pos)
664 for (
Int current_conv_pos = std::max(0, my_local_pos -
from_max_to_left_); c_diff < T_boundary_right; ++current_conv_pos)
666 if (current_conv_pos >= spec_size)
671 c_mz = c_ref[current_conv_pos].getMZ();
672 c_diff = c_mz + origin;
675 current = c_diff > T_boundary_left && c_diff <= T_boundary_right ?
IsotopeWavelet::getValueByLambda(my_local_lambda, c_diff * charge + 1.) * c_ref[current_conv_pos].getIntensity() : 0;
680 c_trans[my_local_pos].setIntensity(value);
684 template <
typename PeakType>
689 Int wavelet_length = 0, quarter_length = 0;
694 typename MSSpectrum::const_iterator start_iter, end_iter;
698 start_iter = c_ref.
MZEnd(c_ref[i].getMZ());
699 end_iter = c_ref.
MZBegin(c_ref[i].getMZ() + c_mz_cutoff);
700 wavelet_length = std::max((
SignedSize) wavelet_length, distance(start_iter, end_iter) + 1);
702 quarter_length = std::max((
SignedSize) quarter_length, distance(end_iter, start_iter) + 1);
714 if (wavelet_length > (
Int) c_ref.size())
716 std::cout <<
"Warning: the extremal length of the wavelet is larger (" << wavelet_length <<
") than the number of data points (" << c_ref.size() <<
"). This might (!) severely affect the transform." << std::endl;
717 std::cout <<
"Minimal spacing: " <<
min_spacing_ << std::endl;
718 std::cout <<
"Warning/Error generated at scan with RT " << c_ref.
getRT() <<
"." << std::endl;
726 template <
typename PeakType>
730 for (
UInt c_conv_pos = 1; c_conv_pos < c_ref.size(); ++c_conv_pos)
736 template <
typename PeakType>
738 const MSSpectrum& ref,
const UInt scan_index,
const UInt c,
const double ampl_cutoff,
const bool check_PPMs)
740 Size scan_size(candidates.size());
742 typename MSSpectrum::const_iterator iter_start, iter_end, iter_p, seed_iter, iter2;
743 double mz_cutoff, seed_mz, c_av_intens = 0, c_score = 0, c_sd_intens = 0, threshold = 0, help_mz, share, share_pos, bwd, fwd;
747 diffed[0].setIntensity(0); diffed[scan_size - 1].setIntensity(0);
749 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 750 std::stringstream stream;
751 stream <<
"diffed_" << ref.
getRT() <<
"_" << c + 1 <<
".trans\0";
752 std::ofstream ofile(stream.str().c_str());
757 for (
UInt i = 0; i < scan_size - 2; ++i)
759 share = candidates[i + 1].getIntensity(), share_pos = candidates[i + 1].getMZ();
760 bwd = (share - candidates[i].getIntensity()) / (share_pos - candidates[i].getMZ());
761 fwd = (candidates[i + 2].getIntensity() - share) / (candidates[i + 2].getMZ() - share_pos);
763 if (!(bwd >= 0 && fwd <= 0) || share > ref[i + 1].getIntensity())
765 diffed[i + 1].setIntensity(0);
768 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 769 ofile << diffed[i + 1].getMZ() <<
"\t" << diffed[i + 1].getIntensity() << std::endl;
775 for (
UInt i = 0; i < scan_size - 2; ++i)
777 share = candidates[i + 1].getIntensity(), share_pos = candidates[i + 1].getMZ();
778 bwd = (share - candidates[i].getIntensity()) / (share_pos - candidates[i].getMZ());
779 fwd = (candidates[i + 2].getIntensity() - share) / (candidates[i + 2].getMZ() - share_pos);
781 if (!(bwd >= 0 && fwd <= 0))
783 diffed[i + 1].setIntensity(0);
786 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 787 ofile << diffed[i + 1].getMZ() <<
"\t" << diffed[i + 1].getIntensity() << std::endl;
791 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 800 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 801 std::stringstream stream2;
802 stream2 <<
"sorted_cpu_" << candidates.
getRT() <<
"_" << c + 1 <<
".trans\0";
803 std::ofstream ofile2(stream2.str().c_str());
804 for (iter = c_sorted_candidate.end() - 1; iter != c_sorted_candidate.begin(); --iter)
806 ofile2 << iter->getMZ() <<
"\t" << iter->getIntensity() << std::endl;
811 std::vector<UInt> processed(scan_size, 0);
821 threshold = ampl_cutoff * c_sd_intens + c_av_intens;
824 for (iter = c_sorted_candidate.end() - 1; iter != c_sorted_candidate.begin(); --iter)
826 if (iter->getIntensity() <= 0)
831 seed_mz = iter->getMZ();
832 seed_iter = ref.
MZBegin(seed_mz);
834 if (seed_iter == ref.end() || processed[distance(ref.begin(), seed_iter)])
845 iter_end = ref.
MZEnd(seed_iter, seed_mz + mz_cutoff / (c + 1.), ref.end());
846 if (iter_end == ref.end())
851 MZ_start = distance(ref.begin(), iter_start);
852 MZ_end = distance(ref.begin(), iter_end);
854 memset(&(processed[MZ_start]), 1,
sizeof(
UInt) * (MZ_end - MZ_start + 1));
858 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 859 if (trunc(seed_mz) == 874)
860 std::cout << seed_mz <<
"\t" << c_score << std::endl;
863 if (c_score <= 0 && c_score != -1000)
873 iter2 = candidates.
MZBegin(help_mz);
874 if (iter2 == candidates.end() || iter2 == candidates.begin())
882 if (iter2 != candidates.end())
889 iter2 = candidates.
MZBegin(help_mz);
890 if (iter2 == candidates.end() || iter2 == candidates.begin())
898 if (iter2 != candidates.end())
908 template <
typename PeakType>
910 const UInt peak_cutoff,
const double seed_mz,
const UInt c,
const double ampl_cutoff)
912 double c_score = 0, c_val;
913 typename MSSpectrum::const_iterator c_left_iter2, c_right_iter2;
914 Int signal_size((
Int)candidate.size());
919 Int p_h_ind = 1, end = 4 * (peak_cutoff - 1) - 1;
921 std::vector<double> positions(end);
922 for (
Int i = 0; i < end; ++i)
927 double l_score = 0, mid_val = 0;
928 Int start_index = distance(candidate.begin(), candidate.
MZBegin(positions[0])) - 1;
929 for (
Int v = 1; v <= end; ++v, ++p_h_ind)
933 if (start_index < signal_size - 1)
938 while (candidate[start_index].getMZ() < positions[v - 1]);
940 if (start_index <= 0 || start_index >= signal_size - 1)
945 c_left_iter2 = candidate.begin() + start_index - 1;
946 c_right_iter2 = c_left_iter2 + 1;
948 c_val = c_left_iter2->getIntensity() + (c_right_iter2->getIntensity() - c_left_iter2->getIntensity()) / (c_right_iter2->getMZ() - c_left_iter2->getMZ()) * (positions[v - 1] - c_left_iter2->getMZ());
950 if (v == (
int)(ceil(end / 2.)))
956 if (p_h_ind % 2 == 1)
959 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 960 if (trunc(seed_mz) == 874)
961 std::cout << -c_val << std::endl;
967 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 968 if (trunc(seed_mz) == 874)
969 std::cout << c_val << std::endl;
974 start_index = distance(candidate.begin(), c_left_iter2);
977 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 978 std::ofstream ofile_score(
"scores.dat", ios::app);
979 std::ofstream ofile_check_score(
"check_scores.dat", ios::app);
981 ofile_check_score.close();
984 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 985 if (trunc(seed_mz) == 874)
986 std::cout <<
"final_score: " << seed_mz <<
"\t" << c_score <<
"\t l_score: " << l_score <<
"\t" << c_score - l_score - mid_val <<
"\t" << c_score - mid_val <<
"\t" << ampl_cutoff << std::endl;
989 if (c_score - mid_val <= 0)
994 if (c_score - mid_val <= ampl_cutoff)
999 if (l_score <= 0 || c_score - l_score - mid_val <= 0)
1007 template <
typename PeakType>
1009 const UInt peak_cutoff,
const double seed_mz,
const UInt c,
const double ampl_cutoff)
1011 double c_score = 0, c_val;
1012 typename MSSpectrum::const_iterator c_left_iter2, c_right_iter2;
1016 Int p_h_ind = 1, end = 4 * (peak_cutoff - 1) - 1;
1018 std::vector<double> positions(end);
1019 for (
Int i = 0; i < end; ++i)
1024 double l_score = 0, mid_val = 0;
1025 Int start_index = distance(candidate.
begin(), candidate.
MZBegin(positions[0])) - 1;
1026 for (
Int v = 1; v <= end; ++v, ++p_h_ind)
1030 if (start_index < signal_size - 1)
1035 while (candidate.
getMZ(start_index) < positions[v - 1]);
1037 if (start_index <= 0 || start_index >= signal_size - 1)
1042 c_left_iter2 = candidate.
begin() + start_index - 1;
1043 c_right_iter2 = c_left_iter2 + 1;
1046 if (v == (
int)(ceil(end / 2.)))
1052 if (p_h_ind % 2 == 1)
1061 start_index = distance(candidate.
begin(), c_left_iter2);
1064 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1065 std::ofstream ofile_score(
"scores.dat", ios::app);
1066 std::ofstream ofile_check_score(
"check_scores.dat", ios::app);
1067 ofile_score << c_check_point <<
"\t" << c_score << std::endl;
1068 ofile_score.close();
1069 ofile_check_score.close();
1072 if (l_score <= 0 || c_score - l_score - mid_val <= 0 || c_score - mid_val <= ampl_cutoff)
1080 template <
typename PeakType>
1084 typename std::multimap<double, Box>::iterator iter;
1085 typename Box::iterator box_iter;
1086 std::vector<BoxElement> final_box;
1087 double c_mz, av_score = 0, av_mz = 0, av_intens = 0, av_abs_intens = 0, count = 0;
1088 double virtual_av_mz = 0, virtual_av_intens = 0, virtual_av_abs_intens = 0, virtual_count = 0;
1090 typename std::pair<double, double> c_extend;
1094 Box& c_box = iter->second;
1095 av_score = 0, av_mz = 0, av_intens = 0, av_abs_intens = 0, count = 0;
1096 virtual_av_mz = 0, virtual_av_intens = 0, virtual_av_abs_intens = 0, virtual_count = 0;
1099 for (box_iter = c_box.begin(); box_iter != c_box.end(); ++box_iter)
1101 if (box_iter->second.score == 0)
1106 c_mz = box_iter->second.mz;
1107 virtual_av_intens += box_iter->second.intens;
1108 virtual_av_abs_intens += fabs(box_iter->second.intens);
1109 virtual_av_mz += c_mz * fabs(box_iter->second.intens);
1114 c_mz = box_iter->second.mz;
1115 av_score += box_iter->second.score;
1116 av_intens += box_iter->second.intens;
1117 av_abs_intens += fabs(box_iter->second.intens);
1118 av_mz += c_mz * fabs(box_iter->second.intens);
1125 av_intens = virtual_av_intens / virtual_count;
1127 av_mz = virtual_av_mz / virtual_av_abs_intens;
1133 av_mz /= av_abs_intens;
1137 c_box_element.
mz = av_mz;
1138 c_box_element.
c =
c;
1139 c_box_element.
score = av_score;
1140 c_box_element.
intens = av_intens;
1142 c_box_element.
RT = c_box.begin()->second.RT;
1143 final_box.push_back(c_box_element);
1146 Size num_o_feature = final_box.size();
1147 if (num_o_feature == 0)
1154 std::vector<double> bwd_diffs(num_o_feature, 0);
1157 for (
Size i = 1; i < num_o_feature; ++i)
1159 bwd_diffs[i] = (final_box[i].intens - final_box[i - 1].intens) / (final_box[i].
mz - final_box[i - 1].
mz);
1162 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1163 std::ofstream ofile_bwd(
"bwd_cpu.dat");
1164 for (
Size i = 0; i < num_o_feature; ++i)
1166 ofile_bwd << final_box[i].mz <<
"\t" << bwd_diffs[i] << std::endl;
1172 for (
Size i = 0; i < num_o_feature - 1; ++i)
1174 while (i < num_o_feature - 2)
1176 if (final_box[i].
score > 0 || final_box[i].
score == -1000)
1181 if (bwd_diffs[i] > 0 && bwd_diffs[i + 1] < 0)
1191 template <
typename PeakType>
1194 double av_intens = 0;
1195 for (
UInt i = 0; i < scan.size(); ++i)
1197 if (scan[i].getIntensity() >= 0)
1199 av_intens += scan[i].getIntensity();
1202 return av_intens / (
double)scan.size();
1205 template <
typename PeakType>
1209 for (
UInt i = 0; i < scan.size(); ++i)
1211 if (scan[i].getIntensity() >= 0)
1213 intens = scan[i].getIntensity();
1217 return sqrt(res / (
double)(scan.size() - 1));
1220 template <
typename PeakType>
1223 std::vector<double> diffs(scan.size() - 1, 0);
1224 for (
UInt i = 0; i < scan.size() - 1; ++i)
1226 diffs[i] = scan[i + 1].getMZ() - scan[i].getMZ();
1229 sort(diffs.begin(), diffs.end());
1230 double av_MZ_spacing = 0;
1231 for (
UInt i = 0; i < diffs.size() / 2; ++i)
1233 av_MZ_spacing += diffs[i];
1236 return av_MZ_spacing / (diffs.size() / 2);
1239 template <
typename PeakType>
1242 double av_intens = 0;
1243 for (
UInt i = 0; i < scan.
size(); ++i)
1253 template <
typename PeakType>
1257 for (
UInt i = 0; i < scan.
size(); ++i)
1265 return sqrt(res / (
double)(scan.
size() - 1));
1268 template <
typename PeakType>
1274 typename std::multimap<double, Box>::iterator upper_iter(
open_boxes_.upper_bound(mz));
1275 typename std::multimap<double, Box>::iterator lower_iter(
open_boxes_.lower_bound(mz));
1280 if (mz != lower_iter->first && lower_iter !=
open_boxes_.begin())
1286 typename std::multimap<double, Box>::iterator insert_iter;
1287 bool create_new_box =
true;
1295 if (fabs((--lower_iter)->first - mz) < dist_constraint)
1297 create_new_box =
false;
1298 insert_iter = lower_iter;
1303 create_new_box =
true;
1308 if (upper_iter ==
open_boxes_.end() && fabs(lower_iter->first - mz) < dist_constraint)
1310 insert_iter = lower_iter;
1311 create_new_box =
false;
1315 create_new_box =
true;
1325 double dist_lower = fabs(lower_iter->first - mz);
1326 double dist_upper = fabs(upper_iter->first - mz);
1327 dist_lower = (dist_lower < dist_constraint) ? dist_lower : INT_MAX;
1328 dist_upper = (dist_upper < dist_constraint) ? dist_upper : INT_MAX;
1330 if (dist_lower >= dist_constraint && dist_upper >= dist_constraint)
1332 create_new_box =
true;
1336 insert_iter = (dist_lower < dist_upper) ? lower_iter : upper_iter;
1337 create_new_box =
false;
1346 if (create_new_box ==
false)
1348 std::pair<UInt, BoxElement> help2(scan, element);
1349 insert_iter->second.insert(help2);
1352 Box replacement(insert_iter->second);
1356 double c_mz = insert_iter->first * (insert_iter->second.size() - 1) + mz;
1357 c_mz /= ((
double) insert_iter->second.size());
1361 std::pair<double, std::multimap<UInt, BoxElement> > help3(c_mz, replacement);
1366 std::pair<UInt, BoxElement> help2(scan, element);
1367 std::multimap<UInt, BoxElement> help3;
1368 help3.insert(help2);
1369 std::pair<double, std::multimap<UInt, BoxElement> > help4(mz, help3);
1374 template <
typename PeakType>
1380 std::multimap<double, Box>& tmp_box(
tmp_boxes_->at(c));
1381 typename std::multimap<double, Box>::iterator upper_iter(tmp_box.upper_bound(mz));
1382 typename std::multimap<double, Box>::iterator lower_iter(tmp_box.lower_bound(mz));
1384 if (lower_iter != tmp_box.end())
1387 if (mz != lower_iter->first && lower_iter != tmp_box.begin())
1393 typename std::multimap<double, Box>::iterator insert_iter;
1394 bool create_new_box =
true;
1395 if (lower_iter == tmp_box.end())
1400 if (!tmp_box.empty())
1402 if (fabs((--lower_iter)->first - mz) < dist_constraint)
1404 create_new_box =
false;
1405 insert_iter = lower_iter;
1410 create_new_box =
true;
1415 if (upper_iter == tmp_box.end() && fabs(lower_iter->first - mz) < dist_constraint)
1417 insert_iter = lower_iter;
1418 create_new_box =
false;
1422 create_new_box =
true;
1427 if (upper_iter != tmp_box.end() && lower_iter != tmp_box.end())
1430 double dist_lower = fabs(lower_iter->first - mz);
1431 double dist_upper = fabs(upper_iter->first - mz);
1432 dist_lower = (dist_lower < dist_constraint) ? dist_lower : INT_MAX;
1433 dist_upper = (dist_upper < dist_constraint) ? dist_upper : INT_MAX;
1435 if (dist_lower >= dist_constraint && dist_upper >= dist_constraint)
1437 create_new_box =
true;
1441 insert_iter = (dist_lower < dist_upper) ? lower_iter : upper_iter;
1442 create_new_box =
false;
1450 if (create_new_box ==
false)
1452 std::pair<UInt, BoxElement> help2(scan, element);
1453 insert_iter->second.insert(help2);
1456 Box replacement(insert_iter->second);
1460 double c_mz = insert_iter->first * (insert_iter->second.size() - 1) + mz;
1461 c_mz /= ((
double) insert_iter->second.size());
1464 tmp_box.erase(insert_iter);
1465 std::pair<double, std::multimap<UInt, BoxElement> > help3(c_mz, replacement);
1466 tmp_box.insert(help3);
1470 std::pair<UInt, BoxElement> help2(scan, element);
1471 std::multimap<UInt, BoxElement> help3;
1472 help3.insert(help2);
1474 std::pair<double, std::multimap<UInt, BoxElement> > help4(mz, help3);
1475 tmp_box.insert(help4);
1479 template <
typename PeakType>
1481 const UInt RT_votes_cutoff,
const Int front_bound,
const Int end_bound)
1483 typename std::multimap<double, Box>::iterator iter, iter2;
1485 if ((
Int)scan_index == end_bound && end_bound != (
Int)map.
size() - 1)
1489 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1490 std::cout <<
"LOW THREAD insert in end_box " << iter->first << std::endl;
1491 typename Box::iterator dings;
1492 for (dings = iter->second.begin(); dings != iter->second.end(); ++dings)
1493 std::cout << map[dings->first].getRT() <<
"\t" << dings->second.c + 1 << std::endl;
1503 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1504 if (front_bound > 0)
1506 std::cout <<
"HIGH THREAD open box. " << iter->first <<
"\t current scan index " << scan_index <<
"\t" << ((iter->second.begin()))->first <<
"\t of last scan " << map.
size() - 1 <<
"\t" << front_bound << std::endl;
1511 UInt lastScan = (--(iter->second.end()))->first;
1512 if (scan_index - lastScan > RT_interleave + 1 || scan_index == map.
size() - 1)
1514 if (iter->second.begin()->first - front_bound <= RT_interleave + 1 && front_bound > 0)
1518 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1519 std::cout <<
"HIGH THREAD insert in front_box " << iter->first << std::endl;
1532 if (iter->second.size() >= RT_votes_cutoff)
1548 template <
typename PeakType>
1551 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1552 std::cout <<
"**** CHECKING FOR BOX EXTENSIONS ****" << std::endl;
1556 typename Box::const_iterator iter;
1557 std::vector<double> elution_profile(box.size());
1559 for (iter = box.begin(); iter != box.end(); ++iter, ++index)
1561 for (
Size i = iter->second.MZ_begin; i != iter->second.MZ_end; ++i)
1563 elution_profile[index] += map[iter->second.RT_index][i].getIntensity();
1565 elution_profile[index] /= iter->second.MZ_end - iter->second.MZ_begin + 1.;
1569 Int max_index = INT_MIN;
1570 for (
Size i = 0; i < elution_profile.size(); ++i)
1572 if (elution_profile[i] > max)
1575 max = elution_profile[i];
1579 Int max_extension = (
Int)(elution_profile.size()) - 2 * max_index;
1581 double av_elution = 0;
1582 for (
Size i = 0; i < elution_profile.size(); ++i)
1584 av_elution += elution_profile[i];
1586 av_elution /= (
double)elution_profile.size();
1588 double sd_elution = 0;
1589 for (
Size i = 0; i < elution_profile.size(); ++i)
1591 sd_elution += (av_elution - elution_profile[i]) * (av_elution - elution_profile[i]);
1593 sd_elution /= (
double)(elution_profile.size() - 1);
1594 sd_elution = sqrt(sd_elution);
1598 for (iter = box.begin(); iter != box.end(); ++iter, ++index)
1600 av_mz += iter->second.mz;
1601 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1602 std::cout << iter->second.RT <<
"\t" << iter->second.mz <<
"\t" << iter->second.c + 1 << std::endl;
1605 av_mz /= (
double)box.size();
1609 if ((
Int)(box.begin()->second.RT_index) - 1 < 0)
1614 UInt pre_index = box.begin()->second.RT_index - 1;
1615 typename MSSpectrum::const_iterator c_iter = map[pre_index].MZBegin(av_mz);
1616 double pre_elution = 0;
1618 double mz_start = map[pre_index + 1][box.begin()->second.MZ_begin].getMZ();
1619 double mz_end = map[pre_index + 1][box.begin()->second.MZ_end].getMZ();
1621 typename MSSpectrum::const_iterator mz_start_iter = map[pre_index].MZBegin(mz_start), mz_end_iter = map[pre_index].MZBegin(mz_end);
1622 for (
typename MSSpectrum::const_iterator mz_iter = mz_start_iter; mz_iter != mz_end_iter; ++mz_iter)
1624 pre_elution += mz_iter->getIntensity();
1629 if (pre_elution <= av_elution - 2 * sd_elution)
1634 Int c_index = max_extension;
1635 Int first_index = box.begin()->second.RT_index;
1636 for (
Int i = 1; i < max_extension; ++i)
1638 c_index = first_index - i;
1645 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1646 std::cout << box.begin()->second.RT <<
"\t" << av_mz <<
"\t" << box.begin()->second.c + 1 <<
"\t" <<
" extending the box " << std::endl;
1649 push2Box_(av_mz, c_index, box.begin()->second.c, box.begin()->second.score, c_iter->getIntensity(),
1650 map[c_index].getRT(), box.
begin()->second.MZ_begin, box.begin()->second.MZ_end);
1654 template <
typename PeakType>
1658 typename std::multimap<double, Box>::iterator iter;
1659 typename Box::iterator box_iter;
1660 std::vector<BoxElement> final_box;
1661 double c_mz, av_score = 0, av_mz = 0, av_intens = 0, av_abs_intens = 0, count = 0;
1662 double virtual_av_mz = 0, virtual_av_intens = 0, virtual_av_abs_intens = 0, virtual_count = 0;
1664 typename std::pair<double, double> c_extend;
1667 Box& c_box = iter->second;
1668 av_score = 0, av_mz = 0, av_intens = 0, av_abs_intens = 0, count = 0;
1669 virtual_av_mz = 0, virtual_av_intens = 0, virtual_av_abs_intens = 0, virtual_count = 0;
1671 for (box_iter = c_box.begin(); box_iter != c_box.end(); ++box_iter)
1673 if (box_iter->second.score == 0)
1678 c_mz = box_iter->second.mz;
1679 virtual_av_intens += box_iter->second.intens;
1680 virtual_av_abs_intens += fabs(box_iter->second.intens);
1681 virtual_av_mz += c_mz * fabs(box_iter->second.intens);
1686 c_mz = box_iter->second.mz;
1687 av_score += box_iter->second.score;
1688 av_intens += box_iter->second.intens;
1689 av_abs_intens += fabs(box_iter->second.intens);
1690 av_mz += c_mz * fabs(box_iter->second.intens);
1697 av_intens = virtual_av_intens / virtual_count;
1699 av_mz = virtual_av_mz / virtual_av_abs_intens;
1705 av_mz /= av_abs_intens;
1709 c_box_element.
mz = av_mz;
1710 c_box_element.
c =
c;
1711 c_box_element.
score = av_score;
1712 c_box_element.
intens = av_intens;
1714 c_box_element.
RT = c_box.begin()->second.RT;
1716 final_box.push_back(c_box_element);
1719 UInt num_o_feature = final_box.size();
1720 if (num_o_feature == 0)
1727 std::vector<double> bwd_diffs(num_o_feature, 0);
1730 for (
UInt i = 1; i < num_o_feature; ++i)
1732 bwd_diffs[i] = (final_box[i].intens - final_box[i - 1].intens) / (final_box[i].
mz - final_box[i - 1].
mz);
1735 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1736 std::ofstream ofile_bwd(
"bwd_gpu.dat");
1737 for (
UInt i = 0; i < num_o_feature; ++i)
1739 ofile_bwd << final_box[i].mz <<
"\t" << bwd_diffs[i] << std::endl;
1744 for (
UInt i = 0; i < num_o_feature - 1; ++i)
1746 while (i < num_o_feature - 2)
1748 if (final_box[i].
score > 0 || final_box[i].
score == -1000)
1753 if (bwd_diffs[i] > 0 && bwd_diffs[i + 1] < 0)
1763 template <
typename PeakType>
1767 typename std::multimap<double, Box>::iterator iter;
1768 typename Box::iterator box_iter;
1769 UInt best_charge_index;
double best_charge_score, c_mz, c_RT;
UInt c_charge;
1770 double av_intens = 0, av_ref_intens = 0, av_score = 0, av_mz = 0, av_RT = 0, mz_cutoff, sum_of_ref_intenses_g;
1771 bool restart =
false;
1773 typename std::pair<double, double> c_extend;
1776 sum_of_ref_intenses_g = 0;
1777 Box& c_box = iter->second;
1783 for (box_iter = c_box.begin(); box_iter != c_box.end(); ++box_iter)
1785 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1786 if (trunc(box_iter->second.mz) == 874)
1787 std::cout << box_iter->second.c <<
"\t" << box_iter->second.intens <<
"\t" << box_iter->second.score << std::endl;
1790 if (box_iter->second.score == -1000)
1796 charge_votes[box_iter->second.c] += box_iter->second.intens;
1797 ++charge_binary_votes[box_iter->second.c];
1806 best_charge_index = 0; best_charge_score = 0;
1809 if (charge_votes[i] > best_charge_score)
1811 best_charge_index = i;
1812 best_charge_score = charge_votes[i];
1817 if (charge_binary_votes[best_charge_index] < RT_votes_cutoff && RT_votes_cutoff <= map.
size())
1822 c_charge = best_charge_index + 1;
1824 av_intens = 0, av_ref_intens = 0, av_score = 0, av_mz = 0, av_RT = 0;
1826 std::vector<DPosition<2> > point_set;
1827 double sum_of_ref_intenses_l;
1828 for (box_iter = c_box.begin(); box_iter != c_box.end(); ++box_iter)
1830 sum_of_ref_intenses_l = 0;
1831 c_mz = box_iter->second.mz;
1832 c_RT = box_iter->second.RT;
1838 point_set.push_back(
DPosition<2>(c_RT, c_mz + mz_cutoff / (
double)c_charge));
1840 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1841 std::cout <<
"Intenstype: " <<
intenstype_ << std::endl;
1846 const MSSpectrum& c_spec(map[box_iter->second.RT_index]);
1848 for (
unsigned int i = 0; i < mz_cutoff; ++i)
1854 while (h_iter != c_spec.begin())
1857 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1858 if (trunc(c_mz) == 874)
1860 std::cout <<
"cmz: " << c_mz + i *
Constants::IW_NEUTRON_MASS / c_charge <<
"\t" << hc_iter->getMZ() <<
"\t" << hc_iter->getIntensity() <<
"\t" << h_iter->getMZ() <<
"\t" << h_iter->getIntensity() << std::endl;
1865 if (h_iter->getIntensity() > hc_iter->getIntensity() || (h_iter->getIntensity() == hc_iter->getIntensity() && hc_iter->getIntensity() == 0))
1875 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1876 if (trunc(c_mz) == 874)
1881 sum_of_ref_intenses_l += hc_iter->getIntensity();
1882 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1883 if (trunc(c_mz) == 874)
1885 std::cout << sum_of_ref_intenses_l <<
"********" << std::endl;
1891 if (best_charge_index == box_iter->second.c)
1893 av_score += box_iter->second.score;
1894 av_intens += box_iter->second.intens;
1895 av_ref_intens += box_iter->second.ref_intens;
1896 sum_of_ref_intenses_g += sum_of_ref_intenses_l;
1897 av_mz += c_mz * box_iter->second.intens;
1903 av_ref_intens /= (
double)charge_binary_votes[best_charge_index];
1904 av_score /= (
double)charge_binary_votes[best_charge_index];
1905 av_RT /= (
double)c_box.size();
1907 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1908 if (trunc(av_mz) == 874)
1909 std::cout << av_mz <<
"\t" << best_charge_index <<
"\t" << best_charge_score << std::endl;
1916 c_feature.
setConvexHulls(std::vector<ConvexHull2D>(1, c_conv_hull));
1922 av_intens /= exp(-2 * lambda) * boost::math::cyl_bessel_i(0, 2 * lambda);
1926 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 1927 if (trunc(c_mz) == 874)
1929 std::cout << sum_of_ref_intenses_g <<
"####" << std::endl;
1933 av_intens = sum_of_ref_intenses_g;
1936 c_feature.
setMZ(av_mz);
1938 c_feature.
setRT(av_RT);
1940 feature_map.push_back(c_feature);
1946 template <
typename PeakType>
1948 const MSSpectrum& ref,
const double seed_mz,
const UInt c,
const UInt scan_index,
const bool check_PPMs,
const double transintens,
const double prev_score)
1950 typename MSSpectrum::const_iterator iter, ref_iter;
1954 iter = candidate.
MZBegin(seed_mz);
1956 if (iter == candidate.begin() || iter == candidate.end())
1961 std::pair<double, double> reals;
1962 ref_iter = ref.
MZBegin(seed_mz);
1964 double real_mz, real_intens;
1968 real_mz = reals.first, real_intens = reals.second;
1971 typename MSSpectrum::const_iterator h_iter = ref_iter, hc_iter = ref_iter;
1972 while (h_iter != ref.begin())
1975 if (h_iter->getIntensity() > hc_iter->getIntensity() || (h_iter->getIntensity() == hc_iter->getIntensity() && hc_iter->getIntensity() == 0))
1990 real_mz = reals.first, real_intens = reals.second;
1991 if (real_mz <= 0 || real_intens <= 0)
1995 real_mz = h_iter->getMZ();
1996 real_intens = h_iter->getIntensity();
2001 reals = std::pair<double, double>(seed_mz, ref_iter->getIntensity());
2002 real_mz = reals.first, real_intens = reals.second;
2004 if (real_mz <= 0 || real_intens <= 0)
2006 typename MSSpectrum::const_iterator h_iter = ref_iter, hc_iter = ref_iter;
2007 while (h_iter != ref.begin())
2010 if (h_iter->getIntensity() > hc_iter->getIntensity() || (h_iter->getIntensity() == hc_iter->getIntensity() && hc_iter->getIntensity() == 0))
2024 real_mz = h_iter->getMZ(), real_intens = h_iter->getIntensity();
2025 if (real_mz <= 0 || real_intens <= 0)
2029 real_mz = h_iter->getMZ();
2030 real_intens = h_iter->getIntensity();
2034 double c_score =
scoreThis_(candidate, peak_cutoff, real_mz, c, 0);
2043 typename MSSpectrum::const_iterator real_r_MZ_iter = ref.
MZBegin(real_l_MZ_iter, real_mz + mz_cutoff / (c + 1.), ref.end());
2044 if (real_r_MZ_iter == ref.end())
2050 UInt real_mz_begin = distance(ref.begin(), real_l_MZ_iter);
2051 UInt real_mz_end = distance(ref.begin(), real_r_MZ_iter);
2053 if (prev_score == -1000)
2055 push2Box_(real_mz, scan_index, c, prev_score, transintens, ref.
getRT(), real_mz_begin, real_mz_end, real_intens);
2059 push2Box_(real_mz, scan_index, c, c_score, transintens, ref.
getRT(), real_mz_begin, real_mz_end, real_intens);
2064 template <
typename PeakType>
2066 const MSSpectrum& ref,
const double seed_mz,
const UInt c,
const UInt scan_index,
const bool check_PPMs,
const double transintens,
const double prev_score)
2068 typename MSSpectrum::const_iterator iter, ref_iter;
2072 iter = candidate.
MZBegin(seed_mz);
2074 if (iter == candidate.
begin() || iter == candidate.
end())
2079 std::pair<double, double> reals;
2080 ref_iter = ref.
MZBegin(seed_mz);
2082 double real_mz, real_intens;
2086 real_mz = reals.first, real_intens = reals.second;
2089 typename MSSpectrum::const_iterator h_iter = ref_iter, hc_iter = ref_iter;
2090 while (h_iter != ref.begin())
2093 if (h_iter->getIntensity() > hc_iter->getIntensity() || (h_iter->getIntensity() == hc_iter->getIntensity() && hc_iter->getIntensity() == 0))
2109 real_mz = reals.first, real_intens = reals.second;
2111 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 2112 std::cout <<
"Plausibility check old_mz: " << iter->getMZ() <<
"\t" << real_mz << std::endl;
2115 if (real_mz <= 0 || real_intens <= 0)
2119 real_mz = h_iter->getMZ();
2120 real_intens = h_iter->getIntensity();
2125 reals = std::pair<double, double>(seed_mz, ref_iter->getIntensity());
2126 real_mz = reals.first, real_intens = reals.second;
2128 if (real_mz <= 0 || real_intens <= 0)
2130 typename MSSpectrum::const_iterator h_iter = ref_iter, hc_iter = ref_iter;
2131 while (h_iter != ref.begin())
2134 if (h_iter->getIntensity() > hc_iter->getIntensity() || (h_iter->getIntensity() == hc_iter->getIntensity() && hc_iter->getIntensity() == 0))
2148 real_mz = h_iter->getMZ(), real_intens = h_iter->getIntensity();
2149 if (real_mz <= 0 || real_intens <= 0)
2153 real_mz = h_iter->getMZ();
2154 real_intens = h_iter->getIntensity();
2158 double c_score =
scoreThis_(candidate, peak_cutoff, real_mz, c, 0);
2167 typename MSSpectrum::const_iterator real_r_MZ_iter = ref.
MZBegin(real_l_MZ_iter, real_mz + mz_cutoff / (c + 1.), ref.end());
2168 if (real_r_MZ_iter == ref.end())
2174 UInt real_mz_begin = distance(ref.begin(), real_l_MZ_iter);
2175 UInt real_mz_end = distance(ref.begin(), real_r_MZ_iter);
2177 if (prev_score == -1000)
2179 push2Box_(real_mz, scan_index, c, prev_score, transintens, ref.
getRT(), real_mz_begin, real_mz_end, real_intens);
2183 push2Box_(real_mz, scan_index, c, c_score, transintens, ref.
getRT(), real_mz_begin, real_mz_end, real_intens);
2189 template <
typename PeakType>
2196 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 2197 std::cout << ::std::setprecision(8) << std::fixed << c_mz <<
"\t =(" <<
"ISO_WAVE" <<
")> " <<
"REJECT \t" << ppms <<
" (rule: " <<
peptideMassRule_(mass) <<
" got: " << mass <<
")" << std::endl;
2199 return std::pair<double, double>(-1, -1);
2202 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET 2203 std::cout << ::std::setprecision(8) << std::fixed << c_mz <<
"\t =(" <<
"ISO_WAVE" <<
")> " <<
"ACCEPT \t" << ppms <<
" (rule: " <<
peptideMassRule_(mass) <<
" got: " << mass <<
")" << std::endl;
2205 return std::pair<double, double>(c_mz, ref.
MZBegin(c_mz)->getIntensity());
2210 #pragma clang diagnostic pop
A more convenient string class.
Definition: String.h:57
bool intensityPointerComparator(PeakType *a, PeakType *b)
Definition: IsotopeWaveletTransform.h:548
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:203
static double getLambdaL(const double m)
Returns the mass-parameter lambda (linear fit).
const double IW_PROTON_MASS
Definition: IsotopeWaveletConstants.h:69
A container for features.
Definition: FeatureMap.h:94
void sortByIntensity(bool reverse=false)
Sorting.
Definition: ConstRefVector.h:752
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
Iterator begin()
Definition: MSExperiment.h:162
Iterator MZEnd(CoordinateType mz)
Binary search for peak range end (returns the past-the-end iterator)
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
static double getValueByLambda(const double lambda, const double tz1)
Returns the value of the isotope wavelet at position t via a fast table lookup. Usually, you do not need to call this function. Please use.
Size size() const
Definition: MSExperiment.h:132
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
IntensityType getIntensity() const
Definition: Peak2D.h:167
A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling...
Definition: ConvexHull2D.h:73
Iterator MZBegin(CoordinateType mz)
Binary search for peak range begin.
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:135
bool intensityComparator(const PeakType &a, const PeakType &b)
Definition: IsotopeWaveletTransform.h:536
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:173
static UInt getNumPeakCutOff(const double mass, const UInt z)
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:215
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:197
An LC-MS feature.
Definition: Feature.h:70
Mutable iterator for the ConstRefVector.
Definition: ConstRefVector.h:242
bool positionComparator(const PeakType &a, const PeakType &b)
Definition: IsotopeWaveletTransform.h:554
const double IW_NEUTRON_MASS
Definition: IsotopeWaveletConstants.h:55
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
void setConvexHulls(const std::vector< ConvexHull2D > &hulls)
Set the convex hulls of single mass traces.
const double PEPTIDE_MASS_RULE_BOUND
Definition: IsotopeWaveletConstants.h:51
void setOverallQuality(QualityType q)
Set the overall quality.
static UInt getMzPeakCutOffAtMonoPos(const double mass, const UInt z)
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
bool intensityAscendingComparator(const PeakType &a, const PeakType &b)
Definition: IsotopeWaveletTransform.h:542
void setCharge(const ChargeType &ch)
Set charge state.
void addPoints(const PointArrayType &points)
This vector holds pointer to the elements of another container.
Definition: ConstRefVector.h:71
const double IW_HALF_NEUTRON_MASS
Definition: IsotopeWaveletConstants.h:56
const double PEPTIDE_MASS_RULE_FACTOR
Definition: IsotopeWaveletConstants.h:50
static IsotopeWavelet * init(const double max_m, const UInt max_charge)
int Int
Signed integer type.
Definition: Types.h:103
const double IW_QUARTER_NEUTRON_MASS
Definition: IsotopeWaveletConstants.h:57
const unsigned int DEFAULT_NUM_OF_INTERPOLATION_POINTS
Definition: IsotopeWaveletConstants.h:44
const double PEPTIDE_MASS_RULE_THEO_PPM_BOUND
Definition: IsotopeWaveletConstants.h:52