示例#1
0
文件: PSM.cs 项目: trishorts/Compass
 public void MatchIsofroms(FragmentTypes type, Tolerance tolerance, double cutoffThreshold, bool phopshoNeutralLoss, params int[] chargeStates)
 {
     foreach (PeptideIsoform isoform in PeptideIsoforms)
     {
         isoform.MatchSpectrum(type, tolerance, cutoffThreshold, phopshoNeutralLoss, chargeStates);
     }
 }
示例#2
0
 public Fragment(FragmentTypes type, int number, double monoisotopicMass, AminoAcidPolymer parent)
 {
     Type             = type;
     Number           = number;
     Parent           = parent;
     MonoisotopicMass = monoisotopicMass;
 }
示例#3
0
        public void TestGetIonCapFailFail()
        {
            FragmentTypes f = FragmentTypes.All;

            Assert.That(() => f.GetIonCap(), Throws.TypeOf <MzLibException>()
                        .With.Property("Message")
                        .EqualTo("Fragment Type must be a single value to determine the ion cap"));
        }
示例#4
0
        public void TestGetTerminusFail()
        {
            FragmentTypes f = FragmentTypes.a | FragmentTypes.adot;

            Assert.That(() => f.GetTerminus(), Throws.TypeOf <MzLibException>()
                        .With.Property("Message")
                        .EqualTo("Fragment Type must be a single value to determine the terminus"));
        }
示例#5
0
 public static ChemicalFormula GetIonCap(this FragmentTypes fragmentType)
 {
     if (fragmentType == FragmentTypes.None || (fragmentType & (fragmentType - 1)) != FragmentTypes.None)
     {
         throw new MzLibException("Fragment Type must be a single value to determine the ion cap");
     }
     return(FragmentIonCaps[fragmentType]);
 }
示例#6
0
 public static Terminus GetTerminus(this FragmentTypes fragmentType)
 {
     // Super handy: http://stackoverflow.com/questions/4624248/c-logical-riddle-with-bit-operations-only-one-bit-is-set
     if (fragmentType == FragmentTypes.None || (fragmentType & (fragmentType - 1)) != FragmentTypes.None)
     {
         throw new MzLibException("Fragment Type must be a single value to determine the terminus");
     }
     return(fragmentType >= FragmentTypes.x ? Terminus.C : Terminus.N);
 }
        public override PeptideSpectralMatch Search(IMassSpectrum massSpectrum, Peptide peptide, FragmentTypes fragmentTypes, Tolerance productMassTolerance)
        {
            double[] eMasses = massSpectrum.MassSpectrum.GetMasses();
            double[] eIntenisties = massSpectrum.MassSpectrum.GetIntensities();
            double tic = massSpectrum.MassSpectrum.GetTotalIonCurrent();

            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;

            return psm;
        }
示例#8
0
 public static IEnumerable <FragmentTypes> GetIndividualFragmentTypes(this FragmentTypes fragmentTypes)
 {
     foreach (FragmentTypes site in Enum.GetValues(typeof(FragmentTypes)))
     {
         if (site == FragmentTypes.None || site == FragmentTypes.All || site == FragmentTypes.Internal)
         {
             continue;
         }
         if ((fragmentTypes & site) == site)
         {
             yield return(site);
         }
     }
 }
        public void SwitchToFragment(FragmentTypes fragmentType)
        {
            switch (fragmentType)
            {
            case FragmentTypes.Home:
                ShowFragment(_homeFragment);

                break;

            case FragmentTypes.Login:
                ShowFragment(_loginFragment);
                break;

            case FragmentTypes.Settings:
                ShowFragment(_settingsFragment);
                break;

            case FragmentTypes.Listoftasks:
                ShowFragment(_listOfTasksFragment);

                break;

            case FragmentTypes.Globaltimelog:
                ShowFragment(_globalTimeLogFragment);
                break;

            case FragmentTypes.Globaltimelogdetails:
                ShowFragment(_timeLogDetailFragment);
                break;

            case FragmentTypes.Listofprojects:
                ShowFragment(_listOfProjectFragment);

                break;

            case FragmentTypes.Taskdetails:
                ShowFragment(_taskDetailFragment);
                break;

            case FragmentTypes.Tasktimelogdetails:
                ShowFragment(_taskTimeLogDetailFragment);
                break;
            }
        }
