protected bool IsValid(SapMatchedCount smc)
        {
            if (smc.MS3Matched.Count < options.MinimumMatchedMS3SpectrumCount)
            {
                return(false);
            }

            if (smc.MS3Matched.All(l => l < options.MinimumMatchedMS3IonCount))
            {
                return(false);
            }

            return(true);
        }
 protected static void OutputIntervalResult(StreamWriter sw, MS2Item query, MS2Item libms2, SapMatchedCount ms3match)
 {
     sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}",
                  query.GetFileScans(),
                  query.Precursor,
                  query.Charge,
                  libms2.Precursor,
                  ms3match.PrecursorMatched.ConvertAll(m => m.ToString()).Merge(";"),
                  ms3match.MS3Matched.ConvertAll(m => m.ToString()).Merge(";"),
                  (query.Precursor - libms2.Precursor) * query.Charge,
                  libms2.GetFileScans(),
                  libms2.Peptide,
                  libms2.Score,
                  libms2.ExpectValue,
                  libms2.Proteins);
 }
        protected void CheckTerminalLoss(List <SapPredicted> predicted, MS2Item query, MS2Item libms2, SapMatchedCount ms3match)
        {
            foreach (var nl in libms2.TerminalLoss)
            {
                if (nl.Precursor >= query.MinPrecursorMz && nl.Precursor <= query.MaxPrecursorMz)
                {
                    var curp = new SapPredicted()
                    {
                        Ms2     = query,
                        LibMs2  = libms2,
                        Matched = ms3match,
                        Target  = new TargetVariant()
                        {
                            Source     = PeptideUtils.GetPureSequence(libms2.Peptide),
                            Target     = new HashSet <string>(new[] { nl.Sequence }),
                            DeltaMass  = (nl.Precursor - libms2.Precursor) * libms2.Charge,
                            TargetType = nl.IsNterminal ? VariantType.NTerminalLoss : VariantType.CTerminalLoss
                        }
                    };

                    predicted.Add(curp);
                }
            }
        }
        protected void CheckTerminalExtension(List <SapPredicted> predicted, MS2Item query, MS2Item libms2, SapMatchedCount ms3match)
        {
            var bNterminalValid = libms2.Peptide.StartsWith("-");
            var bCterminalValid = libms2.Peptide.EndsWith("-");

            if (bNterminalValid || bCterminalValid)
            {
                foreach (var ne in options.ExtensionDeltaMassList)
                {
                    var neMz = libms2.Precursor + ne.DeltaMass / libms2.Charge;
                    if (neMz >= query.MinPrecursorMz && neMz <= query.MaxPrecursorMz)
                    {
                        var seq = PeptideUtils.GetPureSequence(libms2.Peptide);

                        if (bNterminalValid)
                        {
                            predicted.Add(new SapPredicted()
                            {
                                Ms2     = query,
                                LibMs2  = libms2,
                                Matched = ms3match,
                                Target  = new TargetVariant()
                                {
                                    Source     = PeptideUtils.GetPureSequence(libms2.Peptide),
                                    Target     = new HashSet <string>(from t in ne.Target select t + seq),
                                    DeltaMass  = ne.DeltaMass,
                                    TargetType = VariantType.NTerminalExtension
                                }
                            });
                        }

                        if (bCterminalValid)
                        {
                            predicted.Add(new SapPredicted()
                            {
                                Ms2     = query,
                                LibMs2  = libms2,
                                Matched = ms3match,
                                Target  = new TargetVariant()
                                {
                                    Source     = PeptideUtils.GetPureSequence(libms2.Peptide),
                                    Target     = new HashSet <string>(from t in ne.Target select seq + t),
                                    DeltaMass  = ne.DeltaMass,
                                    TargetType = VariantType.CTerminalExtension
                                }
                            });
                        }
                    }
                }
            }
        }
        protected void CheckSAP(List <SapPredicted> predicted, MS2Item query, MS2Item libms2, SapMatchedCount ms3match)
        {
            foreach (var aa in libms2.AminoacidCompsition)
            {
                var lst = options.SubstitutionDeltaMassMap[aa];
                //the list has been ordered by deltamass
                foreach (var ts in lst)
                {
                    var targetMz = libms2.Precursor + ts.DeltaMass / query.Charge;
                    if (targetMz < query.MinPrecursorMz)
                    {
                        continue;
                    }

                    if (targetMz > query.MaxPrecursorMz)
                    {
                        break;
                    }

                    var curp = new SapPredicted()
                    {
                        Ms2     = query,
                        LibMs2  = libms2,
                        Matched = ms3match,
                        Target  = new TargetVariant()
                        {
                            Source     = ts.Source,
                            Target     = ts.Target,
                            DeltaMass  = ts.DeltaMass,
                            TargetType = ts.TargetType
                        }
                    };

                    predicted.Add(curp);
                }
            }
        }