Beispiel #1
0
                public override ComparisonKey Cache(ValueCache valueCache)
                {
                    var comparisonKey = this;

                    if (valueCache.TryGetCachedValue(ref comparisonKey))
                    {
                        return(comparisonKey);
                    }
                    ImmutableList <string> modificationNames = ModificationNames;

                    if (ModificationNames != null)
                    {
                        if (!valueCache.TryGetCachedValue(ref modificationNames))
                        {
                            modificationNames = ImmutableList.ValueOf(modificationNames.Select(valueCache.CacheValue));
                            modificationNames = valueCache.CacheValue(modificationNames);
                        }
                    }
                    comparisonKey = new Peptide(LibraryKey.ValueFromCache(valueCache))
                    {
                        ModificationIndexes = valueCache.CacheValue(ModificationIndexes),
                        ModificationNames   = modificationNames
                    };
                    return(valueCache.CacheValue(comparisonKey));
                }
Beispiel #2
0
        public static bool KeysMatch(LibraryKey key1, LibraryKey key2)
        {
            var comparisonKey1 = ComparisonKey.Get(key1);
            var comparisonKey2 = ComparisonKey.Get(key2);

            return(comparisonKey1.Compare(comparisonKey2, ComparisonLevel.Full) == 0 &&
                   comparisonKey1.AllModificationsMatch(comparisonKey2));
        }
Beispiel #3
0
        public override bool IsEquivalentTo(LibraryKey other)
        {
            var that = other as MoleculeLibraryKey;

            if (that == null)
            {
                return(false);
            }
            return(Equals(PreferredKey, that.PreferredKey) && Equals(Adduct, that.Adduct));
        }
Beispiel #4
0
        public IEnumerable <IndexItem> ItemsMatching(LibraryKey libraryKey, bool matchAdductAlso)
        {
            var         comparisonKey   = ComparisonKey.Get(libraryKey);
            IList <int> matchingIndexes = SearchEntries(comparisonKey,
                                                        matchAdductAlso
                    ? ComparisonLevel.Adduct
                    : ComparisonLevel.PrecisionIndependentModifications);

            return(matchingIndexes.Where(i => _allEntries[i].Key.AllModificationsMatch(comparisonKey)).Select(GetItem));
        }
Beispiel #5
0
            public IEnumerable <IndexItem> ItemsEqualTo(LibraryKey libraryKey)
            {
                var key = libraryKey as TKey;

                if (key == null)
                {
                    return(IndexItem.NONE);
                }
                return(ExactMatches(key));
            }
Beispiel #6
0
            public IEnumerable <IndexItem> ItemsMatchingWithoutModifications(LibraryKey libraryKey)
            {
                var key = libraryKey as TKey;

                if (key == null)
                {
                    return(IndexItem.NONE);
                }
                return(ItemsMatchingWithoutModifications(key));
            }
Beispiel #7
0
        public int IndexOf(LibraryKey libraryKey)
        {
            if (libraryKey == null)
            {
                return(-1);
            }
            var keyToFind = new ViewLibraryPepInfo(new LibKey(libraryKey));
            var range     = CollectionUtil.BinarySearch(_allEntries, entry => ComparePepInfos(entry, keyToFind));

            return(range.Length > 0 ? range.Start : -1);
        }
Beispiel #8
0
            public IEnumerable <IndexItem> ItemsMatching(LibraryKey libraryKey, bool matchAdductAlso)
            {
                var key = libraryKey as TKey;

                if (key == null)
                {
                    return(IndexItem.NONE);
                }
                var matches = ItemsMatching(key);

                return(matchAdductAlso ? matches.Where(item => Equals(item.LibraryKey.Adduct, libraryKey.Adduct)) : matches);
            }
Beispiel #9
0
        public IndexItem?Find(LibraryKey libraryKey)
        {
            var range = SearchEntries(libraryKey, ComparisonLevel.Full);

            foreach (var index in range)
            {
                if (Equals(libraryKey, _allEntries[index].Key.LibraryKey))
                {
                    return(GetItem(index));
                }
            }
            return(null);
        }
Beispiel #10
0
        public IList <IndexItem> ItemsWithUnmodifiedSequence(LibraryKey libraryKey)
        {
            var peptideLibraryKey = libraryKey as PeptideLibraryKey;

            if (peptideLibraryKey != null)
            {
                Range range;
                if (_indexByUnmodifiedSequence.TryGetValue(peptideLibraryKey.UnmodifiedSequence, out range))
                {
                    return(new IndexedSubList <IndexItem>(this, new RangeList(range)));
                }
                return(ImmutableList <IndexItem> .EMPTY);
            }
            var matchingIndexes = SearchEntries(libraryKey, ComparisonLevel.UnmodifiedSequence);

            return(new IndexedSubList <IndexItem>(this, matchingIndexes));
        }