示例#10
0
文件: Lotor.cs 项目: B-Rich/Compass
 public Lotor(string rawFileDirectory, string inputcsvFile, string outputDirectory, List<Modification> fixedModifications, List<Modification> quantifiedModifications, Tolerance prod_Tolerance, int scoreCutoff, bool separateGroups, double productThreshold,bool ignoreCTerminal,bool reduceSites, FragmentTypes fragType, bool phosphoNeutralLoss = false)
 {
     _rawFileDirectory = rawFileDirectory;
     _csvFile = inputcsvFile;
     _outputDirectory = outputDirectory;
     _fixedModifications = fixedModifications;
     FixedModifications = fixedModifications.OfType<IMass>().ToList();
     QuantifiedModifications = quantifiedModifications;
     _prodTolerance = prod_Tolerance;
     _deltaScoreCutoff = scoreCutoff;
     _separateProteinGroups = separateGroups;
     _productThreshold = productThreshold;
     _fragType = fragType;
     _ignoreCTerminal = ignoreCTerminal;
     _reduceSites = reduceSites;
     //LocalizedHit.AScoreThreshold = ascore_threshold;
     LocalizedHit.ScoreThreshold = scoreCutoff;
     _phosphoNeutralLoss = phosphoNeutralLoss;
 }
示例#11
0
 public Lotor(string rawFileDirectory, string inputcsvFile, string outputDirectory, List <Modification> fixedModifications, List <Modification> quantifiedModifications, Tolerance prod_Tolerance, int scoreCutoff, bool separateGroups, double productThreshold, bool ignoreCTerminal, bool reduceSites, FragmentTypes fragType, bool phosphoNeutralLoss = false)
 {
     _rawFileDirectory       = rawFileDirectory;
     _csvFile                = inputcsvFile;
     _outputDirectory        = outputDirectory;
     _fixedModifications     = fixedModifications;
     FixedModifications      = fixedModifications.OfType <IMass>().ToList();
     QuantifiedModifications = quantifiedModifications;
     _prodTolerance          = prod_Tolerance;
     _deltaScoreCutoff       = scoreCutoff;
     _separateProteinGroups  = separateGroups;
     _productThreshold       = productThreshold;
     _fragType               = fragType;
     _ignoreCTerminal        = ignoreCTerminal;
     _reduceSites            = reduceSites;
     //LocalizedHit.AScoreThreshold = ascore_threshold;
     LocalizedHit.ScoreThreshold = scoreCutoff;
     _phosphoNeutralLoss         = phosphoNeutralLoss;
 }
 public DataPointAcquisitionEngine(
     List <PeptideSpectralMatch> goodIdentifications,
     IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile,
     Tolerance mzToleranceForMs1Search,
     Tolerance mzToleranceForMs2Search,
     int numFragmentsNeededForEveryIdentification,
     int minMS1isotopicPeaksNeededForConfirmedIdentification,
     int minMS2isotopicPeaksNeededForConfirmedIdentification,
     FragmentTypes fragmentTypesForCalibration,
     List <string> nestedIds) : base(nestedIds)
 {
     this.goodIdentifications     = goodIdentifications;
     this.myMsDataFile            = myMsDataFile;
     this.mzToleranceForMs1Search = mzToleranceForMs1Search;
     this.mzToleranceForMs2Search = mzToleranceForMs2Search;
     this.numFragmentsNeededForEveryIdentification            = numFragmentsNeededForEveryIdentification;
     this.minMS1isotopicPeaksNeededForConfirmedIdentification = minMS1isotopicPeaksNeededForConfirmedIdentification;
     this.minMS2isotopicPeaksNeededForConfirmedIdentification = minMS2isotopicPeaksNeededForConfirmedIdentification;
     this.fragmentTypesForCalibration = fragmentTypesForCalibration;
 }
