Пример #1
0
 public override int GetHashCode()
 {
     return
         (MaxMissedCleavages.GetHashCode()
          ^ InitiatorMethionineBehavior.GetHashCode()
          ^ MaxModificationIsoforms.GetHashCode()
          ^ MaxModsForPeptide.GetHashCode());
 }
Пример #2
0
        }                                                                    //used to look for unlabeled proteins (in addition to labeled proteins) for SILAC experiments

        public override bool Equals(object obj)
        {
            return(obj is DigestionParams a &&
                   MaxMissedCleavages.Equals(a.MaxMissedCleavages) &&
                   MinPeptideLength.Equals(a.MinPeptideLength) &&
                   MaxPeptideLength.Equals(a.MaxPeptideLength) &&
                   InitiatorMethionineBehavior.Equals(a.InitiatorMethionineBehavior) &&
                   MaxModificationIsoforms.Equals(a.MaxModificationIsoforms) &&
                   MaxModsForPeptide.Equals(a.MaxModsForPeptide) &&
                   Protease.Equals(a.Protease) &&
                   SearchModeType.Equals(a.SearchModeType) &&
                   FragmentationTerminus.Equals(a.FragmentationTerminus) &&
                   GeneratehUnlabeledProteinsForSilac.Equals(a.GeneratehUnlabeledProteinsForSilac));
        }
Пример #3
0
 public DigestionParams(string protease             = "trypsin", int maxMissedCleavages = 2, int minPeptideLength = 7, int maxPeptideLength = int.MaxValue,
                        int maxModificationIsoforms = 1024, InitiatorMethionineBehavior initiatorMethionineBehavior = InitiatorMethionineBehavior.Variable,
                        int maxModsForPeptides      = 2, bool semiProteaseDigestion = false, FragmentationTerminus terminusTypeSemiProtease = FragmentationTerminus.N)
 {
     Protease                    = ProteaseDictionary.Dictionary[protease];
     MaxMissedCleavages          = maxMissedCleavages;
     MinPeptideLength            = minPeptideLength;
     MaxPeptideLength            = maxPeptideLength;
     MaxModificationIsoforms     = maxModificationIsoforms;
     InitiatorMethionineBehavior = initiatorMethionineBehavior;
     MaxModsForPeptide           = maxModsForPeptides;
     SemiProteaseDigestion       = semiProteaseDigestion;
     TerminusTypeSemiProtease    = terminusTypeSemiProtease;
 }
Пример #4
0
        public override bool Equals(object obj)
        {
            var a = obj as IDigestionParams;

            return(a != null &&
                   MaxMissedCleavages.Equals(a.MaxMissedCleavages) &&
                   MinPeptideLength.Equals(a.MinPeptideLength) &&
                   MaxPeptideLength.Equals(a.MaxPeptideLength) &&
                   InitiatorMethionineBehavior.Equals(a.InitiatorMethionineBehavior) &&
                   MaxModificationIsoforms.Equals(a.MaxModificationIsoforms) &&
                   MaxModsForPeptide.Equals(a.MaxModsForPeptide) &&
                   Protease.Equals(a.Protease) &&
                   SemiProteaseDigestion.Equals(a.SemiProteaseDigestion) &&
                   TerminusTypeSemiProtease.Equals(a.TerminusTypeSemiProtease));
        }
Пример #5
0
 public DigestionParams(string protease                        = "trypsin", int maxMissedCleavages = 2, int minPeptideLength = 7, int maxPeptideLength = int.MaxValue,
                        int maxModificationIsoforms            = 1024, InitiatorMethionineBehavior initiatorMethionineBehavior = InitiatorMethionineBehavior.Variable,
                        int maxModsForPeptides                 = 2, CleavageSpecificity searchModeType = CleavageSpecificity.Full, FragmentationTerminus fragmentationTerminus = FragmentationTerminus.Both,
                        bool generateUnlabeledProteinsForSilac = true)
 {
     Protease                    = ProteaseDictionary.Dictionary[protease];
     MaxMissedCleavages          = maxMissedCleavages;
     MinPeptideLength            = minPeptideLength;
     MaxPeptideLength            = maxPeptideLength;
     MaxModificationIsoforms     = maxModificationIsoforms;
     InitiatorMethionineBehavior = initiatorMethionineBehavior;
     MaxModsForPeptide           = maxModsForPeptides;
     SearchModeType              = searchModeType;
     FragmentationTerminus       = fragmentationTerminus;
     RecordSpecificProtease();
     GeneratehUnlabeledProteinsForSilac = generateUnlabeledProteinsForSilac;
 }
 public DatabaseSearcher(IList<string> dataFilepaths,
     int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState,
     double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks,
     bool assignChargeStates, bool deisotope,
     string proteinFastaDatabaseFilepath, bool onTheFlyDecoys,
     Protease protease, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
     IEnumerable<Modification> fixedModifications, IEnumerable<Modification> variableModifications, int maximumVariableModificationIsoforms,
     MassTolerance precursorMassTolerance, MassType precursorMassType,
     bool precursorMonoisotopicPeakCorrection, int minimumPrecursorMonoisotopicPeakOffset, int maximumPrecursorMonoisotopicPeakOffset,
     MassTolerance productMassTolerance, MassType productMassType,
     double maximumFalseDiscoveryRate, bool considerModifiedFormsAsUniquePeptides,
     int maximumThreads, bool minimizeMemoryUsage,
     string outputFolder)
 {
     this.dataFilepaths = dataFilepaths;
     this.assignChargeStates = assignChargeStates;
     this.deisotope = deisotope;
     this.proteinFastaDatabaseFilepath = proteinFastaDatabaseFilepath;
     this.onTheFlyDecoys = onTheFlyDecoys;
     this.protease = protease;
     this.maximumMissedCleavages = maximumMissedCleavages;
     this.initiatorMethionineBehavior = initiatorMethionineBehavior;
     this.fixedModifications = fixedModifications;
     this.variableModifications = variableModifications;
     this.maximumVariableModificationIsoforms = maximumVariableModificationIsoforms;
     this.minimumAssumedPrecursorChargeState = minimumAssumedPrecursorChargeState;
     this.maximumAssumedPrecursorChargeState = maximumAssumedPrecursorChargeState;
     this.absoluteThreshold = absoluteThreshold;
     this.relativeThresholdPercent = relativeThresholdPercent;
     this.maximumNumberOfPeaks = maximumNumberOfPeaks;
     this.precursorMassTolerance = precursorMassTolerance;
     this.precursorMassType = precursorMassType;
     this.precursorMonoisotopicPeakCorrection = precursorMonoisotopicPeakCorrection;
     this.minimumPrecursorMonoisotopicPeakOffset = minimumPrecursorMonoisotopicPeakOffset;
     this.maximumPrecursorMonoisotopicPeakOffset = maximumPrecursorMonoisotopicPeakOffset;
     this.productMassTolerance = productMassTolerance;
     this.productMassType = productMassType;
     this.maximumFalseDiscoveryRate = maximumFalseDiscoveryRate;
     this.considerModifiedFormsAsUniquePeptides = considerModifiedFormsAsUniquePeptides;
     this.maximumThreads = maximumThreads;
     this.minimizeMemoryUsage = minimizeMemoryUsage;
     this.outputFolder = outputFolder;
 }
Пример #7
0
        public DBOptions(string fasta, IConSol console = null)
        {
            if (console == null)
            {
                ConSole = new ConSolCommandLine();
            }
            else
            {
                ConSole = console;
            }
            //Create with default values
            this.DecoyFusion           = true;
            this.FastaDatabaseFilepath = fasta;
            this.MaximumPeptideMass    = 10000;
            ProteaseDictionary proteases = ProteaseDictionary.Instance;

            this.DigestionEnzyme                     = proteases["no enzyme"]; // proteases["trypsin (no proline rule)"];
            this.NoEnzymeSearch                      = true;
            this.ToleratedMissedCleavages            = 100;                    // 3;//determines the length of peptides with no-enzyme option
            this.initiatorMethionineBehavior         = InitiatorMethionineBehavior.Variable;
            this.fixedModifications                  = new GraphML_List <Modification>();
            this.variableModifications               = new GraphML_List <Modification>();
            this.maximumVariableModificationIsoforms = 1024;

            this.MinimumPrecursorChargeState         = 1;
            this.MaximumPrecursorChargeState         = 4;
            this.MaximumNumberOfFragmentsPerSpectrum = 400;
            //TODO Add precision to the precursor by reading MS part of file
            this.precursorMassTolerance = new MassTolerance(0.005, MassToleranceUnits.Da);//2.1
            //TODO Add precision to the product masses by reading corresponding MS part of raw file
            this.productMassTolerance = new MassTolerance(0.005, MassToleranceUnits.Da);

            this.PSMFalseDiscoveryRate = 0.25;             // 0.05;

            this.OutputFolder    = @"C:\_IRIC\DATA\Test2"; //C:\Documents and Settings\ProteoAdmin\Desktop\AEffacer\Morpheus\Output";
            this.MinimumPSMScore = 0.0001;
        }
Пример #8
0
        /// <summary>
        /// Gets the protein intervals based on nonspecific digestion rules
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="minPeptidesLength"></param>
        /// <param name="maxPeptidesLength"></param>
        /// <returns></returns>
        private IEnumerable <Peptide> SemiProteolyticDigestion(Protein protein, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                               int maximumMissedCleavages, int minPeptidesLength, int maxPeptidesLength)
        {
            List <Peptide> intervals = new List <Peptide>();
            List <int>     oneBasedIndicesToCleaveAfter = GetDigestionSiteIndices(protein.BaseSequence);

            for (int i = 0; i < oneBasedIndicesToCleaveAfter.Count - maximumMissedCleavages - 1; i++)
            {
                bool retain           = Retain(i, initiatorMethionineBehavior, protein[0]);
                bool cleave           = Cleave(i, initiatorMethionineBehavior, protein[0]);
                int  cTerminusProtein = oneBasedIndicesToCleaveAfter[i + maximumMissedCleavages + 1];

                if (retain)
                {
                    intervals.AddRange(FixedTermini(oneBasedIndicesToCleaveAfter[i], cTerminusProtein, protein, cleave, minPeptidesLength, maxPeptidesLength));
                }

                if (cleave)
                {
                    intervals.AddRange(FixedTermini(1, cTerminusProtein, protein, cleave, minPeptidesLength, maxPeptidesLength));
                }
            }

            //finish C-term of protein caused by loop being "i < oneBasedIndicesToCleaveAfter.Count - maximumMissedCleavages - 1"
            int last         = oneBasedIndicesToCleaveAfter.Count - 1;
            int maxIndexSemi = maximumMissedCleavages < last ? maximumMissedCleavages : last;

            //Fringe C-term peptides
            for (int i = 1; i <= maxIndexSemi; i++)
            {
                //fixedN
                int nTerminusProtein = oneBasedIndicesToCleaveAfter[last - i];
                int cTerminusProtein = oneBasedIndicesToCleaveAfter[last] - 1;
                for (int j = cTerminusProtein; j > nTerminusProtein; j--)
                {
                    if (OkayLength(j - nTerminusProtein, minPeptidesLength, maxPeptidesLength))
                    {
                        intervals.Add(new Peptide(protein, nTerminusProtein + 1, j, j - nTerminusProtein, "semiN"));
                    }
                }
            }

            //Fringe N-term peptides
            for (int i = 1; i <= maxIndexSemi; i++)
            {
                //fixedC
                int nTerminusProtein = oneBasedIndicesToCleaveAfter[0];
                int cTerminusProtein = oneBasedIndicesToCleaveAfter[i];
                for (int j = nTerminusProtein + 1; j < cTerminusProtein; j++)
                {
                    if (OkayLength(cTerminusProtein - j, minPeptidesLength, maxPeptidesLength))
                    {
                        intervals.Add(new Peptide(protein, j + 1, cTerminusProtein, cTerminusProtein - j, "semiC"));
                    }
                }
            }

            // Also digest using the proteolysis product start/end indices
            // This should only be things where the proteolysis is not K/R and the
            foreach (var proteolysisProduct in protein.ProteolysisProducts)
            {
                if (proteolysisProduct.OneBasedEndPosition.HasValue && proteolysisProduct.OneBasedBeginPosition.HasValue &&
                    (proteolysisProduct.OneBasedBeginPosition != 1 || proteolysisProduct.OneBasedEndPosition != protein.Length))    //if at least one side is not a terminus
                {
                    int i = 0;
                    while (oneBasedIndicesToCleaveAfter[i] < proteolysisProduct.OneBasedBeginPosition) //"<" to prevent additions if same index as residues
                    {
                        i++;                                                                           //last position in protein is an index to cleave after
                    }

                    // Start peptide
                    for (int j = proteolysisProduct.OneBasedBeginPosition.Value; j < oneBasedIndicesToCleaveAfter[i]; j++)
                    {
                        if (OkayLength(j - proteolysisProduct.OneBasedBeginPosition + 1, minPeptidesLength, maxPeptidesLength))
                        {
                            intervals.Add(new Peptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, j,
                                                      j - proteolysisProduct.OneBasedBeginPosition.Value, proteolysisProduct.Type + " start"));
                        }
                    }
                    while (oneBasedIndicesToCleaveAfter[i] < proteolysisProduct.OneBasedEndPosition) //"<" to prevent additions if same index as residues, since i-- is below
                    {
                        i++;
                    }

                    //Now that we've obtained an index to cleave after that is past the proteolysis product
                    //we need to backtrack to get the index to cleave that is immediately before the the proteolysis product
                    //to do this, we will do i--
                    //In the nitch case that the proteolysis product is already an index to cleave
                    //no new peptides will be generated using this, so we will forgo i--
                    //this makes peptides of length 0, which are not generated due to the for loop
                    //removing this if statement will result in crashes from c-terminal proteolysis product end positions
                    if (oneBasedIndicesToCleaveAfter[i] != proteolysisProduct.OneBasedEndPosition)
                    {
                        i--;
                    }

                    // End
                    for (int j = oneBasedIndicesToCleaveAfter[i] + 1; j < proteolysisProduct.OneBasedEndPosition.Value; j++)
                    {
                        if (OkayLength(proteolysisProduct.OneBasedEndPosition - j + 1, minPeptidesLength, maxPeptidesLength))
                        {
                            intervals.Add(new Peptide(protein, j, proteolysisProduct.OneBasedEndPosition.Value,
                                                      proteolysisProduct.OneBasedEndPosition.Value - j, proteolysisProduct.Type + " end"));
                        }
                    }
                }
            }
            return(intervals);
        }
