Exemple #1
0
        public CrosslinkSearchEngine(List <CrosslinkSpectralMatch>[] globalCsms, Ms2ScanWithSpecificMass[] listOfSortedms2Scans, List <PeptideWithSetModifications> peptideIndex,
                                     List <int>[] fragmentIndex, List <int>[] secondFragmentIndex, int currentPartition, CommonParameters commonParameters, Crosslinker crosslinker, bool CrosslinkSearchTop, int CrosslinkSearchTopNum,
                                     bool quench_H2O, bool quench_NH2, bool quench_Tris, List <string> nestedIds)
            : base(null, listOfSortedms2Scans, peptideIndex, fragmentIndex, currentPartition, commonParameters, new OpenSearchMode(), 0, nestedIds)
        {
            this.GlobalCsms          = globalCsms;
            this.Crosslinker         = crosslinker;
            this.CrosslinkSearchTopN = CrosslinkSearchTop;
            this.TopN           = CrosslinkSearchTopNum;
            this.QuenchH2O      = quench_H2O;
            this.QuenchNH2      = quench_NH2;
            this.QuenchTris     = quench_Tris;
            SecondFragmentIndex = secondFragmentIndex;
            if (CommonParameters.ChildScanDissociationType != DissociationType.Unknown && DissociationTypeGenerateSameTypeOfIons(CommonParameters.DissociationType, CommonParameters.ChildScanDissociationType))
            {
                SecondFragmentIndex = FragmentIndex;
            }
            GenerateCrosslinkModifications(crosslinker);
            AllCrosslinkerSites = Crosslinker.CrosslinkerModSites.ToCharArray().Concat(Crosslinker.CrosslinkerModSites2.ToCharArray()).Distinct().ToArray();

            if (commonParameters.PrecursorMassTolerance is PpmTolerance)
            {
                XLPrecusorSearchMode = new SinglePpmAroundZeroSearchMode(commonParameters.PrecursorMassTolerance.Value);
            }
            else
            {
                XLPrecusorSearchMode = new SingleAbsoluteAroundZeroSearchMode(commonParameters.PrecursorMassTolerance.Value);
            }
        }
 /// <summary>
 ///
 /// </summary>
 private void GenerateCrosslinkModifications(Crosslinker crosslinker)
 {
     ModificationMotif.TryGetMotif("X", out var motif);
     TrisDeadEnd = new Modification(_originalId: "Tris Dead End", _modificationType: "Crosslink", _locationRestriction: "Anywhere.", _target: motif, _monoisotopicMass: Crosslinker.DeadendMassTris);
     H2ODeadEnd  = new Modification(_originalId: "H2O Dead End", _modificationType: "Crosslink", _locationRestriction: "Anywhere.", _target: motif, _monoisotopicMass: Crosslinker.DeadendMassH2O);
     NH2DeadEnd  = new Modification(_originalId: "NH2 Dead End", _modificationType: "Crosslink", _locationRestriction: "Anywhere.", _target: motif, _monoisotopicMass: Crosslinker.DeadendMassNH2);
     Loop        = new Modification(_originalId: "Loop", _modificationType: "Crosslink", _locationRestriction: "Anywhere.", _target: motif, _monoisotopicMass: Crosslinker.LoopMass);
 }