示例#13
0
 public DataPointAcquisitionEngine(
     List <PeptideSpectralMatch> goodIdentifications,
     MsDataFile myMsDataFile,
     Tolerance mzToleranceForMs1Search,
     Tolerance mzToleranceForMs2Search,
     int numFragmentsNeededForEveryIdentification,
     int minMS1isotopicPeaksNeededForConfirmedIdentification,
     int minMS2isotopicPeaksNeededForConfirmedIdentification,
     FragmentTypes fragmentTypesForCalibration,
     CommonParameters commonParameters,
     List <string> nestedIds) : base(commonParameters, nestedIds)
 {
     GoodIdentifications     = goodIdentifications;
     MyMsDataFile            = myMsDataFile;
     MzToleranceForMs1Search = mzToleranceForMs1Search;
     MzToleranceForMs2Search = mzToleranceForMs2Search;
     NumFragmentsNeededForEveryIdentification            = numFragmentsNeededForEveryIdentification;
     MinMS1isotopicPeaksNeededForConfirmedIdentification = minMS1isotopicPeaksNeededForConfirmedIdentification;
     MinMS2isotopicPeaksNeededForConfirmedIdentification = minMS2isotopicPeaksNeededForConfirmedIdentification;
     FragmentTypesForCalibration = fragmentTypesForCalibration;
 }
示例#14
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;
        }
示例#15
0
        public void MatchSpectrum(FragmentTypes fragmentTypes, Tolerance tolerance, double cutoffThreshold, bool phosphoNeutralLoss, params int[] chargeStates)
        {
            Fragments = Fragment(fragmentTypes).OrderBy(f => f.ToString()).ToList();

            if (phosphoNeutralLoss)
            {
                List <Fragment> toAdd = new List <Fragment>();
                foreach (Fragment frag in Fragments)
                {
                    List <IMass> mods = frag.GetModifications().ToList();
                    if (mods.Contains(lotorForm.Phosphorylation))
                    {
                        var newFrag = new Fragment(frag.Type, frag.Number, frag.MonoisotopicMass - H3PO4.MonoisotopicMass, frag.Parent);
                        toAdd.Add(newFrag);
                    }
                }
                Fragments.AddRange(toAdd);
            }

            SpectralMatch = new SpectrumFragmentsMatch(Spectrum);
            var matches = SpectralMatch.MatchFragments(Fragments, tolerance, cutoffThreshold, chargeStates);

            MatchedFragments = new HashSet <Fragment>(matches);
        }