Пример #9
0
        /// <summary>
        /// Gets protein intervals for digestion by this specific protease.
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="minPeptidesLength"></param>
        /// <param name="maxPeptidesLength"></param>
        /// <returns></returns>
        private IEnumerable <Peptide> FullDigestion(Protein protein, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                    int maximumMissedCleavages, int minPeptidesLength, int maxPeptidesLength)
        {
            List <int> oneBasedIndicesToCleaveAfter = GetDigestionSiteIndices(protein.BaseSequence);

            for (int missed_cleavages = 0; missed_cleavages <= maximumMissedCleavages; missed_cleavages++)
            {
                for (int i = 0; i < oneBasedIndicesToCleaveAfter.Count - missed_cleavages - 1; i++)
                {
                    if (Retain(i, initiatorMethionineBehavior, protein[0]) &&
                        OkayLength(oneBasedIndicesToCleaveAfter[i + missed_cleavages + 1] - oneBasedIndicesToCleaveAfter[i], minPeptidesLength, maxPeptidesLength))
                    {
                        yield return(new Peptide(protein, oneBasedIndicesToCleaveAfter[i] + 1, oneBasedIndicesToCleaveAfter[i + missed_cleavages + 1],
                                                 missed_cleavages, "full"));
                    }
                    if (Cleave(i, initiatorMethionineBehavior, protein[0]) &&
                        OkayLength(oneBasedIndicesToCleaveAfter[i + missed_cleavages + 1] - 1, minPeptidesLength, maxPeptidesLength))
                    {
                        yield return(new Peptide(protein, 2, oneBasedIndicesToCleaveAfter[i + missed_cleavages + 1],
                                                 missed_cleavages, "full:M cleaved"));
                    }
                }

                // Also digest using the proteolysis product start/end indices
                foreach (var proteolysisProduct in protein.ProteolysisProducts)
                {
                    if (proteolysisProduct.OneBasedBeginPosition != 1 || proteolysisProduct.OneBasedEndPosition != protein.Length)
                    {
                        int i = 0;
                        while (oneBasedIndicesToCleaveAfter[i] < proteolysisProduct.OneBasedBeginPosition)
                        {
                            i++;
                        }

                        bool startPeptide = i + missed_cleavages < oneBasedIndicesToCleaveAfter.Count &&
                                            oneBasedIndicesToCleaveAfter[i + missed_cleavages] <= proteolysisProduct.OneBasedEndPosition &&
                                            proteolysisProduct.OneBasedBeginPosition.HasValue &&
                                            OkayLength(oneBasedIndicesToCleaveAfter[i + missed_cleavages] - proteolysisProduct.OneBasedBeginPosition.Value + 1, minPeptidesLength, maxPeptidesLength);
                        if (startPeptide)
                        {
                            yield return(new Peptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, oneBasedIndicesToCleaveAfter[i + missed_cleavages],
                                                     missed_cleavages, proteolysisProduct.Type + " start"));
                        }

                        while (oneBasedIndicesToCleaveAfter[i] < proteolysisProduct.OneBasedEndPosition)
                        {
                            i++;
                        }

                        bool end = i - missed_cleavages - 1 >= 0 &&
                                   oneBasedIndicesToCleaveAfter[i - missed_cleavages - 1] + 1 >= proteolysisProduct.OneBasedBeginPosition &&
                                   proteolysisProduct.OneBasedEndPosition.HasValue &&
                                   OkayLength(proteolysisProduct.OneBasedEndPosition.Value - oneBasedIndicesToCleaveAfter[i - missed_cleavages - 1] + 1 - 1, minPeptidesLength, maxPeptidesLength);
                        if (end)
                        {
                            yield return(new Peptide(protein, oneBasedIndicesToCleaveAfter[i - missed_cleavages - 1] + 1, proteolysisProduct.OneBasedEndPosition.Value,
                                                     missed_cleavages, proteolysisProduct.Type + " end"));
                        }
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Gets intervals of a protein sequence that will result from digestion by this protease.
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="minPeptidesLength"></param>
        /// <param name="maxPeptidesLength"></param>
        /// <returns></returns>
        internal List <Peptide> GetDigestionIntervals(Protein protein, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                      int minPeptidesLength, int maxPeptidesLength)
        {
            List <Peptide> intervals = new List <Peptide>();

            // proteolytic cleavage in one spot
            if (CleavageSpecificity == CleavageSpecificity.SingleN || CleavageSpecificity == CleavageSpecificity.SingleC)
            {
                bool maxTooBig = protein.Length + maxPeptidesLength < 0; //when maxPeptidesLength is too large, it becomes negative and causes issues
                for (int proteinStart = 1; proteinStart <= protein.Length; proteinStart++)
                {
                    if (CleavageSpecificity == CleavageSpecificity.SingleN && OkayMinLength(protein.Length - proteinStart + 1, minPeptidesLength))
                    {
                        //need Math.Max if max length is int.MaxLength, since +proteinStart will make it negative
                        intervals.Add(new Peptide(protein, proteinStart, maxTooBig ? protein.Length : Math.Min(protein.Length, proteinStart + maxPeptidesLength), 0, "SingleN"));
                    }

                    if (CleavageSpecificity == CleavageSpecificity.SingleC && OkayMinLength(proteinStart, minPeptidesLength))
                    {
                        intervals.Add(new Peptide(protein, Math.Max(1, proteinStart - maxPeptidesLength), proteinStart, 0, "SingleC"));
                    }
                }
            }
            else if (CleavageSpecificity == CleavageSpecificity.None)
            {
                // retain methionine
                if ((initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || protein[0] != 'M') && OkayLength(protein.Length, minPeptidesLength, maxPeptidesLength))
                {
                    intervals.Add(new Peptide(protein, 1, protein.Length, 0, "full"));
                }

                // cleave methionine
                if ((initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && protein[0] == 'M') && OkayLength(protein.Length - 1, minPeptidesLength, maxPeptidesLength))
                {
                    intervals.Add(new Peptide(protein, 2, protein.Length, 0, "full:M cleaved"));
                }

                // Also digest using the proteolysis product start/end indices
                intervals.AddRange(
                    protein.ProteolysisProducts
                    .Where(proteolysisProduct => proteolysisProduct.OneBasedEndPosition.HasValue && proteolysisProduct.OneBasedBeginPosition.HasValue &&
                           OkayLength(proteolysisProduct.OneBasedEndPosition.Value - proteolysisProduct.OneBasedBeginPosition.Value + 1, minPeptidesLength, maxPeptidesLength))
                    .Select(proteolysisProduct =>
                            new Peptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, proteolysisProduct.OneBasedEndPosition.Value, 0, proteolysisProduct.Type)));
            }

            // Full proteolytic cleavage
            else if (CleavageSpecificity == CleavageSpecificity.Full)
            {
                intervals.AddRange(FullDigestion(protein, initiatorMethionineBehavior, maximumMissedCleavages, minPeptidesLength, maxPeptidesLength));
            }

            // Cleavage rules for nonspecific search
            else if (CleavageSpecificity == CleavageSpecificity.Semi)
            {
                intervals.AddRange(SemiProteolyticDigestion(protein, initiatorMethionineBehavior, maximumMissedCleavages, minPeptidesLength, maxPeptidesLength));
            }
            else
            {
                throw new NotImplementedException();
            }

            return(intervals);
        }
Пример #11
0
 /// <summary>
 /// Cleave N-terminal residue?
 /// </summary>
 /// <param name="oneBasedCleaveAfter"></param>
 /// <param name="initiatorMethionineBehavior"></param>
 /// <param name="nTerminus"></param>
 /// <returns></returns>
 internal static bool Cleave(int oneBasedCleaveAfter, InitiatorMethionineBehavior initiatorMethionineBehavior, char nTerminus)
 {
     return(oneBasedCleaveAfter == 0 && // this only pertains to the n-terminus
            initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain &&
            nTerminus == 'M');
 }
Пример #12
0
        /// <summary>
        /// Gets the protein intervals based on semiSpecific digestion rules
        /// This is the classic, slow semi-specific digestion that generates each semi-specific peptide pre-search
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="minPeptideLength"></param>
        /// <param name="maxPeptideLength"></param>
        /// <returns></returns>
        private IEnumerable <ProteolyticPeptide> SemiProteolyticDigestion(Protein protein, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                                          int maximumMissedCleavages, int minPeptideLength, int maxPeptideLength)
        {
            List <ProteolyticPeptide> intervals     = new List <ProteolyticPeptide>();
            List <int> oneBasedIndicesToCleaveAfter = GetDigestionSiteIndices(protein.BaseSequence);

            // It's possible not to go through this loop (maxMissedCleavages+1>number of indexes), and that's okay. It will get digested in the next loops (finish C/N termini)
            for (int i = 0; i < oneBasedIndicesToCleaveAfter.Count - maximumMissedCleavages - 1; i++)
            {
                bool          retain           = Retain(i, initiatorMethionineBehavior, protein[0]);
                bool          cleave           = Cleave(i, initiatorMethionineBehavior, protein[0]) && oneBasedIndicesToCleaveAfter[1] != 1;
                int           cTerminusProtein = oneBasedIndicesToCleaveAfter[i + maximumMissedCleavages + 1];
                HashSet <int> localOneBasedIndicesToCleaveAfter = new HashSet <int>();
                for (int j = i; j < i + maximumMissedCleavages + 1; j++)
                {
                    localOneBasedIndicesToCleaveAfter.Add(oneBasedIndicesToCleaveAfter[j]);
                }
                if (retain)
                {
                    intervals.AddRange(FixedTermini(oneBasedIndicesToCleaveAfter[i], cTerminusProtein, protein, cleave, retain, minPeptideLength, maxPeptideLength, localOneBasedIndicesToCleaveAfter));
                }

                if (cleave)
                {
                    intervals.AddRange(FixedTermini(1, cTerminusProtein, protein, cleave, retain, minPeptideLength, maxPeptideLength, localOneBasedIndicesToCleaveAfter));
                }
            }

            // Finish C-term of protein caused by loop being "i < oneBasedIndicesToCleaveAfter.Count - maximumMissedCleavages - 1"
            int last         = oneBasedIndicesToCleaveAfter.Count - 1;
            int maxIndexSemi = maximumMissedCleavages < last ? maximumMissedCleavages : last;

            // Fringe C-term peptides
            for (int i = 1; i <= maxIndexSemi; i++)
            {
                // FixedN
                int           nTerminusProtein = oneBasedIndicesToCleaveAfter[last - i];
                int           cTerminusProtein = oneBasedIndicesToCleaveAfter[last];
                HashSet <int> localOneBasedIndicesToCleaveAfter = new HashSet <int>();
                for (int j = 0; j < i; j++) //include zero, the c terminus
                {
                    localOneBasedIndicesToCleaveAfter.Add(oneBasedIndicesToCleaveAfter[last - j]);
                }
                for (int j = cTerminusProtein; j > nTerminusProtein; j--)//We are hitting the c-terminus here
                {
                    if (OkayLength(j - nTerminusProtein, minPeptideLength, maxPeptideLength))
                    {
                        intervals.Add(localOneBasedIndicesToCleaveAfter.Contains(j) ?
                                      new ProteolyticPeptide(protein, nTerminusProtein + 1, j, j - nTerminusProtein, CleavageSpecificity.Full, "full") :
                                      new ProteolyticPeptide(protein, nTerminusProtein + 1, j, j - nTerminusProtein, CleavageSpecificity.Semi, "semi"));
                    }
                }
            }

            // Fringe N-term peptides
            for (int i = 1; i <= maxIndexSemi; i++)
            {
                bool retain = initiatorMethionineBehavior == InitiatorMethionineBehavior.Retain;
                // FixedC
                int           nTerminusProtein = retain ? oneBasedIndicesToCleaveAfter[0] : oneBasedIndicesToCleaveAfter[0] + 1; // +1 start after M (since already covered earlier)
                int           cTerminusProtein = oneBasedIndicesToCleaveAfter[i];
                HashSet <int> localOneBasedIndicesToCleaveAfter = new HashSet <int>();
                for (int j = 1; j < i; j++)//j starts at 1, because zero is n terminus
                {
                    localOneBasedIndicesToCleaveAfter.Add(oneBasedIndicesToCleaveAfter[j]);
                }
                int start = nTerminusProtein + 1;//plus one to not doublecount the n terminus (in addition to the M term skip)
                for (int j = start; j < cTerminusProtein; j++)
                {
                    if (OkayLength(cTerminusProtein - j, minPeptideLength, maxPeptideLength) &&
                        !localOneBasedIndicesToCleaveAfter.Contains(j))
                    {
                        intervals.Add(new ProteolyticPeptide(protein, j + 1, cTerminusProtein, cTerminusProtein - j, CleavageSpecificity.Semi, "semi"));
                    }
                }
            }

            // Also digest using the proteolysis product start/end indices
            // This should only be things where the proteolysis is not K/R and the
            foreach (var proteolysisProduct in protein.ProteolysisProducts)
            {
                if (proteolysisProduct.OneBasedEndPosition.HasValue && proteolysisProduct.OneBasedBeginPosition.HasValue &&
                    (proteolysisProduct.OneBasedBeginPosition != 1 || proteolysisProduct.OneBasedEndPosition != protein.Length))    //if at least one side is not a terminus
                {
                    int start = proteolysisProduct.OneBasedBeginPosition.Value;
                    int end   = proteolysisProduct.OneBasedEndPosition.Value;
                    int i     = 0;
                    while (oneBasedIndicesToCleaveAfter[i] < start) //"<" to prevent additions if same index as residues
                    {
                        i++;                                        // Last position in protein is an index to cleave after
                    }

                    // Start peptide
                    for (int j = start; j < oneBasedIndicesToCleaveAfter[i]; j++)
                    {
                        if (OkayLength(j - start + 1, minPeptideLength, maxPeptideLength))
                        {
                            intervals.Add(new ProteolyticPeptide(protein, start, j, j - start, CleavageSpecificity.Full, proteolysisProduct.Type + " start"));
                        }
                    }
                    while (oneBasedIndicesToCleaveAfter[i] < end) //"<" to prevent additions if same index as residues, since i-- is below
                    {
                        i++;
                    }

                    // Now that we've obtained an index to cleave after that is past the proteolysis product
                    // we need to backtrack to get the index to cleave that is immediately before the the proteolysis product
                    // to do this, we will do i--
                    // In the nitch case that the proteolysis product is already an index to cleave
                    // no new peptides will be generated using this, so we will forgo i--
                    // this makes peptides of length 0, which are not generated due to the for loop
                    // removing this if statement will result in crashes from c-terminal proteolysis product end positions
                    if (oneBasedIndicesToCleaveAfter[i] != end)
                    {
                        i--;
                    }

                    // Fin (End)
                    for (int j = oneBasedIndicesToCleaveAfter[i] + 1; j < end; j++)
                    {
                        if (OkayLength(end - j + 1, minPeptideLength, maxPeptideLength))
                        {
                            intervals.Add(new ProteolyticPeptide(protein, j, end, end - j, CleavageSpecificity.Full, proteolysisProduct.Type + " end"));
                        }
                    }
                }
            }
            return(intervals);
        }
Пример #13
0
        public static List <int> GetPossibleCrosslinkerModSites(char[] crosslinkerModSites, PeptideWithSetModifications peptide, InitiatorMethionineBehavior initiatorMethionineBehavior, bool CrosslinkAtCleavageSite)
        {
            List <int> possibleXlPositions = new List <int>();
            bool       wildcard            = crosslinkerModSites.Any(p => p == 'X');

            //Consider the possibility that the site is at Protein N terminal.
            if (crosslinkerModSites.Contains(peptide.BaseSequence[0]))
            {
                if (!CrosslinkAtCleavageSite)
                {
                    if (peptide.OneBasedStartResidueInProtein == 1 ||
                        (peptide.OneBasedStartResidueInProtein == 2 && initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain) ||
                        peptide.Protein.ProteolysisProducts.Any(x => x.OneBasedBeginPosition == peptide.OneBasedStartResidueInProtein))
                    {
                        possibleXlPositions.Add(1);
                    }
                }
                else
                {
                    possibleXlPositions.Add(1);
                }
            }


            List <int> range = Enumerable.Range(1, peptide.BaseSequence.Length - 1).ToList();

            if (!CrosslinkAtCleavageSite && peptide.OneBasedEndResidueInProtein != peptide.Protein.Length &&
                !peptide.Protein.ProteolysisProducts.Any(x => x.OneBasedEndPosition == peptide.OneBasedEndResidueInProtein))
            {
                //The N terminal and C termial cannot be crosslinked and cleaved.
                range = Enumerable.Range(1, peptide.BaseSequence.Length - 2).ToList();
            }
            foreach (var r in range)
            {
                if (crosslinkerModSites.Contains(peptide.BaseSequence[r]) || wildcard)
                {
                    //Try to eliminate those site with mod on it. Consider the possibility that the site is at Protein N terminal.
                    if (!peptide.AllModsOneIsNterminus.Keys.Contains(r + 2))
                    {
                        possibleXlPositions.Add(r + 1);
                    }
                }
            }

            return(possibleXlPositions);
        }
Пример #14
0
        /// <summary>
        /// Gets intervals of a protein sequence that will result from digestion by this protease.
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="minPeptideLength"></param>
        /// <param name="maxPeptideLength"></param>
        /// <returns></returns>
        internal List <ProteolyticPeptide> GetUnmodifiedPeptides(Protein protein, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                                 int minPeptideLength, int maxPeptideLength, Protease specificProtease)
        {
            List <ProteolyticPeptide> peptides = new List <ProteolyticPeptide>();

            // proteolytic cleavage in one spot (N)
            if (CleavageSpecificity == CleavageSpecificity.SingleN)
            {
                peptides = SingleN_Digestion(protein, initiatorMethionineBehavior, maximumMissedCleavages, minPeptideLength, maxPeptideLength, specificProtease);
            }

            // proteolytic cleavage in one spot (C)
            else if (CleavageSpecificity == CleavageSpecificity.SingleC)
            {
                peptides = SingleC_Digestion(protein, initiatorMethionineBehavior, maximumMissedCleavages, minPeptideLength, maxPeptideLength, specificProtease);
            }

            //top-down
            else if (CleavageSpecificity == CleavageSpecificity.None)
            {
                // retain methionine
                if ((initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || protein[0] != 'M') &&
                    OkayLength(protein.Length, minPeptideLength, maxPeptideLength))
                {
                    peptides.Add(new ProteolyticPeptide(protein, 1, protein.Length, 0, CleavageSpecificity.Full, "full"));
                }

                // cleave methionine
                if ((initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && protein[0] == 'M') &&
                    OkayLength(protein.Length - 1, minPeptideLength, maxPeptideLength))
                {
                    peptides.Add(new ProteolyticPeptide(protein, 2, protein.Length, 0, CleavageSpecificity.Full, "full:M cleaved"));
                }

                // Also digest using the proteolysis product start/end indices
                peptides.AddRange(
                    protein.ProteolysisProducts
                    .Where(proteolysisProduct => proteolysisProduct.OneBasedEndPosition.HasValue && proteolysisProduct.OneBasedBeginPosition.HasValue &&
                           OkayLength(proteolysisProduct.OneBasedEndPosition.Value - proteolysisProduct.OneBasedBeginPosition.Value + 1, minPeptideLength, maxPeptideLength))
                    .Select(proteolysisProduct =>
                            new ProteolyticPeptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, proteolysisProduct.OneBasedEndPosition.Value, 0, CleavageSpecificity.Full, proteolysisProduct.Type)));
            }

            // Full proteolytic cleavage
            else if (CleavageSpecificity == CleavageSpecificity.Full)
            {
                peptides.AddRange(FullDigestion(protein, initiatorMethionineBehavior, maximumMissedCleavages, minPeptideLength, maxPeptideLength));
            }

            // Cleavage rules for semi-specific search
            else if (CleavageSpecificity == CleavageSpecificity.Semi)
            {
                peptides.AddRange(SemiProteolyticDigestion(protein, initiatorMethionineBehavior, maximumMissedCleavages, minPeptideLength, maxPeptideLength));
            }
            else
            {
                throw new NotImplementedException();
            }

            return(peptides);
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string fieldNotUsed = "1";

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(XLPrecusorMsTlTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text,
                                                             maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text,
                                                             fieldNotUsed, fieldNotUsed, fieldNotUsed, TopNPeaksTextBox.Text, MinRatioTextBox.Text, numberOfDatabaseSearchesTextBox.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed))
            {
                return;
            }

            TheTask.XlSearchParameters.CrosslinkSearchTop    = ckbXLTopNum.IsChecked.Value;
            TheTask.XlSearchParameters.CrosslinkSearchTopNum = int.Parse(txtXLTopNum.Text, CultureInfo.InvariantCulture);
            //TheTask.XlSearchParameters.CrosslinkSearchWithAllBeta = ckbSearchWithXLAllBeta.IsChecked.Value;
            TheTask.XlSearchParameters.CrosslinkerType = (CrosslinkerType)cbCrosslinker.SelectedIndex;
            //TheTask.XlSearchParameters.FragmentationType = (FragmentaionType)cbFragmentation.SelectedIndex;
            if (cbbXLprecusorMsTl.SelectedIndex == 0)
            {
                TheTask.XlSearchParameters.XlPrecusorMsTl = new AbsoluteTolerance(double.Parse(XLPrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                TheTask.XlSearchParameters.XlPrecusorMsTl = new PpmTolerance(double.Parse(XLPrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture));
            }
            TheTask.XlSearchParameters.XlCharge_2_3 = ckbCharge_2_3.IsChecked.Value;
            TheTask.XlSearchParameters.XlCharge_2_3_PrimeFragment = ckbCharge_2_3_PrimeFragments.IsChecked.Value;
            TheTask.XlSearchParameters.XlQuench_H2O  = ckbQuenchH2O.IsChecked.Value;
            TheTask.XlSearchParameters.XlQuench_NH2  = ckbQuenchNH2.IsChecked.Value;
            TheTask.XlSearchParameters.XlQuench_Tris = ckbQuenchTris.IsChecked.Value;

            if (TheTask.XlSearchParameters.CrosslinkerType == CrosslinkerType.UserDefined)
            {
                TheTask.XlSearchParameters.UdXLkerName            = txtUdXLKerName.Text;
                TheTask.XlSearchParameters.UdXLkerCleavable       = ckbUdXLkerCleavable.IsChecked.Value;
                TheTask.XlSearchParameters.UdXLkerResidues        = txtUdXLkerAminoAcids.Text;
                TheTask.XlSearchParameters.UdXLkerResidues2       = txtUdXLkerAminoAcids2.Text;
                TheTask.XlSearchParameters.UdXLkerLongMass        = string.IsNullOrEmpty(txtUdXLkerLongMass.Text) ? (double?)null : double.Parse(txtUdXLkerLongMass.Text, CultureInfo.InvariantCulture);
                TheTask.XlSearchParameters.UdXLkerShortMass       = string.IsNullOrEmpty(txtUdXLkerShortMass.Text) ? (double?)null : double.Parse(txtUdXLkerShortMass.Text, CultureInfo.InvariantCulture);
                TheTask.XlSearchParameters.UdXLkerTotalMass       = string.IsNullOrEmpty(txtUdXLkerTotalMs.Text) ? (double?)null : double.Parse(txtUdXLkerTotalMs.Text, CultureInfo.InvariantCulture);
                TheTask.XlSearchParameters.UdXLkerLoopMass        = string.IsNullOrEmpty(txtUdXLkerLoopMass.Text) ? (double?)null : double.Parse(txtUdXLkerLoopMass.Text, CultureInfo.InvariantCulture);
                TheTask.XlSearchParameters.UdXLkerDeadendMassH2O  = string.IsNullOrEmpty(txtUdXLkerDeadendH2O.Text) ? (double?)null : double.Parse(txtUdXLkerDeadendH2O.Text, CultureInfo.InvariantCulture);
                TheTask.XlSearchParameters.UdXLkerDeadendMassNH2  = string.IsNullOrEmpty(txtUdXLkerDeadendNH2.Text) ? (double?)null : double.Parse(txtUdXLkerDeadendNH2.Text, CultureInfo.InvariantCulture);
                TheTask.XlSearchParameters.UdXLkerDeadendMassTris = string.IsNullOrEmpty(txtUdXLkerDeadendTris.Text) ? (double?)null : double.Parse(txtUdXLkerDeadendTris.Text, CultureInfo.InvariantCulture);
            }

            TheTask.XlSearchParameters.DecoyType = checkBoxDecoy.IsChecked.Value ? DecoyType.Reverse : DecoyType.None;

            Protease protease                = (Protease)proteaseComboBox.SelectedItem;
            int      MaxMissedCleavages      = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MinPeptideLength        = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxPeptideLength        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxModificationIsoforms = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture));
            InitiatorMethionineBehavior InitiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex);
            DigestionParams             digestionParamsToSave       = new DigestionParams(
                protease: protease.Name,
                maxMissedCleavages: MaxMissedCleavages,
                minPeptideLength: MinPeptideLength,
                maxPeptideLength: MaxPeptideLength,
                maxModificationIsoforms: MaxModificationIsoforms,
                initiatorMethionineBehavior: InitiatorMethionineBehavior);

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            TheTask.XlSearchParameters.XlOutPercolator = ckbPercolator.IsChecked.Value;
            TheTask.XlSearchParameters.XlOutPepXML     = ckbPepXML.IsChecked.Value;
            TheTask.XlSearchParameters.XlOutAll        = ckbAllResults.IsChecked.Value;
            TheTask.XlSearchParameters.XlOutCrosslink  = ckbCrosslink.IsChecked.Value;
            //TheTask.UseProvidedPrecursorInfo = useProvidedPrecursor.IsChecked.Value;

            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in VariableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in FixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            CommonParameters commonParamsToSave = new CommonParameters(
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "XLSearchTask",
                productMassTolerance: ProductMassTolerance,
                doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value,
                useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value,
                digestionParams: digestionParamsToSave,
                trimMs1Peaks: trimMs1.IsChecked.Value,
                trimMsMsPeaks: trimMsMs.IsChecked.Value,
                topNpeaks: int.Parse(TopNPeaksTextBox.Text),
                minRatio: double.Parse(MinRatioTextBox.Text),
                bIons: bCheckBox.IsChecked.Value,
                yIons: yCheckBox.IsChecked.Value,
                cIons: cCheckBox.IsChecked.Value,
                zDotIons: zdotCheckBox.IsChecked.Value,
                scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture),
                totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture),
                listOfModsVariable: listOfModsVariable,
                listOfModsFixed: listOfModsFixed);

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
Пример #16
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(maxCandidatesPerSpectrumTextBox.Text, out int mcps) || mcps <= 0)
            {
                MessageBox.Show("The number of maximum candidates per spectra contains unrecognized characters. \n You entered " + '"' + maxCandidatesPerSpectrumTextBox.Text + '"' + "\n Please enter a positive number.");
                return;
            }
            if (!int.TryParse(maxMissedConsecutiveTextBox.Text, out int mmc) || mmc < 0)
            {
                MessageBox.Show("The number of maximum missed consecutive cleavages contains unrecognized characters. \n You entered " + '"' + maxMissedConsecutiveTextBox.Text + '"' + "\n Please enter a positive number.");
                return;
            }
            if (!int.TryParse(maxMissedTextBox.Text, out int mm) || mm <= 0)
            {
                MessageBox.Show("The number of maximum missed cleavages contains unrecognized characters. \n You entered " + '"' + maxMissedTextBox.Text + '"' + "\n Please enter a positive number.");
                return;
            }

            if (missedCleavagesTextBox.Text.Length == 0)
            {
                MessageBox.Show("The number of missed cleavages was left empty. For no missed cleavages, please enter zero.");
                return;
            }
            if ((!double.TryParse(productMassToleranceTextBox.Text, out double pmt) || pmt <= 0) && productMassToleranceTextBox.Text.Length != 0)
            {
                MessageBox.Show("The product mass tolerance contains unrecognized characters. \n You entered " + '"' + productMassToleranceTextBox.Text + '"' + "\n Please enter a positive number.");
                return;
            }
            if ((!double.TryParse(precursorMassToleranceTextBox.Text, out double premt) || premt <= 0) && precursorMassToleranceTextBox.Text.Length != 0)
            {
                MessageBox.Show("The precursor mass tolerance contains unrecognized characters. \n You entered " + '"' + precursorMassToleranceTextBox.Text + '"' + "\n Please enter a positive number.");
                return;
            }

            //Code for determining SemiSpecific
            NeoParameters neoParameters = new NeoParameters
            {
                Calibrate       = calibrate.IsChecked.Value,
                GPTMD           = gptmd.IsChecked.Value,
                TargetSearch    = searchTarget.IsChecked.Value,
                DecoySearch     = searchDecoy.IsChecked.Value,
                SearchNTerminus = searchN.IsChecked.Value,
                SearchCTerminus = searchC.IsChecked.Value,
                MaxMissedConsecutiveCleavages = int.Parse(maxMissedConsecutiveTextBox.Text),
                MaxMissedCleavages            = int.Parse(maxMissedConsecutiveTextBox.Text),
                MaxCandidatesPerSpectrum      = int.Parse(maxMissedConsecutiveTextBox.Text),
                MinDistanceAllowed            = int.Parse(minCisLengthTextBox.Text),
                MaxDistanceAllowed            = int.Parse(maxCisLengthTextBox.Text),
                NormalCis  = searchNormalCis.IsChecked.Value,
                ReverseCis = searchReverseCis.IsChecked.Value
            };

            if (!searchTarget.IsChecked.Value)
            {
                neoParameters.TargetFilePath = targetPath.Text;
            }
            if (!searchDecoy.IsChecked.Value)
            {
                neoParameters.DecoyFilePath = decoyPath.Text;
            }
            if (!searchN.IsChecked.Value)
            {
                neoParameters.NFilePath = NPath.Text;
            }
            if (!searchC.IsChecked.Value)
            {
                neoParameters.CFilePath = CPath.Text;
            }

            Protease protease                = (Protease)proteaseComboBox.SelectedItem;
            int      maxMissedCleavages      = (int.Parse(missedCleavagesTextBox.Text, CultureInfo.InvariantCulture));
            int      minPeptideLength        = (int.Parse(txtMinPeptideLength.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      maxPeptideLength        = (int.Parse(txtMaxPeptideLength.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      maxModificationIsoforms = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture));
            int      maxModsForPeptide       = (int.Parse(txtMaxModNum.Text, CultureInfo.InvariantCulture));
            InitiatorMethionineBehavior initiatorMethionineBehavior = (InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex;
            DigestionParams             digestionParamsToSave       = new DigestionParams(
                protease: protease.Name,
                maxMissedCleavages: maxMissedCleavages,
                minPeptideLength: minPeptideLength,
                maxPeptideLength: maxPeptideLength,
                maxModificationIsoforms: maxModificationIsoforms,
                initiatorMethionineBehavior: initiatorMethionineBehavior,
                maxModsForPeptides: maxModsForPeptide);

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else if (productMassToleranceTextBox.Text.Length == 0 || precursorMassToleranceTextBox.Text.Length == 0)
            {
                ProductMassTolerance = new PpmTolerance(25);
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance PrecursorMassTolerance;

            if (precursorMassToleranceComboBox.SelectedIndex == 0)
            {
                PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else if (productMassToleranceTextBox.Text.Length == 0 || precursorMassToleranceTextBox.Text.Length == 0)
            {
                PrecursorMassTolerance = new PpmTolerance(15);
            }
            else
            {
                PrecursorMassTolerance = new PpmTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in VariableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in FixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            CommonParameters commonParamsToSave = new CommonParameters(
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "NeoSearchTask",
                digestionParams: digestionParamsToSave,
                bIons: bCheckBox.IsChecked.Value,
                yIons: yCheckBox.IsChecked.Value,
                cIons: cCheckBox.IsChecked.Value,
                zDotIons: zdotCheckBox.IsChecked.Value,
                productMassTolerance: ProductMassTolerance,
                precursorMassTolerance: PrecursorMassTolerance,
                listOfModsFixed: listOfModsFixed,
                listOfModsVariable: listOfModsVariable);

            TheTask.NeoParameters    = neoParameters;
            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
Пример #17
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (nonSpecificSearchRadioButton1.IsChecked.Value || semiSpecificSearchRadioButton.IsChecked.Value)
            {
                if ((bCheckBox.IsChecked.Value || cCheckBox.IsChecked.Value) && (yCheckBox.IsChecked.Value || zdotCheckBox.IsChecked.Value))
                {
                    //MessageBox.Show("Only ion types from a single terminus are allowed for this search algorithm. \ne.g. b- and/or c-ions OR y- and/or zdot-ions. \nC-terminal ions (y and/or zdot) will be chosen by default.");
                    bCheckBox.IsChecked = false;
                    cCheckBox.IsChecked = false;
                }
                if (((Protease)proteaseComboBox.SelectedItem).Name.Contains("non-specific"))
                {
                    proteaseComboBox.SelectedItem = proteaseComboBox.Items.CurrentItem;
                    if ((bCheckBox.IsChecked.Value || cCheckBox.IsChecked.Value))
                    {
                        for (int i = 0; i < proteaseComboBox.Items.Count; i++)
                        {
                            if (((Protease)proteaseComboBox.Items[i]).Name.Equals("singleN"))
                            {
                                proteaseComboBox.SelectedItem = proteaseComboBox.Items[i];
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < proteaseComboBox.Items.Count; i++)
                        {
                            if (((Protease)proteaseComboBox.Items[i]).Name.Equals("singleC"))
                            {
                                proteaseComboBox.SelectedItem = proteaseComboBox.Items[i];
                                break;
                            }
                        }
                    }
                }
                if (((Protease)proteaseComboBox.SelectedItem).Name.Contains("semi-trypsin"))
                {
                    proteaseComboBox.Items.MoveCurrentToFirst();
                    proteaseComboBox.SelectedItem = proteaseComboBox.Items.CurrentItem;
                    while (!((Protease)proteaseComboBox.SelectedItem).Name.Equals("trypsin"))
                    {
                        proteaseComboBox.Items.MoveCurrentToNext();
                        proteaseComboBox.SelectedItem = proteaseComboBox.Items.CurrentItem;
                    }
                }
                if (!addCompIonCheckBox.IsChecked.Value)
                {
                    MessageBox.Show("Warning: Complementary ions are strongly recommended when using this algorithm.");
                }
            }

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(precursorMassToleranceTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text,
                                                             maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text,
                                                             peakFindingToleranceTextBox.Text, histogramBinWidthTextBox.Text, DeconvolutionMaxAssumedChargeStateTextBox.Text, TopNPeaksTextBox.Text,
                                                             MinRatioTextBox.Text, numberOfDatabaseSearchesTextBox.Text, MaxModNumTextBox.Text, MaxFragmentMassTextBox.Text, QValueTextBox.Text))
            {
                return;
            }

            Protease     protease = (Protease)proteaseComboBox.SelectedItem;
            bool         semiProteaseDigestion        = (semiSpecificSearchRadioButton.IsChecked.Value && ((Protease)proteaseComboBox.SelectedItem).CleavageSpecificity != CleavageSpecificity.SingleN && ((Protease)proteaseComboBox.SelectedItem).CleavageSpecificity != CleavageSpecificity.SingleC);
            TerminusType terminusTypeSemiProtease     = (bCheckBox.IsChecked.Value || cCheckBox.IsChecked.Value ? TerminusType.N : TerminusType.C);
            int          maxMissedCleavages           = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int          minPeptideLengthValue        = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int          maxPeptideLengthValue        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int          maxModificationIsoformsValue = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture));
            int          maxModsForPeptideValue       = (int.Parse(MaxModNumTextBox.Text, CultureInfo.InvariantCulture));
            InitiatorMethionineBehavior initiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex);
            DigestionParams             digestionParamsToSave       = new DigestionParams(
                protease: protease.Name,
                semiProteaseDigestion: semiProteaseDigestion,
                terminusTypeSemiProtease: terminusTypeSemiProtease,
                maxMissedCleavages: maxMissedCleavages,
                minPeptideLength: minPeptideLengthValue,
                maxPeptideLength: maxPeptideLengthValue,
                maxModificationIsoforms: maxModificationIsoformsValue,
                initiatorMethionineBehavior: initiatorMethionineBehavior,
                maxModsForPeptides: maxModsForPeptideValue);

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance PrecursorMassTolerance;

            if (precursorMassToleranceComboBox.SelectedIndex == 0)
            {
                PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                PrecursorMassTolerance = new PpmTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            TheTask.SearchParameters.MaxFragmentSize = Double.Parse(MaxFragmentMassTextBox.Text, CultureInfo.InvariantCulture);

            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in VariableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in FixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable))
            {
                return;
            }

            bool   TrimMs1Peaks  = trimMs1.IsChecked.Value;
            bool   TrimMsMsPeaks = trimMsMs.IsChecked.Value;
            int    TopNpeaks     = int.Parse(TopNPeaksTextBox.Text);
            double MinRatio      = double.Parse(MinRatioTextBox.Text);

            bool parseMaxThreadsPerFile = !maxThreadsTextBox.Text.Equals("") && (int.Parse(maxThreadsTextBox.Text) <= Environment.ProcessorCount && int.Parse(maxThreadsTextBox.Text) > 0);

            CommonParameters commonParamsToSave = new CommonParameters(
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "SearchTask",
                maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile,
                useDeltaScore: deltaScoreCheckBox.IsChecked.Value,
                reportAllAmbiguity: allAmbiguity.IsChecked.Value,
                deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture),
                totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture),
                doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value,
                useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value,
                scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture),
                calculateEValue: eValueCheckBox.IsChecked.Value,
                listOfModsFixed: listOfModsFixed,
                listOfModsVariable: listOfModsVariable,
                bIons: bCheckBox.IsChecked.Value,
                yIons: yCheckBox.IsChecked.Value,
                cIons: cCheckBox.IsChecked.Value,
                zDotIons: zdotCheckBox.IsChecked.Value,
                precursorMassTolerance: PrecursorMassTolerance,
                productMassTolerance: ProductMassTolerance,
                digestionParams: digestionParamsToSave,
                trimMs1Peaks: TrimMs1Peaks,
                trimMsMsPeaks: TrimMsMsPeaks,
                topNpeaks: TopNpeaks,
                minRatio: MinRatio,
                addCompIons: addCompIonCheckBox.IsChecked.Value,
                qValueOutputFilter: QValueCheckBox.IsChecked.Value ? double.Parse(QValueTextBox.Text, CultureInfo.InvariantCulture) : double.PositiveInfinity);

            if (classicSearchRadioButton.IsChecked.Value)
            {
                TheTask.SearchParameters.SearchType = SearchType.Classic;
            }
            else if (modernSearchRadioButton.IsChecked.Value)
            {
                TheTask.SearchParameters.SearchType = SearchType.Modern;
            }
            else //if (nonSpecificSearchRadioButton.IsChecked.Value)
            {
                TheTask.SearchParameters.SearchType = SearchType.NonSpecific;
            }

            TheTask.SearchParameters.DoParsimony             = checkBoxParsimony.IsChecked.Value;
            TheTask.SearchParameters.NoOneHitWonders         = checkBoxNoOneHitWonders.IsChecked.Value;
            TheTask.SearchParameters.DoQuantification        = checkBoxQuantification.IsChecked.Value;
            TheTask.SearchParameters.Normalize               = checkBoxNormalize.IsChecked.Value;
            TheTask.SearchParameters.MatchBetweenRuns        = checkBoxMatchBetweenRuns.IsChecked.Value;
            TheTask.SearchParameters.ModPeptidesAreDifferent = modPepsAreUnique.IsChecked.Value;
            TheTask.SearchParameters.QuantifyPpmTol          = double.Parse(peakFindingToleranceTextBox.Text, CultureInfo.InvariantCulture);
            TheTask.SearchParameters.SearchTarget            = checkBoxTarget.IsChecked.Value;
            TheTask.SearchParameters.WriteMzId               = ckbMzId.IsChecked.Value;
            //TheTask.SearchParameters.OutPepXML = ckbPepXML.IsChecked.Value;

            if (checkBoxDecoy.IsChecked.Value)
            {
                if (radioButtonReverseDecoy.IsChecked.Value)
                {
                    TheTask.SearchParameters.DecoyType = DecoyType.Reverse;
                }
                else //if (radioButtonSlideDecoy.IsChecked.Value)
                {
                    TheTask.SearchParameters.DecoyType = DecoyType.Slide;
                }
            }
            else
            {
                TheTask.SearchParameters.DecoyType = DecoyType.None;
            }

            if (massDiffAcceptExact.IsChecked.HasValue && massDiffAcceptExact.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Exact;
            }
            if (massDiffAccept1mm.IsChecked.HasValue && massDiffAccept1mm.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.OneMM;
            }
            if (massDiffAccept2mm.IsChecked.HasValue && massDiffAccept2mm.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.TwoMM;
            }
            if (massDiffAccept3mm.IsChecked.HasValue && massDiffAccept3mm.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.ThreeMM;
            }
            if (massDiffAccept187.IsChecked.HasValue && massDiffAccept187.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.ModOpen;
            }
            if (massDiffAcceptOpen.IsChecked.HasValue && massDiffAcceptOpen.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Open;
            }
            if (massDiffAcceptCustom.IsChecked.HasValue && massDiffAcceptCustom.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Custom;
                TheTask.SearchParameters.CustomMdac           = customkMdacTextBox.Text;
            }

            // displays warning if classic search is enabled with an open search mode
            if (TheTask.SearchParameters.SearchType == SearchType.Classic &&
                (TheTask.SearchParameters.MassDiffAcceptorType == MassDiffAcceptorType.ModOpen || TheTask.SearchParameters.MassDiffAcceptorType == MassDiffAcceptorType.Open))
            {
                MessageBoxResult result = MessageBox.Show("We recommend using Modern Search mode when conducting open precursor mass searches to reduce search time.\n\n" +
                                                          "Continue anyway?", "Modern search recommended", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            TheTask.SearchParameters.DoHistogramAnalysis      = checkBoxHistogramAnalysis.IsChecked.Value;
            TheTask.SearchParameters.HistogramBinTolInDaltons = double.Parse(histogramBinWidthTextBox.Text, CultureInfo.InvariantCulture);

            TheTask.SearchParameters.WritePrunedDatabase = writePrunedDBCheckBox.IsChecked.Value;

            SetModSelectionForPrunedDB();

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
Пример #18
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (lstData.Items.Count == 0)
            {
                MessageBox.Show("No data files selected");
                btnAdd.Focus();
                return;
            }
            List <string> data_filepaths = new List <string>(lstData.Items.Count);

            foreach (string data_filepath in lstData.Items)
            {
                data_filepaths.Add(data_filepath);
            }
            bool   assign_charge_states = chkAssignChargeStates.Checked;
            bool   deisotope            = chkDeisotope.Checked;
            string fasta_filepath       = txtFastaFile.Text;

            if (!File.Exists(fasta_filepath))
            {
                if (fasta_filepath.Length > 0)
                {
                    MessageBox.Show("Invalid protein database file: " + fasta_filepath);
                }
                else
                {
                    MessageBox.Show("Invalid protein database file");
                }
                txtFastaFile.Focus();
                return;
            }
            bool     on_the_fly_decoys    = chkOnTheFlyDecoys.Checked;
            Protease protease             = (Protease)cboProtease.SelectedItem;
            int      max_missed_cleavages = (int)numMaxMissedCleavages.Value;
            InitiatorMethionineBehavior initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), cboInitiatorMethionineBehavior.Text, true);
            List <Modification>         fixed_modifications           = new List <Modification>(clbFixedModifications.CheckedItems.Count);

            foreach (object fixed_modification in clbFixedModifications.CheckedItems)
            {
                fixed_modifications.Add((Modification)fixed_modification);
            }
            List <Modification> variable_modifications = new List <Modification>(clbVariableModifications.CheckedItems.Count);

            foreach (object variable_modification in clbVariableModifications.CheckedItems)
            {
                variable_modifications.Add((Modification)variable_modification);
            }
            int    max_variable_mod_isoforms          = (int)numMaxVariableModIsoforms.Value;
            int    min_assumed_precursor_charge_state = (int)numMinimumAssumedPrecursorChargeState.Value;
            int    max_assumed_precursor_charge_state = (int)numMaximumAssumedPrecursorChargeState.Value;
            double absolute_threshold = -1.0;

            if (chkAbsoluteThreshold.Checked)
            {
                if (!double.TryParse(txtAbsoluteThreshold.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out absolute_threshold))
                {
                    MessageBox.Show("Cannot parse absolute MS/MS peak threshold: " + txtAbsoluteThreshold.Text);
                    txtAbsoluteThreshold.Focus();
                    return;
                }
            }
            double relative_threshold_percent = -1.0;

            if (chkRelativeThreshold.Checked)
            {
                if (!double.TryParse(txtRelativeThresholdPercent.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out relative_threshold_percent))
                {
                    MessageBox.Show("Cannot parse relative MS/MS peak threshold: " + txtRelativeThresholdPercent.Text);
                    txtRelativeThresholdPercent.Focus();
                    return;
                }
            }
            int max_peaks = -1;

            if (chkMaxNumPeaks.Checked)
            {
                max_peaks = (int)numMaxPeaks.Value;
            }
            MassTolerance precursor_mass_tolerance       = new MassTolerance((double)numPrecursorMassTolerance.Value, (MassToleranceUnits)cboPrecursorMassToleranceUnits.SelectedIndex);
            MassType      precursor_mass_type            = (MassType)cboPrecursorMassType.SelectedIndex;
            List <double> accepted_precursor_mass_errors = new List <double>();

            if (txtAcceptedPrecursorMassErrors.Text.Length > 0)
            {
                foreach (string accepted_precursor_mass_error_text in txtAcceptedPrecursorMassErrors.Text.Split(';'))
                {
                    double accepted_precursor_mass_error;
                    if (!double.TryParse(accepted_precursor_mass_error_text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out accepted_precursor_mass_error))
                    {
                        MessageBox.Show("Cannot parse accepted precursor mass errors: " + txtRelativeThresholdPercent.Text);
                        txtAcceptedPrecursorMassErrors.Focus();
                        return;
                    }
                    accepted_precursor_mass_errors.Add(accepted_precursor_mass_error);
                }
            }
            else
            {
                accepted_precursor_mass_errors.Add(0.0);
            }
            MassTolerance product_mass_tolerance   = new MassTolerance((double)numProductMassTolerance.Value, (MassToleranceUnits)cboProductMassToleranceUnits.SelectedIndex);
            MassType      product_mass_type        = (MassType)cboProductMassType.SelectedIndex;
            double        max_false_discovery_rate = (double)numMaximumFalseDiscoveryRatePercent.Value / 100.0;
            bool          consider_modified_unique = chkConsiderModifiedUnique.Checked;
            int           max_threads           = (int)numMaxThreads.Value;
            bool          minimize_memory_usage = chkMinimizeMemoryUsage.Checked;
            string        output_folder         = txtOutputFolder.Text;

            if (!Directory.Exists(output_folder))
            {
                try
                {
                    Directory.CreateDirectory(output_folder);
                }
                catch
                {
                    if (output_folder.Length > 0)
                    {
                        MessageBox.Show("Invalid output folder: " + output_folder);
                    }
                    else
                    {
                        MessageBox.Show("Invalid output folder");
                    }
                    txtOutputFolder.Focus();
                    return;
                }
            }

            DatabaseSearcher database_searcher = new DatabaseSearcher(data_filepaths,
                                                                      min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                                                                      absolute_threshold, relative_threshold_percent, max_peaks,
                                                                      assign_charge_states, deisotope,
                                                                      fasta_filepath, on_the_fly_decoys,
                                                                      protease, max_missed_cleavages, initiator_methionine_behavior,
                                                                      fixed_modifications, variable_modifications, max_variable_mod_isoforms,
                                                                      precursor_mass_tolerance, precursor_mass_type,
                                                                      accepted_precursor_mass_errors,
                                                                      product_mass_tolerance, product_mass_type,
                                                                      max_false_discovery_rate, consider_modified_unique,
                                                                      max_threads, minimize_memory_usage,
                                                                      output_folder);

            database_searcher.Starting     += HandleStarting;
            database_searcher.StartingFile += HandleStartingFile;
            database_searcher.UpdateStatus += HandleUpdateStatus;
            database_searcher.ReportTaskWithoutProgress += HandleReportTaskWithoutProgress;
            database_searcher.ReportTaskWithProgress    += HandleReportTaskWithProgress;
            database_searcher.UpdateProgress            += HandleUpdateProgress;
            database_searcher.ThrowException            += HandleThrowException;
            database_searcher.FinishedFile += HandleFinishedFile;
            database_searcher.Finished     += HandleFinished;

            lstData.SelectedItem = null;
            tspbProgress.Value   = tspbProgress.Minimum;

            Thread thread = new Thread(new ThreadStart(database_searcher.Search));

            thread.IsBackground = true;
            thread.Start();
        }
