Esempio n. 1
0
        private void FindById(IProteoformModificationLookup lookup, ProFormaKey key, ProFormaEvidenceType evidenceType,
                              int correctId, string extraPrefix)
        {
            Assert.IsNotNull(lookup.GetModification(new ProFormaDescriptor(key, evidenceType, $"{extraPrefix}{correctId}")));
            Assert.IsNotNull(lookup.GetModification(new ProFormaDescriptor(key, evidenceType, $"{correctId}")));

            Assert.Throws <ProteoformModificationLookupException>(
                () => lookup.GetModification(new ProFormaDescriptor(key, evidenceType, "-1")));
            Assert.Throws <ProteoformModificationLookupException>(
                () => lookup.GetModification(new ProFormaDescriptor(key, evidenceType, $"{extraPrefix}0")));
            Assert.Throws <ProteoformModificationLookupException>(
                () => lookup.GetModification(new ProFormaDescriptor(key, evidenceType, $"{extraPrefix}2200")));
        }
Esempio n. 2
0
        private void FindByName(IProteoformModificationLookup lookup, ProFormaEvidenceType evidenceType,
                                bool isDefault, string correctName)
        {
            if (isDefault)
            {
                Assert.IsNotNull(lookup.GetModification(new ProFormaDescriptor(ProFormaKey.Name, ProFormaEvidenceType.None, correctName)));
            }

            Assert.IsNotNull(lookup.GetModification(new ProFormaDescriptor(ProFormaKey.Name, evidenceType, correctName)));

            Assert.Throws <ProteoformModificationLookupException>(
                () => lookup.GetModification(new ProFormaDescriptor(ProFormaKey.Name, ProFormaEvidenceType.None, "Something")));
            Assert.Throws <ProteoformModificationLookupException>(
                () => lookup.GetModification(new ProFormaDescriptor(ProFormaKey.Name, evidenceType, "Something")));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public void FormulaLookup()
        {
            string             formulaString      = "C2H2O";
            ProFormaDescriptor proFormaDescriptor = new ProFormaDescriptor(ProFormaKey.Formula, formulaString);
            ChemicalFormula    chemicalFormula    = new ChemicalFormula(new IEntityCardinality <IElement>[]
            {
                new EntityCardinality <IElement>(_elementProvider.GetElement("C"), 2),
                new EntityCardinality <IElement>(_elementProvider.GetElement("H"), 2),
                new EntityCardinality <IElement>(_elementProvider.GetElement("O"), 1),
            });

            var proteoformModification = _formulaLookup.GetModification(proFormaDescriptor);

            Assert.IsInstanceOf(typeof(IHasChemicalFormula), proteoformModification);
            var formulaMod = (IHasChemicalFormula)proteoformModification;

            Assert.AreEqual(chemicalFormula, formulaMod.GetChemicalFormula());
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void PsiModIsotope()
        {
            var parser = new PsiModOboParser();

            PsiModTerm[] modifications = parser.Parse(PsiModOboParserTest.GetFilePath()).ToArray();

            PsiModTerm psiMod402 = modifications.Single(x => x.Id == "MOD:00402");
            IProteoformModificationLookup psiModLookup = PsiModModificationLookup.CreateFromModifications(new[] { psiMod402 },
                                                                                                          _elementProvider);

            this.FindById(psiModLookup, ProFormaKey.Identifier, ProFormaEvidenceType.PsiMod, 402, "MOD:");

            var mod = psiModLookup.GetModification(new ProFormaDescriptor(ProFormaKey.Identifier,
                                                                          ProFormaEvidenceType.PsiMod, "MOD:00402"));

            ChemicalFormula chemicalFormula = new ChemicalFormula(
                new IEntityCardinality <IElement>[]
            {
                new EntityCardinality <IElement>(_elementProvider.GetElement("C"), 22),
                new EntityCardinality <IElement>(_elementProvider.GetElement("H", 1), 30),
                new EntityCardinality <IElement>(_elementProvider.GetElement("H", 2), 8),
                new EntityCardinality <IElement>(_elementProvider.GetElement("N"), 4),
                new EntityCardinality <IElement>(_elementProvider.GetElement("O"), 6),
                new EntityCardinality <IElement>(_elementProvider.GetElement("S"), 1),
            });

            Assert.IsInstanceOf(typeof(IHasChemicalFormula), mod);
            var formulaMod = (IHasChemicalFormula)mod;

            Assert.IsTrue(chemicalFormula.Equals(formulaMod.GetChemicalFormula()));

            Assert.IsInstanceOf(typeof(IIdentifiable), mod);
            var idMod = (IIdentifiable)mod;

            Assert.AreEqual("MOD:00402", idMod.Id);
            Assert.AreEqual("Gygi ICAT(TM) d8 modified cysteine", idMod.Name);
        }
Esempio n. 8
0
 private void InvalidIdHandling(string id, IProteoformModificationLookup lookup, ProFormaKey key,
                                ProFormaEvidenceType evidenceType = ProFormaEvidenceType.None)
 {
     Assert.Throws <ProteoformModificationLookupException>(
         () => lookup.GetModification(new ProFormaDescriptor(key, evidenceType, id)));
 }