Beispiel #1
0
 public override FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
 {
     if (bookmarkEnumerator.CurrentChromInfo == null)
     {
         var nodePep = bookmarkEnumerator.CurrentDocNode as PeptideDocNode;
         if (nodePep != null)
         {
             return(IsMatch(nodePep) ? new FindMatch(DisplayName) : null);
         }
         var nodeGroup = bookmarkEnumerator.CurrentDocNode as TransitionGroupDocNode;
         if (nodeGroup != null)
         {
             var nodeParent = bookmarkEnumerator.Document.FindNode(bookmarkEnumerator.IdentityPath.Parent)
                              as PeptideDocNode;
             return(!IsMatch(nodeParent) && IsMatch(nodeGroup) ? new FindMatch(DisplayName) : null);
         }
         var nodeTran = bookmarkEnumerator.CurrentDocNode as TransitionDocNode;
         if (nodeTran != null)
         {
             var nodeGrandParent = bookmarkEnumerator.Document.FindNode(bookmarkEnumerator.IdentityPath.Parent.Parent)
                                   as PeptideDocNode;
             var nodeParent = bookmarkEnumerator.Document.FindNode(bookmarkEnumerator.IdentityPath.Parent)
                              as TransitionGroupDocNode;
             return(!IsMatch(nodeGrandParent) && !IsMatch(nodeParent) && IsMatch(nodeParent, nodeTran) ? new FindMatch(DisplayName) : null);
         }
     }
     return(null);
 }
Beispiel #2
0
        public void TestForwardBackward()
        {
            var assembly = Assembly.GetAssembly(typeof(BookmarkEnumeratorTest));
            var stream   = assembly.GetManifestResourceStream(
                typeof(BookmarkEnumeratorTest).Namespace + ".BookmarkEnumeratorTest.sky");

            Assert.IsNotNull(stream);
            var document = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream);

            Assert.IsNotNull(document);
            var forwardEnumerator  = new BookmarkEnumerator(document);
            var backwardEnumerator = new BookmarkEnumerator(forwardEnumerator)
            {
                Forward = false
            };
            var forwardList  = new List <Bookmark>(forwardEnumerator);
            var backwardList = new List <Bookmark>(backwardEnumerator);

            Assert.AreNotEqual(0, forwardList.Count);
            Assert.AreEqual(forwardList.Count, backwardList.Count);

            // The very last location is the same for both the forwards and backwards enumerators.
            backwardList.Reverse(0, backwardList.Count - 1);
            CollectionAssert.AreEqual(forwardList, backwardList);

            var forwardSet = new HashSet <Bookmark>(forwardList);

            Assert.AreEqual(forwardList.Count, forwardSet.Count);
            forwardSet.UnionWith(backwardList);
            Assert.AreEqual(forwardList.Count, forwardSet.Count);
        }
 public override FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
 {
     if (bookmarkEnumerator.CurrentChromInfo == null)
     {
         var nodePep = bookmarkEnumerator.CurrentDocNode as PeptideDocNode;
         if (nodePep != null)
         {
             return IsMatch(nodePep) ? new FindMatch(DisplayName) : null;
         }
         var nodeGroup = bookmarkEnumerator.CurrentDocNode as TransitionGroupDocNode;
         if (nodeGroup != null)
         {
             var nodeParent = bookmarkEnumerator.Document.FindNode(bookmarkEnumerator.IdentityPath.Parent)
                              as PeptideDocNode;
             return !IsMatch(nodeParent) && IsMatch(nodeGroup) ? new FindMatch(DisplayName) : null;
         }
         var nodeTran = bookmarkEnumerator.CurrentDocNode as TransitionDocNode;
         if (nodeTran != null)
         {
             var nodeGrandParent = bookmarkEnumerator.Document.FindNode(bookmarkEnumerator.IdentityPath.Parent.Parent)
                              as PeptideDocNode;
             var nodeParent = bookmarkEnumerator.Document.FindNode(bookmarkEnumerator.IdentityPath.Parent)
                              as TransitionGroupDocNode;
             return !IsMatch(nodeGrandParent) && !IsMatch(nodeParent) && IsMatch(nodeParent, nodeTran) ? new FindMatch(DisplayName) : null;
         }
     }
     return null;
 }