示例#16
0
        private (List <PeptideSpectralMatch>, DataPointAquisitionResults) GetDataAcquisitionResults(IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile, string currentDataFile, List <ModificationWithMass> variableModifications, List <ModificationWithMass> fixedModifications, List <Protein> proteinList, string taskId, ICommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol)
        {
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(currentDataFile);
            MassDiffAcceptor searchMode;

            if (initPrecTol is PpmTolerance)
            {
                searchMode = new SinglePpmAroundZeroSearchMode(initPrecTol.Value);
            }
            else
            {
                searchMode = new SingleAbsoluteAroundZeroSearchMode(initPrecTol.Value);
            }

            FragmentTypes fragmentTypesForCalibration = FragmentTypes.None;

            if (combinedParameters.BIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.b;
            }
            if (combinedParameters.YIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.y;
            }
            if (combinedParameters.CIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.c;
            }
            if (combinedParameters.ZdotIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.zdot;
            }

            var listOfSortedms2Scans = GetMs2Scans(myMsDataFile, currentDataFile, combinedParameters.DoPrecursorDeconvolution, combinedParameters.UseProvidedPrecursorInfo, combinedParameters.DeconvolutionIntensityRatio, combinedParameters.DeconvolutionMaxAssumedChargeState, combinedParameters.DeconvolutionMassTolerance).OrderBy(b => b.PrecursorMass).ToArray();

            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            List <ProductType> lp = new List <ProductType>();

            if (combinedParameters.BIons)
            {
                lp.Add(ProductType.B);
            }
            if (combinedParameters.YIons)
            {
                lp.Add(ProductType.Y);
            }
            if (combinedParameters.CIons)
            {
                lp.Add(ProductType.C);
            }
            if (combinedParameters.ZdotIons)
            {
                lp.Add(ProductType.Zdot);
            }

            Log("Searching with searchMode: " + searchMode, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            });
            Log("Searching with productMassTolerance: " + initProdTol, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            });

            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, lp, searchMode, false, combinedParameters, initProdTol, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run();

            List <PeptideSpectralMatch> allPsms = allPsmsArray.ToList();

            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > compactPeptideToProteinPeptideMatching = ((SequencesToActualProteinPeptidesEngineResults) new SequencesToActualProteinPeptidesEngine(allPsms, proteinList, fixedModifications, variableModifications, lp, new List <IDigestionParams> {
                combinedParameters.DigestionParams
            }, combinedParameters.ReportAllAmbiguity, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run()).CompactPeptideToProteinPeptideMatching;

            foreach (var huh in allPsms)
            {
                if (huh != null)
                {
                    huh.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);
                }
            }

            allPsms = allPsms.Where(b => b != null).OrderByDescending(b => b.Score).ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue).GroupBy(b => (b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)).Select(b => b.First()).ToList();

            new FdrAnalysisEngine(allPsms, searchMode.NumNotches, false, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run();

            List <PeptideSpectralMatch> goodIdentifications = allPsms.Where(b => b.FdrInfo.QValueNotch < 0.01 && !b.IsDecoy && b.FullSequence != null).ToList();

            if (!goodIdentifications.Any())
            {
                Warn("No PSMs below 1% FDR observed!");
                return(new List <PeptideSpectralMatch>(), null);
            }

            var dissociationTypes = MetaMorpheusEngine.DetermineDissociationType(lp);

            foreach (var psm in allPsms)
            {
                var    theScan          = myMsDataFile.GetOneBasedScan(psm.ScanNumber);
                double thePrecursorMass = psm.ScanPrecursorMass;

                foreach (var huh in lp)
                {
                    var ionMasses = psm.CompactPeptides.First().Key.ProductMassesMightHaveDuplicatesAndNaNs(new List <ProductType> {
                        huh
                    });
                    Array.Sort(ionMasses);
                    List <double> matchedIonMassesList    = new List <double>();
                    List <double> productMassErrorDaList  = new List <double>();
                    List <double> productMassErrorPpmList = new List <double>();
                    LocalizationEngine.MatchIons(theScan, initProdTol, ionMasses, matchedIonMassesList, productMassErrorDaList, productMassErrorPpmList, thePrecursorMass, dissociationTypes, false);
                    double[] matchedIonMassesOnlyMatches = matchedIonMassesList.ToArray();
                    psm.MatchedIonDictOnlyMatches.Add(huh, matchedIonMassesOnlyMatches);
                    psm.ProductMassErrorDa.Add(huh, productMassErrorDaList.ToArray());
                    psm.ProductMassErrorPpm.Add(huh, productMassErrorPpmList.ToArray());
                }
            }

            DataPointAquisitionResults currentResult = (DataPointAquisitionResults) new DataPointAcquisitionEngine(
                goodIdentifications,
                myMsDataFile,
                initPrecTol,
                initProdTol,
                CalibrationParameters.NumFragmentsNeededForEveryIdentification,
                CalibrationParameters.MinMS1IsotopicPeaksNeededForConfirmedIdentification,
                CalibrationParameters.MinMS2IsotopicPeaksNeededForConfirmedIdentification,
                fragmentTypesForCalibration,
                new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run();

            return(goodIdentifications, currentResult);
        }
示例#17
0
文件: Lotor.cs 项目: B-Rich/Compass
        private List<LocalizedHit> CalculateBestIsoforms(List<PSM> psms, FragmentTypes fragType, Tolerance prod_tolerance, double productThreshold, bool phosphoNeutralLosses)
        {
            Log("Localizing Best Isoforms...");
            int totalisofromscount = 0;
            int count = 0;
            int psm_count = 0;
            int localized_psm = 0;
            List<LocalizedHit> hits = new List<LocalizedHit>();
            foreach (PSM psm in psms)
            {
                psm_count++;
                count++;

                // Generate all the isoforms for the PSM
                int isoformCount = psm.GenerateIsoforms(_ignoreCTerminal);

                if(isoformCount == 0)
                    continue;

                totalisofromscount += isoformCount;

                // Calculate the probability of success for random matches
                //double pvalue = GetPValue(psm, prod_tolerance, productThreshold);

                // Match all the isoforms to the spectrum and log the results
                psm.MatchIsofroms(fragType, prod_tolerance, productThreshold, phosphoNeutralLosses, 1);

                // Perform the localization for all combinations of isoforms
                //double[,] res = psm.Calc(pvalue);

                Tuple<int, int, double> scores = LocalizedIsoformSimple(psm);

                // Check if the localization is above some threshold
                //Tuple<int, int, double> scores = LocalizedIsoform(res);
                int bestIsoform = scores.Item1;
                int secondBestIsoform = scores.Item2;
                double ascore = scores.Item3;
                //int numSDFs = psm.NumSiteDeterminingFragments[bestIsoform, secondBestIsoform];

                List<PeptideIsoform> isoforms = psm.PeptideIsoforms.ToList();
                //LocalizedHit hit = new LocalizedHit(psm, isoforms[bestIsoform], isoforms[secondBestIsoform], numSDFs,
                //    psm.BestSiteDeterminingFragments[bestIsoform, secondBestIsoform],
                //    psm.BestSiteDeterminingFragments[secondBestIsoform, bestIsoform], pvalue, ascore);

                LocalizedHit hit = new LocalizedHit(psm, isoforms[bestIsoform], isoforms[secondBestIsoform], 0,
                   0,
                   0, 0, ascore);
                hits.Add(hit);
                if (hit.IsLocalized)
                {
                    localized_psm++;
                }

                psm.PeptideIsoforms.Clear();

                // Progress Bar Stuff
                if (count <= 50)
                    continue;
                count = 0;
                ProgressUpdate((double)psm_count / psms.Count);
            }
            ProgressUpdate(1.0);
            Log(string.Format("Total Number of Possible Isoforms Considered: {0:N0}",totalisofromscount));
            Log(string.Format("Total Number of PSMs Considered: {0:N0}", psm_count));
            Log(string.Format("Total Number of PSMs Localized: {0:N0} ({1:00.00}%)", localized_psm, localized_psm * 100 / psm_count));
            ProgressUpdate(0);
            return hits;
        }
示例#18
0
        public IEnumerable <Fragment> Fragment(FragmentTypes types, int minIndex, int maxIndex, bool calculateChemicalFormula)
        {
            foreach (FragmentTypes type in types.GetIndividualFragmentTypes())
            {
                bool            isChemicalFormula = calculateChemicalFormula;
                ChemicalFormula capFormula        = type.GetIonCap();
                bool            isCTerminal       = type.GetTerminus() == Terminus.C;

                double          monoMass = capFormula.MonoisotopicMass;
                ChemicalFormula formula  = new ChemicalFormula(capFormula);

                IHasChemicalFormula terminus = isCTerminal ? CTerminus : NTerminus;
                monoMass += terminus.MonoisotopicMass;
                if (isChemicalFormula)
                {
                    formula.Add(terminus);
                }

                bool first  = true;
                bool hasMod = _modifications != null;

                for (int i = 0; i <= maxIndex; i++)
                {
                    int aaIndex = isCTerminal ? Length - i : i - 1;

                    // Handle the terminus mods first in a special case
                    IHasMass mod;
                    if (first)
                    {
                        first = false;
                        if (hasMod)
                        {
                            mod = _modifications[aaIndex + 1];
                            if (mod != null)
                            {
                                monoMass += mod.MonoisotopicMass;
                                if (isChemicalFormula)
                                {
                                    if (mod is IHasChemicalFormula modFormula)
                                    {
                                        formula.Add(modFormula);
                                    }
                                    else
                                    {
                                        isChemicalFormula = false;
                                    }
                                }
                            }
                        }
                        continue;
                    }

                    monoMass += residues[aaIndex].MonoisotopicMass;
                    formula.Add(residues[aaIndex]);

                    if (hasMod)
                    {
                        mod = _modifications[aaIndex + 1];

                        if (mod != null)
                        {
                            monoMass += mod.MonoisotopicMass;
                            if (isChemicalFormula)
                            {
                                if (mod is IHasChemicalFormula modFormula)
                                {
                                    formula.Add(modFormula);
                                }
                                else
                                {
                                    isChemicalFormula = false;
                                }
                            }
                        }
                    }

                    if (i < minIndex)
                    {
                        continue;
                    }

                    if (isChemicalFormula)
                    {
                        yield return(new ChemicalFormulaFragment(type, i, formula, this));
                    }
                    else
                    {
                        yield return(new Fragment(type, i, monoMass, this));
                    }
                }
            }
        }
示例#19
0
 public IEnumerable <Fragment> Fragment(FragmentTypes types, int minIndex, int maxIndex)
 {
     return(Fragment(types, minIndex, maxIndex, false));
 }
示例#20
0
        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);
        }