Пример #19
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string fieldNotUsed = "1";

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(PrecusorMsTlTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text,
                                                             maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text,
                                                             fieldNotUsed, fieldNotUsed, fieldNotUsed, TopNPeaksTextBox.Text, MinRatioTextBox.Text, null, null, numberOfDatabaseSearchesTextBox.Text, TxtBoxMaxModPerPep.Text, fieldNotUsed, fieldNotUsed))
            {
                return;
            }

            DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()];

            DissociationType childDissociationType = DissociationType.Unknown;

            if (ChildScanDissociationTypeComboBox.SelectedItem.ToString() != "Null")
            {
                childDissociationType = GlobalVariables.AllSupportedDissociationTypes[ChildScanDissociationTypeComboBox.SelectedItem.ToString()];
            }
            CustomFragmentationWindow.Close();


            if (RbtOGlycoSearch.IsChecked.Value)
            {
                TheTask._glycoSearchParameters.GlycoSearchType = EngineLayer.GlycoSearch.GlycoSearchType.OGlycanSearch;
            }
            else if (RbtNGlycoSearch.IsChecked.Value)
            {
                TheTask._glycoSearchParameters.GlycoSearchType = EngineLayer.GlycoSearch.GlycoSearchType.NGlycanSearch;
            }
            else if (Rbt_N_O_GlycoSearch.IsChecked.Value)
            {
                TheTask._glycoSearchParameters.GlycoSearchType = EngineLayer.GlycoSearch.GlycoSearchType.N_O_GlycanSearch;
            }


            TheTask._glycoSearchParameters.OGlycanDatabasefile   = CmbOGlycanDatabase.SelectedItem.ToString();
            TheTask._glycoSearchParameters.NGlycanDatabasefile   = CmbNGlycanDatabase.SelectedItem.ToString();
            TheTask._glycoSearchParameters.GlycoSearchTopNum     = int.Parse(txtTopNum.Text, CultureInfo.InvariantCulture);
            TheTask._glycoSearchParameters.MaximumOGlycanAllowed = int.Parse(TbMaxOGlycanNum.Text, CultureInfo.InvariantCulture);
            TheTask._glycoSearchParameters.OxoniumIonFilt        = CkbOxoniumIonFilt.IsChecked.Value;

            if (CheckBoxDecoy.IsChecked.Value)
            {
                if (RadioButtonReverseDecoy.IsChecked.Value)
                {
                    TheTask._glycoSearchParameters.DecoyType = DecoyType.Reverse;
                }
                else //if (radioButtonSlideDecoy.IsChecked.Value)
                {
                    TheTask._glycoSearchParameters.DecoyType = DecoyType.Slide;
                }
            }
            else
            {
                TheTask._glycoSearchParameters.DecoyType = DecoyType.None;
            }

            Protease protease                = (Protease)proteaseComboBox.SelectedItem;
            int      MaxMissedCleavages      = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MinPeptideLength        = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxPeptideLength        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxModificationIsoforms = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture));
            int      MaxModPerPep            = (int.Parse(TxtBoxMaxModPerPep.Text, CultureInfo.InvariantCulture));
            InitiatorMethionineBehavior InitiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex);
            DigestionParams             digestionParamsToSave       = new DigestionParams(
                protease: protease.Name,
                maxMissedCleavages: MaxMissedCleavages,
                minPeptideLength: MinPeptideLength,
                maxPeptideLength: MaxPeptideLength,
                maxModificationIsoforms: MaxModificationIsoforms,
                maxModsForPeptides: MaxModPerPep,
                initiatorMethionineBehavior: InitiatorMethionineBehavior);

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance PrecursorMassTolerance;

            if (cbbPrecusorMsTl.SelectedIndex == 0)
            {
                PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(PrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                PrecursorMassTolerance = new PpmTolerance(double.Parse(PrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture));
            }


            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in VariableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in FixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            CommonParameters commonParamsToSave = new CommonParameters(
                precursorMassTolerance: PrecursorMassTolerance,
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "GlycoSearchTask",
                productMassTolerance: ProductMassTolerance,
                doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value,
                useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value,
                digestionParams: digestionParamsToSave,
                trimMs1Peaks: trimMs1.IsChecked.Value,
                trimMsMsPeaks: trimMsMs.IsChecked.Value,
                numberOfPeaksToKeepPerWindow: int.Parse(TopNPeaksTextBox.Text),
                minimumAllowedIntensityRatioToBasePeak: double.Parse(MinRatioTextBox.Text, CultureInfo.InvariantCulture),
                dissociationType: dissociationType,
                ms2childScanDissociationType: childDissociationType,
                scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture),
                totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture),
                maxThreadsToUsePerFile: int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture),
                listOfModsVariable: listOfModsVariable,
                listOfModsFixed: listOfModsFixed,
                assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down");

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string fieldNotUsed = "1";

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(PrecursorMassToleranceTextBox.Text, ProductMassToleranceTextBox.Text, MissedCleavagesTextBox.Text,
                                                             MaxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, MaxThreadsTextBox.Text, MinScoreAllowed.Text,
                                                             fieldNotUsed, fieldNotUsed, DeconvolutionMaxAssumedChargeStateTextBox.Text, NumberOfPeaksToKeepPerWindowTextBox.Text, MinimumAllowedIntensityRatioToBasePeakTexBox.Text, null, null, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed))
            {
                return;
            }

            Protease protease                = (Protease)ProteaseComboBox.SelectedItem;
            int      maxMissedCleavages      = string.IsNullOrEmpty(MissedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(MissedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      minPeptideLength        = int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture);
            int      maxPeptideLength        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      minVariantDepth         = int.Parse(MinVariantDepthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture);
            int      maxHeterozygousVariants = int.Parse(MaxHeterozygousVariantsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture);
            int      maxModificationIsoforms = int.Parse(MaxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture);
            int      maxModsPerPeptide       = int.Parse(MaxModsPerPeptideTextBox.Text, CultureInfo.InvariantCulture);
            InitiatorMethionineBehavior initiatorMethionineBehavior = (InitiatorMethionineBehavior)InitiatorMethionineBehaviorComboBox.SelectedIndex;
            DissociationType            dissociationType            = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()];

            CustomFragmentationWindow.Close();

            Tolerance productMassTolerance;

            if (ProductMassToleranceComboBox.SelectedIndex == 0)
            {
                productMassTolerance = new AbsoluteTolerance(double.Parse(ProductMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                productMassTolerance = new PpmTolerance(double.Parse(ProductMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance precursorMassTolerance;

            if (PrecursorMassToleranceComboBox.SelectedIndex == 0)
            {
                precursorMassTolerance = new AbsoluteTolerance(double.Parse(PrecursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                precursorMassTolerance = new PpmTolerance(double.Parse(PrecursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            List <(string, string)> listOfModsVariable = new List <(string, string)>();

            foreach (var heh in variableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable))
            {
                return;
            }

            bool TrimMs1Peaks  = TrimMs1.IsChecked.Value;
            bool TrimMsMsPeaks = TrimMsMs.IsChecked.Value;

            int?numPeaksToKeep = null;

            if (!string.IsNullOrWhiteSpace(NumberOfPeaksToKeepPerWindowTextBox.Text))
            {
                if (int.TryParse(NumberOfPeaksToKeepPerWindowTextBox.Text, out int numberOfPeaksToKeeep))
                {
                    numPeaksToKeep = numberOfPeaksToKeeep;
                }
                else
                {
                    MessageBox.Show("The value that you entered for number of peaks to keep is not acceptable. Try again.");
                    return;
                }
            }

            double?minimumAllowedIntensityRatioToBasePeak = null;

            if (!string.IsNullOrWhiteSpace(MinimumAllowedIntensityRatioToBasePeakTexBox.Text))
            {
                if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, out double minimumAllowedIntensityRatio))
                {
                    minimumAllowedIntensityRatioToBasePeak = minimumAllowedIntensityRatio;
                }
                else
                {
                    MessageBox.Show("The value that you entered for minimum allowed intensity ratio to keep is not acceptable. Try again.");
                    return;
                }
            }

            List <(string, string)> listOfModsFixed = new List <(string, string)>();

            foreach (var heh in fixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }
            bool parseMaxThreadsPerFile = int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) <= Environment.ProcessorCount && int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) > 0;

            CommonParameters commonParamsToSave = new CommonParameters(
                useProvidedPrecursorInfo: UseProvidedPrecursor.IsChecked.Value,
                deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture),
                doPrecursorDeconvolution: DeconvolutePrecursors.IsChecked.Value,
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "GPTMDTask",
                maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile,
                digestionParams: new DigestionParams(
                    protease: protease.Name,
                    maxMissedCleavages: maxMissedCleavages,
                    minPeptideLength: minPeptideLength,
                    maxPeptideLength: maxPeptideLength,
                    maxModificationIsoforms: maxModificationIsoforms,
                    maxModsForPeptides: maxModsPerPeptide,
                    initiatorMethionineBehavior: initiatorMethionineBehavior),
                dissociationType: dissociationType,
                scoreCutoff: double.Parse(MinScoreAllowed.Text, CultureInfo.InvariantCulture),
                precursorMassTolerance: precursorMassTolerance,
                productMassTolerance: productMassTolerance,
                trimMs1Peaks: TrimMs1Peaks,
                trimMsMsPeaks: TrimMsMsPeaks,
                numberOfPeaksToKeepPerWindow: numPeaksToKeep,
                minimumAllowedIntensityRatioToBasePeak: minimumAllowedIntensityRatioToBasePeak,
                listOfModsFixed: listOfModsFixed,
                listOfModsVariable: listOfModsVariable,
                assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down",
                addCompIons: AddCompIonCheckBox.IsChecked.Value,
                minVariantDepth: minVariantDepth,
                maxHeterozygousVariants: maxHeterozygousVariants);

            TheTask.GptmdParameters.ListOfModsGptmd = new List <(string, string)>();
            foreach (var heh in gptmdModTypeForTreeViewObservableCollection)
            {
                TheTask.GptmdParameters.ListOfModsGptmd.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
Пример #21
0
        /// <summary>
        /// Gets peptides for the singleC protease
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="minPeptideLength"></param>
        /// <param name="maxPeptideLength"></param>
        /// <param name="specificProtease"></param>
        /// <returns></returns>
        private List <ProteolyticPeptide> SingleC_Digestion(Protein protein, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                            int maximumMissedCleavages, int minPeptideLength, int maxPeptideLength, Protease specificProtease)
        {
            List <ProteolyticPeptide> peptides = new List <ProteolyticPeptide>();
            int proteinStart = Retain(0, initiatorMethionineBehavior, protein[0]) ? 1 : 2; //where does the protein start?

            if (Equals(specificProtease))
            {
                int lengthDifference = proteinStart - 1; //take it back one for zero based index
                for (int proteinEnd = 1; proteinEnd <= protein.Length; proteinEnd++)
                {
                    //length of peptide will be at least the start index
                    if (OkayMinLength(proteinEnd - lengthDifference, minPeptideLength)) //is the maximum possible length longer than the minimum?
                    {
                        //use the start index as the max of the N-terminus or the c-terminus minus the max (+1 because inclusive, otherwise peptides will be one AA too long)
                        peptides.Add(new ProteolyticPeptide(protein, Math.Max(proteinStart, proteinEnd - maxPeptideLength + 1), proteinEnd, 0, CleavageSpecificity.SingleC, "SingleC"));
                    }
                }
            }
            else //if there's a specific protease, then we need to adhere to the specified missed cleavage rules
            {
                //generate only peptides with the maximum number of missed cleavages, unless the protein has fewer than the max or we're near the unselected terminus (where we run to the end of the protein)
                List <int> oneBasedIndicesToCleaveAfter = specificProtease.GetDigestionSiteIndices(protein.BaseSequence); //get peptide bonds to cleave SPECIFICALLY (termini included)
                oneBasedIndicesToCleaveAfter[0] = proteinStart - 1;                                                       //update the first cleavage to represent the initiator methionine rules
                int maximumMissedCleavagesIndexShift = maximumMissedCleavages + 1;

                for (int i = oneBasedIndicesToCleaveAfter.Count - 1; i > maximumMissedCleavagesIndexShift; i--)
                {
                    int endProteaseIndex   = oneBasedIndicesToCleaveAfter[i];
                    int startProteaseIndex = oneBasedIndicesToCleaveAfter[i - maximumMissedCleavagesIndexShift];
                    int peptideLength      = endProteaseIndex - startProteaseIndex;
                    if (peptideLength >= minPeptideLength) //if bigger than min
                    {
                        int startActualIndex = startProteaseIndex;
                        if (peptideLength > maxPeptideLength) //if the next cleavage is too far away, crop it to the max length
                        {
                            startActualIndex = endProteaseIndex - maxPeptideLength;
                        }
                        int nextEndIndex = oneBasedIndicesToCleaveAfter[i - 1];
                        //make SingleC peptides until we reach the next index to cleave at or until the peptides are too small
                        for (; (endProteaseIndex > nextEndIndex) && (endProteaseIndex - startActualIndex >= minPeptideLength); endProteaseIndex--)
                        {
                            peptides.Add(new ProteolyticPeptide(protein, startActualIndex + 1, endProteaseIndex, maximumMissedCleavages, CleavageSpecificity.SingleC, "SingleC"));

                            //update startIndex if needed
                            if (startActualIndex != startProteaseIndex)
                            {
                                startActualIndex--;
                            }
                        }
                    }
                }
                //wrap up the terminus
                //if there are more missed cleavages allowed than there are cleavages to cleave, change the effective number of missed cleavages to the max
                if (oneBasedIndicesToCleaveAfter.Count <= maximumMissedCleavagesIndexShift)
                {
                    maximumMissedCleavagesIndexShift = oneBasedIndicesToCleaveAfter.Count - 1;
                }
                int lastEndIndex = oneBasedIndicesToCleaveAfter[maximumMissedCleavagesIndexShift];
                int startIndex   = Math.Max(proteinStart, lastEndIndex - maxPeptideLength + 1);
                int minPeptideLengthOneBasedResidueShift = minPeptideLength - 1;
                for (; lastEndIndex >= startIndex + minPeptideLengthOneBasedResidueShift; lastEndIndex--)
                {
                    peptides.Add(new ProteolyticPeptide(protein, startIndex, lastEndIndex, maximumMissedCleavages, CleavageSpecificity.SingleC, "SingleC"));

                    //update the start if needed
                    if (startIndex != proteinStart)
                    {
                        startIndex--;
                    }
                }
            }
            return(peptides);
        }
Пример #22
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string fieldNotUsed = "1";

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(precursorMassToleranceTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text,
                                                             maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text,
                                                             fieldNotUsed, fieldNotUsed, DeconvolutionMaxAssumedChargeStateTextBox.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed))

            {
                return;
            }

            Protease protease                = (Protease)proteaseComboBox.SelectedItem;
            int      MaxMissedCleavages      = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MinPeptideLength        = int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture);
            int      MaxPeptideLength        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxModificationIsoforms = int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture);
            InitiatorMethionineBehavior InitiatorMethionineBehavior = (InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex;

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance PrecursorMassTolerance;

            if (precursorMassToleranceComboBox.SelectedIndex == 0)
            {
                PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                PrecursorMassTolerance = new PpmTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in variableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable))
            {
                return;
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in fixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }
            bool parseMaxThreadsPerFile = int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) <= Environment.ProcessorCount && int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) > 0;

            CommonParameters commonParamsToSave = new CommonParameters(
                useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value,
                deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture),
                doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value,
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "GPTMDTask",
                maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile,
                digestionParams: new DigestionParams(
                    protease: protease.Name,
                    maxMissedCleavages: MaxMissedCleavages,
                    minPeptideLength: MinPeptideLength,
                    maxPeptideLength: MaxPeptideLength,
                    maxModificationIsoforms: MaxModificationIsoforms,
                    initiatorMethionineBehavior: InitiatorMethionineBehavior),
                bIons: bCheckBox.IsChecked.Value,
                yIons: yCheckBox.IsChecked.Value,
                cIons: cCheckBox.IsChecked.Value,
                zDotIons: zdotCheckBox.IsChecked.Value,
                scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture),
                precursorMassTolerance: PrecursorMassTolerance,
                productMassTolerance: ProductMassTolerance,
                listOfModsFixed: listOfModsFixed,
                listOfModsVariable: listOfModsVariable);

            TheTask.GptmdParameters.ListOfModsGptmd = new List <(string, string)>();
            foreach (var heh in gptmdModTypeForTreeViewObservableCollection)
            {
                TheTask.GptmdParameters.ListOfModsGptmd.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.DisplayName)));
            }

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
Пример #23
0
        public IEnumerable <Peptide> Digest(Protease protease, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                            int?minimumPeptideLength, int?maximumPeptideLength)
        {
            if (Length > 0)
            {
                if (protease.CleavageSpecificity != CleavageSpecificity.None)
                {
                    // these are the 0-based residue indices the protease cleaves AFTER
                    List <int> indices = protease.GetDigestionSiteIndices(this);
                    indices.Insert(0, -1);
                    indices.Add(Length - 1);

                    if (protease.CleavageSpecificity == CleavageSpecificity.Full)
                    {
                        for (int missed_cleavages = 0; missed_cleavages <= maximumMissedCleavages; missed_cleavages++)
                        {
                            for (int i = 0; i < indices.Count - missed_cleavages - 1; i++)
                            {
                                if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || indices[i] + 1 != 0 || this[0] != 'M')
                                {
                                    int length = indices[i + missed_cleavages + 1] - indices[i];
                                    if ((!minimumPeptideLength.HasValue || length >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || length <= maximumPeptideLength.Value))
                                    {
                                        // start residue number: +1 for starting at the next residue after the cleavage, +1 for 0->1 indexing
                                        // end residue number: +1 for 0->1 indexing
                                        Peptide peptide = new Peptide(this, indices[i] + 1 + 1, indices[i + missed_cleavages + 1] + 1, missed_cleavages);
                                        yield return(peptide);
                                    }
                                }

                                if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && indices[i] + 1 == 0 && this[0] == 'M')
                                {
                                    int length = indices[i + missed_cleavages + 1] - indices[i] - 1;
                                    if (length > 0 && (!minimumPeptideLength.HasValue || length >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || length <= maximumPeptideLength.Value))
                                    {
                                        // start residue number: +1 for skipping initiator methionine, +1 for starting at the next residue after the cleavage, +1 for 0->1 indexing
                                        // end residue number: +1 for 0->1 indexing
                                        Peptide peptide_without_initiator_methionine = new Peptide(this, indices[i] + 1 + 1 + 1, indices[i + missed_cleavages + 1] + 1, missed_cleavages);
                                        yield return(peptide_without_initiator_methionine);
                                    }
                                }
                            }
                        }
                    }
                    else  // protease.CleavageSpecificity == CleavageSpecificity.Semi || protease.CleavageSpecificity == CleavageSpecificity.SemiN || protease.CleavageSpecificity == CleavageSpecificity.SemiC
                    {
                        if (protease.CleavageSpecificity == CleavageSpecificity.Semi || protease.CleavageSpecificity == CleavageSpecificity.SemiN)
                        {
                            for (int missed_cleavages = 0; missed_cleavages <= maximumMissedCleavages; missed_cleavages++)
                            {
                                for (int i = 0; i < indices.Count - missed_cleavages - 1; i++)
                                {
                                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || indices[i] + 1 != 0 || this[0] != 'M')
                                    {
                                        // conditional ensures that we are generating peptides at their lowest missed cleavage state
                                        for (int length = indices[i + missed_cleavages + 1] - indices[i]; length > (indices[i + missed_cleavages + 1] - indices[i]) - (indices[i + missed_cleavages + 1] - indices[(i + missed_cleavages + 1) - 1]); length--)
                                        {
                                            if ((indices[i] + 1 + 1) + length - 1 <= Length)
                                            {
                                                if ((!minimumPeptideLength.HasValue || length >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || length <= maximumPeptideLength.Value))
                                                {
                                                    // start residue number: +1 for starting at the next residue after the cleavage, +1 for 0->1 indexing
                                                    // end residue number: start residue number + length - 1
                                                    Peptide peptide = new Peptide(this, indices[i] + 1 + 1, (indices[i] + 1 + 1) + length - 1, missed_cleavages);
                                                    yield return(peptide);
                                                }
                                            }
                                        }
                                    }

                                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && indices[i] + 1 == 0 && this[0] == 'M')
                                    {
                                        // conditional ensures that we are generating peptides at their lowest missed cleavage state
                                        for (int length = indices[i + missed_cleavages + 1] - indices[i]; length > (indices[i + missed_cleavages + 1] - indices[i]) - (indices[i + missed_cleavages + 1] - indices[(i + missed_cleavages + 1) - 1]); length--)
                                        {
                                            if ((indices[i] + 1 + 1 + 1) + length - 1 <= Length)
                                            {
                                                if ((!minimumPeptideLength.HasValue || length >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || length <= maximumPeptideLength.Value))
                                                {
                                                    // start residue number: +1 for skipping initiator methionine, +1 for starting at the next residue after the cleavage, +1 for 0->1 indexing
                                                    // end residue number: start residue number + length - 1
                                                    Peptide peptide_without_initiator_methionine = new Peptide(this, indices[i] + 1 + 1 + 1, (indices[i] + 1 + 1 + 1) + length - 1, missed_cleavages);
                                                    yield return(peptide_without_initiator_methionine);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (protease.CleavageSpecificity == CleavageSpecificity.Semi || protease.CleavageSpecificity == CleavageSpecificity.SemiC)
                        {
                            for (int missed_cleavages = 0; missed_cleavages <= maximumMissedCleavages; missed_cleavages++)
                            {
                                for (int i = 0; i < indices.Count - missed_cleavages - 1; i++)
                                {
                                    // handling for initiator methionine not required

                                    // - (protease.CleavageSpecificity == CleavageSpecificity.Semi ? 1 : 0) ensures that we don't repeat the same peptides we generated above in the SemiN digestion
                                    // conditional ensures that we are generating peptides at their lowest missed cleavage state
                                    for (int length = indices[i + missed_cleavages + 1] - indices[i] - (protease.CleavageSpecificity == CleavageSpecificity.Semi ? 1 : 0); length > (indices[i + missed_cleavages + 1] - indices[i]) - (indices[i + 1] - indices[i]); length--)
                                    {
                                        if ((indices[i + missed_cleavages + 1] + 1) - length + 1 >= 1)
                                        {
                                            if ((!minimumPeptideLength.HasValue || length >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || length <= maximumPeptideLength.Value))
                                            {
                                                // start residue number: end residue number - length + 1
                                                // end residue number: +1 for 0->1 indexing
                                                Peptide peptide = new Peptide(this, (indices[i + missed_cleavages + 1] + 1) - length + 1, indices[i + missed_cleavages + 1] + 1, missed_cleavages);
                                                yield return(peptide);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else  // protease.CleavageSpecificity == CleavageSpecificity.None
                {
                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || this[0] != 'M')
                    {
                        if ((!minimumPeptideLength.HasValue || Length >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || Length <= maximumPeptideLength.Value))
                        {
                            Peptide peptide = new Peptide(this, 1, Length, -1);
                            yield return(peptide);
                        }
                    }

                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && this[0] == 'M')
                    {
                        if (Length > 1 && (!minimumPeptideLength.HasValue || Length - 1 >= minimumPeptideLength.Value) && (!maximumPeptideLength.HasValue || Length - 1 <= maximumPeptideLength.Value))
                        {
                            Peptide peptide_without_initiator_methionine = new Peptide(this, 2, Length, -1);
                            yield return(peptide_without_initiator_methionine);
                        }
                    }
                }
            }
        }
Пример #24
0
 /// <summary>
 /// Retain N-terminal residue?
 /// </summary>
 /// <param name="oneBasedCleaveAfter"></param>
 /// <param name="initiatorMethionineBehavior"></param>
 /// <param name="nTerminus"></param>
 /// <returns></returns>
 internal static bool Retain(int oneBasedCleaveAfter, InitiatorMethionineBehavior initiatorMethionineBehavior, char nTerminus)
 {
     return(oneBasedCleaveAfter != 0 || // this only pertains to the n-terminus
            initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave ||
            nTerminus != 'M');
 }
Пример #25
0
        /*
         * public static int TargetDecoyComparison(Protein left, Protein right)
         * {
         *  if (left.Target)
         *      if (right.Target)
         *          return 0;
         *      else
         *          return -1;
         *  else
         *      if (right.Target)
         *          return 1;
         *      else
         *          return 0;
         * }//*/

        public IEnumerable <Peptide> Digest(Protease protease, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                            int?minimumPeptideLength, int?maximumPeptideLength, bool onTheFlyDecoy)
        {
            List <int> indices = protease.GetDigestionSiteIndices(this);

            indices.Insert(0, -1);
            indices.Add(Length - 1);

            for (int missed_cleavages = 0; missed_cleavages <= maximumMissedCleavages; missed_cleavages++)
            {
                for (int i = 0; i < indices.Count - missed_cleavages - 1; i++)
                {
                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || indices[i] + 1 != 0 || this[0] != 'M')
                    {
                        Peptide peptide = new Peptide(this, indices[i] + 1, indices[i + missed_cleavages + 1], missed_cleavages);

                        if ((!minimumPeptideLength.HasValue || peptide.Length >= minimumPeptideLength.Value) &&
                            (!maximumPeptideLength.HasValue || peptide.Length <= maximumPeptideLength.Value))
                        {
                            yield return(peptide);

                            if (onTheFlyDecoy)
                            {
                                yield return(new Peptide(this, indices[i + missed_cleavages + 1], indices[i] + 1, missed_cleavages));
                            }
                        }
                    }

                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && indices[i] + 1 == 0 && this[0] == 'M')
                    {
                        Peptide peptide_without_initiator_methionine = new Peptide(this, indices[i] + 1 + 1, indices[i + missed_cleavages + 1], missed_cleavages);

                        if ((!minimumPeptideLength.HasValue || peptide_without_initiator_methionine.Length >= minimumPeptideLength.Value) &&
                            (!maximumPeptideLength.HasValue || peptide_without_initiator_methionine.Length <= maximumPeptideLength.Value))
                        {
                            yield return(peptide_without_initiator_methionine);

                            if (onTheFlyDecoy)
                            {
                                yield return(new Peptide(this, indices[i + missed_cleavages + 1], indices[i] + 1 + 1, missed_cleavages));
                            }
                        }
                    }
                }
            }
        }
Пример #26
0
        /// <summary>
        /// Gets protein intervals for digestion by this specific protease.
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="minPeptideLength"></param>
        /// <param name="maxPeptideLength"></param>
        /// <returns></returns>
        private IEnumerable <ProteolyticPeptide> FullDigestion(Protein protein, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                               int maximumMissedCleavages, int minPeptideLength, int maxPeptideLength)
        {
            List <int> oneBasedIndicesToCleaveAfter = GetDigestionSiteIndices(protein.BaseSequence);
            char       firstResidueInProtein        = protein[0];

            for (int missedCleavages = 0; missedCleavages <= maximumMissedCleavages; missedCleavages++)
            {
                for (int i = 0; i < oneBasedIndicesToCleaveAfter.Count - missedCleavages - 1; i++)
                {
                    if (Retain(i, initiatorMethionineBehavior, firstResidueInProtein) &&
                        OkayLength(oneBasedIndicesToCleaveAfter[i + missedCleavages + 1] - oneBasedIndicesToCleaveAfter[i], minPeptideLength, maxPeptideLength))
                    {
                        yield return(new ProteolyticPeptide(protein, oneBasedIndicesToCleaveAfter[i] + 1, oneBasedIndicesToCleaveAfter[i + missedCleavages + 1],
                                                            missedCleavages, CleavageSpecificity.Full, "full"));
                    }
                    if (Cleave(i, initiatorMethionineBehavior, firstResidueInProtein) && oneBasedIndicesToCleaveAfter[1] != 1 && //prevent duplicates if that bond is cleaved by the protease
                        OkayLength(oneBasedIndicesToCleaveAfter[i + missedCleavages + 1] - 1, minPeptideLength, maxPeptideLength))
                    {
                        yield return(new ProteolyticPeptide(protein, 2, oneBasedIndicesToCleaveAfter[i + missedCleavages + 1],
                                                            missedCleavages, CleavageSpecificity.Full, "full:M cleaved"));
                    }
                }

                //TODO: Generate all the proteolytic products as distinct proteins during XML reading and delete all of the code below
                // Also digest using the proteolysis product start/end indices
                foreach (var proteolysisProduct in protein.ProteolysisProducts)
                {
                    //if the proteolysis product contains something other than just the start AND end residues of the protein
                    if (proteolysisProduct.OneBasedBeginPosition != 1 || proteolysisProduct.OneBasedEndPosition != protein.Length)
                    {
                        int cleavageIndexWithinProteolysisProduct = 0;
                        //get the first cleavage index after the start of the proteolysis product
                        while (oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct] < proteolysisProduct.OneBasedBeginPosition)
                        {
                            cleavageIndexWithinProteolysisProduct++;
                        }

                        bool startPeptide = cleavageIndexWithinProteolysisProduct + missedCleavages < oneBasedIndicesToCleaveAfter.Count && //if the current missed cleavages doesn't hit the end
                                            oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct + missedCleavages] <= proteolysisProduct.OneBasedEndPosition && //and the cleavage occurs before the proteolytic end
                                            proteolysisProduct.OneBasedBeginPosition.HasValue && //and the proteolytic peptide even has a beginning
                                            !oneBasedIndicesToCleaveAfter.Contains(proteolysisProduct.OneBasedBeginPosition.Value - 1) && //and we haven't already cleaved here
                                            (proteolysisProduct.OneBasedBeginPosition.Value != 1 || !Cleave(0, initiatorMethionineBehavior, firstResidueInProtein)) && //and it's not the initiator methionine
                                            OkayLength(oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct + missedCleavages] - proteolysisProduct.OneBasedBeginPosition.Value + 1, minPeptideLength, maxPeptideLength); //and it's the correct size
                        if (startPeptide)
                        {
                            yield return(new ProteolyticPeptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct + missedCleavages],
                                                                missedCleavages, CleavageSpecificity.Full, proteolysisProduct.Type + " start"));
                        }

                        //get the cleavage index before the end of the proteolysis product
                        while (oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct] < proteolysisProduct.OneBasedEndPosition)
                        {
                            cleavageIndexWithinProteolysisProduct++;
                        }

                        bool endPeptide = cleavageIndexWithinProteolysisProduct - missedCleavages - 1 >= 0 && //if we're not going to go out of bounds (-1 to get in front of the end)
                                          oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct - missedCleavages - 1] + 1 >= proteolysisProduct.OneBasedBeginPosition && //and it's not before the beginning
                                          proteolysisProduct.OneBasedEndPosition.HasValue && //and the proteolytic peptide even has an end
                                          !oneBasedIndicesToCleaveAfter.Contains(proteolysisProduct.OneBasedEndPosition.Value) && //and we haven't already cleaved here
                                          OkayLength(proteolysisProduct.OneBasedEndPosition.Value - oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct - missedCleavages - 1] + 1 - 1, minPeptideLength, maxPeptideLength); //and it's the correct size
                        if (endPeptide)
                        {
                            yield return(new ProteolyticPeptide(protein, oneBasedIndicesToCleaveAfter[cleavageIndexWithinProteolysisProduct - missedCleavages - 1] + 1, proteolysisProduct.OneBasedEndPosition.Value,
                                                                missedCleavages, CleavageSpecificity.Full, proteolysisProduct.Type + " end"));
                        }
                    }
                }
            }

            //add intact proteolysis products (if acceptable)
            foreach (var proteolysisProduct in protein.ProteolysisProducts)
            {
                if (proteolysisProduct.OneBasedBeginPosition.HasValue && //begin has value
                    proteolysisProduct.OneBasedEndPosition.HasValue && //and end has value
                    (proteolysisProduct.OneBasedBeginPosition.Value != 1 || !Cleave(0, initiatorMethionineBehavior, firstResidueInProtein)) && //and it's not the initiator methionine
                    !oneBasedIndicesToCleaveAfter.Contains(proteolysisProduct.OneBasedBeginPosition.Value - 1) && //and we haven't already cleaved here
                    !oneBasedIndicesToCleaveAfter.Contains(proteolysisProduct.OneBasedEndPosition.Value))    //and we haven't already cleaved there
                {
                    int firstCleavage = 0;
                    //get the first cleavage index after the start of the proteolysis product
                    while (oneBasedIndicesToCleaveAfter[firstCleavage] < proteolysisProduct.OneBasedBeginPosition)
                    {
                        firstCleavage++;
                    }

                    int lastCleavage = firstCleavage;
                    //get the last cleavage index before the end of the proteolysis product
                    while (oneBasedIndicesToCleaveAfter[lastCleavage] < proteolysisProduct.OneBasedEndPosition)
                    {
                        lastCleavage++;
                    }
                    if (lastCleavage - firstCleavage < maximumMissedCleavages &&                                                                                       //if there aren't too many missed cleavages
                        OkayLength(proteolysisProduct.OneBasedEndPosition.Value - proteolysisProduct.OneBasedBeginPosition.Value, minPeptideLength, maxPeptideLength)) //and it's the correct size
                    {
                        yield return(new ProteolyticPeptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, proteolysisProduct.OneBasedEndPosition.Value,
                                                            lastCleavage - firstCleavage, CleavageSpecificity.Full, proteolysisProduct.Type + " end"));
                    }
                }
            }
        }
