当前位置: 首页>>代码示例>>C#>>正文


C# SrmDocument.ReplaceChild方法代码示例

本文整理汇总了C#中SrmDocument.ReplaceChild方法的典型用法代码示例。如果您正苦于以下问题:C# SrmDocument.ReplaceChild方法的具体用法?C# SrmDocument.ReplaceChild怎么用?C# SrmDocument.ReplaceChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SrmDocument的用法示例。


在下文中一共展示了SrmDocument.ReplaceChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveMissing

        /// <summary>
        /// Removes peaks and annotations that were in the document but not in the file, so that all peptide results that were not explicitly imported as part of this file are now blank
        /// </summary>
        /// <param name="docNew">SrmDocument for which missing peaks should be removed</param>
        /// <param name="trackAdjustedResults">List of peaks that were in the imported file</param>
        /// <param name="changePeaks">If true, remove both peaks and annotations.  If false, only remove annotations</param>
        /// <returns></returns>
        private SrmDocument RemoveMissing(SrmDocument docNew, ICollection<ResultsKey> trackAdjustedResults, bool changePeaks)
        {
            var measuredResults = docNew.Settings.MeasuredResults;
            var chromatogramSets = measuredResults.Chromatograms;
            for (int i = 0; i < chromatogramSets.Count; ++i)
            {
                var set = chromatogramSets[i];
                var nameSet = set.Name;
                for (int k = 0; k < docNew.MoleculeCount; ++k)
                {
                    IdentityPath pepPath = docNew.GetPathTo((int)SrmDocument.Level.Molecules, k);
                    var pepNode = (PeptideDocNode)Document.FindNode(pepPath);
                    if (pepNode.IsDecoy)
                        continue;
                    if (pepNode.GlobalStandardType != null)
                        continue;
                    foreach (var groupNode in pepNode.TransitionGroups)
                    {
                        var groupPath = new IdentityPath(pepPath, groupNode.Id);
                        var chromInfos = groupNode.Results[i];
                        if (chromInfos == null)
                            continue;

                        foreach (var groupChromInfo in chromInfos)
                        {
                            if (groupChromInfo == null)
                                continue;
                            var key = new ResultsKey(groupChromInfo.FileId.GlobalIndex, groupNode.Id);
                            if (!trackAdjustedResults.Contains(key))
                            {
                                CountMissing++;
                                var fileId = groupChromInfo.FileId;
                                var fileInfo = set.GetFileInfo(fileId);
                                var filePath = fileInfo.FilePath;
                                // Remove annotations for defs that were imported into the document and were on this peptide prior to import
                                var newAnnotationValues = groupChromInfo.Annotations.ListAnnotations().ToList();
                                newAnnotationValues = newAnnotationValues.Where(a => !AnnotationsAdded.Contains(a.Key)).ToList();
                                var newAnnotations = new Annotations(groupChromInfo.Annotations.Note, newAnnotationValues, groupChromInfo.Annotations.ColorIndex);
                                var newGroupNode = groupNode.ChangePrecursorAnnotations(fileId, newAnnotations);
                                if (!ReferenceEquals(groupNode, newGroupNode))
                                    docNew = (SrmDocument) docNew.ReplaceChild(groupPath.Parent, newGroupNode);
                                // Adjust peaks to null if they weren't in the file
                                if (changePeaks)
                                {
                                    docNew = docNew.ChangePeak(groupPath, nameSet, filePath,
                                        null, null, null, UserSet.IMPORTED, null, false);
                                }
                            }
                        }
                    }
                }
            }
            return docNew;
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:61,代码来源:ImportPeakBoundaries.cs

示例2: AddPeptides


//.........这里部分代码省略.........
                    {
                        peptideGroupDocNode = null;
                    }
                }
                else
                {
                    peptideGroupDocNode = FindPeptideGroupDocNode(document, proteinName);
                }
                if (peptideGroupDocNode == null)
                {
                    if (string.IsNullOrEmpty(proteinName))
                    {
                        peptideGroupDocNode = new PeptideGroupDocNode(new PeptideGroup(),
                                                                      document.GetPeptideGroupId(true), null,
                                                                      new PeptideDocNode[0]);
                    }
                    else
                    {
                        ProteinMetadata metadata = null;
                        PeptideGroup peptideGroup = backgroundProteome.IsNone ? new PeptideGroup()
                            : (backgroundProteome.GetFastaSequence(proteinName, out metadata) ??
                                                    new PeptideGroup());
                        if (metadata != null)
                            peptideGroupDocNode = new PeptideGroupDocNode(peptideGroup, metadata, new PeptideDocNode[0]);
                        else
                            peptideGroupDocNode = new PeptideGroupDocNode(peptideGroup, proteinName,
                                                                      peptideGroup.Description, new PeptideDocNode[0]);
                    }
                    // Add to the end, if no insert node
                    var to = selectedPath;
                    if (to == null || to.Depth < (int)SrmDocument.Level.MoleculeGroups)
                        document = (SrmDocument)document.Add(peptideGroupDocNode);
                    else
                    {
                        Identity toId = selectedPath.GetIdentity((int) SrmDocument.Level.MoleculeGroups);
                        document = (SrmDocument) document.Insert(toId, peptideGroupDocNode);
                    }
                    selectedPath = new IdentityPath(peptideGroupDocNode.Id);
                }
                var peptides = new List<PeptideDocNode>();
                foreach (PeptideDocNode peptideDocNode in peptideGroupDocNode.Children)
                {
                    peptides.Add(peptideDocNode);
                }

                var fastaSequence = peptideGroupDocNode.PeptideGroup as FastaSequence;
                PeptideDocNode nodePepNew;
                if (fastaSequence != null)
                {
                    // Attempt to create node for error checking.
                    nodePepNew = fastaSequence.CreateFullPeptideDocNode(document.Settings,
                                                                        FastaSequence.StripModifications(pepModSequence));
                    if (nodePepNew == null)
                    {
                        ShowPeptideError(new PasteError
                                             {
                                                 Column = colPeptideSequence.Index,
                                                 Line = i,
                                                 Message = Resources.PasteDlg_AddPeptides_This_peptide_sequence_was_not_found_in_the_protein_sequence
                                             });
                        return null;
                    }
                }
                // Create node using ModificationMatcher.
                nodePepNew = matcher.GetModifiedNode(pepModSequence, fastaSequence).ChangeSettings(document.Settings,
                                                                                                  SrmSettingsDiff.ALL);
                // Avoid adding an existing peptide a second time.
                if (!peptides.Contains(nodePep => Equals(nodePep.Key, nodePepNew.Key)))
                {
                    if (nodePepNew.Peptide.FastaSequence != null)
                    {
                        peptides.Add(nodePepNew);
                        peptides.Sort(FastaSequence.ComparePeptides);
                    }
                    else
                    {
                        int groupGlobalIndex = peptideGroupDocNode.PeptideGroup.GlobalIndex;
                        if (groupGlobalIndex == lastGroupGlobalIndex && lastPeptideIndex != -1)
                        {
                            peptides.Insert(lastPeptideIndex, nodePepNew);
                        }
                        else
                        {
                            lastPeptideIndex = peptides.Count;
                            peptides.Add(nodePepNew);
                        }
                        lastGroupGlobalIndex = groupGlobalIndex;
                    }
                    var newPeptideGroupDocNode = new PeptideGroupDocNode(peptideGroupDocNode.PeptideGroup, peptideGroupDocNode.Annotations, peptideGroupDocNode.Name, peptideGroupDocNode.Description, peptides.ToArray(), false);
                    document = (SrmDocument)document.ReplaceChild(newPeptideGroupDocNode);
                }
            }
            if (!validating && listPeptideSequences.Count > 0)
            {
                var pepModsNew = matcher.GetDocModifications(document);
                document = document.ChangeSettings(document.Settings.ChangePeptideModifications(mods => pepModsNew));
                document.Settings.UpdateDefaultModifications(false);
            }
            return document;
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:101,代码来源:PasteDlg.cs