示例#21
0
        private List <LocalizedHit> CalculateBestIsoforms(List <PSM> psms, FragmentTypes fragType, Tolerance prod_tolerance, double productThreshold, bool phosphoNeutralLosses)
        {
            Log("Localizing Best Isoforms...");
            int totalisofromscount = 0;
            int count                = 0;
            int psm_count            = 0;
            int localized_psm        = 0;
            List <LocalizedHit> hits = new List <LocalizedHit>();

            foreach (PSM psm in psms)
            {
                psm_count++;
                count++;

                // Generate all the isoforms for the PSM
                int isoformCount = psm.GenerateIsoforms(_ignoreCTerminal);

                if (isoformCount == 0)
                {
                    continue;
                }

                totalisofromscount += isoformCount;

                // Calculate the probability of success for random matches
                //double pvalue = GetPValue(psm, prod_tolerance, productThreshold);

                // Match all the isoforms to the spectrum and log the results
                psm.MatchIsofroms(fragType, prod_tolerance, productThreshold, phosphoNeutralLosses, 1);

                // Perform the localization for all combinations of isoforms
                //double[,] res = psm.Calc(pvalue);

                Tuple <int, int, double> scores = LocalizedIsoformSimple(psm);

                // Check if the localization is above some threshold
                //Tuple<int, int, double> scores = LocalizedIsoform(res);
                int    bestIsoform       = scores.Item1;
                int    secondBestIsoform = scores.Item2;
                double ascore            = scores.Item3;
                //int numSDFs = psm.NumSiteDeterminingFragments[bestIsoform, secondBestIsoform];

                List <PeptideIsoform> isoforms = psm.PeptideIsoforms.ToList();
                //LocalizedHit hit = new LocalizedHit(psm, isoforms[bestIsoform], isoforms[secondBestIsoform], numSDFs,
                //    psm.BestSiteDeterminingFragments[bestIsoform, secondBestIsoform],
                //    psm.BestSiteDeterminingFragments[secondBestIsoform, bestIsoform], pvalue, ascore);

                LocalizedHit hit = new LocalizedHit(psm, isoforms[bestIsoform], isoforms[secondBestIsoform], 0,
                                                    0,
                                                    0, 0, ascore);
                hits.Add(hit);
                if (hit.IsLocalized)
                {
                    localized_psm++;
                }

                psm.PeptideIsoforms.Clear();

                // Progress Bar Stuff
                if (count <= 50)
                {
                    continue;
                }
                count = 0;
                ProgressUpdate((double)psm_count / psms.Count);
            }
            ProgressUpdate(1.0);
            Log(string.Format("Total Number of Possible Isoforms Considered: {0:N0}", totalisofromscount));
            Log(string.Format("Total Number of PSMs Considered: {0:N0}", psm_count));
            Log(string.Format("Total Number of PSMs Localized: {0:N0} ({1:00.00}%)", localized_psm, localized_psm * 100 / psm_count));
            ProgressUpdate(0);
            return(hits);
        }
