/// /// \brief Vespucci::Math::Quantification::FindBandwidthMat /// \param X /// \param abscissa /// \param min /// \param max /// \param midlines /// \param baselines /// \return /// Finds the bandwidth of every column of a arma::matrix. arma::vec Vespucci::Math::Quantification::FindBandwidthMat(const arma::mat &X, arma::vec abscissa, double &min, double &max, arma::mat &midlines, arma::mat &baselines, arma::uvec &boundaries) { double delta = std::abs(abscissa(1) - abscissa(0)); arma::uvec left_bound = find(((min-delta) <= abscissa) && (abscissa <= (min+delta))); arma::uvec right_bound = find(((max-delta) <= abscissa) && (abscissa <= (max+delta))); arma::uword min_index = left_bound(0); arma::uword max_index = right_bound(0); boundaries << min_index << arma::endr << max_index; min = abscissa(min_index); max = abscissa(max_index); arma::uword size = abscissa.subvec(min_index, max_index).n_elem; arma::vec results(X.n_cols); midlines.set_size(X.n_cols, size); baselines.set_size(X.n_cols, size); arma::vec midline; arma::vec baseline; for (arma::uword i = 0; i < X.n_cols; ++i){ results(i) = FindBandwidth(X.col(i), min_index, max_index, midline, baseline, delta); midlines.row(i) = midline; baselines.row(i) = baseline; } return results; }
!is_russian_baltic_conflict(*letr) && // 17.07.2001 E.P. !is_russian_turkish_conflict(*letr) // 21.05.2002 E.P. ) break; } } else { if (cut->dh != 0 && strchr("еиИнНпПоОсС",let) && // "хш╚э═я╧ю╬ё╤" !is_russian_baltic_conflict(let) && // 17.07.2001 E.P. !is_russian_turkish_conflict(let) && // 21.05.2002 E.P. (letp==(uchar)'г' || letp==(uchar)'Г')) // у├ { m_row=my_bases.bm+(int16_t)((int32_t)nIncline*(r->left+cut->x)/2048); x0=right_bound(r,0,cut->x,(int16_t)(m_row-r->top+1),(int16_t)(r->h-1)); } else if (cut->dh != 0 && strchr("есС",let) && !is_russian_baltic_conflict(let) && // 17.07.2001 E.P. (letp==(uchar)'п' || letp==(uchar)'П')) { m_row=my_bases.bm+(int16_t)((int32_t)nIncline*(r->left+cut->x)/2048); x0=right_bound(r,0,cut->x,0,(int16_t)(m_row-r->top)); } else if (cut->dh != 0 && (letp==(uchar)'ь' || letp==(uchar)'Ь') && !is_russian_baltic_conflict(letp) // 17.07.2001 E.P. ) { x0=cut->x-((cut_list[ip].x-cut->x)>>2);
void ElutionPeakDetection::findLocalExtrema(const MassTrace& tr, const Size& num_neighboring_peaks, std::vector<Size>& chrom_maxes, std::vector<Size>& chrom_mins) { std::vector<double> smoothed_ints_vec(tr.getSmoothedIntensities()); Size mt_length(smoothed_ints_vec.size()); if (mt_length != tr.getSize()) { throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__, "MassTrace was not smoothed before! Aborting...", String(smoothed_ints_vec.size())); } // first make sure that everything is cleared chrom_maxes.clear(); chrom_mins.clear(); // Extract RTs from the chromatogram and store them into into vectors for index access // std::cout << "neighboring peaks: " << num_neighboring_peaks << std::endl; // Store indices along with smoothed_ints to keep track of the peak order std::multimap<double, Size> intensity_indices; boost::dynamic_bitset<> used_idx(mt_length); for (Size i = 0; i < mt_length; ++i) { intensity_indices.insert(std::make_pair(smoothed_ints_vec[i], i)); } for (std::multimap<double, Size>::const_iterator c_it = intensity_indices.begin(); c_it != intensity_indices.end(); ++c_it) { double ref_int = c_it->first; Size ref_idx = c_it->second; if (!(used_idx[ref_idx]) && ref_int > 0.0) { bool real_max = true; // iterate up the RT Size start_idx(0); if (ref_idx > num_neighboring_peaks) { start_idx = ref_idx - num_neighboring_peaks; } Size end_idx = ref_idx + num_neighboring_peaks; if (end_idx > mt_length) { end_idx = mt_length; } for (Size j = start_idx; j < end_idx; ++j) { if (used_idx[j]) { real_max = false; break; } if (j == ref_idx) { continue; } if (smoothed_ints_vec[j] > ref_int) { real_max = false; } } if (real_max) { chrom_maxes.push_back(ref_idx); for (Size j = start_idx; j < end_idx; ++j) { used_idx[j] = true; } } } } std::sort(chrom_maxes.begin(), chrom_maxes.end()); if (chrom_maxes.size() > 1) { Size i(0), j(1); //for (Size i = 0; i < chrom_maxes.size() - 1; ++i) while (i < j && j < chrom_maxes.size()) { // bisection Size left_bound(chrom_maxes[i] + 1); Size right_bound(chrom_maxes[j] - 1); while ((left_bound + 1) < right_bound) { double mid_dist((right_bound - left_bound) / 2.0); Size mid_element_idx(left_bound + std::floor(mid_dist)); double mid_element_int = smoothed_ints_vec[mid_element_idx]; if (mid_element_int <= smoothed_ints_vec[mid_element_idx + 1]) { right_bound = mid_element_idx; } else // or to the right... { left_bound = mid_element_idx; } } Size min_rt((smoothed_ints_vec[left_bound] < smoothed_ints_vec[right_bound]) ? left_bound : right_bound); // check for valley depth between chromatographic peaks double min_int(1.0); if (smoothed_ints_vec[min_rt] > min_int) { min_int = smoothed_ints_vec[min_rt]; } double left_max_int(smoothed_ints_vec[chrom_maxes[i]]); double right_max_int(smoothed_ints_vec[chrom_maxes[j]]); double left_rt(tr[chrom_maxes[i]].getRT()); double mid_rt(tr[min_rt].getRT()); double right_rt(tr[chrom_maxes[j]].getRT()); double left_dist(std::fabs(mid_rt - left_rt)); double right_dist(std::fabs(right_rt - mid_rt)); double min_dist(min_fwhm_ / 2.0); // out debug info // std::cout << tr.getLabel() << ": i,j " << i << "," << j << ":" << left_max_int << " min: " << min_int << " " << right_max_int << " l " << left_rt << " r " << right_rt << " m " << mid_rt << std::endl; if (left_max_int / min_int >= 2.0 && right_max_int / min_int >= 2.0 && left_dist >= min_dist && right_dist >= min_dist) { chrom_mins.push_back(min_rt); // std::cout << "min added!" << std::endl; i = j; ++j; } else { // keep one of the chrom_maxes, iterate the other if (left_max_int > right_max_int) { ++j; } else { i = j; ++j; } } // chrom_mins.push_back(min_rt); } } return; }