本文整理汇总了C++中ConsensusMap::sortByMZ方法的典型用法代码示例。如果您正苦于以下问题:C++ ConsensusMap::sortByMZ方法的具体用法?C++ ConsensusMap::sortByMZ怎么用?C++ ConsensusMap::sortByMZ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConsensusMap
的用法示例。
在下文中一共展示了ConsensusMap::sortByMZ方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
//.........这里部分代码省略.........
{
nn_distance_0[fi0].second = distance;
}
}
// update entries for map 1:
if (distance < nn_distance_1[fi1].second)
{
if (valid && (distance < nn_distance_1[fi1].first))
{
nn_distance_1[fi1].second = nn_distance_1[fi1].first;
nn_distance_1[fi1].first = distance;
nn_index_1[fi1] = fi0;
}
else
{
nn_distance_1[fi1].second = distance;
}
}
}
}
// if features from the two maps are nearest neighbors of each other, they
// can become a pair:
for (UInt fi0 = 0; fi0 < input_maps[0].size(); ++fi0)
{
UInt fi1 = nn_index_0[fi0]; // nearest neighbor of "fi0" in map 1
// cout << "index: " << fi0 << ", RT: " << input_maps[0][fi0].getRT()
// << ", MZ: " << input_maps[0][fi0].getMZ() << endl
// << "neighbor: " << fi1 << ", RT: " << input_maps[1][fi1].getRT()
// << ", MZ: " << input_maps[1][fi1].getMZ() << endl
// << "d(i,j): " << nn_distance_0[fi0].first << endl
// << "d2(i): " << nn_distance_0[fi0].second << endl
// << "d2(j): " << nn_distance_1[fi1].second << endl;
// criteria set by the parameters must be fulfilled:
if ((nn_distance_0[fi0].first < FeatureDistance::infinity) &&
(nn_distance_0[fi0].first * second_nearest_gap_ <= nn_distance_0[fi0].second))
{
// "fi0" satisfies constraints...
if ((nn_index_1[fi1] == fi0) &&
(nn_distance_1[fi1].first * second_nearest_gap_ <= nn_distance_1[fi1].second))
{
// ...nearest neighbor of "fi0" also satisfies constraints (yay!)
// cout << "match!" << endl;
result_map.push_back(ConsensusFeature());
ConsensusFeature& f = result_map.back();
f.insert(input_maps[0][fi0]);
f.getPeptideIdentifications().insert(f.getPeptideIdentifications().end(),
input_maps[0][fi0].getPeptideIdentifications().begin(),
input_maps[0][fi0].getPeptideIdentifications().end());
f.insert(input_maps[1][fi1]);
f.getPeptideIdentifications().insert(f.getPeptideIdentifications().end(),
input_maps[1][fi1].getPeptideIdentifications().begin(),
input_maps[1][fi1].getPeptideIdentifications().end());
f.computeConsensus();
double quality = 1.0 - nn_distance_0[fi0].first;
double quality0 = 1.0 - nn_distance_0[fi0].first * second_nearest_gap_ / nn_distance_0[fi0].second;
double quality1 = 1.0 - nn_distance_1[fi1].first * second_nearest_gap_ / nn_distance_1[fi1].second;
quality = quality * quality0 * quality1; // TODO other formula?
// incorporate existing quality values:
Size size0 = max(input_maps[0][fi0].size(), size_t(1));
Size size1 = max(input_maps[1][fi1].size(), size_t(1));
// quality contribution from first map:
quality0 = input_maps[0][fi0].getQuality() * (size0 - 1);
// quality contribution from second map:
quality1 = input_maps[1][fi1].getQuality() * (size1 - 1);
f.setQuality((quality + quality0 + quality1) / (size0 + size1 - 1));
is_singleton[0][fi0] = false;
is_singleton[1][fi1] = false;
}
}
}
// write out unmatched consensus features
for (UInt input = 0; input <= 1; ++input)
{
for (UInt index = 0; index < input_maps[input].size(); ++index)
{
if (is_singleton[input][index])
{
result_map.push_back(input_maps[input][index]);
if (result_map.back().size() < 2) // singleton consensus feature
{
result_map.back().setQuality(0.0);
}
}
}
}
// canonical ordering for checking the results, and the ids have no real meaning anyway
result_map.sortByMZ();
// protein IDs and unassigned peptide IDs are added to the result by the
// FeatureGroupingAlgorithm!
}
示例2: group
void FeatureGroupingAlgorithmUnlabeled::group(const std::vector<FeatureMap> & maps, ConsensusMap & out)
{
// check that the number of maps is ok
if (maps.size() < 2)
{
throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "At least two maps must be given!");
}
// define reference map (the one with most peaks)
Size reference_map_index = 0;
Size max_count = 0;
for (Size m = 0; m < maps.size(); ++m)
{
if (maps[m].size() > max_count)
{
max_count = maps[m].size();
reference_map_index = m;
}
}
std::vector<ConsensusMap> input(2);
// build a consensus map of the elements of the reference map (contains only singleton consensus elements)
MapConversion::convert(reference_map_index, maps[reference_map_index],
input[0]);
// loop over all other maps, extend the groups
StablePairFinder pair_finder;
pair_finder.setParameters(param_.copy("", true));
for (Size i = 0; i < maps.size(); ++i)
{
if (i != reference_map_index)
{
MapConversion::convert(i, maps[i], input[1]);
// compute the consensus of the reference map and map i
ConsensusMap result;
pair_finder.run(input, result);
input[0].swap(result);
}
}
// replace result with temporary map
out.swap(input[0]);
// copy back the input maps (they have been deleted while swapping)
out.getFileDescriptions() = input[0].getFileDescriptions();
// add protein IDs and unassigned peptide IDs to the result map here,
// to keep the same order as the input maps (useful for output later)
for (std::vector<FeatureMap>::const_iterator map_it = maps.begin();
map_it != maps.end(); ++map_it)
{
// add protein identifications to result map
out.getProteinIdentifications().insert(
out.getProteinIdentifications().end(),
map_it->getProteinIdentifications().begin(),
map_it->getProteinIdentifications().end());
// add unassigned peptide identifications to result map
out.getUnassignedPeptideIdentifications().insert(
out.getUnassignedPeptideIdentifications().end(),
map_it->getUnassignedPeptideIdentifications().begin(),
map_it->getUnassignedPeptideIdentifications().end());
}
// canonical ordering for checking the results, and the ids have no real meaning anyway
#if 1 // the way this was done in DelaunayPairFinder and StablePairFinder
out.sortByMZ();
#else
out.sortByQuality();
out.sortByMaps();
out.sortBySize();
#endif
return;
}
示例3: run
//.........这里部分代码省略.........
for (DoubleList::const_iterator dist_it = mz_pair_dists.begin(); dist_it != mz_pair_dists.end(); ++dist_it)
{
double mz_pair_dist = *dist_it;
RefMap::const_iterator it2 = lower_bound(model_ref.begin(), model_ref.end(), it->getRT() + rt_pair_dist - rt_dev_low, ConsensusFeature::RTLess());
while (it2 != model_ref.end() && it2->getRT() <= it->getRT() + rt_pair_dist + rt_dev_high)
{
// if in mrm mode, we need to compare precursor mass difference and fragment mass difference, charge remains the same
double prec_mz_diff(0);
if (mrm)
{
prec_mz_diff = fabs((double)it2->getMetaValue("MZ") - (double)it->getMetaValue("MZ"));
if (it->getCharge() != 0)
{
prec_mz_diff = fabs(prec_mz_diff - mz_pair_dist / it->getCharge());
}
else
{
prec_mz_diff = fabs(prec_mz_diff - mz_pair_dist);
}
}
bool mrm_correct_dist(false);
double frag_mz_diff = fabs(it->getMZ() - it2->getMZ());
//cerr << it->getRT() << " charge1=" << it->getCharge() << ", charge2=" << it2->getCharge() << ", prec_diff=" << prec_mz_diff << ", frag_diff=" << frag_mz_diff << endl;
if (mrm &&
it2->getCharge() == it->getCharge() &&
prec_mz_diff < mz_dev &&
(frag_mz_diff < mz_dev || fabs(frag_mz_diff - mz_pair_dist) < mz_dev))
{
mrm_correct_dist = true;
//cerr << "mrm_correct_dist" << endl;
}
if ((mrm && mrm_correct_dist) || (!mrm &&
it2->getCharge() == it->getCharge() &&
it2->getMZ() >= it->getMZ() + mz_pair_dist / it->getCharge() - mz_dev &&
it2->getMZ() <= it->getMZ() + mz_pair_dist / it->getCharge() + mz_dev
))
{
//cerr << "dist correct" << endl;
double score = sqrt(
PValue_(it2->getMZ() - it->getMZ(), mz_pair_dist / it->getCharge(), mz_dev, mz_dev) *
PValue_(it2->getRT() - it->getRT(), rt_pair_dist, rt_dev_low, rt_dev_high)
);
// Note: we used to copy the id from the light feature here, but that strategy does not generalize to more than two labels.
// We might want to report consensus features where the light one is missing but more than one heavier variant was found.
// Also, the old strategy is inconsistent with what was done in the unlabeled case. Thus now we assign a new unique id here.
matches.push_back(ConsensusFeature());
matches.back().setUniqueId();
matches.back().insert(light_index, *it);
matches.back().clearMetaInfo();
matches.back().insert(heavy_index, *it2);
matches.back().setQuality(score);
matches.back().setCharge(it->getCharge());
matches.back().computeMonoisotopicConsensus();
}
++it2;
}
}
}
//compute best pairs
// - sort matches by quality
// - take highest-quality matches first (greedy) and mark them as used
set<Size> used_features;
matches.sortByQuality(true);
for (ConsensusMap::const_iterator match = matches.begin(); match != matches.end(); ++match)
{
//check if features are not used yet
if (used_features.find(match->begin()->getUniqueId()) == used_features.end() &&
used_features.find(match->rbegin()->getUniqueId()) == used_features.end()
)
{
//if unused, add it to the final set of elements
result_map.push_back(*match);
used_features.insert(match->begin()->getUniqueId());
used_features.insert(match->rbegin()->getUniqueId());
}
}
//Add protein identifications to result map
for (Size i = 0; i < input_maps.size(); ++i)
{
result_map.getProteinIdentifications().insert(result_map.getProteinIdentifications().end(), input_maps[i].getProteinIdentifications().begin(), input_maps[i].getProteinIdentifications().end());
}
//Add unassigned peptide identifications to result map
for (Size i = 0; i < input_maps.size(); ++i)
{
result_map.getUnassignedPeptideIdentifications().insert(result_map.getUnassignedPeptideIdentifications().end(), input_maps[i].getUnassignedPeptideIdentifications().begin(), input_maps[i].getUnassignedPeptideIdentifications().end());
}
// Very useful for checking the results, and the ids have no real meaning anyway
result_map.sortByMZ();
}