示例#22
0
 public IEnumerable <Fragment> Fragment(FragmentTypes types)
 {
     return(Fragment(types, false));
 }
示例#23
0
 public abstract PeptideSpectralMatch Search(IMassSpectrum massSpectrum, Peptide peptide, FragmentTypes fragmentTypes, Tolerance productMassTolerance);
        public override PeptideSpectralMatch Search(IMassSpectrum massSpectrum, Peptide peptide, FragmentTypes fragmentTypes, Tolerance productMassTolerance)
        {
            double[] eMasses      = massSpectrum.MassSpectrum.GetMasses();
            double[] eIntenisties = massSpectrum.MassSpectrum.GetIntensities();
            double   tic          = massSpectrum.MassSpectrum.GetTotalIonCurrent();

            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;

            return(psm);
        }
 public ChemicalFormulaFragment(FragmentTypes type, int number, string chemicalFormula, AminoAcidPolymer parent)
     : this(type, number, new ChemicalFormula(chemicalFormula), parent)
 {
 }
        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);
        }
示例#27
0
文件: PSM.cs 项目: kmmbvnr/Compass
 public void MatchIsofroms(FragmentTypes type, Tolerance tolerance, double cutoffThreshold, bool phopshoNeutralLoss, params int[] chargeStates)
 {
     foreach (PeptideIsoform isoform in PeptideIsoforms)
     {
         isoform.MatchSpectrum(type, tolerance, cutoffThreshold,phopshoNeutralLoss, chargeStates);
     }
 }
