Esempio n. 1
0
        /// <summary>
        /// Check if iso cyanic acid loss is present in the spectrum's MS1 scan.
        /// </summary>
        /// <param name="spectrum">The spectrum to be checked.</param>
        /// <returns>True, if isocyanic acid is present; Otherwise, false.</returns>
        private static bool IsIsoCyanicAcidLossPresentMs1(MsSpectrum spectrum)
        {
            // Get the precursor m/z value
            double precursorMz = spectrum.PreCursorMz;

            // Loop through all of the M/Z-values
            foreach (double mzVal in spectrum.ParentScan.MzValues)
            {
                // Check that the m/z is not greater than the precursor, because the code is looking for an loss i.e. a value less than the precursor
                // TODO: Maybe insert to increase speed.
                //if(mzVal > precursorMz) { break; }

                // Check if the isocyanic neutral loss is present.
                if (HelperUtilities.IsApproximately(mzVal, precursorMz - 43, ScoreSettings.CyanicLossTolerance))
                {
                    // The isocyanic netural loss ion is found
                    // If that is the case set the M/Z value of the ion
                    spectrum.IsoCyanicMzMs1 = mzVal;
                    // Return true, because the ion was found
                    return(true);
                }
            }

            // No loss was found. Set the m/z value for the loss ion to an impossible value
            spectrum.IsoCyanicMzMs1 = -1;
            // Return false, because no ion was found
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Calculate the extracted ion count from a <paramref name="spectrum"/>.
        /// </summary>
        /// <param name="spectrum">The spectrum to be calculated.</param>
        /// <param name="xic">The current extracted ion count.</param>
        /// <param name="input">The input file.</param>
        /// <returns>The extracted ion count for the spectrum.</returns>
        private static double CalculateExtractedIonCount(MsSpectrum spectrum, double xic, Input input)
        {
            // Calculate the retention time interval
            int timeLow  = spectrum.RetentionTime - (rTInterval * 60);
            int timeHigh = spectrum.RetentionTime + (rTInterval * 60);

            // Loop through the MS1 scans
            foreach (RawScan ms1 in input.MS1Scans)
            {
                // Check if the retention time are within the interval
                if (ms1.RetentionTime >= timeLow & ms1.RetentionTime <= timeHigh)
                {
                    // If so, loop through the M/Z values
                    for (int i = 0; i <= ms1.MzValues.Length - 1; i++)
                    {
                        // Calculate the PPM deviation. TODO: Is this correct?
                        double delta = CalculatePPMDeviation(spectrum.PreCursorMz, ppm);
                        // If the difference between the precursor M/Z and current M/Z value is less than the deviation, then add the intensity to the extracted ion count
                        if (spectrum.PreCursorMz - ms1.MzValues[i] <= delta)
                        {
                            xic += ms1.Intencities[i];
                        }
                    }
                }
            }

            return(xic);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the spectra from the new quantification.
        /// </summary>
        /// <param name="result">The quantification result.</param>
        private void GetSpectra(QuantResult result)
        {
            // Get the cit spectrum ID
            int citSpectrumId = result.CitSpectrumID;

            // From the validation type, get the spectra information
            if (result.ValidationBy == "Cit-paired")
            {
                // Loop through all of the cit spectra to get the spectra
                foreach (var item in Quantification.citSpecSpecDict)
                {
                    if (item.Key.ID == citSpectrumId)
                    {
                        citSpectrum = item.Key;
                        argSpectrum = item.Value;
                    }
                }
            }
            else
            {
                // Loop through all of the arg spectra to get the spectra
                foreach (var item in Quantification.argSpecScanDict)
                {
                    if (item.Value.ScanNumber == citSpectrumId)
                    {
                        citSpectrum = item.Value;
                        argSpectrum = item.Key;
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get the spectra from the new quantification.
        /// </summary>
        /// <param name="result">The quantification result.</param>
        private void GetSpectra(QuantResult result)
        {
            // Get the cit spectrum ID
            int citSpectrumId = result.CitSpectrumID;

            foreach (var item in Quantification.loneCitSpecList)
            {
                if (item.ID == citSpectrumId)
                {
                    citSpectrum = item;
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create the quantification result dictionary.
        /// </summary>
        /// <returns>The dictionary with the quantification result and the spectra in keyvaluepair.</returns>
        private Dictionary <QuantResult, KeyValuePair <MsSpectrum, MsSpectrum> > CreateQuantificationResultDictionary()
        {
            // Create an empty dictionary to hold the the results
            Dictionary <QuantResult, KeyValuePair <MsSpectrum, MsSpectrum> > dict = new Dictionary <QuantResult, KeyValuePair <MsSpectrum, MsSpectrum> >();

            // Loop through all of the quantification results
            foreach (QuantResult result in Quantification.QuantificationResults)
            {
                MsSpectrum citSpectrum = null;
                MsSpectrum argSpectrum = null;

                // Get the spectra depending on on the validation type
                if (result.ValidationBy == "Cit-paired")
                {
                    var spec = Quantification.citSpecSpecDict.Where(citSpec => citSpec.Key.ID == result.CitSpectrumID).First();
                    citSpectrum = spec.Key;
                    argSpectrum = spec.Value;
                }
                else if (result.ValidationBy == "Arg-paired")
                {
                    var spec = Quantification.argSpecScanDict.Where(citSpec => citSpec.Value.ScanNumber == result.CitSpectrumID).First();
                    citSpectrum = spec.Value;
                    argSpectrum = spec.Key;
                }
                else if (result.ValidationBy == "Lone")
                {
                    citSpectrum = Quantification.loneCitSpecList.Where(citSpec => citSpec.ID == result.CitSpectrumID).First();
                    argSpectrum = null;
                }
                else
                {
                    // If it is none if them, something is wrong. Write to debug console and contine
                    System.Console.WriteLine($"WARNING: Quantification result (Citrullination: ID {result.CitSpectrumID} from '{result.CitFileName}'." +
                                             $"Arginine: ID {result.ArgSpectrumID} from '{result.ArgFileName})' has an invalid validation type '{result.ValidationBy}'");
                    continue;
                }

                // Add data to dictionary
                dict.Add(result, new KeyValuePair <MsSpectrum, MsSpectrum>(citSpectrum, argSpectrum));
            }

            // Return result
            return(dict);
        }
Esempio n. 6
0
        /// <summary>
        /// Validate spectrum fragmentation.
        /// </summary>
        /// <param name="spectrum">The spectrum with the fragmentation to be validated.</param>
        /// <param name="aaSequence">The amino acid sequence.</param>
        /// <returns>True, if valid fragmentation; Otherwise, false.</returns>
        private static bool ValidateSpectrumFragmentation(MsSpectrum spectrum, string[] aaSequence)
        {
            // Check that spectrum contains an arginine
            if (aaSequence.Contains("R") == false)
            {
                return(false);
            }

            // Check spectrum whether the spectrum contains  and N/Q.
            if ((aaSequence.Contains("N") | aaSequence.Contains("Q")) == false)
            {
                //If it does not contain, N / Q it is concidered valid
                return(true);
            }

            // Get the closset N/Q and R amino acid indexes
            GetClossetNQRAaRange(aaSequence, out int[] aaIndexes);

            // Loop through all of the aa indexes
            for (int aaIndex = 0; aaIndex < aaIndexes.Length; aaIndex++)
            {
                // Get the amino acid index
                int aa = aaIndexes[aaIndex];

                if (spectrum.BIonIndex.Contains(aa))
                {
                    return(true);
                }
                if (spectrum.YIonIndex.Contains(-aa + aaSequence.Length - 1))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// Count the presence of isocyanic acid loss on MS2.
        /// </summary>
        /// <param name="citSpectrum">The citrullinated spectrum.</param>
        /// <param name="citIndex">The index of the citrullinated arginine.</param>
        /// <param name="aaSeq">The amino acid sequence.</param>
        /// <returns>The number of isocyanic acid losses.</returns>
        private static double CountIsoCyanicAcidLossPresentMs2(MsSpectrum citSpectrum, int citIndex, string[] aaSeq)
        {
            // Create temporay list of isocyanic loss M/Z
            List <double> cyanlossMz = new List <double>();

            // Create scores
            int aIonCount   = 0;
            int bIonCount   = 0;
            int b17IonCount = 0;
            int b18IonCount = 0;
            int yIonCount   = 0;
            int y17IonCount = 0;
            int y18IonCount = 0;

            List <double> mzValues = citSpectrum.MzValues.ToList();

            mzValues.Reverse();
            foreach (double mzVal in mzValues)
            {
                // Loop through the all of amino acid sequence.However only the index is used.
                for (int i = 0; i < aaSeq.Length; i++)
                {
                    if (IsoListContains(cyanlossMz, mzVal))
                    {
                        continue;
                    }
                    // Check that the this is the citrullinated a- or b-ions. The aa index is greater than or equal to the index of the citrullination.
                    if (i >= citIndex)
                    {
                        // Check that both spectra contains the A-ion at this specific amino acid
                        if (citSpectrum.AIonIndex.Contains(i))
                        {
                            /* Calculate A-ion */
                            // Get the M/Z value for A-ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleAIons[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                aIonCount++;
                                continue;
                            }
                        }

                        // Check that both spectra contains the B-ion at this specific amino acid
                        if (citSpectrum.BIonIndex.Contains(i))
                        {
                            /* Calculate B-ion */
                            // Get the M/Z value for B-ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleBIons[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                bIonCount++;
                                continue;
                            }
                        }

                        // Check that both spectra contains the B-17 ion at this specific amino acid
                        if (citSpectrum.B17IonIndex.Contains(i))
                        {
                            /* Calculate B-17 ion */
                            // Get the M/Z value for B-17 ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleBm17Ions[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                b17IonCount++;
                                continue;
                            }
                        }

                        // Check that both spectra contains the B-18 ion at this specific amino acid
                        if (citSpectrum.B18IonIndex.Contains(i))
                        {
                            /* Calculate B-18 ion */
                            // Get the M/Z value for B-18 ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleBm18Ions[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                b18IonCount++;
                                continue;
                            }
                        }
                    }
                    // Check that the this is the citrullinated y-ion. The aa index is less than or equal to the index of the citrullination.
                    if (i <= citIndex)
                    {
                        // Check that both spectra contains the Y-ion at this specific amino acid
                        if (citSpectrum.YIonIndex.Contains(i))
                        {
                            /* Calculate Y-ion */
                            // Get the M/Z value for Y-ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleYIons[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                yIonCount++;
                                continue;
                            }
                        }

                        // Check that both spectra contains the Y-17 ion at this specific amino acid
                        if (citSpectrum.Y17IonIndex.Contains(i))
                        {
                            /* Calculate Y-17 ion */
                            // Get the M/Z value for Y-17 ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleYm17Ions[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                y17IonCount++;
                                continue;
                            }
                        }

                        // Check that both spectra contains the Y-18 ion at this specific amino acid
                        if (citSpectrum.Y18IonIndex.Contains(i))
                        {
                            /* Calculate Y-18 ion */
                            // Get the M/Z value for Y-18 ion on the complementary citrullinated spectrum
                            double citMz = citSpectrum.SpectrumPossibleYm18Ions[i];
                            // If the spectrum has an ion that is 43 Da less than the cit spectrum, add the spectrum m/z to the list
                            if (HelperUtilities.IsApproximately(mzVal, citMz - 43, ScoreSettings.CyanicLossTolerance))
                            {
                                cyanlossMz.Add(mzVal);
                                y18IonCount++;
                                continue;
                            }
                        }
                    }
                }
            }

            // Set collection
            citSpectrum.IsoCyanicLossMzMs2 = cyanlossMz.ToArray();
            // Calculate score
            double score = aIonCount * ScoreSettings.MS2IsoCyanLossAScore;

            score += bIonCount * ScoreSettings.MS2IsoCyanLossBScore;
            score += b17IonCount * (ScoreSettings.MS2IsoCyanLossBScore / ScoreSettings.MS2IsoCyanOnLossScoreDivider);
            score += b18IonCount * (ScoreSettings.MS2IsoCyanLossBScore / ScoreSettings.MS2IsoCyanOnLossScoreDivider);
            score += yIonCount * ScoreSettings.MS2IsoCyanLossYScore;
            score += y17IonCount * (ScoreSettings.MS2IsoCyanLossYScore / ScoreSettings.MS2IsoCyanOnLossScoreDivider);
            score += y18IonCount * (ScoreSettings.MS2IsoCyanLossYScore / ScoreSettings.MS2IsoCyanOnLossScoreDivider);
            // TODO: Set score instead of count
            //return cyanlossMz.Count;
            return(score);
        }