Пример #27
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string fieldNotUsed = "1";

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(XLPrecusorMsTlTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text,
                                                             maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text,
                                                             fieldNotUsed, fieldNotUsed, fieldNotUsed, TopNPeaksTextBox.Text, MinRatioTextBox.Text, null, null, numberOfDatabaseSearchesTextBox.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed))
            {
                return;
            }

            DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()];

            DissociationType childDissociationType = DissociationType.Unknown;

            if (ChildScanDissociationTypeComboBox.SelectedItem != null)
            {
                childDissociationType = GlobalVariables.AllSupportedDissociationTypes[ChildScanDissociationTypeComboBox.SelectedItem.ToString()];
            }
            CustomFragmentationWindow.Close();

            //TheTask.XlSearchParameters.SearchGlyco = RbSearchGlyco.IsChecked.Value;
            //TheTask.XlSearchParameters.SearchGlycoWithBgYgIndex = CkbSearchGlycoWithBgYgIndex.IsChecked.Value;
            TheTask.XlSearchParameters.RestrictToTopNHits      = ckbXLTopNum.IsChecked.Value;
            TheTask.XlSearchParameters.CrosslinkSearchTopNum   = int.Parse(txtXLTopNum.Text, CultureInfo.InvariantCulture);
            TheTask.XlSearchParameters.CrosslinkAtCleavageSite = ckbCrosslinkAtCleavageSite.IsChecked.Value;
            TheTask.XlSearchParameters.Crosslinker             = (Crosslinker)cbCrosslinkers.SelectedItem;


            TheTask.XlSearchParameters.XlQuench_H2O  = ckbQuenchH2O.IsChecked.Value;
            TheTask.XlSearchParameters.XlQuench_NH2  = ckbQuenchNH2.IsChecked.Value;
            TheTask.XlSearchParameters.XlQuench_Tris = ckbQuenchTris.IsChecked.Value;


            TheTask.XlSearchParameters.DecoyType = checkBoxDecoy.IsChecked.Value ? DecoyType.Reverse : DecoyType.None;

            Protease protease                = (Protease)proteaseComboBox.SelectedItem;
            int      MaxMissedCleavages      = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MinPeptideLength        = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxPeptideLength        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int      MaxModificationIsoforms = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture));
            InitiatorMethionineBehavior InitiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex);
            DigestionParams             digestionParamsToSave       = new DigestionParams(
                protease: protease.Name,
                maxMissedCleavages: MaxMissedCleavages,
                minPeptideLength: MinPeptideLength,
                maxPeptideLength: MaxPeptideLength,
                maxModificationIsoforms: MaxModificationIsoforms,
                initiatorMethionineBehavior: InitiatorMethionineBehavior);

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance PrecursorMassTolerance;

            if (cbbXLprecusorMsTl.SelectedIndex == 0)
            {
                PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(XLPrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                PrecursorMassTolerance = new PpmTolerance(double.Parse(XLPrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture));
            }

            TheTask.XlSearchParameters.WriteOutputForPercolator = ckbPercolator.IsChecked.Value;
            TheTask.XlSearchParameters.WritePepXml = ckbPepXML.IsChecked.Value;

            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in VariableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in FixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            CommonParameters commonParamsToSave = new CommonParameters(
                precursorMassTolerance: PrecursorMassTolerance,
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "XLSearchTask",
                productMassTolerance: ProductMassTolerance,
                doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value,
                useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value,
                digestionParams: digestionParamsToSave,
                trimMs1Peaks: trimMs1.IsChecked.Value,
                trimMsMsPeaks: trimMsMs.IsChecked.Value,
                numberOfPeaksToKeepPerWindow: int.Parse(TopNPeaksTextBox.Text),
                minimumAllowedIntensityRatioToBasePeak: double.Parse(MinRatioTextBox.Text, CultureInfo.InvariantCulture),
                dissociationType: dissociationType,
                childScanDissociationType: childDissociationType,
                scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture),
                totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture),
                listOfModsVariable: listOfModsVariable,
                listOfModsFixed: listOfModsFixed,
                assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down");

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }
Пример #28
0
        /// <summary>
        /// Gets peptides for the singleN protease
        /// </summary>
        /// <param name="protein"></param>
        /// <param name="initiatorMethionineBehavior"></param>
        /// <param name="maximumMissedCleavages"></param>
        /// <param name="minPeptideLength"></param>
        /// <param name="maxPeptideLength"></param>
        /// <param name="specificProtease"></param>
        /// <returns></returns>
        private List <ProteolyticPeptide> SingleN_Digestion(Protein protein, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                                            int maximumMissedCleavages, int minPeptideLength, int maxPeptideLength, Protease specificProtease)
        {
            List <ProteolyticPeptide> peptides = new List <ProteolyticPeptide>();
            int proteinStart = Retain(0, initiatorMethionineBehavior, protein[0]) ? 1 : 2; //where does the protein start?

            if (Equals(specificProtease))
            {
                bool maxTooBig = protein.Length + maxPeptideLength < 0; //when maxPeptideLength is too large, it becomes negative and causes issues
                                                                        //This happens when maxPeptideLength == int.MaxValue or something close to it
                for (; proteinStart <= protein.Length; proteinStart++)
                {
                    if (OkayMinLength(protein.Length - proteinStart + 1, minPeptideLength))
                    {
                        //need Math.Max if max length is int.MaxLength, since +proteinStart will make it negative
                        //if the max length is too big to be an int (ie infinity), just do the protein length.
                        //if it's not too big to be an int, it might still be too big. Take the minimum of the protein length or the maximum length (-1, because the index is inclusive. Without -1, peptides will be one AA too long)
                        peptides.Add(new ProteolyticPeptide(protein, proteinStart, maxTooBig ? protein.Length : Math.Min(protein.Length, proteinStart + maxPeptideLength - 1), 0, CleavageSpecificity.SingleN, "SingleN"));
                    }
                }
            }
            else //if there's a specific protease, then we need to adhere to the specified missed cleavage rules
            {
                //generate only peptides with the maximum number of missed cleavages, unless the protein has fewer than the max or we're near the unselected terminus (where we run to the end of the protein)
                List <int> oneBasedIndicesToCleaveAfter = specificProtease.GetDigestionSiteIndices(protein.BaseSequence); //get peptide bonds to cleave SPECIFICALLY (termini included)
                oneBasedIndicesToCleaveAfter[0] = proteinStart - 1;                                                       //update the first cleavage to represent the initiator methionine rules
                int maximumMissedCleavagesIndexShift = maximumMissedCleavages + 1;

                for (int i = 0; i < oneBasedIndicesToCleaveAfter.Count - maximumMissedCleavagesIndexShift; i++)
                {
                    int startIndex       = oneBasedIndicesToCleaveAfter[i];
                    int endProteaseIndex = oneBasedIndicesToCleaveAfter[i + maximumMissedCleavagesIndexShift];
                    int peptideLength    = endProteaseIndex - startIndex;
                    if (peptideLength >= minPeptideLength) //if bigger than min
                    {
                        int endActualIndex = endProteaseIndex;
                        if (peptideLength > maxPeptideLength) //if the next cleavage is too far away, crop it to the max length
                        {
                            endActualIndex = startIndex + maxPeptideLength;
                        }
                        int nextStartIndex = oneBasedIndicesToCleaveAfter[i + 1] + 1;

                        //make SingleN peptides until we reach the next index to cleave at or until the peptides are too small
                        for (; (startIndex + 1 < nextStartIndex) && (endActualIndex - startIndex >= minPeptideLength); startIndex++)
                        {
                            peptides.Add(new ProteolyticPeptide(protein, startIndex + 1, endActualIndex, maximumMissedCleavages, CleavageSpecificity.SingleN, "SingleN"));

                            //update endIndex if needed
                            if (endActualIndex != endProteaseIndex)
                            {
                                endActualIndex++;
                            }
                        }
                    }
                }
                //wrap up the terminus
                if (oneBasedIndicesToCleaveAfter.Count < maximumMissedCleavagesIndexShift)
                {
                    maximumMissedCleavagesIndexShift = oneBasedIndicesToCleaveAfter.Count;
                }
                int lastStartIndex  = oneBasedIndicesToCleaveAfter[oneBasedIndicesToCleaveAfter.Count - maximumMissedCleavagesIndexShift] + 1;
                int proteinEndIndex = oneBasedIndicesToCleaveAfter[oneBasedIndicesToCleaveAfter.Count - 1]; //end of protein
                int lastEndIndex    = Math.Min(proteinEndIndex, lastStartIndex + maxPeptideLength - 1);     //end of protein
                for (; lastStartIndex + minPeptideLength - 1 <= lastEndIndex; lastStartIndex++)
                {
                    peptides.Add(new ProteolyticPeptide(protein, lastStartIndex, lastEndIndex, maximumMissedCleavages, CleavageSpecificity.SingleN, "SingleN"));

                    //update the end if needed
                    if (lastEndIndex != proteinEndIndex)
                    {
                        lastEndIndex++;
                    }
                }
            }
            return(peptides);
        }