示例3: AddTransitionList


//.........这里部分代码省略.........
                        .Append(productMzText).AppendLine();
                    // Build FASTA sequence text in cases where it is known
                    if (!dictNameSeq.ContainsKey(proteinName))
                    {
                        var fastaSeq = backgroundProteome.GetFastaSequence(proteinName);
                        if (fastaSeq != null)
                            dictNameSeq.Add(proteinName, fastaSeq);
                    }
                }

                if (sbTransitionList.Length == 0)
                    return document;

                // Do the actual import into PeptideGroupDocNodes
                IEnumerable<PeptideGroupDocNode> peptideGroupDocNodes;
                try
                {
                    List<TransitionImportErrorInfo> errorList;
                    List<MeasuredRetentionTime> irtPeptides;
                    List<SpectrumMzInfo> librarySpectra;
                    var inputs = new MassListInputs(sbTransitionList.ToString(), LocalizationHelper.CurrentCulture, TRANSITION_LIST_SEPARATOR);
                    var importer = new MassListImporter(document, inputs);
                    // TODO: support long-wait broker
                    peptideGroupDocNodes = importer.Import(null,
                        TRANSITION_LIST_COL_INDICES,
                        dictNameSeq,
                        out irtPeptides,
                        out librarySpectra,
                        out errorList);
                    if (errorList.Any())
                    {
                        var firstError = errorList[0];
                        if (firstError.Row.HasValue)
                        {
                            throw new LineColNumberedIoException(firstError.ErrorMessage, firstError.Row.Value, firstError.Column ?? -1);
                        }
                        else
                        {
                            throw new InvalidDataException(firstError.ErrorMessage);
                        }
                    }
                }
                catch (LineColNumberedIoException x)
                {
                    var columns = new[]
                    {
                        colTransitionProteinName,
                        colPeptideSequence,
                        colTransitionPrecursorMz,
                        colTransitionProductMz
                    };

                    ShowTransitionError(new PasteError
                    {
                        Column = x.ColumnIndex >= 0 ? columns[x.ColumnIndex].Index : 0,
                        Line = (int) x.LineNumber - 1,
                        Message = x.PlainMessage
                    });
                    return null;
                }
                catch (InvalidDataException x)
                {
                    ShowTransitionError(new PasteError
                    {
                        Message = x.Message
                    });
                    return null;
                }

                // Insert the resulting nodes into the document tree, merging when possible
                bool after = false;
                foreach (var nodePepGroup in peptideGroupDocNodes)
                {
                    PeptideGroupDocNode nodePepGroupExist = FindPeptideGroupDocNode(document, nodePepGroup);
                    if (nodePepGroupExist != null)
                    {
                        var nodePepGroupNew = nodePepGroupExist.Merge(nodePepGroup);
                        if (!ReferenceEquals(nodePepGroupExist, nodePepGroupNew))
                            document = (SrmDocument) document.ReplaceChild(nodePepGroupNew);

                    }
                    else
                    {
                        // Add to the end, if no insert node
                        var to = selectedPath;
                        if (to == null || to.Depth < (int) SrmDocument.Level.MoleculeGroups)
                            document = (SrmDocument) document.Add(nodePepGroup);
                        else
                        {
                            Identity toId = selectedPath.GetIdentity((int) SrmDocument.Level.MoleculeGroups);
                            document = (SrmDocument) document.Insert(toId, nodePepGroup, after);
                        }
                        selectedPath = new IdentityPath(nodePepGroup.Id);
                        // All future insertions should be after, to avoid reversing the list
                        after = true;
                    }
                }
            }
            return document;
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:101,代码来源:PasteDlg.cs

