예제 #1
0
        private SrmDocument GetDocumentFinal(CancellationToken cancellationToken, SrmDocument doc, int minPeptides, bool removeRepeated, bool removeDuplicate, out int?emptyProteins)
        {
            emptyProteins = null;

            // Remove repeated/duplicate peptides
            var newDoc = removeRepeated || removeDuplicate
                ? new RefinementSettings {
                RemoveRepeatedPeptides = removeRepeated, RemoveDuplicatePeptides = removeDuplicate
            }.Refine(doc)
                : doc;

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            // Remove proteins without enough peptides
            newDoc = ImportPeptideSearch.RemoveProteinsByPeptideCount(newDoc, minPeptides);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            // Move iRT proteins to top
            var irtPeptides = new HashSet <Target>(RCalcIrt.IrtPeptides(newDoc));
            var proteins    = new List <PeptideGroupDocNode>(newDoc.PeptideGroups);
            var proteinsIrt = new List <PeptideGroupDocNode>();

            for (var i = 0; i < proteins.Count; i++)
            {
                var nodePepGroup = proteins[i];
                if (nodePepGroup.Peptides.All(nodePep => irtPeptides.Contains(new Target(nodePep.ModifiedSequence))))
                {
                    proteinsIrt.Add(nodePepGroup);
                    proteins.RemoveAt(i--);
                }
            }
            if (proteinsIrt.Any())
            {
                newDoc = (SrmDocument)newDoc.ChangeChildrenChecked(proteinsIrt.Concat(proteins).Cast <DocNode>().ToArray());
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            // Add decoys
            newDoc = AddDecoys(newDoc);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            // Count empty proteins
            emptyProteins = newDoc.PeptideGroups.Count(pepGroup => pepGroup.PeptideCount == 0);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            return(newDoc);
        }