示例#28
0
 public abstract PeptideSpectralMatch Search(IMassSpectrum massSpectrum, Peptide peptide, FragmentTypes fragmentTypes, Tolerance productMassTolerance);
示例#29
0
        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;
        }
示例#30
0
 /// <summary>
 /// Calculates all the fragments of the types you specify
 /// </summary>
 /// <param name="types"></param>
 /// <param name="calculateChemicalFormula"></param>
 /// <returns></returns>
 public IEnumerable <Fragment> Fragment(FragmentTypes types, bool calculateChemicalFormula)
 {
     return(Fragment(types, 1, Length - 1, calculateChemicalFormula));
 }
示例#31
0
 public IEnumerable <Fragment> Fragment(FragmentTypes types, int number)
 {
     return(Fragment(types, number, false));
 }
示例#32
0
 public IEnumerable <Fragment> Fragment(FragmentTypes types, int number, bool calculateChemicalFormula)
 {
     return(Fragment(types, number, number, calculateChemicalFormula));
 }
示例#33
0
 public ChemicalFormulaFragment(FragmentTypes type, int number, ChemicalFormula formula, AminoAcidPolymer parent)
     : base(type, number, formula.MonoisotopicMass, parent)
 {
     ThisChemicalFormula = ChemicalFormula.ParseFormula(formula.Formula);
 }