示例4: ConvertToExplicitRetentionTimes

 public SrmDocument ConvertToExplicitRetentionTimes(SrmDocument document, double timeOffset, double winOffset)
 {
     for (bool changing = true; changing;)
     {
         changing = false;
         foreach (var peptideGroupDocNode in document.MoleculeGroups)
         {
             var pepGroupPath = new IdentityPath(IdentityPath.ROOT, peptideGroupDocNode.Id);
             foreach (var nodePep in peptideGroupDocNode.Molecules)
             {
                 var pepPath = new IdentityPath(pepGroupPath, nodePep.Id);
                 var rt = nodePep.AverageMeasuredRetentionTime;
                 if (rt.HasValue)
                 {
                     double? rtWin = document.Settings.PeptideSettings.Prediction.MeasuredRTWindow;
                     var explicitRetentionTimeInfo = new ExplicitRetentionTimeInfo(rt.Value+timeOffset, rtWin+winOffset);
                     if (!explicitRetentionTimeInfo.Equals(nodePep.ExplicitRetentionTime))
                     {
                         document = (SrmDocument)document.ReplaceChild(pepPath.Parent, nodePep.ChangeExplicitRetentionTime(explicitRetentionTimeInfo));
                         changing = true;
                         break;
                     }
                 }
             }
             if (changing)
                 break;
         }
     }
     return document;
 }
