public static double GetPValue(PSM psm, Tolerance prod_tolerance, double cutoff) { // Get the width of the product ion tolerance at the isolation mz; double productToleranceWidth = prod_tolerance.GetRange(psm.IsolationMZ).Width; double cutoffThreshold = psm.Spectrum.GetBasePeakIntensity()*cutoff; return Math.Min(1.0, psm.Spectrum.Count(peak => peak.Intensity >= cutoffThreshold)*2*productToleranceWidth/psm.ScanWidth); }
public static double GetPValue(PSM psm, Tolerance prod_tolerance, double cutoff) { // Get the width of the product ion tolerance at the isolation mz; double productToleranceWidth = prod_tolerance.GetRange(psm.IsolationMZ).Width; double cutoffThreshold = psm.Spectrum.GetBasePeakIntensity() * cutoff; return(Math.Min(1.0, psm.Spectrum.Count(peak => peak.Intensity >= cutoffThreshold) * 2 * productToleranceWidth / psm.ScanWidth)); }
private Tuple <int, int, double> LocalizedIsoformSimple(PSM psm) { int length = psm.Isoforms; List <PeptideIsoform> isoforms = psm.PeptideIsoforms.ToList(); if (length == 1) { return(new Tuple <int, int, double>(0, 0, double.PositiveInfinity)); } int biggesti = 0; int bestI = 0; for (int i = 0; i < length; i++) { var isoform = isoforms[i]; if (isoform.SpectralMatch.Matches > biggesti) { biggesti = isoform.SpectralMatch.Matches; bestI = i; } } int biggestj = 0; int bestJ = bestI; for (int j = 0; j < length; j++) { if (j == bestI) { continue; } var isoform = isoforms[j]; if (isoform.SpectralMatch.Matches > biggestj) { biggestj = isoform.SpectralMatch.Matches; bestJ = j; } } return(new Tuple <int, int, double>(bestI, bestJ, double.PositiveInfinity)); }
private Tuple<int, int, double> LocalizedIsoformSimple(PSM psm) { int length = psm.Isoforms; List<PeptideIsoform> isoforms = psm.PeptideIsoforms.ToList(); if (length == 1) return new Tuple<int, int, double>(0, 0, double.PositiveInfinity); int biggesti = 0; int bestI = 0; for (int i = 0; i < length; i++) { var isoform = isoforms[i]; if (isoform.SpectralMatch.Matches > biggesti) { biggesti = isoform.SpectralMatch.Matches; bestI = i; } } int biggestj = 0; int bestJ = bestI; for (int j = 0; j < length; j++) { if (j == bestI) continue; var isoform = isoforms[j]; if (isoform.SpectralMatch.Matches > biggestj) { biggestj = isoform.SpectralMatch.Matches; bestJ = j; } } return new Tuple<int, int, double>(bestI, bestJ, double.PositiveInfinity); }
private List<PSM> LoadAllPSMs(string csvFile, string rawFileDirectory, List<Modification> fixedMods) { ProgressUpdate(0.0); //force the progressbar to go into marquee mode Log("Reading PSMs from " + csvFile); Dictionary<string, ThermoRawFile> rawFiles = Directory.EnumerateFiles(rawFileDirectory, "*.raw", SearchOption.AllDirectories) .ToDictionary(Path.GetFileNameWithoutExtension, file => new ThermoRawFile(file)); _dataFiles = new HashSet<MSDataFile>(); List<PSM> psms = new List<PSM>(); int totalPsms = 0; using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true)) { while (reader.ReadNextRecord()) { string mods = reader["Mods"]; totalPsms++; // Skip if there are no modifications if (string.IsNullOrEmpty(mods)) continue; // Convert the text mod line into a list of modification objects List<Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).ToList(); // Only keep things with quantified Modifications if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod))) continue; string filename = reader["Filename/id"]; string rawname = filename.Split('.')[0]; int scanNumber = int.Parse(reader["Spectrum number"]); PSM psm = new PSM(scanNumber, rawname); psm.StartResidue = int.Parse(reader["Start"]); psm.Charge = int.Parse(reader["Charge"]); psm.BasePeptide = new Peptide(reader["Peptide"].ToUpper()); psm.Defline = reader["Defline"]; psm.ProteinGroup = reader["Best PG Name"]; psm.NumberOfSharingProteinGroups = int.Parse(reader["# of Sharing PGs"]); psm.Filename = filename; // Apply all the fix modifications psm.BasePeptide.SetModifications(fixedMods); int i = 0; while (i < variableMods.Count) { if (fixedMods.Contains(variableMods[i])) { variableMods.RemoveAt(i); } else { i++; } } // Save all the variable mod types psm.VariabledModifications = variableMods; psms.Add(psm); } } Log(string.Format("{0:N0} PSMs were loaded....", totalPsms)); Log(string.Format("{0:N0} PSMs were kept.... ({1:F2} %)", psms.Count, 100.0 * (double)psms.Count / totalPsms)); Log("Reading Spectral Data..."); ThermoRawFile currentRawFile = null; string currentRawFileName = null; int counter = 0; foreach (PSM psm in psms.OrderBy(psm => psm.RawFileName)) { string rawfilename = psm.RawFileName; if(!rawfilename.Equals(currentRawFileName)) { currentRawFileName = rawfilename; if (currentRawFile != null && currentRawFile.IsOpen) currentRawFile.Dispose(); if (!rawFiles.TryGetValue(rawfilename, out currentRawFile)) { throw new NullReferenceException(string.Format("Raw File: {0}.raw was not found! Aborting.", rawfilename)); } currentRawFile.Open(); } psm.SetRawFile(currentRawFile); counter++; if(counter % 25 == 0) { ProgressUpdate((double)counter / psms.Count); } } return psms; }
private List <PSM> LoadAllPSMs(string csvFile, string rawFileDirectory, List <Modification> fixedMods) { ProgressUpdate(0.0); //force the progressbar to go into marquee mode Log("Reading PSMs from " + csvFile); Dictionary <string, ThermoRawFile> rawFiles = Directory.EnumerateFiles(rawFileDirectory, "*.raw", SearchOption.AllDirectories) .ToDictionary(Path.GetFileNameWithoutExtension, file => new ThermoRawFile(file)); _dataFiles = new HashSet <MSDataFile>(); List <PSM> psms = new List <PSM>(); int totalPsms = 0; using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true)) { while (reader.ReadNextRecord()) { string mods = reader["Mods"]; totalPsms++; // Skip if there are no modifications if (string.IsNullOrEmpty(mods)) { continue; } // Convert the text mod line into a list of modification objects List <Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).ToList(); // Only keep things with quantified Modifications if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod))) { continue; } string filename = reader["Filename/id"]; string rawname = filename.Split('.')[0]; int scanNumber = int.Parse(reader["Spectrum number"]); PSM psm = new PSM(scanNumber, rawname); psm.StartResidue = int.Parse(reader["Start"]); psm.Charge = int.Parse(reader["Charge"]); psm.BasePeptide = new Peptide(reader["Peptide"].ToUpper()); psm.Defline = reader["Defline"]; psm.ProteinGroup = reader["Best PG Name"]; psm.NumberOfSharingProteinGroups = int.Parse(reader["# of Sharing PGs"]); psm.Filename = filename; // Apply all the fix modifications psm.BasePeptide.SetModifications(fixedMods); int i = 0; while (i < variableMods.Count) { if (fixedMods.Contains(variableMods[i])) { variableMods.RemoveAt(i); } else { i++; } } // Save all the variable mod types psm.VariabledModifications = variableMods; psms.Add(psm); } } Log(string.Format("{0:N0} PSMs were loaded....", totalPsms)); Log(string.Format("{0:N0} PSMs were kept.... ({1:F2} %)", psms.Count, 100.0 * (double)psms.Count / totalPsms)); Log("Reading Spectral Data..."); ThermoRawFile currentRawFile = null; string currentRawFileName = null; int counter = 0; foreach (PSM psm in psms.OrderBy(psm => psm.RawFileName)) { string rawfilename = psm.RawFileName; if (!rawfilename.Equals(currentRawFileName)) { currentRawFileName = rawfilename; if (currentRawFile != null && currentRawFile.IsOpen) { currentRawFile.Dispose(); } if (!rawFiles.TryGetValue(rawfilename, out currentRawFile)) { throw new NullReferenceException(string.Format("Raw File: {0}.raw was not found! Aborting.", rawfilename)); } currentRawFile.Open(); } psm.SetRawFile(currentRawFile); counter++; if (counter % 25 == 0) { ProgressUpdate((double)counter / psms.Count); } } return(psms); }