/* triple wave building codesnippet * * int length = (int)(SampleRate * BlockAlign * duration); * byte[] buffer = new byte[length]; * * double A = frequency * 2 * Math.PI / (double)SampleRate; * for (int i = 0; i < length; i++) * { * if (i > 1) buffer[i] = (byte)(2 * Math.Cos(A) * buffer[i - 1] - buffer[i - 2]); * else if (i > 0) buffer[i] = (byte)(2 * Math.Cos(A) * buffer[i - 1] - (Math.Cos(A))); * else buffer[i] = (byte)(2 * Math.Cos(A) * Math.Cos(A) - Math.Cos(2 * A)); * } * * public double CalculateGoertzel(byte[] sample, double frequency, int samplerate) * { * double Skn, Skn1, Skn2; * Skn = Skn1 = Skn2 = 0; * for (int i = 0; i < sample.Length; i++) * { * Skn2 = Skn1; * Skn1 = Skn; * Skn = 2 * Math.Cos(2 * Math.PI * frequency / samplerate) * Skn1 - Skn2 + sample[i]; * } * * double WNk = Math.Exp(-2 * Math.PI * frequency / samplerate); * * return 20 * Math.Log10(Math.Abs((Skn - WNk * Skn1))); * } * * public int TestGoertzel(int frequency, byte[] sample, int samplerate) * { * int stepsize = frequency / 5; * Dictionary<int, double> res = new Dictionary<int, double>(); * for (int i = 0; i < 10; i++) * { * int freq = stepsize * i; * res.Add(freq, CalculateGoertzel(sample, freq, samplerate)); * } * } */ private void BuildDiagram(ZedGraph.ZedGraphControl zg, byte[] _data) { ZedGraph.GraphPane myPane = zg.GraphPane; ZedGraph.LineItem curve = null; if (myPane.CurveList.Count >= 1) { curve = myPane.CurveList[0] as ZedGraph.LineItem; curve.Clear(); } else { curve = new ZedGraph.LineItem("SPS"); } // Make sure that the curvelist has at least one curve for (int i = 0; i < _data.Length; i++) { curve.AddPoint(i, _data[i]); } ZedGraph.IPointList list = curve.Points as ZedGraph.IPointList; if (myPane.CurveList.Count == 0) { myPane.AddCurve("Wave", list, Color.DimGray, ZedGraph.SymbolType.None); } zg.AxisChange(); zg.Invalidate(); }
public PointMap(ZedGraph.IPointList pointList) { for (int i = 0; i < pointList.Count; ++i) { Add(pointList[i].X, pointList[i].Y); } }
public void deltaScoreTest() { Spectrum rawSpectrum = spectrum.Element; // Work around to have a sort function in List. ZedGraph.IPointList peaks = spectrum.Points; List <ScoringUtils.Peak> rawPeaks = new List <ScoringUtils.Peak>(); for (int i = 0; i < peaks.Count; ++i) { rawPeaks.Add(new ScoringUtils.Peak(peaks[i].X, peaks[i].Y)); } // Remove the precursor and associated neutral loss peaks double precursorMZ = rawSpectrum.precursors[0].selectedIons[0].cvParam(pwiz.CLI.cv.CVID.MS_selected_ion_m_z).value; ScoringUtils.erasePrecursorIons(precursorMZ, ref rawPeaks); // Filter the peaks and rank them based on increasing // order of intensity: i.e. intense peaks get higher ranks rawPeaks = ScoringUtils.filterByPeakCount(rawPeaks, 100); Set <ScoringUtils.Peak> rankedPeaks = new Set <ScoringUtils.Peak>(rawPeaks); //Set<Peak> rankedPeaks = rankPeaks(rawPeaks); //string alt = ""; //InputBox("Alternative", "Enter Alt peptide", ref alt); Peptide alternative; try { alternative = new Peptide(annotation.SecondarySequence, pwiz.CLI.proteome.ModificationParsing.ModificationParsing_Auto, pwiz.CLI.proteome.ModificationDelimiter.ModificationDelimiter_Brackets); } catch (Exception) { return; } Set <double> primaryMatchFragMasses = new Set <double>(); ScoringUtils.calculateSequenceIons(annotation.Peptide, 2, ref primaryMatchFragMasses); Set <double> secondaryMatchFragMasses = new Set <double>(); ScoringUtils.calculateSequenceIons(alternative, 2, ref secondaryMatchFragMasses); Set <ScoringUtils.Peak> primarySeqMatchedIons = new Set <ScoringUtils.Peak>(); double primarySeqMatchedIntens = 0.0; foreach (var peak in primaryMatchFragMasses) { ScoringUtils.Peak match = ScoringUtils.findNear(rankedPeaks, peak, 0.5); if (match != null) { primarySeqMatchedIons.Add(match); primarySeqMatchedIntens += match.rankOrIntensity; } } Set <ScoringUtils.Peak> secondarySeqMatchedIons = new Set <ScoringUtils.Peak>(); double secondarySeqMatchedIntens = 0; foreach (var peak in secondaryMatchFragMasses) { ScoringUtils.Peak match = ScoringUtils.findNear(rankedPeaks, peak, 0.5); if (match != null) { secondarySeqMatchedIons.Add(match); secondarySeqMatchedIntens += match.rankOrIntensity; } } double TIC = 0.0; foreach (var peak in rankedPeaks) { TIC += peak.rankOrIntensity; } MessageBox.Show("PRS:" + primarySeqMatchedIntens + " SRS:" + secondarySeqMatchedIntens + " TIC:" + TIC); }