Пример #29
0
        public static List <ProteinGroup> ApplyProteinParsimony(IEnumerable <PeptideSpectrumMatch> peptideSpectrumMatches, double morpheusScoreThreshold, FileStream proteinFastaDatabase, bool onTheFlyDecoys, IDictionary <string, Modification> knownVariableModifications, Protease protease, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior, int maximumThreads)
        {
            // make a list of the all the distinct base leucine peptide sequences
            Dictionary <string, List <Protein> > peptide_proteins = new Dictionary <string, List <Protein> >();

            foreach (PeptideSpectrumMatch psm in peptideSpectrumMatches)
            {
                if (psm.MorpheusScore >= morpheusScoreThreshold)
                {
                    if (!peptide_proteins.ContainsKey(psm.Peptide.BaseLeucineSequence))
                    {
                        peptide_proteins.Add(psm.Peptide.BaseLeucineSequence, new List <Protein>());
                    }
                }
            }

            // record all proteins that could have been the source of each peptide
            ParallelOptions parallel_options = new ParallelOptions();

            parallel_options.MaxDegreeOfParallelism = maximumThreads;
            Parallel.ForEach(ProteomeDatabaseReader.ReadProteins(proteinFastaDatabase, onTheFlyDecoys, REQUIRE_MATCHING_KNOWN_MODIFICATIONS_IN_PROTEIN_PARSIMONY ? knownVariableModifications : null), parallel_options, protein =>
            {
                foreach (Peptide peptide in protein.Digest(protease, maximumMissedCleavages, initiatorMethionineBehavior, null, null))
                {
                    lock (peptide_proteins)
                    {
                        List <Protein> proteins;
                        if (peptide_proteins.TryGetValue(peptide.BaseLeucineSequence, out proteins))
                        {
                            List <Peptide> peptides;
                            if (!protein.IdentifiedPeptides.TryGetValue(peptide.BaseLeucineSequence, out peptides))
                            {
                                peptides = new List <Peptide>();
                                peptides.Add(peptide);
                                protein.IdentifiedPeptides.Add(peptide.BaseLeucineSequence, peptides);
                            }
                            else
                            {
                                peptides.Add(peptide);
                            }
                            proteins.Add(protein);
                        }
                    }
                }
            }
                             );

            // create protein groups (initially with just one protein each) and assign PSMs to them
            Dictionary <string, ProteinGroup> proteins_by_description = new Dictionary <string, ProteinGroup>();

            foreach (PeptideSpectrumMatch psm in peptideSpectrumMatches)
            {
                if (psm.MorpheusScore >= morpheusScoreThreshold)
                {
                    foreach (Protein protein in peptide_proteins[psm.Peptide.BaseLeucineSequence])
                    {
                        if (REQUIRE_MATCHING_KNOWN_MODIFICATIONS_IN_PROTEIN_PARSIMONY)
                        {
                            // check to make sure this protein's known modifications match the PSM's
                            bool known_modification_match = true;
                            if (psm.Peptide.VariableModifications != null && psm.Peptide.VariableModifications.Count > 0)
                            {
                                foreach (KeyValuePair <int, Modification> kvp in psm.Peptide.VariableModifications)
                                {
                                    if (kvp.Value.Known)
                                    {
                                        List <Modification> protein_modifications = null;
                                        if (protein.KnownModifications == null ||
                                            !protein.KnownModifications.TryGetValue(psm.Peptide.StartResidueNumber - 1 + kvp.Key, out protein_modifications) ||
                                            !protein_modifications.Contains(kvp.Value))
                                        {
                                            known_modification_match = false;
                                            break;
                                        }
                                    }
                                }
                                if (!known_modification_match)
                                {
                                    continue;
                                }
                            }
                        }

                        ProteinGroup protein_group;
                        if (!proteins_by_description.TryGetValue(protein.Description, out protein_group))
                        {
                            protein_group = new ProteinGroup();
                            protein_group.Add(protein);
                            protein_group.PeptideSpectrumMatches.Add(psm);
                            proteins_by_description.Add(protein.Description, protein_group);
                        }
                        else
                        {
                            protein_group.PeptideSpectrumMatches.Add(psm);
                        }
                    }
                }
            }

            List <ProteinGroup> protein_groups = new List <ProteinGroup>(proteins_by_description.Values);

            protein_groups.Sort(ProteinGroup.DescendingSummedMorpheusScoreProteinGroupComparison);

            // todo: remove shared peptides from lower-scoring protein group?

            // merge indistinguishable proteins (technically protein groups but they only contain a single protein thus far)
            for (int i = 0; i < protein_groups.Count - 1; i++)
            {
                ProteinGroup protein_group = protein_groups[i];

                int j = i + 1;
                while (j < protein_groups.Count)
                {
                    ProteinGroup lower_protein_group = protein_groups[j];

                    if (lower_protein_group.SummedMorpheusScore < protein_group.SummedMorpheusScore)
                    {
                        break;
                    }

                    if (lower_protein_group.BaseLeucinePeptideSequences.SetEquals(protein_group.BaseLeucinePeptideSequences))
                    {
                        protein_group.UnionWith(lower_protein_group);  // should only ever be one protein in the group to add
                        protein_groups.RemoveAt(j);
                    }
                    else
                    {
                        j++;
                    }
                }
            }

            // remove subset and subsumable protein groups
            int k = protein_groups.Count - 1;

            while (k >= 1)
            {
                ProteinGroup     protein_group          = protein_groups[k];
                HashSet <string> protein_group_peptides = new HashSet <string>(protein_group.BaseLeucinePeptideSequences);

                for (int l = 0; l < k; l++)
                {
                    ProteinGroup higher_protein_group = protein_groups[l];

                    protein_group_peptides.ExceptWith(higher_protein_group.BaseLeucinePeptideSequences);
                    if (protein_group_peptides.Count == 0)
                    {
                        break;
                    }
                }

                if (protein_group_peptides.Count == 0)
                {
                    protein_groups.RemoveAt(k);
                }
                k--;
            }

            return(protein_groups);
        }