开发者ID:lgatto,项目名称:proteowizard,代码行数:30,代码来源:RefinementSettings.cs

示例5: AddProteomePeptides


//.........这里部分代码省略.........
                    bool foundInList = false;
                    if (!foundInDoc)
                    {
                        // If the protein is not already in the document,
                        // check to see if we have already created a PeptideGroupDocNode for it.
                        if (dictPeptideGroupsNew.TryGetValue(name, out peptideGroupDocNode))
                            foundInList = true;
                        // If not, create a new PeptideGroupDocNode.
                        else
                        {
                            List<ProteinMetadata> alternativeProteins = new List<ProteinMetadata>(protein.Alternatives);
                            peptideGroupDocNode = new PeptideGroupDocNode(
                                    new FastaSequence(name, protein.ProteinMetadata.Description, alternativeProteins, protein.Sequence),
                                    null, null, new PeptideDocNode[0]);
                        }
                    }
                    // Create a new peptide that matches this protein.
                    var fastaSequence = peptideGroupDocNode.PeptideGroup as FastaSequence;
                    var peptideSequence = pepMatch.NodePep.Peptide.Sequence;
                    // ReSharper disable PossibleNullReferenceException
                    var begin = fastaSequence.Sequence.IndexOf(peptideSequence, StringComparison.Ordinal);
                    // ReSharper restore PossibleNullReferenceException
                    // Create a new PeptideDocNode using this peptide.
                    var newPeptide = new Peptide(fastaSequence, peptideSequence, begin, begin + peptideSequence.Length,
                                                 Settings.PeptideSettings.Enzyme.CountCleavagePoints(peptideSequence));
                    // Make sure we keep the same children.
                    PeptideMatch match = pepMatch;
                    var newNodePep = ((PeptideDocNode) new PeptideDocNode(newPeptide, pepMatch.NodePep.ExplicitMods, pepMatch.NodePep.ExplicitRetentionTime)
                            .ChangeChildren(pepMatch.NodePep.Children.ToList().ConvertAll(nodeGroup =>
                                {
                                    // Create copies of the children in order to prevent transition groups with the same
                                    // global indices.
                                    var nodeTranGroup = (TransitionGroupDocNode) nodeGroup;
                                    if(match.Proteins != null && match.Proteins.Count() > 1)
                                    {
                                        nodeTranGroup = (TransitionGroupDocNode) nodeTranGroup.CopyId();
                                        nodeTranGroup = (TransitionGroupDocNode) nodeTranGroup.ChangeChildren(
                                            nodeTranGroup.Children.ToList().ConvertAll(nodeTran => nodeTran.CopyId()));
                                    }
                                    return (DocNode) nodeTranGroup;
                                })).ChangeAutoManageChildren(false)).ChangeSettings(document.Settings, SrmSettingsDiff.ALL);
                    // If this PeptideDocNode is already a child of the PeptideGroupDocNode,
                    // ignore it.
                    if (peptideGroupDocNode.Children.Contains(nodePep => Equals(((PeptideDocNode) nodePep).Key, newNodePep.Key)))
                    {
                        Console.WriteLine(Resources.ViewLibraryPepMatching_AddProteomePeptides_Skipping__0__already_present, newNodePep.Peptide.Sequence);
                        continue;
                    }
                    // Otherwise, add it to the list of children for the PeptideGroupNode.
                    var newChildren = peptideGroupDocNode.Children.Cast<PeptideDocNode>().ToList();
                    newChildren.Add(newNodePep);
                    newChildren.Sort(FastaSequence.ComparePeptides);

                    // Store modified proteins by global index in a HashSet for second pass.
                    var newPeptideGroupDocNode = peptideGroupDocNode.ChangeChildren(newChildren.Cast<DocNode>().ToArray())
                        .ChangeAutoManageChildren(false);
                    // If the protein was already in the document, replace with the new PeptideGroupDocNode.
                    if (foundInDoc)
                        document = (SrmDocument)document.ReplaceChild(newPeptideGroupDocNode);
                    // Otherwise, update the list of new PeptideGroupDocNodes to add.
                    else
                    {
                        if (foundInList)
                            dictPeptideGroupsNew.Remove(peptideGroupDocNode.Name);
                        dictPeptideGroupsNew.Add(peptideGroupDocNode.Name, (PeptideGroupDocNode) newPeptideGroupDocNode);
                    }
                    // If we are only adding a single node, select it.
                    if (PeptideMatches.Count == 1)
                        selectedPath = new IdentityPath(new[] {peptideGroupDocNode.Id, newNodePep.Peptide});
                    // If the user only wants to add the first protein found,
                    // we break the foreach loop after peptide has been added to its first protein.)
                    if (FilterMultipleProteinMatches == BackgroundProteome.DuplicateProteinsFilter.FirstOccurence)
                        break;
                }
            }

            if (dictPeptideGroupsNew.Count == 0)
            {
                return document;
            }

            // Sort the peptides.
            var nodePepGroupsSortedChildren = new List<PeptideGroupDocNode>();
            foreach(PeptideGroupDocNode nodePepGroup in dictPeptideGroupsNew.Values)
            {
                var newChildren = nodePepGroup.Children.ToList();
                // Have to cast all children to PeptideDocNodes in order to sort.
                var newChildrenNodePeps = newChildren.Cast<PeptideDocNode>().ToList();
                newChildrenNodePeps.Sort(FastaSequence.ComparePeptides);
                nodePepGroupsSortedChildren.Add((PeptideGroupDocNode)
                    nodePepGroup.ChangeChildren(newChildrenNodePeps.Cast<DocNode>().ToArray()));
            }
            // Sort the proteins.
            nodePepGroupsSortedChildren.Sort((node1, node2) => Comparer<string>.Default.Compare(node1.Name, node2.Name));
            IdentityPath selPathTemp = selectedPath, nextAdd;
            document = document.AddPeptideGroups(nodePepGroupsSortedChildren, false,
                toPath, out selectedPath, out nextAdd);
            selectedPath = PeptideMatches.Count == 1 ? selPathTemp : selectedPath;
            return document;
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:101,代码来源:ViewLibraryPepMatching.cs

示例6: AddPeptidesToLibraryGroup

        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>();
            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));
            }

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

            // Use existing group by this name, if present.
            var nodePepGroupNew = FindPeptideGroupDocNode(document, Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Peptides);
            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(),
                                                          Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Peptides,
                                                          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;
            }
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:64,代码来源:ViewLibraryPepMatching.cs


注:本文中的SrmDocument.ReplaceChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。