コード例 #1
0
ファイル: ViewLibraryPepMatching.cs プロジェクト: zrolfs/pwiz
        private static SrmDocument AddPeptidesToLibraryGroup(SrmDocument document,
                                                             ICollection <PeptideMatch> listMatches,
                                                             ILongWaitBroker broker,
                                                             IdentityPath toPath,
                                                             out IdentityPath selectedPath)
        {
            // Get starting progress values
            int startPercent     = (broker != null ? broker.ProgressValue : 0);
            int processedPercent = 0;
            int processedCount   = 0;
            int totalMatches     = listMatches.Count;

            var listPeptides      = new List <PeptideDocNode>();
            var hasSmallMolecules = false;

            foreach (var match in listMatches)
            {
                // Show progress, if in a long wait
                if (broker != null)
                {
                    if (broker.IsCanceled)
                    {
                        selectedPath = null;
                        return(document);
                    }
                    processedCount++;
                    int processPercentNow = processedCount * (100 - startPercent) / totalMatches;
                    if (processedPercent != processPercentNow)
                    {
                        processedPercent     = processPercentNow;
                        broker.ProgressValue = startPercent + processedPercent;
                    }
                }

                listPeptides.Add(match.NodePep.ChangeSettings(document.Settings, SrmSettingsDiff.ALL));
                hasSmallMolecules |= !match.NodePep.IsProteomic;
            }

            bool hasVariable =
                listPeptides.Contains(nodePep => nodePep.HasExplicitMods && nodePep.ExplicitMods.IsVariableStaticMods);

            // Use existing group by this name, if present.
            var nodeName = hasSmallMolecules
                ? Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Molecules
                : Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Peptides;
            var nodePepGroupNew = FindPeptideGroupDocNode(document, nodeName);

            if (nodePepGroupNew != null)
            {
                var newChildren = nodePepGroupNew.Children.ToList();
                newChildren.AddRange(listPeptides.ConvertAll(nodePep => (DocNode)nodePep));
                selectedPath    = (listPeptides.Count == 1 ? new IdentityPath(nodePepGroupNew.Id, listPeptides[0].Id) : toPath);
                nodePepGroupNew = (PeptideGroupDocNode)nodePepGroupNew.ChangeChildren(newChildren);
                if (hasVariable)
                {
                    nodePepGroupNew = (PeptideGroupDocNode)nodePepGroupNew.ChangeAutoManageChildren(false);
                }
                return((SrmDocument)document.ReplaceChild(nodePepGroupNew));
            }
            else
            {
                nodePepGroupNew = new PeptideGroupDocNode(new PeptideGroup(),
                                                          nodeName,
                                                          string.Empty, listPeptides.ToArray());
                if (hasVariable)
                {
                    nodePepGroupNew = (PeptideGroupDocNode)nodePepGroupNew.ChangeAutoManageChildren(false);
                }
                IdentityPath nextAdd;
                document = document.AddPeptideGroups(new[] { nodePepGroupNew }, true,
                                                     toPath, out selectedPath, out nextAdd);
                selectedPath = new IdentityPath(selectedPath, nodePepGroupNew.Children[0].Id);
                return(document);
            }
        }
コード例 #2
0
        private static SrmDocument AddPeptidesToLibraryGroup(SrmDocument document,
                                                             ICollection <PeptideMatch> listMatches,
                                                             ILongWaitBroker broker,
                                                             IdentityPath toPath,
                                                             out IdentityPath selectedPath)
        {
            // Get starting progress values
            int startPercent     = (broker != null ? broker.ProgressValue : 0);
            int processedPercent = 0;
            int processedCount   = 0;
            int totalMatches     = listMatches.Count;

            selectedPath = null;

            // Some .blib files provide protein accessions (understood as Molecule List Names fro small molecules).
            // If those are provided we will use them as node names.
            // TODO(bspratt) for now we will do this only for small molecules since it might be a surprise to proteomics users. We should revisit that decision.
            foreach (var proteinName in listMatches.Select(m => m.LibInfo.Protein).Distinct())
            {
                var listPeptides      = new List <PeptideDocNode>();
                var hasSmallMolecules = false;
                foreach (var match in listMatches.Where(m => Equals(proteinName, m.LibInfo.Protein)))
                {
                    // Show progress, if in a long wait
                    if (broker != null)
                    {
                        if (broker.IsCanceled)
                        {
                            selectedPath = null;
                            return(document);
                        }
                        processedCount++;
                        int processPercentNow = processedCount * (100 - startPercent) / totalMatches;
                        if (processedPercent != processPercentNow)
                        {
                            processedPercent     = processPercentNow;
                            broker.ProgressValue = startPercent + processedPercent;
                        }
                    }

                    listPeptides.Add(match.NodePep.ChangeSettings(document.Settings, SrmSettingsDiff.ALL));
                    hasSmallMolecules |= !match.NodePep.IsProteomic;
                }

                bool hasVariable =
                    listPeptides.Contains(nodePep => nodePep.HasExplicitMods && nodePep.ExplicitMods.IsVariableStaticMods);

                // Use existing group by this name, if present.
                // If library provides a RefSpectraProteins table, use that to name the group
                // TODO(bspratt) for now we will use RefSpectraProteins names only for small molecules
                var genericLibraryPeptidesGroupName = hasSmallMolecules
                    ? Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Molecules
                    : Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Peptides;
                var nodeName = string.IsNullOrEmpty(proteinName) ||
                               listPeptides.Any(p => p.IsProteomic) // TODO(bspratt) revisit this caution-driven decision
                    ? genericLibraryPeptidesGroupName
                    : proteinName;
                var nodePepGroupNew = FindPeptideGroupDocNode(document, nodeName, null);
                if (nodePepGroupNew != null)
                {
                    var newChildren = nodePepGroupNew.Children.ToList();
                    newChildren.AddRange(listPeptides.ConvertAll(nodePep => (DocNode)nodePep));
                    selectedPath    = (listPeptides.Count == 1 ? new IdentityPath(nodePepGroupNew.Id, listPeptides[0].Id) : toPath);
                    nodePepGroupNew = (PeptideGroupDocNode)nodePepGroupNew.ChangeChildren(newChildren);
                    if (hasVariable)
                    {
                        nodePepGroupNew = (PeptideGroupDocNode)nodePepGroupNew.ChangeAutoManageChildren(false);
                    }
                    document = (SrmDocument)document.ReplaceChild(nodePepGroupNew);
                }
                else
                {
                    nodePepGroupNew = new PeptideGroupDocNode(new PeptideGroup(),
                                                              nodeName,
                                                              string.Empty, listPeptides.ToArray());
                    if (hasVariable)
                    {
                        nodePepGroupNew = (PeptideGroupDocNode)nodePepGroupNew.ChangeAutoManageChildren(false);
                    }
                    IdentityPath nextAdd;
                    document = document.AddPeptideGroups(new[] { nodePepGroupNew }, true,
                                                         toPath, out selectedPath, out nextAdd);
                    selectedPath = new IdentityPath(selectedPath, nodePepGroupNew.Children[0].Id);
                }
            }
            return(document);
        }