Exemple #3
0
        private void PopulateChoices()
        {
            foreach (var crosslinker in GlobalVariables.Crosslinkers)
            {
                cbCrosslinkers.Items.Add(crosslinker);
            }
            Crosslinker DSSO = GlobalVariables.Crosslinkers.First();

            cbCrosslinkers.SelectedItem = DSSO;

            foreach (string dissassociationType in GlobalVariables.AllSupportedDissociationTypes.Keys)
            {
                DissociationTypeComboBox.Items.Add(dissassociationType);
                ChildScanDissociationTypeComboBox.Items.Add(dissassociationType);
            }

            cbbXLprecusorMsTl.Items.Add("Da");
            cbbXLprecusorMsTl.Items.Add("ppm");

            foreach (Protease protease in ProteaseDictionary.Dictionary.Values)
            {
                proteaseComboBox.Items.Add(protease);
            }
            Protease trypsin = ProteaseDictionary.Dictionary["trypsin"];

            proteaseComboBox.SelectedItem = trypsin;

            foreach (string initiatior_methionine_behavior in Enum.GetNames(typeof(InitiatorMethionineBehavior)))
            {
                initiatorMethionineBehaviorComboBox.Items.Add(initiatior_methionine_behavior);
            }

            productMassToleranceComboBox.Items.Add("Da");
            productMassToleranceComboBox.Items.Add("ppm");

            foreach (var hm in GlobalVariables.AllModsKnown.GroupBy(b => b.ModificationType))
            {
                var theModType = new ModTypeForTreeView(hm.Key, false);
                FixedModTypeForTreeViewObservableCollection.Add(theModType);
                foreach (var uah in hm)
                {
                    theModType.Children.Add(new ModForTreeView(uah.ToString(), false, uah.IdWithMotif, false, theModType));
                }
            }
            fixedModsTreeView.DataContext = FixedModTypeForTreeViewObservableCollection;
            foreach (var hm in GlobalVariables.AllModsKnown.GroupBy(b => b.ModificationType))
            {
                var theModType = new ModTypeForTreeView(hm.Key, false);
                VariableModTypeForTreeViewObservableCollection.Add(theModType);
                foreach (var uah in hm)
                {
                    theModType.Children.Add(new ModForTreeView(uah.ToString(), false, uah.IdWithMotif, false, theModType));
                }
            }
            variableModsTreeView.DataContext = VariableModTypeForTreeViewObservableCollection;
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string crosslinkerPath     = Path.Combine(GlobalVariables.DataDir, @"Data");
            string customCrosslinkPath = Path.Combine(crosslinkerPath, @"CustomCrosslinkers.tsv");

            List <string> customCrosslinkerText = new List <string>();

            if (File.Exists(customCrosslinkPath))
            {
                customCrosslinkerText = File.ReadAllLines(customCrosslinkPath).ToList();
            }
            else
            {
                customCrosslinkerText.Add("Name\tCrosslinkAminoAcid\tCrosslinkerAminoAcid2\tCleavable\tDissociationType\tCrosslinkerTotalMass\tCrosslinkerShortMass\tCrosslinkerLongMass\tQuenchMassH2O\tQuenchMassNH2\tQuenchMassTris");
            }

            string name              = txtUdXLKerName.Text;
            string aminoAcid1        = txtUdXLkerAminoAcids.Text;
            string aminoAcid2        = txtUdXLkerAminoAcids2.Text;
            bool   isCleavable       = ckbUdXLkerCleavable.IsChecked.Value;
            string dissociationTypes = txtDissociationType.Text;
            double mass              = double.Parse(txtUdXLkerTotalMs.Text == "" ? "0" : txtUdXLkerTotalMs.Text);
            double shortMass         = double.Parse(txtUdXLkerShortMass.Text == "" ? "0" : txtUdXLkerShortMass.Text);
            double longMass          = double.Parse(txtUdXLkerLongMass.Text == "" ? "0" : txtUdXLkerLongMass.Text);
            double H2OQuenchMass     = double.Parse(txtH2OQuenchMass.Text == "" ? "0" : txtH2OQuenchMass.Text);
            double NH2QuenchMass     = double.Parse(txtNH2QuenchMass.Text == "" ? "0" : txtNH2QuenchMass.Text);
            double TrisQuenchMass    = double.Parse(txtTrisQuenchMass.Text == "" ? "0" : txtTrisQuenchMass.Text);

            if (GlobalVariables.Crosslinkers.Any(p => p.CrosslinkerName.Contains(name)))
            {
                MessageBox.Show("A crosslinker already exists with the name: " + name, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            }

            var newCrosslinker = new Crosslinker(crosslinkerName: name, crosslinkerModSites: aminoAcid1, crosslinkerModSites2: aminoAcid2, totalMass: mass, cleavable: isCleavable, dissociationTypes: dissociationTypes,
                                                 cleaveMassShort: shortMass, cleaveMassLong: longMass, loopMass: mass, deadendMassH2O: H2OQuenchMass, deadendMassNH2: NH2QuenchMass, deadendMassTris: TrisQuenchMass);

            customCrosslinkerText.Add(newCrosslinker.ToString(true));

            try
            {
                File.Delete(customCrosslinkPath);
                File.WriteAllLines(customCrosslinkPath, customCrosslinkerText);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem saving custom crosslinker to file: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            }

            GlobalVariables.AddCrosslinkers(new List <Crosslinker> {
                newCrosslinker
            });
            DialogResult = true;
        }
Exemple #5
0
        public static void XlTestXlPosCal()
        {
            var prot = new Protein("MNNNKQQQQ", null);
            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("New Custom Protease", CleavageSpecificity.Full, null, null, motifs);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            DigestionParams     digestionParams       = new DigestionParams(protease: protease.Name, minPeptideLength: 1, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <Modification> variableModifications = new List <Modification>();

            var ye = prot.Digest(digestionParams, new List <Modification>(), variableModifications).ToList();

            var pep = ye[0];

            Assert.AreEqual(pep.BaseSequence, "MNNNK");
            Crosslinker crosslinker = GlobalVariables.Crosslinkers.Where(p => p.CrosslinkerName == "DSS").First();

            Assert.AreEqual(crosslinker.CrosslinkerModSites, "K");
            Assert.AreEqual(Residue.GetResidue(crosslinker.CrosslinkerModSites).MonoisotopicMass, 128.09496301518999, 1e-9);
            var n = pep.Fragment(DissociationType.HCD, FragmentationTerminus.N);
            var c = pep.Fragment(DissociationType.HCD, FragmentationTerminus.C);

            Assert.AreEqual(n.Count(), 4);
            Assert.AreEqual(c.Count(), 4);
            Assert.AreEqual(c.First().NeutralMass, 146.10552769899999, 1e-6);
            var x = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), pep).ToArray();

            Assert.AreEqual(x[0], 5);

            var pep2 = ye[2];

            Assert.AreEqual("MNNNKQQQQ", pep2.BaseSequence);
            var n2 = pep2.Fragment(DissociationType.HCD, FragmentationTerminus.N);
            var c2 = pep2.Fragment(DissociationType.HCD, FragmentationTerminus.C);

            Assert.AreEqual(n2.Count(), 8);
            Assert.AreEqual(c2.Count(), 8);
            var x2 = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), pep2).ToArray();

            Assert.AreEqual(x2[0], 5);

            //Test crosslinker with multiple types of mod
            var protSTC = new Protein("GASTACK", null);
            var peps    = protSTC.Digest(digestionParams, new List <Modification>(), variableModifications).ToList();
            var pepSTC  = peps[0];

            Assert.AreEqual(pepSTC.BaseSequence, "GASTACK");
            Crosslinker crosslinker2           = new Crosslinker("ST", "C", "crosslinkerSTC", false, -18.01056, 0, 0, 0, 0, 0, 0);
            string      crosslinkerModSitesAll = new string((crosslinker2.CrosslinkerModSites + crosslinker2.CrosslinkerModSites2).ToCharArray().Distinct().ToArray());

            Assert.AreEqual(crosslinkerModSitesAll, "STC");
        }
        /// <summary>
        /// Localizes the crosslink position on the alpha and beta peptides
        /// </summary>
        private CrosslinkSpectralMatch LocalizeCrosslinkSites(Ms2ScanWithSpecificMass theScan, BestPeptideScoreNotch alphaPeptide, BestPeptideScoreNotch betaPeptide, Crosslinker crosslinker, int ind, int inx)
        {
            CrosslinkSpectralMatch localizedCrosslinkedSpectralMatch = null;

            List <Tuple <List <int>, List <int> > > pairs = new List <Tuple <List <int>, List <int> > >();

            if (crosslinker.CrosslinkerModSites.Equals(crosslinker.CrosslinkerModSites2))
            {
                List <int> possibleAlphaXlSites = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), alphaPeptide.BestPeptide);
                List <int> possibleBetaXlSites  = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), betaPeptide.BestPeptide);

                pairs.Add(new Tuple <List <int>, List <int> >(possibleAlphaXlSites, possibleBetaXlSites));
            }
            else
            {
                List <int> possibleAlphaXlSites = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), alphaPeptide.BestPeptide);
                List <int> possibleBetaXlSites  = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites2.ToCharArray(), betaPeptide.BestPeptide);

                pairs.Add(new Tuple <List <int>, List <int> >(possibleAlphaXlSites, possibleBetaXlSites));

                possibleAlphaXlSites = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites2.ToCharArray(), alphaPeptide.BestPeptide);
                possibleBetaXlSites  = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), betaPeptide.BestPeptide);

                pairs.Add(new Tuple <List <int>, List <int> >(possibleAlphaXlSites, possibleBetaXlSites));
            }

            foreach (var pair in pairs)
            {
                List <int> possibleAlphaXlSites = pair.Item1;
                List <int> possibleBetaXlSites  = pair.Item2;

                if (possibleAlphaXlSites.Any() && possibleBetaXlSites.Any())
                {
                    int bestAlphaSite = 0;
                    int bestBetaSite  = 0;
                    List <MatchedFragmentIon> bestMatchedAlphaIons = new List <MatchedFragmentIon>();
                    List <MatchedFragmentIon> bestMatchedBetaIons  = new List <MatchedFragmentIon>();
                    Dictionary <int, List <MatchedFragmentIon> > bestMatchedChildAlphaIons = new Dictionary <int, List <MatchedFragmentIon> >();
                    Dictionary <int, List <MatchedFragmentIon> > bestMatchedChildBetaIons  = new Dictionary <int, List <MatchedFragmentIon> >();
                    double bestAlphaLocalizedScore = 0;
                    double bestBetaLocalizedScore  = 0;

                    var fragmentsForEachAlphaLocalizedPossibility = CrosslinkedPeptide.XlGetTheoreticalFragments(CommonParameters.DissociationType,
                                                                                                                 Crosslinker, possibleAlphaXlSites, betaPeptide.BestPeptide.MonoisotopicMass, alphaPeptide.BestPeptide).ToList();

                    foreach (int possibleSite in possibleAlphaXlSites)
                    {
                        foreach (var setOfFragments in fragmentsForEachAlphaLocalizedPossibility.Where(v => v.Item1 == possibleSite))
                        {
                            var    matchedChildAlphaIons = new Dictionary <int, List <MatchedFragmentIon> >();
                            var    matchedIons           = MatchFragmentIons(theScan, setOfFragments.Item2, CommonParameters);
                            double score = CalculatePeptideScore(theScan.TheScan, matchedIons);

                            // search child scans (MS2+MS3)
                            foreach (Ms2ScanWithSpecificMass childScan in theScan.ChildScans)
                            {
                                var matchedChildIons = ScoreChildScan(theScan, childScan, possibleSite, alphaPeptide, betaPeptide);

                                if (matchedChildIons == null)
                                {
                                    continue;
                                }

                                matchedChildAlphaIons.Add(childScan.OneBasedScanNumber, matchedChildIons);
                                //double childScore = CalculatePeptideScore(childScan.TheScan, matchedChildIons);

                                //score += childScore;
                            }

                            if (score > bestAlphaLocalizedScore)
                            {
                                bestAlphaLocalizedScore   = score;
                                bestAlphaSite             = possibleSite;
                                bestMatchedAlphaIons      = matchedIons;
                                bestMatchedChildAlphaIons = matchedChildAlphaIons;
                            }
                        }
                    }

                    var fragmentsForEachBetaLocalizedPossibility = CrosslinkedPeptide.XlGetTheoreticalFragments(CommonParameters.DissociationType,
                                                                                                                Crosslinker, possibleBetaXlSites, alphaPeptide.BestPeptide.MonoisotopicMass, betaPeptide.BestPeptide).ToList();

                    var alphaMz = new HashSet <double>(bestMatchedAlphaIons.Select(p => p.Mz));

                    foreach (int possibleSite in possibleBetaXlSites)
                    {
                        foreach (var setOfFragments in fragmentsForEachBetaLocalizedPossibility.Where(v => v.Item1 == possibleSite))
                        {
                            var matchedIons          = MatchFragmentIons(theScan, setOfFragments.Item2, CommonParameters);
                            var matchedChildBetaIons = new Dictionary <int, List <MatchedFragmentIon> >();

                            // remove any matched beta ions that also matched to the alpha peptide
                            matchedIons.RemoveAll(p => alphaMz.Contains(p.Mz));

                            double score = CalculatePeptideScore(theScan.TheScan, matchedIons);

                            // search child scans (MS2+MS3)
                            foreach (Ms2ScanWithSpecificMass childScan in theScan.ChildScans)
                            {
                                var matchedChildIons = ScoreChildScan(theScan, childScan, possibleSite, betaPeptide, alphaPeptide);

                                if (matchedChildIons == null)
                                {
                                    continue;
                                }

                                matchedChildBetaIons.Add(childScan.OneBasedScanNumber, matchedChildIons);
                                //double childScore = CalculatePeptideScore(childScan.TheScan, matchedChildIons);

                                //score += childScore;
                            }

                            if (score > bestBetaLocalizedScore)
                            {
                                bestBetaLocalizedScore   = score;
                                bestBetaSite             = possibleSite;
                                bestMatchedBetaIons      = matchedIons;
                                bestMatchedChildBetaIons = matchedChildBetaIons;
                            }
                        }
                    }

                    if (bestAlphaLocalizedScore < CommonParameters.ScoreCutoff ||
                        bestBetaLocalizedScore < CommonParameters.ScoreCutoff)
                    {
                        return(null);
                    }

                    var localizedAlpha = new CrosslinkSpectralMatch(alphaPeptide.BestPeptide, alphaPeptide.BestNotch, bestAlphaLocalizedScore, 0, theScan, alphaPeptide.BestPeptide.DigestionParams, bestMatchedAlphaIons);
                    var localizedBeta  = new CrosslinkSpectralMatch(betaPeptide.BestPeptide, betaPeptide.BestNotch, bestBetaLocalizedScore, 0, theScan, betaPeptide.BestPeptide.DigestionParams, bestMatchedBetaIons);

                    localizedAlpha.XlRank = new List <int> {
                        ind, inx
                    };
                    localizedAlpha.XLTotalScore = localizedAlpha.Score + localizedBeta.Score;
                    localizedAlpha.BetaPeptide  = localizedBeta;

                    localizedAlpha.ChildMatchedFragmentIons = bestMatchedChildAlphaIons;
                    localizedBeta.ChildMatchedFragmentIons  = bestMatchedChildBetaIons;

                    if (crosslinker.Cleavable)
                    {
                        //TODO: re-enable intensity ranks
                        //psmCrossAlpha.ParentIonMaxIntensityRanks = psmCrossAlpha.MatchedFragmentIons.Where(p => p.NeutralTheoreticalProduct.ProductType == ProductType.M).Select(p => p.IntensityRank).ToList();
                        //localizedAlpha.ParentIonMaxIntensityRanks = new List<int>();

                        //localizedAlpha.ParentIonExistNum = psmCrossAlpha.ParentIonMaxIntensityRanks.Count;
                    }

                    localizedAlpha.CrossType          = PsmCrossType.Cross;
                    localizedCrosslinkedSpectralMatch = localizedAlpha;
                    localizedCrosslinkedSpectralMatch.LinkPositions = new List <int> {
                        bestAlphaSite
                    };
                    localizedCrosslinkedSpectralMatch.BetaPeptide.LinkPositions = new List <int> {
                        bestBetaSite
                    };
                }
            }

            return(localizedCrosslinkedSpectralMatch);
        }
        public void WritePepXML_xl(List <CrosslinkSpectralMatch> items, List <Protein> proteinList, string databasePath, List <Modification> variableModifications, List <Modification> fixedModifications, List <string> localizeableModificationTypes, string outputFolder, string fileName, List <string> nestedIds)
        {
            if (!items.Any())
            {
                return;
            }

            XmlSerializer _indexedSerializer = new XmlSerializer(typeof(pepXML.Generated.msms_pipeline_analysis));
            var           _pepxml            = new pepXML.Generated.msms_pipeline_analysis();

            _pepxml.date        = DateTime.Now;
            _pepxml.summary_xml = items[0].FullFilePath + ".pep.XML";

            string proteaseC = ""; string proteaseNC = "";

            foreach (var x in CommonParameters.DigestionParams.Protease.DigestionMotifs.Select(m => m.InducingCleavage))
            {
                proteaseC += x;
            }
            foreach (var x in CommonParameters.DigestionParams.Protease.DigestionMotifs.Select(m => m.PreventingCleavage))
            {
                proteaseNC += x;
            }

            Crosslinker crosslinker = XlSearchParameters.Crosslinker;

            string fileNameNoExtension = Path.GetFileNameWithoutExtension(items[0].FullFilePath);
            string filePathNoExtension = Path.ChangeExtension(items[0].FullFilePath, null);
            string modSites            = crosslinker.CrosslinkerModSites.ToCharArray().Concat(crosslinker.CrosslinkerModSites2.ToCharArray()).Distinct().ToString();

            var para = new List <pepXML.Generated.nameValueType>();

            {
                para.Add(new pepXML.Generated.nameValueType {
                    name = "threads", value = CommonParameters.MaxThreadsToUsePerFile.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "database", value = databasePath
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "MS_data_file", value = items[0].FullFilePath
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-link precursor Mass Tolerance", value = CommonParameters.PrecursorMassTolerance.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-linker type", value = crosslinker.CrosslinkerName
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-linker mass", value = crosslinker.TotalMass.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-linker cleavable", value = crosslinker.Cleavable.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-linker cleavable long mass", value = crosslinker.CleaveMassLong.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-linker cleavable short mass", value = crosslinker.CleaveMassShort.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Cross-linker xl site", value = modSites
                });

                para.Add(new pepXML.Generated.nameValueType {
                    name = "Generate decoy proteins", value = XlSearchParameters.DecoyType.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "MaxMissed Cleavages", value = CommonParameters.DigestionParams.MaxMissedCleavages.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Protease", value = CommonParameters.DigestionParams.Protease.Name
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Initiator Methionine", value = CommonParameters.DigestionParams.InitiatorMethionineBehavior.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Max Modification Isoforms", value = CommonParameters.DigestionParams.MaxModificationIsoforms.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Min Peptide Len", value = CommonParameters.DigestionParams.MinPeptideLength.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Max Peptide Len", value = CommonParameters.DigestionParams.MaxPeptideLength.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Product Mass Tolerance", value = CommonParameters.ProductMassTolerance.ToString()
                });
                para.Add(new pepXML.Generated.nameValueType {
                    name = "Ions to search", value = String.Join(", ", DissociationTypeCollection.ProductsFromDissociationType[CommonParameters.DissociationType])
                });

                foreach (var fixedMod in fixedModifications)
                {
                    para.Add(new pepXML.Generated.nameValueType {
                        name = "Fixed Modifications: " + fixedMod.IdWithMotif, value = fixedMod.MonoisotopicMass.ToString()
                    });
                }
                foreach (var variableMod in variableModifications)
                {
                    para.Add(new pepXML.Generated.nameValueType {
                        name = "Variable Modifications: " + variableMod.IdWithMotif, value = variableMod.MonoisotopicMass.ToString()
                    });
                }

                para.Add(new pepXML.Generated.nameValueType {
                    name = "Localize All Modifications", value = "true"
                });
            }

            _pepxml.msms_run_summary = new pepXML.Generated.msms_pipeline_analysisMsms_run_summary[1]
            {
                new pepXML.Generated.msms_pipeline_analysisMsms_run_summary
                {
                    base_name     = filePathNoExtension,
                    raw_data_type = "raw",
                    raw_data      = ".mzML",
                    sample_enzyme = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySample_enzyme()
                    {
                        name        = CommonParameters.DigestionParams.Protease.Name,
                        specificity = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySample_enzymeSpecificity[1]
                        {
                            new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySample_enzymeSpecificity
                            {
                                cut    = proteaseC,
                                no_cut = proteaseNC,
                            }
                        }
                    },

                    search_summary = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySearch_summary[1]
                    {
                        new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySearch_summary
                        {
                            base_name             = filePathNoExtension,
                            search_engine_version = GlobalVariables.MetaMorpheusVersion,
                            precursor_mass_type   = pepXML.Generated.massType.monoisotopic,
                            fragment_mass_type    = pepXML.Generated.massType.monoisotopic,
                            search_id             = 1,
                            search_database       = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySearch_summarySearch_database
                            {
                                local_path = databasePath,
                                type       = pepXML.Generated.msms_pipeline_analysisMsms_run_summarySearch_summarySearch_databaseType.AA,
                            },
                            enzymatic_search_constraint = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySearch_summaryEnzymatic_search_constraint
                            {
                                enzyme = CommonParameters.DigestionParams.Protease.Name,
                                max_num_internal_cleavages = CommonParameters.DigestionParams.MaxMissedCleavages.ToString(),
                                //min_number_termini = "2"
                            },

                            parameter = para.ToArray()
                        }
                    },
                }
            };

            _pepxml.msms_run_summary[0].spectrum_query = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_query[items.Count];

            var searchHits = new List <pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit>();

            for (int i = 0; i < items.Count; i++)
            {
                var mods         = new List <pepXML.Generated.modInfoDataTypeMod_aminoacid_mass>();
                var alphaPeptide = items[i].BestMatchingPeptides.First().Peptide;

                foreach (var modification in alphaPeptide.AllModsOneIsNterminus)
                {
                    var mod = new pepXML.Generated.modInfoDataTypeMod_aminoacid_mass
                    {
                        mass = modification.Value.MonoisotopicMass.Value,

                        // convert from one-based to zero-based (N-term is zero in the pepXML output)
                        position = (modification.Key - 1).ToString()
                    };
                    mods.Add(mod);
                }

                if (items[i].CrossType == PsmCrossType.Single)
                {
                    var searchHit = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit
                    {
                        hit_rank              = 1,
                        peptide               = alphaPeptide.BaseSequence,
                        peptide_prev_aa       = alphaPeptide.PreviousAminoAcid.ToString(),
                        peptide_next_aa       = alphaPeptide.NextAminoAcid.ToString(),
                        protein               = alphaPeptide.Protein.Accession,
                        num_tot_proteins      = 1,
                        calc_neutral_pep_mass = (float)items[i].ScanPrecursorMass,
                        massdiff              = (items[i].ScanPrecursorMass - items[i].PeptideMonisotopicMass.Value).ToString(),
                        xlink_typeSpecified   = true,
                        xlink_type            = pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlink_type.na,
                        modification_info     = new pepXML.Generated.modInfoDataType {
                            mod_aminoacid_mass = mods.ToArray()
                        },
                        search_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "xlTotalScore", value = items[i].XLTotalScore.ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "Qvalue", value = items[i].FdrInfo.QValue.ToString()
                            }
                        },
                    };
                    searchHits.Add(searchHit);
                }
                else if (items[i].CrossType == PsmCrossType.DeadEnd || items[i].CrossType == PsmCrossType.DeadEndH2O || items[i].CrossType == PsmCrossType.DeadEndNH2 || items[i].CrossType == PsmCrossType.DeadEndTris)
                {
                    double crosslinkerDeadEndMass = 0;
                    switch (items[i].CrossType)
                    {
                    case PsmCrossType.DeadEndNH2:
                        crosslinkerDeadEndMass = crosslinker.DeadendMassNH2;
                        break;

                    case PsmCrossType.DeadEndTris:
                        crosslinkerDeadEndMass = crosslinker.DeadendMassTris;
                        break;

                    default:
                        crosslinkerDeadEndMass = crosslinker.DeadendMassH2O;
                        break;
                    }
                    var mod = new pepXML.Generated.modInfoDataTypeMod_aminoacid_mass {
                        mass = crosslinkerDeadEndMass, position = items[i].LinkPositions.First().ToString()
                    };
                    mods.Add(mod);
                    var searchHit = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit
                    {
                        hit_rank              = 1,
                        peptide               = alphaPeptide.BaseSequence,
                        peptide_prev_aa       = alphaPeptide.PreviousAminoAcid.ToString(),
                        peptide_next_aa       = alphaPeptide.NextAminoAcid.ToString(),
                        protein               = alphaPeptide.Protein.Accession,
                        num_tot_proteins      = 1,
                        calc_neutral_pep_mass = (float)items[i].ScanPrecursorMass,
                        massdiff              = (items[i].ScanPrecursorMass - items[i].PeptideMonisotopicMass.Value - crosslinkerDeadEndMass).ToString(),
                        xlink_typeSpecified   = true,
                        xlink_type            = pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlink_type.na,
                        modification_info     = new pepXML.Generated.modInfoDataType {
                            mod_aminoacid_mass = mods.ToArray()
                        },
                        search_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "xlTotalScore", value = items[i].XLTotalScore.ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "Qvalue", value = items[i].FdrInfo.QValue.ToString()
                            }
                        },
                    };
                    searchHits.Add(searchHit);
                }
                else if (items[i].CrossType == PsmCrossType.Inter || items[i].CrossType == PsmCrossType.Intra || items[i].CrossType == PsmCrossType.Cross)
                {
                    var betaPeptide = items[i].BetaPeptide.BestMatchingPeptides.First().Peptide;
                    var modsBeta    = new List <pepXML.Generated.modInfoDataTypeMod_aminoacid_mass>();

                    foreach (var mod in betaPeptide.AllModsOneIsNterminus)
                    {
                        var modBeta = new pepXML.Generated.modInfoDataTypeMod_aminoacid_mass
                        {
                            mass = mod.Value.MonoisotopicMass.Value,

                            // convert from one-based to zero-based (N-term is zero in the pepXML output)
                            position = (mod.Key - 1).ToString()
                        };
                        modsBeta.Add(modBeta);
                    }

                    var alpha = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlinkLinked_peptide
                    {
                        peptide               = alphaPeptide.BaseSequence,
                        peptide_prev_aa       = alphaPeptide.PreviousAminoAcid.ToString(),
                        peptide_next_aa       = alphaPeptide.NextAminoAcid.ToString(),
                        protein               = alphaPeptide.Protein.Accession,
                        num_tot_proteins      = 1,
                        calc_neutral_pep_mass = (float)items[i].PeptideMonisotopicMass.Value,
                        complement_mass       = (float)(items[i].ScanPrecursorMass - alphaPeptide.MonoisotopicMass),
                        designation           = "alpha",
                        modification_info     = new pepXML.Generated.modInfoDataType {
                            mod_aminoacid_mass = mods.ToArray()
                        },
                        xlink_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "xlscore", value = items[i].XLTotalScore.ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "link", value = items[i].LinkPositions.First().ToString()
                            },
                        }
                    };
                    var beta = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlinkLinked_peptide
                    {
                        peptide               = betaPeptide.BaseSequence,
                        peptide_prev_aa       = betaPeptide.PreviousAminoAcid.ToString(),
                        peptide_next_aa       = betaPeptide.NextAminoAcid.ToString(),
                        protein               = betaPeptide.Protein.Accession,
                        num_tot_proteins      = 1,
                        calc_neutral_pep_mass = (float)betaPeptide.MonoisotopicMass,
                        complement_mass       = (float)(items[i].ScanPrecursorMass - betaPeptide.MonoisotopicMass),
                        designation           = "beta",
                        modification_info     = new pepXML.Generated.modInfoDataType {
                            mod_aminoacid_mass = modsBeta.ToArray()
                        },
                        xlink_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "xlscore", value = items[i].BetaPeptide.Score.ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "link", value = items[i].BetaPeptide.LinkPositions.First().ToString()
                            },
                        }
                    };
                    var cross = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlinkLinked_peptide[2] {
                        alpha, beta
                    };
                    var searchHit = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit
                    {
                        hit_rank              = 1,
                        peptide               = "-",
                        peptide_prev_aa       = "-",
                        peptide_next_aa       = "-",
                        protein               = "-",
                        num_tot_proteins      = 1,
                        calc_neutral_pep_mass = (float)items[i].ScanPrecursorMass,
                        massdiff              = (items[i].ScanPrecursorMass - betaPeptide.MonoisotopicMass - alphaPeptide.MonoisotopicMass - crosslinker.TotalMass).ToString(),
                        xlink_typeSpecified   = true,
                        xlink_type            = pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlink_type.xl,
                        xlink = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlink
                        {
                            identifier     = crosslinker.CrosslinkerName,
                            mass           = (float)crosslinker.TotalMass,
                            linked_peptide = cross
                        },
                        search_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "xlTotalScore", value = items[i].XLTotalScore.ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "Qvalue", value = items[i].FdrInfo.QValue.ToString()
                            }
                        }
                    };
                    searchHits.Add(searchHit);
                }
                else if (items[i].CrossType == PsmCrossType.Loop)
                {
                    var thePeptide = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlinkLinked_peptide
                    {
                        xlink_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "link", value = items[i].LinkPositions.First().ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "link", value = items[i].LinkPositions[1].ToString()
                            }
                        }
                    };
                    var cross = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlinkLinked_peptide[1] {
                        thePeptide
                    };
                    var searchHit = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit
                    {
                        hit_rank              = 1,
                        peptide               = alphaPeptide.BaseSequence,
                        peptide_prev_aa       = alphaPeptide.PreviousAminoAcid.ToString(),
                        peptide_next_aa       = alphaPeptide.NextAminoAcid.ToString(),
                        protein               = alphaPeptide.Protein.Accession,
                        num_tot_proteins      = 1,
                        calc_neutral_pep_mass = (float)items[i].ScanPrecursorMass,
                        massdiff              = (items[i].ScanPrecursorMass - alphaPeptide.MonoisotopicMass - crosslinker.LoopMass).ToString(),
                        xlink_typeSpecified   = true,
                        xlink_type            = pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlink_type.loop,
                        modification_info     = new pepXML.Generated.modInfoDataType {
                            mod_aminoacid_mass = mods.ToArray()
                        },
                        xlink = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hitXlink
                        {
                            identifier     = crosslinker.CrosslinkerName,
                            mass           = (float)crosslinker.TotalMass,
                            linked_peptide = cross
                        },
                        search_score = new pepXML.Generated.nameValueType[]
                        {
                            new pepXML.Generated.nameValueType {
                                name = "xlTotalScore", value = items[i].XLTotalScore.ToString()
                            },
                            new pepXML.Generated.nameValueType {
                                name = "Qvalue", value = items[i].FdrInfo.QValue.ToString()
                            }
                        }
                    };
                    searchHits.Add(searchHit);
                }
            }

            for (int i = 0; i < items.Count; i++)
            {
                _pepxml.msms_run_summary[0].spectrum_query[i] = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_query()
                {
                    spectrum               = fileNameNoExtension + "." + items[i].ScanNumber.ToString(),
                    start_scan             = Convert.ToUInt32(items[i].ScanNumber),
                    end_scan               = Convert.ToUInt32(items[i].ScanNumber),
                    precursor_neutral_mass = (float)items[i].ScanPrecursorMass,
                    assumed_charge         = items[i].ScanPrecursorCharge.ToString(),
                    index = Convert.ToUInt32(i + 1),
                    retention_time_sec = (float)(items[i].ScanRetentionTime * 60),
                    search_result      = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_result[1]
                    {
                        new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_result
                        {
                            search_hit = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit[1]
                            {
                                searchHits[i]
                            }
                        }
                    }
                };
            }

            TextWriter writer = new StreamWriter(Path.Combine(outputFolder, fileName + ".pep.XML"));

            _indexedSerializer.Serialize(writer, _pepxml);
            writer.Close();
            FinishedWritingFile(Path.Combine(outputFolder, fileName + ".pep.XML"), nestedIds);
        }
        public void WriteCrosslinkToTxtForPercolator(List <CrosslinkSpectralMatch> items, string outputFolder, string fileName, Crosslinker crosslinker, List <string> nestedIds)
        {
            if (items.Count == 0)
            {
                return;
            }
            var writtenFile = Path.Combine(outputFolder, fileName + ".txt");

            using (StreamWriter output = new StreamWriter(writtenFile))
            {
                output.WriteLine("SpecId\tLabel\tScannr\tScore\tdScore\tNormRank\tCharge\tMass\tPPM\tLenShort\tLenLong\tLenSum" +
                                 "\tPeptide\tProtein");
                foreach (var item in items)
                {
                    if (item.BaseSequence != null && item.BetaPeptide.BaseSequence != null && item.ProteinAccession != null && item.BetaPeptide.ProteinAccession != null)
                    {
                        string x = "T"; int label = 1;
                        if (item.IsDecoy || item.BetaPeptide.IsDecoy)
                        {
                            x = "D"; label = -1;
                        }
                        output.WriteLine(
                            x + "-" + item.ScanNumber.ToString(CultureInfo.InvariantCulture) + "-" + item.ScanRetentionTime.ToString(CultureInfo.InvariantCulture)
                            + "\t" + label.ToString(CultureInfo.InvariantCulture)
                            + "\t" + item.ScanNumber.ToString(CultureInfo.InvariantCulture)
                            + "\t" + item.XLTotalScore.ToString(CultureInfo.InvariantCulture)
                            + "\t" + item.DeltaScore.ToString(CultureInfo.InvariantCulture)
                            + "\t" + (item.XlRank[0] + item.XlRank[1]).ToString(CultureInfo.InvariantCulture)
                            + "\t" + item.ScanPrecursorCharge.ToString(CultureInfo.InvariantCulture)
                            + "\t" + item.ScanPrecursorMass.ToString(CultureInfo.InvariantCulture)
                            + "\t" + ((item.PeptideMonisotopicMass.HasValue && item.BetaPeptide.PeptideMonisotopicMass.HasValue) ? ((item.ScanPrecursorMass - item.BetaPeptide.PeptideMonisotopicMass.Value - item.PeptideMonisotopicMass.Value - crosslinker.TotalMass) / item.ScanPrecursorMass * 1E6).ToString(CultureInfo.InvariantCulture) : "---")
                            + "\t" + item.BetaPeptide.BaseSequence.Length.ToString(CultureInfo.InvariantCulture)
                            + "\t" + item.BaseSequence.Length.ToString(CultureInfo.InvariantCulture)
                            + "\t" + (item.BetaPeptide.BaseSequence.Length + item.BaseSequence.Length).ToString(CultureInfo.InvariantCulture)
                            + "\t" + "-." + item.FullSequence + item.LinkPositions.First().ToString(CultureInfo.InvariantCulture) + "--" + item.BetaPeptide.FullSequence + item.BetaPeptide.LinkPositions.First().ToString(CultureInfo.InvariantCulture) + ".-"
                            + "\t" + item.BestMatchingPeptides.First().Peptide.Protein.Accession.ToString(CultureInfo.InvariantCulture)
                            + "(" + item.XlProteinPos.ToString(CultureInfo.InvariantCulture) + ")"
                            + "\t" + item.BetaPeptide.BestMatchingPeptides.First().Peptide.Protein.Accession.ToString(CultureInfo.InvariantCulture)
                            + "(" + item.BetaPeptide.XlProteinPos.ToString(CultureInfo.InvariantCulture) + ")"
                            );
                    }
                }
            }
            FinishedWritingFile(writtenFile, nestedIds);
        }
        public static IEnumerable <Tuple <int, List <Product> > > XlGetTheoreticalFragments(DissociationType dissociationType, Crosslinker crosslinker,
                                                                                            List <int> possibleCrosslinkerPositions, double otherPeptideMass, PeptideWithSetModifications peptide)
        {
            List <double> massesToLocalize = new List <double>();

            if (crosslinker.Cleavable && crosslinker.CleaveDissociationTypes.Contains(dissociationType))
            {
                massesToLocalize.Add(crosslinker.CleaveMassShort);
                massesToLocalize.Add(crosslinker.CleaveMassLong);
            }
            else
            {
                massesToLocalize.Add(crosslinker.TotalMass + otherPeptideMass);
            }

            var fragments           = new List <Product>();
            HashSet <double> masses = new HashSet <double>();

            foreach (int crosslinkerPosition in possibleCrosslinkerPositions)
            {
                List <Product> theoreticalProducts = new List <Product>(); //need a new one each time to pass as a reference, don't clear
                masses.Clear();

                foreach (double massToLocalize in massesToLocalize)
                {
                    Dictionary <int, Modification> testMods = new Dictionary <int, Modification> {
                        { crosslinkerPosition + 1, new Modification(_monoisotopicMass: massToLocalize) }
                    };

                    foreach (var mod in peptide.AllModsOneIsNterminus)
                    {
                        testMods.Add(mod.Key, mod.Value);
                    }

                    var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein,
                                                                      peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods);

                    testPeptide.Fragment(dissociationType, FragmentationTerminus.Both, fragments);

                    // add fragmentation ions for this crosslinker position guess
                    foreach (var fragment in fragments)
                    {
                        if (!masses.Contains(fragment.NeutralMass))
                        {
                            theoreticalProducts.Add(fragment);
                            masses.Add(fragment.NeutralMass);
                        }
                    }

                    // add signature ions
                    if (crosslinker.Cleavable)
                    {
                        theoreticalProducts.Add(new Product(ProductType.M, FragmentationTerminus.None, peptide.MonoisotopicMass + massToLocalize,
                                                            peptide.Length, peptide.Length, 0));
                    }
                }

                yield return(new Tuple <int, List <Product> >(crosslinkerPosition, theoreticalProducts));
            }
        }