Beispiel #4
0
 public FindResult(FindPredicate findPredicate, BookmarkEnumerator bookmarkEnumerator, FindMatch match)
 {
     FindPredicate = findPredicate;
     Bookmark      = bookmarkEnumerator.Current;
     Document      = bookmarkEnumerator.Document;
     LocationName  = bookmarkEnumerator.GetLocationName(findPredicate.DisplaySettings);
     LocationType  = bookmarkEnumerator.GetLocationType();
     FindMatch     = match;
     IsValid       = true;
 }
Beispiel #5
0
 public FindResult(FindPredicate findPredicate, BookmarkEnumerator bookmarkEnumerator, FindMatch match)
 {
     FindPredicate = findPredicate;
     Bookmark = bookmarkEnumerator.Current;
     Document = bookmarkEnumerator.Document;
     LocationName = bookmarkEnumerator.GetLocationName(findPredicate.DisplaySettings);
     LocationType = bookmarkEnumerator.GetLocationType();
     FindMatch = match;
     IsValid = true;
 }
 public override FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
 {
     var transitionChromInfo = bookmarkEnumerator.CurrentChromInfo as TransitionChromInfo;
     if (transitionChromInfo == null)
     {
         return null;
     }
     if (transitionChromInfo.IsEmpty)
     {
         return new FindMatch(Resources.UnintegratedTransitionFinder_Match_Unintegrated_transition);
     }
     return null;
 }
Beispiel #7
0
 public virtual FindMatch NextMatch(BookmarkEnumerator bookmarkEnumerator)
 {
     do
     {
         bookmarkEnumerator.MoveNext();
         var findMatch = Match(bookmarkEnumerator);
         if (findMatch != null)
         {
             return findMatch;
         }
     } while (!bookmarkEnumerator.AtStart);
     return null;
 }
        public override FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
        {
            if (bookmarkEnumerator.ResultsIndex == -1)
            {
                var pair = _pairs.Find(p => ReferenceEquals(p.Peptide, bookmarkEnumerator.CurrentDocNode));
                if (pair != null)
                {
                    var displayText = GetDisplayText(_displayCV, pair.Annotation);
                    return(new FindMatch(displayText));
                }
            }

            return(null);
        }
 public FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
 {
     var transitionGroupChromInfo = bookmarkEnumerator.CurrentChromInfo as TransitionGroupChromInfo;
     if (transitionGroupChromInfo != null)
     {
         return MatchTransitionGroup(transitionGroupChromInfo);
     }
     var transitionChromInfo = bookmarkEnumerator.CurrentChromInfo as TransitionChromInfo;
     if (transitionChromInfo != null)
     {
         return MatchTransition(transitionChromInfo);
     }
     return null;
 }
Beispiel #10
0
 public virtual IEnumerable<Bookmark> FindAll(SrmDocument document)
 {
     var bookmarkEnumerator = new BookmarkEnumerator(document);
     while (true)
     {
         bookmarkEnumerator.MoveNext();
         if (Match(bookmarkEnumerator) != null)
         {
             yield return bookmarkEnumerator.Current;
         }
         if (bookmarkEnumerator.AtStart)
         {
             yield break;
         }
     }
 }
 public override FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
 {
     var nodePep = bookmarkEnumerator.CurrentDocNode as PeptideDocNode;
     if (nodePep == null)
         return null;
     if (bookmarkEnumerator.CurrentChromInfo == null)
     {
         _isLastNodeMatch = IsMatch(nodePep);
         if (_isLastNodeMatch)
             return new FindMatch(string.Format(Resources.MissingScoresFinder_Match__0__missing_from_peptide, _calculatorName));
     }
     else if (IsMatch(bookmarkEnumerator.CurrentChromInfo, nodePep) && !_isLastNodeMatch)
     {
         return new FindMatch(string.Format(Resources.MissingScoresFinder_Match__0__missing_from_chromatogram_peak, _calculatorName));
     }
     return null;
 }
 public FindMatch NextMatch(BookmarkEnumerator bookmarkEnumerator)
 {
     var allBookmarks = new HashSet<Bookmark>(FindAll(bookmarkEnumerator.Document));
     if (allBookmarks.Count == 0)
     {
         return null;
     }
     do
     {
         bookmarkEnumerator.MoveNext();
         if (allBookmarks.Contains(bookmarkEnumerator.Current))
         {
             var findMatch = Match(bookmarkEnumerator);
             if (findMatch != null)
             {
                 return findMatch;
             }
         }
     } while (!bookmarkEnumerator.AtStart);
     return null;
 }
