Example #1
0
        public void DescriptorHandling()
        {
            this.DescriptorHandling(_unimodLookup, ProFormaEvidenceType.Unimod, true);
            this.DescriptorHandling(_residLookup, ProFormaEvidenceType.Resid, false);
            this.DescriptorHandling(_psiModLookup, ProFormaEvidenceType.PsiMod, true);
            this.DescriptorHandling(_uniProtModLookup, ProFormaEvidenceType.UniProt, false);

            Assert.IsTrue(_formulaLookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Formula, "Anything")));
        }
Example #2
0
        public void InvalidIntegerHandling()
        {
            var descriptor = new ProFormaDescriptor(ProFormaKey.Name, ProFormaEvidenceType.Unimod, "abc");

            // I want this to return true and then throw an exception later.
            // This gives me an opportunity to give a meaningful error (and not just return false)

            // In this case, it is also obvious that the Unimod handler was intended, so an attempt to create
            //  a modification should be made.
            Assert.True(_unimodLookup.CanHandleDescriptor(descriptor));
            Assert.Throws <ProteoformModificationLookupException>(() => _unimodLookup.GetModification(descriptor));
        }
Example #3
0
        private IProteoformMassDelta?GetModification(IList <ProFormaDescriptor>?descriptors, IProteoformModificationLookup modificationLookup,
                                                     string multipleModsErrorMessage)
        {
            IProteoformMassDelta?modification = null;

            if (descriptors != null && descriptors.Count > 0)
            {
                if (modificationLookup == null)
                {
                    throw new ProteoformGroupCreateException("Cannot lookup tag because lookup wasn't provided.");
                }

                foreach (var descriptor in descriptors)
                {
                    IProteoformMassDelta?mod = null;

                    if (modificationLookup.CanHandleDescriptor(descriptor))
                    {
                        mod = modificationLookup.GetModification(descriptor);
                    }
                    else
                    {
                        throw new ProteoformGroupCreateException($"Couldn't handle descriptor {descriptor}.");
                    }

                    if (modification == null)
                    {
                        modification = mod;
                    }
                    else if (mod != null)
                    {
                        if (mod is IHasChemicalFormula form1 &&
                            modification is IHasChemicalFormula form2 &&
                            !form1.GetChemicalFormula().Equals(form2.GetChemicalFormula()))
                        {
                            throw new ProteoformGroupCreateException(multipleModsErrorMessage);
                        }
                    }
                }
            }

            return(modification);
        }
Example #4
0
        private void DescriptorHandling(IProteoformModificationLookup lookup, ProFormaEvidenceType key, bool isDefault)
        {
            // If the key is a specific mod type, always handle
            Assert.IsTrue(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, key, "Anything")));
            Assert.IsTrue(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, key, "")));
            Assert.IsTrue(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, key, null)));

            // If using modification name, must have no ending or end in proper ending
            Assert.IsTrue(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, key, "Something")));
            Assert.IsFalse(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, "Something")));
            Assert.IsFalse(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, ProFormaEvidenceType.Brno, "Something")));

            // This is malformed and must be interpreted as a mod "name" ... will fail when looking up modification
            //Assert.AreEqual(lookup.CanHandleDescriptor(new ProFormaDescriptor(ProFormaKey.Name, $"Something [{key}]")), isDefault);
        }
Example #5
0
        private IProteoformMassDelta?GetModification(IProFormaDescriptor?descriptor, IProteoformModificationLookup modificationLookup)
        {
            IProteoformMassDelta?modification = null;

            if (descriptor != null)
            {
                if (modificationLookup == null)
                {
                    throw new ProteoformGroupCreateException("Cannot lookup tag because lookup wasn't provided.");
                }

                if (modificationLookup.CanHandleDescriptor(descriptor))
                {
                    return(modificationLookup.GetModification(descriptor));
                }

                throw new ProteoformGroupCreateException($"Couldn't handle descriptor {descriptor}.");
            }

            return(modification);
        }