本文整理汇总了C#中Set.LowerBound方法的典型用法代码示例。如果您正苦于以下问题:C# Set.LowerBound方法的具体用法?C# Set.LowerBound怎么用?C# Set.LowerBound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.LowerBound方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: findClose
/// <summary>
/// This function takes a set of peaks, a lookup mass, and
/// finds the closest peak with in a certain tolerance. If
/// multiple peaks exists with in the window, most closest peak
/// is selected
/// </summary>
/// <param name="peaks">A spectrum</param>
/// <param name="mz">Look up m/z</param>
/// <param name="tolerance">Mass tolerance for look-up</param>
/// <returns>Peak if found</returns>
public static Peak findClose(Set<Peak> peaks, double mz, double tolerance)
{
Set<Peak>.Enumerator cur, min, max;
min = peaks.LowerBound(new Peak(mz - tolerance));
max = peaks.LowerBound(new Peak(mz + tolerance));
if (!min.IsValid && !max.IsValid)
return null;
if (!min.IsValid && max.IsValid)
return max.Current;
if (min.IsValid && !max.IsValid)
return min.Current;
if (min.Current == max.Current)
return null;
// If we found multiple matching peaks,
// return the closest peak.
Peak best = min.Current;
//find the peak closest to the desired mz
double minDiff = Math.Abs(mz - best.mz);
for (cur = min; cur.Current != max.Current; cur.MoveNext())
{
double curDiff = Math.Abs(mz - cur.Current.mz);
if (curDiff < minDiff)
{
minDiff = curDiff;
best = cur.Current;
}
}
return best;
}
示例2: findNear
/// <summary>
/// This function takes a set of peaks, a lookup mass, and
/// finds the closest peak with in a certain tolerance. If
/// multiple peaks exists with in the window, most intense peak
/// is selected
/// </summary>
/// <param name="peaks">A spectrum</param>
/// <param name="mz">Look up m/z</param>
/// <param name="tolerance">Mass tolerance for look-up</param>
/// <returns>Peak if found</returns>
public static Peak findNear(Set<Peak> peaks, double mz, double tolerance)
{
Set<Peak>.Enumerator cur, min, max;
min = peaks.LowerBound(new Peak(mz - tolerance));
max = peaks.LowerBound(new Peak(mz + tolerance));
if (!min.IsValid && !max.IsValid)
return null;
if (!min.IsValid && max.IsValid)
return max.Current;
if (min.IsValid && !max.IsValid)
return min.Current;
if (min.Current == max.Current)
return null;
// If we found multiple matching peaks,
// return the peak with best intensity.
Peak best = min.Current;
double bestIntensityOrRank = best.rankOrIntensity;
for (cur = min; cur.Current != max.Current; cur.MoveNext())
{
double curRank = cur.Current.rankOrIntensity;
if (curRank > bestIntensityOrRank)
{
bestIntensityOrRank = curRank;
best = cur.Current;
}
}
return best;
}
示例3: chargeAssignment
/// <summary>
/// This function takes a set of peaks, iterate through the peaks
/// and assign each fragment with a charge label with:
/// 0: unknown; 1: +1; 2: +2; 3:+3 et al.
/// note: the spectrum peaks comes from a +3 precursor.
/// also I require 5% basepeak intensity cutoff for the peaklist
/// BASED ON FINDCLOSE METHOD.
/// </summary>
public static Set<Peak> chargeAssignment(Set<Peak> peaklist)
{
Set<Peak> finalPeakList = new Set<Peak>();
//first step should be sort the peaks from least to highest by mz
Set<Peak>.Enumerator cur, min, max, prev;
//find the min mz and max mz
double minMZ = 0;
//double intensity_min = 0;
double maxMZ = 0;
//double intensity_max = 0;
foreach (var peak in peaklist)
{
if (peak.mz > maxMZ)
{
maxMZ = peak.mz;
//intensity_max = peak.rankOrIntensity;
}
if (peak.mz < minMZ)
{
minMZ = peak.mz;
//intensity_min = peak.rankOrIntensity;
}
}
min = peaklist.LowerBound(new Peak(minMZ));
max = peaklist.LowerBound(new Peak(maxMZ));
//find the difference of adjacent peaks
int size = peaklist.Count;
double prev_mz = min.Current.mz;
//double prev_diff = 0;
int[] assignment = new int[size - 1];
int itr = 0;
for (cur = min; cur.Current != max.Current; cur.MoveNext())
{
//the diff of the first element (min) is 0
//Console.WriteLine("current mz is: " + cur.Current.mz);
//double 1/2H = 0.503638; round to 0.504
//double H = 1.007276; round to 1.007
//it turns out that TWO peaks will be enough for
double diff = Math.Round(cur.Current.mz - prev_mz,1);
//Console.WriteLine(diff);
if (diff == 0.5)
{
//assignment[itr - 2] = 2;
assignment[itr - 1] = 2;
assignment[itr] = 2;
}
else if (diff == 1)
{
//assignment[itr - 2] = 1;
assignment[itr - 1] = 1;
assignment[itr] = 1;
}
else assignment[itr] = 0;
//Console.WriteLine("========\n");
//Console.WriteLine(prev_diff + "\n");
//Console.WriteLine(diff + "\n");
prev = cur;
//prev_diff = diff;
prev_mz = cur.Current.mz;
itr++;
}
//if the diff patterns shows a successive 3-peak of 0.5 (which is 2 diff), then assign 2
//if the diff goes like 0.33333, then assign 3 or does not count?
//if the diff goes like 1, then assign 1.
//otherwise assign just 0
//the key is 5% cutoff.
min = peaklist.LowerBound(new Peak(minMZ));
max = peaklist.LowerBound(new Peak(maxMZ));
//Console.WriteLine(min.Current.mz);
//Console.WriteLine(max.Current.mz);
itr = 0;
for (cur = min; cur.Current != max.Current; cur.MoveNext())
{
//Console.WriteLine("adding peak\n");
finalPeakList.Add(new Peak(cur.Current.mz, cur.Current.rankOrIntensity, assignment[itr]));
//Console.WriteLine(assignment[itr]);
itr++;
}
return finalPeakList;
}