Пример #30
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Arguments     arguments = new Arguments(args);
                List <string> data      = new List <string>(arguments["d"].Split(','));
                int           min_assumed_precursor_charge_state = 2;
                if (arguments["minprecz"] != null)
                {
                    min_assumed_precursor_charge_state = int.Parse(arguments["minprecz"]);
                }
                int max_assumed_precursor_charge_state = 4;
                if (arguments["maxprecz"] != null)
                {
                    max_assumed_precursor_charge_state = int.Parse(arguments["maxprecz"]);
                }
                double abs_threshold = -1.0;
                if (arguments["at"] != null)
                {
                    abs_threshold = double.Parse(arguments["at"], CultureInfo.InvariantCulture);
                }
                double rel_threshold_percent = -1.0;
                if (arguments["rt"] != null)
                {
                    rel_threshold_percent = double.Parse(arguments["rt"], CultureInfo.InvariantCulture);
                }
                int max_peaks = 400;
                if (arguments["mp"] != null)
                {
                    max_peaks = int.Parse(arguments["mp"]);
                }
                bool assign_charge_states = true;
                if (arguments["acs"] != null)
                {
                    assign_charge_states = bool.Parse(arguments["acs"]);
                }
                bool deisotope = true;
                if (arguments["di"] != null)
                {
                    deisotope = bool.Parse(arguments["di"]);
                }
                string database = arguments["db"];
                Dictionary <string, Modification> known_variable_modifications = null;
                HashSet <Modification>            variable_mods = new HashSet <Modification>();
                if (Path.GetExtension(database).Equals(".xml", StringComparison.InvariantCultureIgnoreCase))
                {
                    bool no_uniprot_mods = false;
                    if (arguments["noup"] != null)
                    {
                        no_uniprot_mods = bool.Parse(arguments["noup"]);
                    }
                    if (!no_uniprot_mods)
                    {
                        known_variable_modifications = ProteomeDatabaseReader.ReadUniProtXmlModifications(database);
                        variable_mods.UnionWith(known_variable_modifications.Values);
                    }
                }
                bool append_decoys = false;
                if (arguments["ad"] != null)
                {
                    append_decoys = bool.Parse(arguments["ad"]);
                }
                else
                {
                    append_decoys = Path.GetExtension(database).Equals(".xml", StringComparison.InvariantCultureIgnoreCase) || !ProteomeDatabaseReader.HasDecoyProteins(database);
                }
                ProteaseDictionary proteases = ProteaseDictionary.Instance;
                Protease           protease  = proteases["trypsin (no proline rule)"];
                if (arguments["p"] != null)
                {
                    protease = proteases[arguments["p"]];
                }
                int max_missed_cleavages = 2;
                if (arguments["mmc"] != null)
                {
                    max_missed_cleavages = int.Parse(arguments["mmc"]);
                }
                InitiatorMethionineBehavior initiator_methionine_behavior = InitiatorMethionineBehavior.Variable;
                if (arguments["imb"] != null)
                {
                    initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), arguments["imb"], true);
                }
                ModificationDictionary mods       = ModificationDictionary.Instance;
                List <Modification>    fixed_mods = new List <Modification>();
                if (arguments["fm"] != null)
                {
                    foreach (string fixed_mod in arguments["fm"].Split(';'))
                    {
                        fixed_mods.Add(mods[fixed_mod]);
                    }
                }
                if (arguments["vm"] != null)
                {
                    foreach (string variable_mod in arguments["vm"].Split(';'))
                    {
                        Modification mod;
                        if (!mods.TryGetValue(variable_mod, out mod))
                        {
                            known_variable_modifications.TryGetValue(variable_mod, out mod);
                        }
                        variable_mods.Add(mod);
                    }
                }
                int max_variable_mod_isoforms_per_peptide = 1024;
                if (arguments["mvmi"] != null)
                {
                    max_variable_mod_isoforms_per_peptide = int.Parse(arguments["mvmi"]);
                }
                double precursor_mass_tolerance_value = 2.1;
                if (arguments["precmtv"] != null)
                {
                    precursor_mass_tolerance_value = double.Parse(arguments["precmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits precursor_mass_tolerance_units = MassToleranceUnits.Da;
                if (arguments["precmtu"] != null)
                {
                    precursor_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["precmtu"], true);
                }
                MassTolerance precursor_mass_tolerance = new MassTolerance(precursor_mass_tolerance_value, precursor_mass_tolerance_units);
                MassType      precursor_mass_type      = MassType.Monoisotopic;
                if (arguments["precmt"] != null)
                {
                    precursor_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["precmt"], true);
                }
                List <double> accepted_precursor_mass_errors = new List <double>();
                if (arguments["apme"] != null && arguments["apme"].Length > 0)
                {
                    foreach (string accepted_precursor_mass_error in arguments["apme"].Split(';'))
                    {
                        accepted_precursor_mass_errors.Add(double.Parse(accepted_precursor_mass_error, CultureInfo.InvariantCulture));
                    }
                }
                else
                {
                    accepted_precursor_mass_errors.Add(0.0);
                }
                double product_mass_tolerance_value = 0.015;
                if (arguments["prodmtv"] != null)
                {
                    product_mass_tolerance_value = double.Parse(arguments["prodmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits product_mass_tolerance_units = MassToleranceUnits.Da;
                if (arguments["prodmtu"] != null)
                {
                    product_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["prodmtu"], true);
                }
                MassTolerance product_mass_tolerance = new MassTolerance(product_mass_tolerance_value, product_mass_tolerance_units);
                MassType      product_mass_type      = MassType.Monoisotopic;
                if (arguments["prodmt"] != null)
                {
                    product_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["prodmt"], true);
                }
                double max_fdr = 0.01;
                if (arguments["fdr"] != null)
                {
                    max_fdr = double.Parse(arguments["fdr"], CultureInfo.InvariantCulture) / 100.0;
                }
                bool consider_mods_unique = false;
                if (arguments["cmu"] != null)
                {
                    consider_mods_unique = bool.Parse(arguments["cmu"]);
                }
                int max_threads = Environment.ProcessorCount;
                if (arguments["mt"] != null)
                {
                    max_threads = int.Parse(arguments["mt"]);
                }
                bool minimize_memory_usage = false;
                if (arguments["mmu"] != null)
                {
                    minimize_memory_usage = bool.Parse(arguments["mmu"]);
                }
                string output_folder = Environment.CurrentDirectory;
                if (arguments["o"] != null)
                {
                    output_folder = arguments["o"];
                }

                DatabaseSearcher database_searcher = new DatabaseSearcher(data,
                                                                          min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                                                                          abs_threshold, rel_threshold_percent, max_peaks,
                                                                          assign_charge_states, deisotope,
                                                                          database, append_decoys,
                                                                          protease, max_missed_cleavages, initiator_methionine_behavior,
                                                                          fixed_mods, variable_mods, max_variable_mod_isoforms_per_peptide,
                                                                          precursor_mass_tolerance, precursor_mass_type,
                                                                          accepted_precursor_mass_errors,
                                                                          product_mass_tolerance, product_mass_type,
                                                                          max_fdr, consider_mods_unique,
                                                                          max_threads, minimize_memory_usage,
                                                                          output_folder);

                database_searcher.Starting       += HandleStarting;
                database_searcher.StartingFile   += HandleStartingFile;
                database_searcher.UpdateStatus   += HandleUpdateStatus;
                database_searcher.UpdateProgress += HandleUpdateProgress;
                database_searcher.ThrowException += HandleThrowException;
                database_searcher.FinishedFile   += HandleFinishedFile;
                database_searcher.Finished       += HandleFinished;

                database_searcher.Search();
            }
            else
            {
                Console.WriteLine(Program.GetProductNameAndVersion() + " USAGE");
            }
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            CleavageSpecificity searchModeType = CleavageSpecificity.Full; //classic and modern by default

            if (semiSpecificSearchRadioButton.IsChecked.Value)             //semi
            {
                searchModeType = CleavageSpecificity.Semi;
            }
            else if (nonSpecificSearchRadioButton.IsChecked.Value) //non
            {
                searchModeType = CleavageSpecificity.None;
            }
            //else it's the default of full

            if (searchModeType != CleavageSpecificity.Full)
            {
                if (((Protease)proteaseComboBox.SelectedItem).Name.Contains("non-specific"))
                {
                    searchModeType = CleavageSpecificity.None; //prevents an accidental semi attempt of a non-specific protease

                    if (cTerminalIons.IsChecked.Value)
                    {
                        Protease singleC = ProteaseDictionary.Dictionary["singleC"];
                        proteaseComboBox.SelectedItem = singleC;
                    }
                    else //we're not allowing no ion types. It must have N if it doesn't have C.
                    {
                        Protease singleN = ProteaseDictionary.Dictionary["singleN"];
                        proteaseComboBox.SelectedItem = singleN;
                    }
                }
                if (!addCompIonCheckBox.IsChecked.Value)
                {
                    MessageBox.Show("Warning: Complementary ions are strongly recommended when using this algorithm.");
                }
                //only use N or C termini, not both
                if (cTerminalIons.IsChecked.Value)
                {
                    nTerminalIons.IsChecked = false;
                }
                else
                {
                    nTerminalIons.IsChecked = true;
                }
            }

            if (!GlobalGuiSettings.CheckTaskSettingsValidity(precursorMassToleranceTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text,
                                                             maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text,
                                                             peakFindingToleranceTextBox.Text, histogramBinWidthTextBox.Text, DeconvolutionMaxAssumedChargeStateTextBox.Text, NumberOfPeaksToKeepPerWindowTextBox.Text,
                                                             MinimumAllowedIntensityRatioToBasePeakTexBox.Text, WindowWidthThomsonsTextBox.Text, NumberOfWindowsTextBox.Text, numberOfDatabaseSearchesTextBox.Text, MaxModNumTextBox.Text, MaxFragmentMassTextBox.Text, QValueTextBox.Text))
            {
                return;
            }

            Protease protease = (Protease)proteaseComboBox.SelectedItem;

            DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[dissociationTypeComboBox.SelectedItem.ToString()];

            CustomFragmentationWindow.Close();

            FragmentationTerminus fragmentationTerminus = FragmentationTerminus.Both;

            if (nTerminalIons.IsChecked.Value && !cTerminalIons.IsChecked.Value)
            {
                fragmentationTerminus = FragmentationTerminus.N;
            }
            else if (!nTerminalIons.IsChecked.Value && cTerminalIons.IsChecked.Value)
            {
                fragmentationTerminus = FragmentationTerminus.C;
            }
            else if (!nTerminalIons.IsChecked.Value && !cTerminalIons.IsChecked.Value) //why would you want this
            {
                fragmentationTerminus = FragmentationTerminus.None;
                MessageBox.Show("Warning: No ion types were selected. MetaMorpheus will be unable to search MS/MS spectra.");
            }
            //else both

            int maxMissedCleavages           = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int minPeptideLengthValue        = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int maxPeptideLengthValue        = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture));
            int MinVariantDepth              = int.Parse(MinVariantDepthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture);
            int MaxHeterozygousVariants      = int.Parse(MaxHeterozygousVariantsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture);
            int maxModificationIsoformsValue = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture));
            int maxModsForPeptideValue       = (int.Parse(MaxModNumTextBox.Text, CultureInfo.InvariantCulture));
            InitiatorMethionineBehavior initiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex);

            DigestionParams digestionParamsToSave = new DigestionParams(
                protease: protease.Name,
                maxMissedCleavages: maxMissedCleavages,
                minPeptideLength: minPeptideLengthValue,
                maxPeptideLength: maxPeptideLengthValue,
                maxModificationIsoforms: maxModificationIsoformsValue,
                initiatorMethionineBehavior: initiatorMethionineBehavior,
                maxModsForPeptides: maxModsForPeptideValue,
                searchModeType: searchModeType,
                fragmentationTerminus: fragmentationTerminus,
                generateUnlabeledProteinsForSilac: CheckBoxQuantifyUnlabeledForSilac.IsChecked.Value);

            Tolerance ProductMassTolerance;

            if (productMassToleranceComboBox.SelectedIndex == 0)
            {
                ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }

            Tolerance PrecursorMassTolerance;

            if (precursorMassToleranceComboBox.SelectedIndex == 0)
            {
                PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            else
            {
                PrecursorMassTolerance = new PpmTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture));
            }
            TheTask.SearchParameters.MaxFragmentSize = Double.Parse(MaxFragmentMassTextBox.Text, CultureInfo.InvariantCulture);

            var listOfModsVariable = new List <(string, string)>();

            foreach (var heh in VariableModTypeForTreeViewObservableCollection)
            {
                listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            var listOfModsFixed = new List <(string, string)>();

            foreach (var heh in FixedModTypeForTreeViewObservableCollection)
            {
                listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName)));
            }

            if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable))
            {
                return;
            }

            bool TrimMs1Peaks  = trimMs1.IsChecked.Value;
            bool TrimMsMsPeaks = trimMsMs.IsChecked.Value;

            int?numPeaksToKeep = null;

            if (int.TryParse(NumberOfPeaksToKeepPerWindowTextBox.Text, out int numberOfPeaksToKeeep))
            {
                numPeaksToKeep = numberOfPeaksToKeeep;
            }

            double?minimumAllowedIntensityRatioToBasePeak = null;

            if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, out double minimumAllowedIntensityRatio))
            {
                minimumAllowedIntensityRatioToBasePeak = minimumAllowedIntensityRatio;
            }

            double?windowWidthThompsons = null;

            if (double.TryParse(WindowWidthThomsonsTextBox.Text, out double windowWidth))
            {
                windowWidthThompsons = windowWidth;
            }

            int?numberOfWindows = null;

            if (int.TryParse(NumberOfWindowsTextBox.Text, out int numWindows))
            {
                numberOfWindows = numWindows;
            }

            bool normalizePeaksAccrossAllWindows = normalizePeaksInWindowCheckBox.IsChecked.Value;

            bool parseMaxThreadsPerFile = !maxThreadsTextBox.Text.Equals("") && (int.Parse(maxThreadsTextBox.Text) <= Environment.ProcessorCount && int.Parse(maxThreadsTextBox.Text) > 0);

            CommonParameters commonParamsToSave = new CommonParameters(
                taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "SearchTask",
                maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile,
                useDeltaScore: deltaScoreCheckBox.IsChecked.Value,
                reportAllAmbiguity: allAmbiguity.IsChecked.Value,
                deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture),
                totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture),
                doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value,
                useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value,
                scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture),
                listOfModsFixed: listOfModsFixed,
                listOfModsVariable: listOfModsVariable,
                dissociationType: dissociationType,
                precursorMassTolerance: PrecursorMassTolerance,
                productMassTolerance: ProductMassTolerance,
                digestionParams: digestionParamsToSave,
                trimMs1Peaks: TrimMs1Peaks,
                trimMsMsPeaks: TrimMsMsPeaks,
                numberOfPeaksToKeepPerWindow: numPeaksToKeep,
                minimumAllowedIntensityRatioToBasePeak: minimumAllowedIntensityRatioToBasePeak,
                windowWidthThomsons: windowWidthThompsons,
                numberOfWindows: numberOfWindows,                                 //maybe change this some day
                normalizePeaksAccrossAllWindows: normalizePeaksAccrossAllWindows, //maybe change this some day
                addCompIons: addCompIonCheckBox.IsChecked.Value,
                qValueOutputFilter: QValueCheckBox.IsChecked.Value ? double.Parse(QValueTextBox.Text, CultureInfo.InvariantCulture) : 1.0,
                assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down",
                minVariantDepth: MinVariantDepth,
                maxHeterozygousVariants: MaxHeterozygousVariants);

            if (classicSearchRadioButton.IsChecked.Value)
            {
                TheTask.SearchParameters.SearchType = SearchType.Classic;
            }
            else if (modernSearchRadioButton.IsChecked.Value)
            {
                TheTask.SearchParameters.SearchType = SearchType.Modern;
            }
            else //both semi and nonspecific are termed "nonspecific", because they both contain at least one nonspecific cleavage and they share the same algorithm
            {
                TheTask.SearchParameters.SearchType = SearchType.NonSpecific;
            }

            TheTask.SearchParameters.DoParsimony      = checkBoxParsimony.IsChecked.Value;
            TheTask.SearchParameters.NoOneHitWonders  = checkBoxNoOneHitWonders.IsChecked.Value;
            TheTask.SearchParameters.DoQuantification = !checkBoxNoQuant.IsChecked.Value;

            //SilacLabel deconvolution
            {
                if (StaticSilacLabelsObservableCollection.Count == 0)
                {
                    TheTask.SearchParameters.SilacLabels = null;
                }
                else
                {
                    List <Proteomics.SilacLabel> labelsToSave = new List <Proteomics.SilacLabel>();
                    foreach (SilacInfoForDataGrid info in StaticSilacLabelsObservableCollection)
                    {
                        Proteomics.SilacLabel labelToAdd = info.SilacLabel[0];

                        //This is needed to prevent double adding of additional labels.
                        //A quick test is to create a silac condition with two labels, save, reopen the task, save, and reopen again.
                        //Without this line, the second label will be doubled (K+8)&(R+10)&(R+10)
                        if (labelToAdd.AdditionalLabels != null)
                        {
                            labelToAdd.AdditionalLabels.Clear();
                        }

                        for (int infoIndex = 1; infoIndex < info.SilacLabel.Count; infoIndex++)
                        {
                            labelToAdd.AddAdditionalSilacLabel(info.SilacLabel[infoIndex]);
                        }
                        labelsToSave.Add(labelToAdd);
                    }
                    TheTask.SearchParameters.SilacLabels = labelsToSave;
                }
            }

            TheTask.SearchParameters.Normalize               = checkBoxNormalize.IsChecked.Value;
            TheTask.SearchParameters.MatchBetweenRuns        = checkBoxMatchBetweenRuns.IsChecked.Value;
            TheTask.SearchParameters.ModPeptidesAreDifferent = modPepsAreUnique.IsChecked.Value;
            TheTask.SearchParameters.QuantifyPpmTol          = double.Parse(peakFindingToleranceTextBox.Text, CultureInfo.InvariantCulture);
            TheTask.SearchParameters.SearchTarget            = checkBoxTarget.IsChecked.Value;
            TheTask.SearchParameters.WriteMzId               = ckbMzId.IsChecked.Value;
            TheTask.SearchParameters.WriteDecoys             = writeDecoyCheckBox.IsChecked.Value;
            TheTask.SearchParameters.WriteContaminants       = writeContaminantCheckBox.IsChecked.Value;
            //TheTask.SearchParameters.OutPepXML = ckbPepXML.IsChecked.Value;

            if (checkBoxDecoy.IsChecked.Value)
            {
                if (radioButtonReverseDecoy.IsChecked.Value)
                {
                    TheTask.SearchParameters.DecoyType = DecoyType.Reverse;
                }
                else //if (radioButtonSlideDecoy.IsChecked.Value)
                {
                    TheTask.SearchParameters.DecoyType = DecoyType.Slide;
                }
            }
            else
            {
                TheTask.SearchParameters.DecoyType = DecoyType.None;
            }

            if (massDiffAcceptExact.IsChecked.HasValue && massDiffAcceptExact.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Exact;
            }
            if (massDiffAccept1mm.IsChecked.HasValue && massDiffAccept1mm.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.OneMM;
            }
            if (massDiffAccept2mm.IsChecked.HasValue && massDiffAccept2mm.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.TwoMM;
            }
            if (massDiffAccept3mm.IsChecked.HasValue && massDiffAccept3mm.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.ThreeMM;
            }
            if (massDiffAccept187.IsChecked.HasValue && massDiffAccept187.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.ModOpen;
            }
            if (massDiffAcceptOpen.IsChecked.HasValue && massDiffAcceptOpen.IsChecked.Value)
            {
                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Open;
            }
            if (massDiffAcceptCustom.IsChecked.HasValue && massDiffAcceptCustom.IsChecked.Value)
            {
                try
                {
                    MassDiffAcceptor customMassDiffAcceptor = SearchTask.GetMassDiffAcceptor(null, MassDiffAcceptorType.Custom, customkMdacTextBox.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not parse custom mass difference acceptor: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Custom;
                TheTask.SearchParameters.CustomMdac           = customkMdacTextBox.Text;
            }

            //determine if semi or nonspecific with a specific protease.
            if (searchModeType == CleavageSpecificity.Semi || protease.CleavageSpecificity == CleavageSpecificity.Semi)
            {
                TheTask.SearchParameters.LocalFdrCategories = new List <FdrCategory> {
                    FdrCategory.FullySpecific, FdrCategory.SemiSpecific
                };
            }
            else if (searchModeType == CleavageSpecificity.None && protease.CleavageSpecificity != CleavageSpecificity.None)
            {
                TheTask.SearchParameters.LocalFdrCategories = new List <FdrCategory> {
                    FdrCategory.FullySpecific, FdrCategory.SemiSpecific, FdrCategory.NonSpecific
                };
            }
            else
            {
                TheTask.SearchParameters.LocalFdrCategories = new List <FdrCategory> {
                    FdrCategory.FullySpecific
                };
            }

            // displays warning if classic search is enabled with an open search mode
            if (TheTask.SearchParameters.SearchType == SearchType.Classic &&
                (TheTask.SearchParameters.MassDiffAcceptorType == MassDiffAcceptorType.ModOpen || TheTask.SearchParameters.MassDiffAcceptorType == MassDiffAcceptorType.Open))
            {
                MessageBoxResult result = MessageBox.Show("Modern Search mode is recommended when conducting open precursor mass searches to reduce search time.\n\n" +
                                                          "Continue anyway?", "Modern search recommended", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            TheTask.SearchParameters.DoHistogramAnalysis      = checkBoxHistogramAnalysis.IsChecked.Value;
            TheTask.SearchParameters.HistogramBinTolInDaltons = double.Parse(histogramBinWidthTextBox.Text, CultureInfo.InvariantCulture);

            TheTask.SearchParameters.WritePrunedDatabase = writePrunedDBCheckBox.IsChecked.Value;

            SetModSelectionForPrunedDB();

            TheTask.CommonParameters = commonParamsToSave;

            DialogResult = true;
        }