public bool ApexCheck(Feature feature, double startTime, double stopTime) { var relevantPeaks = feature.SmoothRTPeaks.Where(x => x.RT <= stopTime && x.RT >= startTime).ToList(); if (relevantPeaks.Count > 0) { double startIntensity = relevantPeaks.First().Intensity; double stopIntensity = relevantPeaks.Last().Intensity; double maxIntensity = 0; RTPeak maxPeak = null; bool valid = false; foreach (RTPeak peak in relevantPeaks) { if (peak.Intensity > startIntensity && peak.Intensity > stopIntensity) { valid = true; if (peak.Intensity > maxIntensity) { maxIntensity = peak.Intensity; maxPeak = peak; feature.MaxPeak = peak; } } } return(valid); } return(false); }
public int GetRTPeakIndex(Feature feature, RTPeak peak) { int returnIndex = Array.BinarySearch(feature.SmoothRTPeaks.ToArray(), peak); if (returnIndex < 0) { returnIndex = ~returnIndex; } return(returnIndex); }
public Feature(MZPeak firstPeak, double RT, double HCDEnergy = 0) { this.allRTPeaks = new List <RTPeak>(); this.smoothRTPeaks = new List <RTPeak>(); this.minRT = RT; this.maxRT = RT; RTPeak newRTPeak = new RTPeak(firstPeak, RT); this.allRTPeaks.Add(newRTPeak); this.maxPeak = newRTPeak; this.totalMZTimesIntensity += (firstPeak.Intensity * firstPeak.MZ); this.totalIntensity += (firstPeak.Intensity); this.averageMZ = firstPeak.MZ; newRTPeak.HCDEnergy = HCDEnergy; }
public int GetRightStopIndex(int startIndex, List <RTPeak> smoothPeaks, double threshold) { if (startIndex + 1 < smoothPeaks.Count) { RTPeak previousPeak = smoothPeaks[startIndex]; RTPeak currentpeak = smoothPeaks[startIndex + 1]; if (currentpeak.Intensity > previousPeak.Intensity && currentpeak.Intensity < threshold) { return(startIndex); } return(GetRightStopIndex(startIndex + 1, smoothPeaks, threshold)); } return(startIndex); }
public static List <Feature> GetFeatures(string name, SQLiteConnection conn, double minTime, double maxTime) { var queryText = "SELECT s.ID, s.mz, s.Name, s.ApexRT, s.ApexIntensity, s.SmoothFeatureString FROM featureTable s WHERE s.Name=@Name AND s.ApexRT<@Max AND s.ApexRT>@Min"; var queryCommand = new SQLiteCommand(queryText, conn); queryCommand.Parameters.AddWithValue("@Name", name); queryCommand.Parameters.AddWithValue("@Min", minTime); queryCommand.Parameters.AddWithValue("@Max", maxTime); List <Feature> returnFeatures = new List <Feature>(); var reader = queryCommand.ExecuteReader(); while (reader.Read()) { var id = reader["ID"].ToString(); double mz = double.Parse(reader["mz"].ToString()); var apexRT = double.Parse(reader["ApexRT"].ToString()); var apexIntensity = double.Parse(reader["ApexIntensity"].ToString()); var featString = reader["SmoothFeatureString"].ToString(); string[] parts = featString.Split('|'); //double mz = double.Parse(parts[0]); //double rt = double.Parse(parts[1]); string[] peaks = parts[0].Split(';'); var feature = new Feature(); // feature.AverageMZ = mz; feature.ApexTime = apexRT; foreach (var peak in peaks) { if (!string.IsNullOrEmpty(peak)) { string[] peakParts = peak.Split(','); double time = double.Parse(peakParts[0]); double intensity = double.Parse(peakParts[1]); var newPeak = new RTPeak(mz, intensity, time); feature.AddSmoothPeak(newPeak); if (Math.Round(newPeak.RT, 3) == Math.Round(apexRT, 3)) { feature.totalIntensity += newPeak.Intensity; } } } feature.AverageMZ = mz; feature.maxIntensity = apexIntensity; returnFeatures.Add(feature); } return(returnFeatures); }
public void AddSmoothPeak(RTPeak peak) { this.smoothRTPeaks.Add(peak); if (this.maxPeak == null) { this.maxPeak = peak; } if (peak.Intensity > this.maxPeak.Intensity) { this.maxPeak = peak; } this.totalMZTimesIntensity += (peak.Intensity * peak.MZ); this.totalIntensity += (peak.Intensity); this.averageMZ = (this.totalMZTimesIntensity / this.totalIntensity); }
public void AddPeak(MZPeak peak, double RT, double HCDEnergy = 0) { RTPeak newRTPeak = new RTPeak(peak, RT); this.allRTPeaks.Add(newRTPeak); if (peak.Intensity > maxPeak.Intensity) { apexTime = RT; maxPeak = newRTPeak; } this.maxRT = RT; this.totalMZTimesIntensity += (peak.Intensity * peak.MZ); this.totalIntensity += (peak.Intensity); this.averageMZ = (this.totalMZTimesIntensity / this.totalIntensity); newRTPeak.HCDEnergy = HCDEnergy; }
public void AddPeak(RTPeak peak) { this.allRTPeaks.Add(peak); if (maxPeak == null) { MaxPeak = peak; } if (peak.Intensity > maxPeak.Intensity) { apexTime = peak.RT; maxPeak = peak; } this.maxRT = peak.RT; this.totalMZTimesIntensity += (peak.Intensity * peak.MZ); this.totalIntensity += (peak.Intensity); this.averageMZ = (this.totalMZTimesIntensity / this.totalIntensity); }
public int GetLeftStopIndex(int startIndex, List <RTPeak> smoothPeaks, double threshold) { if (startIndex - 1 >= 0) { RTPeak previousPeak = smoothPeaks[startIndex]; RTPeak currentpeak = smoothPeaks[startIndex - 1]; if (currentpeak.Intensity > previousPeak.Intensity && currentpeak.Intensity < threshold) { return(startIndex); } return(GetLeftStopIndex(startIndex - 1, smoothPeaks, threshold)); } else { return(startIndex); } }
public static List <RTPeak> ConvertFeatureStringToPeakList(string featureString) { List <RTPeak> returnList = new List <RTPeak>(); string[] parts = featureString.Split(';'); foreach (var part in parts) { if (!string.IsNullOrEmpty(part)) { string[] subparts = part.Split(','); double rt = double.Parse(subparts[0]); double intensity = double.Parse(subparts[1]); var newRTPeak = new RTPeak(); newRTPeak.RT = rt; newRTPeak.Intensity = intensity; returnList.Add(newRTPeak); } } return(returnList); }
public List <RTPeak> GetRollingAveragePeaks(List <RTPeak> peaks, int period) { List <RTPeak> outPeaks = new List <RTPeak>(); for (int i = 0; i < peaks.Count; i++) { if (i >= period) { double total = 0; for (int x = i; x > (i - period); x--) { total += peaks[x].Intensity; } double average = total / (double)period; RTPeak newPeak = new RTPeak(peaks[i].MZ, average, peaks[i - (period / 2)].RT); outPeaks.Add(newPeak); } } return(outPeaks); }
public List <Feature> GetApexTimePoints(Feature feature) { List <RTPeak> rtPeaks = feature.SmoothRTPeaks; List <double> apexPoints = new List <double>(); List <int> apexIndexes = new List <int>(); List <Feature> returnFeatures = new List <Feature>(); double peakRise = 1.05; double peakFall = 0.9; if (rtPeaks.Count > 0) { double intensityLeft = rtPeaks.First().Intensity; double intensityRight = rtPeaks.Last().Intensity; double threshold = intensityLeft * 2.5; if (intensityRight < intensityLeft) { threshold = intensityRight * 2.5; } bool rising = false; bool falling = false; RTPeak holdingMaxPeak = new RTPeak(0, 0, 0); int holdingMaxIndex = 0; for (int i = 0; i < rtPeaks.Count - 1; i++) { RTPeak currentPoint = rtPeaks[i]; RTPeak nextPoint = rtPeaks[i + 1]; if (!rising && !falling) { if (nextPoint.Intensity >= (currentPoint.Intensity * peakRise) && nextPoint.Intensity > threshold) { rising = true; } } if (rising) { if (nextPoint.Intensity > currentPoint.Intensity) { continue; } else { holdingMaxPeak = currentPoint; holdingMaxIndex = i; rising = false; falling = true; } } if (falling) { if (nextPoint.Intensity < holdingMaxPeak.Intensity) { if (nextPoint.Intensity < holdingMaxPeak.Intensity * peakFall) { apexPoints.Add(holdingMaxPeak.RT); apexIndexes.Add(holdingMaxIndex); falling = false; } } else { holdingMaxPeak = nextPoint; holdingMaxIndex = i + 1; } } } var subFeatures = GetSubFeatures(feature, apexIndexes).ToList(); return(subFeatures); } return(null); }
public bool Equals(RTPeak obj) { return(obj is RTPeak && Equals((RTPeak)obj)); }
public int CompareTo(Object other) { RTPeak otherPeak = (RTPeak)other; return(RT.CompareTo(otherPeak.RT)); }
public int CompareTo(RTPeak other) { return(RT.CompareTo(other.RT)); }