Beispiel #11
0
        public static bool KeysMatch(LibraryKey key1, LibraryKey key2)
        {
            if (Equals(key1, key2))
            {
                return(true);
            }
            if (!Equals(key1.Adduct, key2.Adduct))
            {
                return(false);
            }
            var peptideKey1 = key1 as PeptideLibraryKey;
            var peptideKey2 = key2 as PeptideLibraryKey;

            if (peptideKey1 == null || peptideKey2 == null)
            {
                return(false);
            }
            if (!Equals(peptideKey1.UnmodifiedSequence, peptideKey2.UnmodifiedSequence))
            {
                return(false);
            }
            var mods1 = peptideKey1.GetModifications();
            var mods2 = peptideKey2.GetModifications();

            if (mods1.Count != mods2.Count)
            {
                return(false);
            }
            if (!mods1.Select(mod => mod.Key).SequenceEqual(mods2.Select(mod => mod.Key)))
            {
                return(false);
            }

            for (int i = 0; i < mods1.Count; i++)
            {
                if (!ModificationsMatch(mods1[i].Value, mods2[i].Value))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #12
0
            public static ComparisonKey Get(LibraryKey libraryKey)
            {
                var peptideLibraryKey = libraryKey as PeptideLibraryKey;

                if (peptideLibraryKey != null)
                {
                    return(new Peptide(peptideLibraryKey));
                }
                var moleculeLibraryKey = libraryKey as MoleculeLibraryKey;

                if (moleculeLibraryKey != null)
                {
                    return(new SmallMolecule(moleculeLibraryKey));
                }
                var precursorKey = libraryKey as PrecursorLibraryKey;

                if (precursorKey != null)
                {
                    return(new Precursor(precursorKey));
                }
                return(new ComparisonKey(KeyTypeEnum.unknown, libraryKey));
            }
Beispiel #13
0
 public IEnumerable <TItem> ItemsMatching(LibraryKey libraryKey, bool matchAdductAlso)
 {
     return(_index.ItemsMatching(libraryKey, matchAdductAlso).Select(GetItem));
 }
Beispiel #14
0
 public IndexItem(LibraryKey libraryKey, int originalIndex) : this()
 {
     LibraryKey    = libraryKey;
     OriginalIndex = originalIndex;
 }
Beispiel #15
0
 public IEnumerable <IndexItem> ItemsWithUnmodifiedSequence(LibraryKey libraryKey)
 {
     return(_subIndexes.SelectMany(index => index.ItemsMatchingWithoutModifications(libraryKey)));
 }
Beispiel #16
0
 public IEnumerable <IndexItem> ItemsMatching(LibraryKey libraryKey, bool matchAdductAlso)
 {
     return(_subIndexes.SelectMany(index => index.ItemsMatching(libraryKey, matchAdductAlso)));
 }
Beispiel #17
0
 public IndexItem?Find(LibraryKey libraryKey)
 {
     return(_subIndexes.SelectMany(index => index.ItemsEqualTo(libraryKey)).FirstOrDefault());
 }
Beispiel #18
0
        public int IndexOf(LibraryKey libraryKey)
        {
            var indexItem = _index.Find(libraryKey);

            return(indexItem.HasValue ? indexItem.Value.OriginalIndex : -1);
        }
Beispiel #19
0
 protected RangeList SearchEntries(LibraryKey libraryKey, ComparisonLevel level)
 {
     return(SearchEntries(ComparisonKey.Get(libraryKey), level));
 }
Beispiel #20
0
 public virtual bool IsEquivalentTo(LibraryKey that)
 {
     return(Equals(that));
 }
Beispiel #21
0
 protected ComparisonKey(KeyTypeEnum keyType, LibraryKey libraryKey)
 {
     LibraryKey = libraryKey;
     KeyType    = keyType;
 }
Beispiel #22
0
 public IEnumerable <KeyValuePair <LibKey, TItem> > KeyPairsMatching(LibraryKey libraryKey, bool matchAdductAlso)
 {
     return(_index.ItemsMatching(libraryKey, matchAdductAlso).Select(GetKeyPair));
 }
Beispiel #23
0
 private Peptide(LibraryKey libraryKey) : base(KeyTypeEnum.peptide, libraryKey)
 {
 }