示例#34
0
        private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, List <ModificationWithMass> variableModifications, List <ModificationWithMass> fixedModifications, List <Protein> proteinList, string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol)
        {
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(currentDataFile);
            MassDiffAcceptor searchMode  = initPrecTol is PpmTolerance ?
                                           (MassDiffAcceptor) new SinglePpmAroundZeroSearchMode(initPrecTol.Value) :
                                           new SingleAbsoluteAroundZeroSearchMode(initPrecTol.Value);

            FragmentTypes fragmentTypesForCalibration = FragmentTypes.None;

            if (combinedParameters.BIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.b;
            }
            if (combinedParameters.YIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.y;
            }
            if (combinedParameters.CIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.c;
            }
            if (combinedParameters.ZdotIons)
            {
                fragmentTypesForCalibration = fragmentTypesForCalibration | FragmentTypes.zdot;
            }

            var listOfSortedms2Scans = GetMs2Scans(myMsDataFile, currentDataFile, combinedParameters.DoPrecursorDeconvolution, combinedParameters.UseProvidedPrecursorInfo, combinedParameters.DeconvolutionIntensityRatio, combinedParameters.DeconvolutionMaxAssumedChargeState, combinedParameters.DeconvolutionMassTolerance).OrderBy(b => b.PrecursorMass).ToArray();

            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            List <ProductType> productTypes = new List <ProductType>();

            if (combinedParameters.BIons)
            {
                productTypes.Add(ProductType.B);
            }
            if (combinedParameters.YIons)
            {
                productTypes.Add(ProductType.Y);
            }
            if (combinedParameters.CIons)
            {
                productTypes.Add(ProductType.C);
            }
            if (combinedParameters.ZdotIons)
            {
                productTypes.Add(ProductType.Zdot);
            }

            Log("Searching with searchMode: " + searchMode, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            });
            Log("Searching with productMassTolerance: " + initProdTol, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            });

            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, productTypes, searchMode, combinedParameters, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run();

            List <PeptideSpectralMatch> allPsms = allPsmsArray.Where(p => p != null).ToList();

            var compactPeptideToProteinPeptideMatching = ((SequencesToActualProteinPeptidesEngineResults) new SequencesToActualProteinPeptidesEngine
                                                              (allPsms, proteinList, fixedModifications, variableModifications, productTypes, new List <DigestionParams> {
                combinedParameters.DigestionParams
            },
                                                              combinedParameters.ReportAllAmbiguity, combinedParameters, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run()).CompactPeptideToProteinPeptideMatching;

            foreach (var huh in allPsms)
            {
                huh.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);
            }

            allPsms = allPsms.OrderByDescending(b => b.Score)
                      .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue)
                      .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)).Select(b => b.First()).ToList();

            new FdrAnalysisEngine(allPsms, searchMode.NumNotches, CommonParameters, new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run();

            List <PeptideSpectralMatch> goodIdentifications = allPsms.Where(b => b.FdrInfo.QValueNotch < 0.01 && !b.IsDecoy && b.FullSequence != null).ToList();

            if (!goodIdentifications.Any())
            {
                return(new DataPointAquisitionResults(null, new List <PeptideSpectralMatch>(), new List <LabeledDataPoint>(), new List <LabeledDataPoint>(), 0, 0, 0, 0));
            }

            DataPointAquisitionResults currentResult = (DataPointAquisitionResults) new DataPointAcquisitionEngine(
                goodIdentifications,
                myMsDataFile,
                initPrecTol,
                initProdTol,
                CalibrationParameters.NumFragmentsNeededForEveryIdentification,
                CalibrationParameters.MinMS1IsotopicPeaksNeededForConfirmedIdentification,
                CalibrationParameters.MinMS2IsotopicPeaksNeededForConfirmedIdentification,
                fragmentTypesForCalibration,
                CommonParameters,
                new List <string> {
                taskId, "Individual Spectra Files", fileNameWithoutExtension
            }).Run();

            return(currentResult);
        }
 public ChemicalFormulaFragment(FragmentTypes type, int number, ChemicalFormula formula, AminoAcidPolymer parent)
     : base(type, number, formula.MonoisotopicMass, parent)
 {
     ChemicalFormula = new ChemicalFormula(formula);
 }
示例#36
0
        /// <summary>
        /// Returns all fragments that are present in either fragmentation of A or B, but not in both
        /// </summary>
        public static IEnumerable <Fragment> GetSiteDeterminingFragments(AminoAcidPolymer peptideA, AminoAcidPolymer peptideB, FragmentTypes types)
        {
            HashSet <Fragment> aFrags = new HashSet <Fragment>(peptideA.Fragment(types));

            aFrags.SymmetricExceptWith(peptideB.Fragment(types));
            return(aFrags);
        }
示例#37
0
 /// <summary>
 /// Calculates the fragments that are different between this and another aminoacidpolymer
 /// </summary>
 /// <param name="other"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public IEnumerable <Fragment> GetSiteDeterminingFragments(AminoAcidPolymer other, FragmentTypes type)
 {
     return(GetSiteDeterminingFragments(this, other, type));
 }
示例#38
0
 public ChemicalFormulaFragment(FragmentTypes type, int number, string chemicalFormula, AminoAcidPolymer parent)
     : this(type, number, new ChemicalFormula(chemicalFormula), parent)
 {
 }