public override SortedMaxSizedContainer <PeptideSpectralMatch> Search(IMassSpectrum spectrum, IEnumerable <Peptide> peptides, FragmentTypes fragmentTypes, Tolerance productMassTolerance) { SortedMaxSizedContainer <PeptideSpectralMatch> results = new SortedMaxSizedContainer <PeptideSpectralMatch>(MaxMatchesPerSpectrum); double[] eMasses = spectrum.MassSpectrum.GetMasses(); double[] eIntenisties = spectrum.MassSpectrum.GetIntensities(); double tic = spectrum.MassSpectrum.GetTotalIonCurrent(); ; foreach (var peptide in peptides) { PeptideSpectralMatch psm = new PeptideSpectralMatch(DefaultPsmScoreType) { Peptide = peptide }; double[] tMasses = peptide.Fragment(fragmentTypes) .Select(frag => Mass.MzFromMass(frag.MonoisotopicMass, 1)) .OrderBy(val => val) .ToArray(); double score = Search(eMasses, eIntenisties, tMasses, productMassTolerance, tic); psm.Score = score; results.Add(psm); } return(results); }
public void SortedMaxSizedContainerMaxSizeNotExceeded() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 1, 2, 3, 4, 5, 6, 7 }; Assert.AreEqual(container.Count, container.MaxSize); }
public void SortedMaxSizedContainerRemoveExistentItem() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; Assert.IsTrue(container.Remove(3)); }
public void SortedMaxSizedContainerDoesNotContainsItem() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; Assert.IsFalse(container.Contains(7)); }
public void SortedMaxSizedContainerContainsItem() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; Assert.IsTrue(container.Contains(3)); }
public void SortedMaxSizedContainerAddDefaultItem() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 0, 0, 0, 0, 0, 0, 0, 0 }; Assert.AreEqual(container.Count, 5); }
public void SortedMaxSizedContainerRemoveExistentItemProperCount() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; container.Remove(3); Assert.AreEqual(container.Count, 4); }
public void SortedMaxSizedContainerRemoveExistentItemDoesntContain() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; container.Remove(3); Assert.IsFalse(container.Contains(3)); }
public void SortedMaxSizedContainerClear() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 1, 2, 3 }; container.Clear(); Assert.AreEqual(container.Count, 0); }
public void SortedMaxSizedContainerOnlySmallestItemsRemain() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 1, 2, 3, 4, 5 }); }
public void SortedMaxSizedContainerClearMaxSizeUneffected() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 1, 2, 3 }; container.Clear(); Assert.AreEqual(container.MaxSize, 5); }
public void SortedMaxSizedContainerInverseComparer() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5, Comparer <int> .Create((a, b) => b.CompareTo(a))) { 7, 6, 5, 4, 3, 2, 1 }; int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 7, 6, 5, 4, 3 }); }
public void SortedMaxSizedContainerRemoveFirstItemCorrectCollection() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 7, 6, 5, 4, 3, 2, 1 }; container.Remove(1); int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 2, 3, 4, 5 }); }
public void SortedMaxSizedContainerLargeRemoveCount() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(25); for (int i = 0; i < 30; i++) { container.Add(i); } container.Remove(17); Assert.AreEqual(container.Count, 24); }
public void SortedMaxSizedContainerLargeRemove() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(25); for (int i = 0; i < 30; i++) { container.Add(i); } Assert.IsTrue(container.Remove(17)); }
public void SortedMaxSizedContainerLarge() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(25); for (int i = 0; i < 30; i++) { container.Add(i); } Assert.AreEqual(container.Count, 25); }
public void SortedMaxSizedContainerRemoveDuplicateItemCorrectCollection() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5) { 1, 1, 1, 1, 1, 1, 1 }; container.Remove(1); int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 1, 1, 1, 1 }); }
public virtual SortedMaxSizedContainer <PeptideSpectralMatch> Search(IMassSpectrum massSpectrum, IEnumerable <Peptide> peptides, FragmentTypes fragmentTypes, Tolerance productMassTolerance) { SortedMaxSizedContainer <PeptideSpectralMatch> results = new SortedMaxSizedContainer <PeptideSpectralMatch>(MaxMatchesPerSpectrum); foreach (var peptide in peptides) { results.Add(Search(massSpectrum, peptide, fragmentTypes, productMassTolerance)); } return(results); }
public void Read(IList <Modification> fixedModifications, int numberOfTopHits = 1, bool higherScoresAreBetter = false) { _data.Clear(); bool first = true; using (CsvReader reader = new CsvReader(new StreamReader(FilePath), true)) { string[] headers = reader.GetFieldHeaders(); HasPPMInfo = headers.Contains("Precursor Mass Error (ppm)"); while (reader.ReadNextRecord()) { if (first) { RawFileName = reader["Filename/id"].Split('.')[0]; first = false; } int scanNumber = int.Parse(reader["Spectrum number"]); PSM psm = new PSM(scanNumber) { Score = double.Parse(reader["E-value"]) }; SortedMaxSizedContainer <PSM> peptides; if (!_data.TryGetValue(scanNumber, out peptides)) { peptides = new SortedMaxSizedContainer <PSM>(numberOfTopHits); _data.Add(scanNumber, peptides); } if (!peptides.Add(psm)) { continue; } psm.FileName = reader["Filename/id"]; psm.Charge = int.Parse(reader["Charge"]); psm.IsDecoy = reader["Defline"].StartsWith("DECOY_"); if (HasPPMInfo) { psm.PrecursorMassError = double.Parse(reader["Precursor Mass Error (ppm)"]); } psm.SetSequenceAndMods(reader["Peptide"].ToUpper(), fixedModifications, reader["Mods"]); } } PeptideSpectralMatches.Clear(); foreach (SortedMaxSizedContainer <PSM> set in _data.Values) { PeptideSpectralMatches.AddRange(set); } }
public void SortedMaxSizedContainerLargeRemoveEach() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(25); for (int i = 0; i < 30; i++) { container.Add(i); } for (int i = 0; i < 25; i++) { container.Remove(i); } Assert.AreEqual(container.Count, 0); }
public override SortedMaxSizedContainer<PeptideSpectralMatch> Search(IMassSpectrum spectrum, IEnumerable<Peptide> peptides, FragmentTypes fragmentTypes, Tolerance productMassTolerance) { SortedMaxSizedContainer<PeptideSpectralMatch> results = new SortedMaxSizedContainer<PeptideSpectralMatch>(MaxMatchesPerSpectrum); double[] eMasses = spectrum.MassSpectrum.GetMasses(); double[] eIntenisties = spectrum.MassSpectrum.GetIntensities(); double tic = spectrum.MassSpectrum.TotalIonCurrent; foreach (var peptide in peptides) { PeptideSpectralMatch psm = new PeptideSpectralMatch(DefaultPsmScoreType) {Peptide = peptide}; double[] tMasses = peptide.Fragment(fragmentTypes) .Select(frag => Mass.MzFromMass(frag.MonoisotopicMass, 1)) .OrderBy(val => val) .ToArray(); double score = Search(eMasses, eIntenisties, tMasses, productMassTolerance, tic); psm.Score = score; results.Add(psm); } return results; }
public void SortedMaxSizedContainerRemoveNonExistentItem() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; Assert.IsFalse(container.Remove(7)); }
public void SortedMaxSizedContainerRemoveExistentItemProperCount() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; container.Remove(3); Assert.AreEqual(container.Count, 4); }
public void SortedMaxSizedContainerMaxSize() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5); Assert.AreEqual(container.MaxSize, 5); }
public void SortedMaxSizedContainerLarge() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(25); for (int i = 0; i < 30; i++) container.Add(i); Assert.AreEqual(container.Count, 25); }
public void SortedMaxSizedContainerDoesNotContainsItem() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; Assert.IsFalse(container.Contains(7)); }
public void SortedMaxSizedContainerContainsItem() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; Assert.IsTrue(container.Contains(3)); }
public void SortedMaxSizedContainerClear() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 1, 2, 3 }; container.Clear(); Assert.AreEqual(container.Count, 0); }
public void SortedMaxSizedContainerLargeRemove() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(25); for (int i = 0; i < 30; i++) container.Add(i); Assert.IsTrue(container.Remove(17)); }
public void Read(IList<Modification> fixedModifications, int numberOfTopHits = 1, bool higherScoresAreBetter = false) { _data.Clear(); bool first = true; using (CsvReader reader = new CsvReader(new StreamReader(FilePath), true)) { string[] headers = reader.GetFieldHeaders(); HasPPMInfo = headers.Contains("Precursor Mass Error (ppm)"); while (reader.ReadNextRecord()) { if (first) { RawFileName = reader["Filename/id"].Split('.')[0]; first = false; } int scanNumber = int.Parse(reader["Spectrum number"]); PSM psm = new PSM(scanNumber) {Score = double.Parse(reader["E-value"])}; SortedMaxSizedContainer<PSM> peptides; if (!_data.TryGetValue(scanNumber, out peptides)) { peptides = new SortedMaxSizedContainer<PSM>(numberOfTopHits); _data.Add(scanNumber, peptides); } if (!peptides.Add(psm)) continue; psm.FileName = reader["Filename/id"]; psm.Charge = int.Parse(reader["Charge"]); psm.IsDecoy = reader["Defline"].StartsWith("DECOY_"); if (HasPPMInfo) psm.PrecursorMassError = double.Parse(reader["Precursor Mass Error (ppm)"]); psm.SetSequenceAndMods(reader["Peptide"].ToUpper(), fixedModifications, reader["Mods"]); } } PeptideSpectralMatches.Clear(); foreach (SortedMaxSizedContainer<PSM> set in _data.Values) { PeptideSpectralMatches.AddRange(set); } }
public void UpdatePsmInformation(MSDataFile dataFile, bool is2dFDR = true, bool useMedian = true, double evalueThreshold = 1e-3) { List <double> errors = new List <double>(); MaximumPrecursorMassError = 0; int count = 0; int msms = 0; int ms = 0; int localMSMS = -1; List <int> msmsBetweenMS = new List <int>(); List <double> injectionTimes = new List <double>(); for (int sn = dataFile.FirstSpectrumNumber; sn <= dataFile.LastSpectrumNumber; sn++) { int order = dataFile.GetMsnOrder(sn); if (order == 1) { ms++; if (localMSMS >= 0) { msmsBetweenMS.Add(localMSMS); } localMSMS = 0; } else { localMSMS++; msms++; injectionTimes.Add(dataFile.GetInjectionTime(sn)); } } MaxMSMSScansBetweenMS = msmsBetweenMS.Max(); AverageMSMSSCansBetweenMS = msmsBetweenMS.Average(); TotalMSMSscans = msms; TotalMSscans = ms; AverageMSMSInjectionTime = injectionTimes.Average(); MaxMSMSInjectionTime = injectionTimes.Max(); foreach (KeyValuePair <int, SortedMaxSizedContainer <PSM> > kvp in _data) { int scanNumber = kvp.Key; SortedMaxSizedContainer <PSM> psms = kvp.Value; double isolationMZ = dataFile.GetPrecusorMz(scanNumber); Polarity polarity = dataFile.GetPolarity(scanNumber); foreach (PSM psm in psms) { psm.Charge *= (int)polarity; // For negative mode ions psm.IsolationMz = isolationMZ; double isolationMass = Mass.MassFromMz(isolationMZ, psm.Charge); double theoreticalMass = psm.MonoisotopicMass; int nominalMassOffset; double adjustedIsolationMass; Tolerance tolerancePPM = Tolerance.CalculatePrecursorMassError(theoreticalMass, isolationMass, out nominalMassOffset, out adjustedIsolationMass); psm.AdjustedIsolationMass = adjustedIsolationMass; psm.IsotopeSelected = nominalMassOffset; if (!HasPPMInfo) { psm.PrecursorMassError = tolerancePPM.Value; } double positive = Math.Abs(psm.PrecursorMassError); if (positive > MaximumPrecursorMassError) { MaximumPrecursorMassError = positive; } if (psm.FdrScoreMetric <= evalueThreshold) { errors.Add(psm.PrecursorMassError); } count++; } } SystematicPrecursorMassError = useMedian ? GetMedianValue(errors) : errors.Average(); // Adjust all psms to foreach (PSM psm in PeptideSpectralMatches) { psm.CorrectedPrecursorMassError = psm.PrecursorMassError - SystematicPrecursorMassError; } }
public void SortedMaxSizedContainerRemoveNonExistentItemCorrectCollection() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; container.Remove(8); int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 1, 2, 3, 4, 5 }); }
public void SortedMaxSizedContainerMaxSize() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5); Assert.AreEqual(container.MaxSize, 5); }
public void SortedMaxSizedContainerAddDefaultItem() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 0, 0, 0, 0, 0, 0, 0, 0 }; Assert.AreEqual(container.Count, 5); }
public void SortedMaxSizedContainerMaxSizeNotExceeded() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 1, 2, 3, 4, 5, 6, 7 }; Assert.AreEqual(container.Count, container.MaxSize); }
public void SortedMaxSizedContainerClearMaxSizeUneffected() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 1, 2, 3 }; container.Clear(); Assert.AreEqual(container.MaxSize, 5); }
public void SortedMaxSizedContainerOnlySmallestItemsRemain() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 1, 2, 3, 4, 5 }); }
public void SortedMaxSizedContainerCountIntiallyZero() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5); Assert.AreEqual(container.Count, 0); }
public void SortedMaxSizedContainerRemoveDuplicateItemCorrectCollection() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 1, 1, 1, 1, 1, 1, 1 }; container.Remove(1); int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 1, 1, 1, 1 }); }
public void SortedMaxSizedContainerInverseComparer() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5, Comparer<int>.Create((a, b) => b.CompareTo(a))) { 7, 6, 5, 4, 3, 2, 1 }; int[] data = container.ToArray(); Assert.AreEqual(data, new[] { 7, 6, 5, 4, 3 }); }
public void SortedMaxSizedContainerRemoveExistentItemDoesntContain() { SortedMaxSizedContainer<int> container = new SortedMaxSizedContainer<int>(5) { 7, 6, 5, 4, 3, 2, 1 }; container.Remove(3); Assert.IsFalse(container.Contains(3)); }
public virtual SortedMaxSizedContainer<PeptideSpectralMatch> Search(IMassSpectrum massSpectrum, IEnumerable<Peptide> peptides, FragmentTypes fragmentTypes, Tolerance productMassTolerance) { SortedMaxSizedContainer<PeptideSpectralMatch> results = new SortedMaxSizedContainer<PeptideSpectralMatch>(MaxMatchesPerSpectrum); foreach (var peptide in peptides) { results.Add(Search(massSpectrum, peptide, fragmentTypes, productMassTolerance)); } return results; }
public void SortedMaxSizedContainerCountIntiallyZero() { SortedMaxSizedContainer <int> container = new SortedMaxSizedContainer <int>(5); Assert.AreEqual(container.Count, 0); }