Beispiel #13
0
        public FindResult ChangeDocument(SrmDocument document)
        {
            var result = new FindResult(this)
            {
                Document = document
            };
            var       bookMarkEnumerator = BookmarkEnumerator.TryGet(document, Bookmark);
            FindMatch findMatch          = null;

            if (bookMarkEnumerator != null)
            {
                findMatch = FindPredicate.Match(bookMarkEnumerator);
            }
            if (findMatch == null)
            {
                result.IsValid = false;
            }
            else
            {
                result.IsValid   = true;
                result.FindMatch = findMatch;
            }
            return(result);
        }
        public void TestForwardBackward()
        {
            var assembly = Assembly.GetAssembly(typeof (BookmarkEnumeratorTest));
            var stream = assembly.GetManifestResourceStream(
                typeof (BookmarkEnumeratorTest).Namespace + ".BookmarkEnumeratorTest.sky");
            Assert.IsNotNull(stream);
            var document = (SrmDocument) new XmlSerializer(typeof (SrmDocument)).Deserialize(stream);
            Assert.IsNotNull(document);
            var forwardEnumerator = new BookmarkEnumerator(document);
            var backwardEnumerator = new BookmarkEnumerator(forwardEnumerator) {Forward = false};
            var forwardList = new List<Bookmark>(forwardEnumerator);
            var backwardList = new List<Bookmark>(backwardEnumerator);
            Assert.AreNotEqual(0, forwardList.Count);
            Assert.AreEqual(forwardList.Count, backwardList.Count);

            // The very last location is the same for both the forwards and backwards enumerators.
            backwardList.Reverse(0, backwardList.Count - 1);
            CollectionAssert.AreEqual(forwardList, backwardList);

            var forwardSet = new HashSet<Bookmark>(forwardList);
            Assert.AreEqual(forwardList.Count, forwardSet.Count);
            forwardSet.UnionWith(backwardList);
            Assert.AreEqual(forwardList.Count, forwardSet.Count);
        }
Beispiel #15
0
 public abstract FindMatch Match(BookmarkEnumerator bookmarkEnumerator);
Beispiel #16
0
 public FindResult FindNext(BookmarkEnumerator bookmarkEnumerator)
 {
     var customMatches = new Dictionary<Bookmark, FindMatch>();
     foreach (var finder in FindOptions.CustomFinders)
     {
         var customEnumerator = new BookmarkEnumerator(bookmarkEnumerator);
         var nextMatch = finder.NextMatch(customEnumerator);
         if (nextMatch == null || customMatches.ContainsKey(customEnumerator.Current))
         {
             continue;
         }
         customMatches.Add(customEnumerator.Current, nextMatch);
     }
     do
     {
         bookmarkEnumerator.MoveNext();
         FindMatch findMatch;
         if (customMatches.TryGetValue(bookmarkEnumerator.Current, out findMatch))
         {
             return new FindResult(this, bookmarkEnumerator, findMatch);
         }
         findMatch = MatchInternal(bookmarkEnumerator);
         if (findMatch != null)
         {
             return new FindResult(this, bookmarkEnumerator, findMatch);
         }
     } while (!bookmarkEnumerator.AtStart);
     return null;
 }
Beispiel #17
0
 public FindMatch Match(BookmarkEnumerator bookmarkEnumerator)
 {
     return MatchCustom(bookmarkEnumerator) ?? MatchInternal(bookmarkEnumerator);
 }
Beispiel #18
0
 FindMatch MatchCustom(BookmarkEnumerator bookmarkEnumerator)
 {
     foreach (var finder in FindOptions.CustomFinders)
     {
         var findMatch = finder.Match(bookmarkEnumerator);
         if (findMatch != null)
         {
             return findMatch;
         }
     }
     return null;
 }