Exemple #10
0
        public static void XlTest_BSA_DSSO()
        {
            //Generate parameters
            var commonParameters = new CommonParameters(doPrecursorDeconvolution: false, dissociationType: DissociationType.EThcD,
                                                        scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 5), precursorMassTolerance: new PpmTolerance(10));

            var xlSearchParameters = new XlSearchParameters();

            //Create databases contain two protein.
            var proteinList = new List <Protein> {
                new Protein("EKVLTSSAR", "Fake01"), new Protein("LSQKFPK", "Fake02")
            };

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif1);
            Modification mod1 = new Modification(_originalId: "Oxidation of M", _modificationType: "Common Variable", _target: motif1, _locationRestriction: "Anywhere.", _monoisotopicMass: 15.99491461957);

            ModificationMotif.TryGetMotif("C", out ModificationMotif motif2);
            Modification mod2 = new Modification(_originalId: "Carbamidomethyl of C", _modificationType: "Common Fixed", _target: motif2, _locationRestriction: "Anywhere.", _monoisotopicMass: 57.02146372068994);
            var          variableModifications = new List <Modification>()
            {
                mod1
            };
            var fixedModifications = new List <Modification>()
            {
                mod2
            };
            var localizeableModifications = new List <Modification>();

            //Run index engine
            var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.Reverse, commonParameters, 30000, false, new List <FileInfo>(), new List <string>());

            var indexResults = (IndexingResults)indexEngine.Run();

            var indexedFragments = indexResults.FragmentIndex.Where(p => p != null).SelectMany(v => v).ToList();

            Assert.AreEqual(82, indexedFragments.Count);
            Assert.AreEqual(3, indexResults.PeptideIndex.Count);

            //Get MS2 scans.
            var myMsDataFile         = new XLTestDataFile();
            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            //Generate crosslinker, which is DSSO here.
            Crosslinker crosslinker = GlobalVariables.Crosslinkers.Where(p => p.CrosslinkerName == "DSSO").First();

            CrosslinkSpectralMatch[] possiblePsms = new CrosslinkSpectralMatch[listOfSortedms2Scans.Length];
            new CrosslinkSearchEngine(possiblePsms, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, commonParameters, crosslinker, xlSearchParameters.RestrictToTopNHits, xlSearchParameters.CrosslinkSearchTopNum, xlSearchParameters.XlQuench_H2O, xlSearchParameters.XlQuench_NH2, xlSearchParameters.XlQuench_Tris, new List <string> {
            }).Run();

            var newPsms = possiblePsms.Where(p => p != null).ToList();

            foreach (var item in newPsms)
            {
                item.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            }

            //Test newPsms
            Assert.AreEqual(3, newPsms.Count);

            //Test Output
            var task = new XLSearchTask();

            task.WritePepXML_xl(newPsms, proteinList, null, variableModifications, fixedModifications, null, TestContext.CurrentContext.TestDirectory, "pep.XML", new List <string> {
            });

            //Test PsmCross.XlCalculateTotalProductMasses
            //var psmCrossAlpha = new CrosslinkSpectralMatch(digestedList[1], 0, 0, 0, listOfSortedms2Scans[0], commonParameters.DigestionParams, new List<MatchedFragmentIon>());
            //var psmCrossBeta = new CrosslinkSpectralMatch(digestedList[2], 0, 0, 0, listOfSortedms2Scans[0], commonParameters.DigestionParams, new List<MatchedFragmentIon>());
            //var linkPos = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), digestedList[1]);
            //var productMassesAlphaList = CrosslinkedPeptide.XlGetTheoreticalFragments(DissociationType.EThcD, false, crosslinker, linkPos, digestedList[2].MonoisotopicMass, digestedList[1]);
            //Assert.AreEqual(productMassesAlphaList.First().Value.Count, 50); //TO DO: The number here should be manually verified.
            File.Delete(@"singlePsms.tsv");
            File.Delete(@"pep.XML.pep.xml");
            File.Delete(@"allPsms.tsv");
        }