Beispiel #19
0
 private FindMatch MatchInternal(BookmarkEnumerator bookmarkEnumerator)
 {
     if (string.IsNullOrEmpty(FindOptions.Text))
     {
         return null;
     }
     var chromInfo = bookmarkEnumerator.CurrentChromInfo;
     if (chromInfo != null)
     {
         return MatchAnnotations(GetAnnotations(chromInfo));
     }
     var docNode = bookmarkEnumerator.CurrentDocNode;
     if (docNode == null)
     {
         return null;
     }
     return MatchText(docNode.GetDisplayText(DisplaySettings))
         ?? MatchAnnotations(docNode.Annotations);
 }
Beispiel #20
0
        public void HighlightFindResult(FindResult findResult)
        {
            if (!IsComplete)
            {
                _pendingFindResult = findResult;
                return;
            }
            var bookmarkEnumerator = BookmarkEnumerator.TryGet(_dataSchema.Document, findResult.Bookmark);

            if (bookmarkEnumerator == null)
            {
                return;
            }
            var chromInfo = bookmarkEnumerator.CurrentChromInfo;

            if (chromInfo == null)
            {
                return;
            }
            int?iRowMatch = null;

            for (int iRow = 0; iRow < BindingListSource.Count; iRow++)
            {
                var rowItem = BindingListSource[iRow] as RowItem;
                if (rowItem == null)
                {
                    continue;
                }
                var replicate = rowItem.Value as Replicate;
                if (replicate != null)
                {
                    if (replicate.Files.Any(file => ReferenceEquals(file.ChromFileInfoId, chromInfo.FileId)))
                    {
                        iRowMatch = iRow;
                        break;
                    }
                }
                var result = rowItem.Value as Result;
                if (null != result)
                {
                    if (ReferenceEquals(result.GetResultFile().ChromFileInfoId, chromInfo.FileId))
                    {
                        iRowMatch = iRow;
                        break;
                    }
                }
            }
            if (!iRowMatch.HasValue)
            {
                return;
            }
            BindingListSource.Position = iRowMatch.Value;
            DataGridViewColumn column;

            if (findResult.FindMatch.Note)
            {
                column = FindColumn(PropertyPath.Root.Property("Note")); // Not L10N
            }
            else if (findResult.FindMatch.AnnotationName != null)
            {
                column = FindColumn(PropertyPath.Root.Property(
                                        AnnotationDef.ANNOTATION_PREFIX + findResult.FindMatch.AnnotationName));
            }
            else
            {
                return;
            }
            if (null != column && null != DataGridView.CurrentRow)
            {
                DataGridView.CurrentCell = DataGridView.CurrentRow.Cells[column.Index];
            }
        }
Beispiel #21
0
 public IEnumerable<FindResult> FindAll(ILongWaitBroker longWaitBroker, SrmDocument document)
 {
     longWaitBroker.Message = Resources.FindPredicate_FindAll_Found_0_matches;
     var customMatches = new HashSet<Bookmark>[FindOptions.CustomFinders.Count];
     for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++)
     {
         var customFinder = FindOptions.CustomFinders[iFinder];
         var bookmarkSet = new HashSet<Bookmark>();
         longWaitBroker.Message = string.Format(Resources.FindPredicate_FindAll_Searching_for__0__, customFinder.DisplayName);
         foreach (var bookmark in customFinder.FindAll(document))
         {
             if (longWaitBroker.IsCanceled)
             {
                 yield break;
             }
             bookmarkSet.Add(bookmark);
         }
         customMatches[iFinder] = bookmarkSet;
     }
     var bookmarkEnumerator = new BookmarkEnumerator(document);
     int matchCount = 0;
     do
     {
         bookmarkEnumerator.MoveNext();
         if (longWaitBroker.IsCanceled)
         {
             yield break;
         }
         FindMatch findMatch = null;
         for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++)
         {
             if (customMatches[iFinder].Contains(bookmarkEnumerator.Current))
             {
                 findMatch = FindOptions.CustomFinders[iFinder].Match(bookmarkEnumerator);
             }
         }
         findMatch = findMatch ?? MatchInternal(bookmarkEnumerator);
         if (findMatch != null)
         {
             matchCount++;
             longWaitBroker.Message = matchCount == 1
                                          ? Resources.FindPredicate_FindAll_Found_1_match
                                          : string.Format(Resources.FindPredicate_FindAll_Found__0__matches, matchCount);
             yield return new FindResult(this, bookmarkEnumerator, findMatch);
         }
     } while (!bookmarkEnumerator.AtStart);
 }