Exemple #1
0
        public IEnumerable<DigestedPeptide> Digest(Protein protein)
        {
            Regex regex = new Regex(Regex);
            int begin = 0;
            int len = protein.Sequence.Length;
            while (begin < len)
            {
                int end = begin;
                int endFirst = begin;
                int missed = 0;
                do
                {
                    string sequence = protein.Sequence;
                    Match m = regex.Match(sequence, end);
                    end = (m.Success ? m.Index + 1 : len);

                    // Save the end of the first cleavage
                    if (missed == 0)
                        endFirst = end;
                    // TODO(nicksh)
                    //// Deal with 'ragged ends', or cleavages one amino acid apart
                    //// i.e. KR, RR, etc. for trypsin
                    //if (settings.ExcludeRaggedEnds && end < len)
                    //{
                    //    Match mNext = regex.Match(sequence, end);
                    //    if (mNext.Success && mNext.Index == end)
                    //    {
                    //        // If there are no missed cleavages, then move the
                    //        // begin index to the next cleavage point that is
                    //        // not part of a run.
                    //        if (missed == 0)
                    //            endFirst = GetDiscontiguousCleavageIndex(regex, mNext, sequence);
                    //        break;
                    //    }
                    //}

                    // Single amino acid peptides have no fragment ions.
                    int count = end - begin;
                    if (count > 1 && sequence.IndexOfAny(new[] { '*', '-' }, begin, count) == -1) // Not L10N
                    {
                        DigestedPeptide peptide = new DigestedPeptide
                                                      {
                                                          Index = begin,
                                                          Sequence = sequence.Substring(begin, end - begin)
                                                      };
                        yield return peptide;
                    }

                    // Increment missed cleavages for next loop.
                    missed++;

                }
                while (end < len);

                begin = endFirst;
            }
        }
 internal ProteolyticPeptide(Protein protein, int oneBasedStartResidueInProtein, int oneBasedEndResidueInProtein, int missedCleavages, CleavageSpecificity cleavageSpecificityForFdrCategory, string peptideDescription = null, string baseSequence = null)
 {
     _protein = protein;
     OneBasedStartResidueInProtein = oneBasedStartResidueInProtein;
     OneBasedEndResidueInProtein   = oneBasedEndResidueInProtein;
     MissedCleavages = missedCleavages;
     CleavageSpecificityForFdrCategory = cleavageSpecificityForFdrCategory;
     PeptideDescription = peptideDescription;
     _baseSequence      = baseSequence;
 }
Exemple #3
0
        public string ToInsert()
        {
            var weight  = Weight.ToString().Replace(',', '.');
            var kcal    = Kcal.ToString().Replace(',', '.');
            var protein = Protein.ToString().Replace(',', '.');
            var fat     = Fat.ToString().Replace(',', '.');
            var carbs   = Carbs.ToString().Replace(',', '.');

            return($"('{ID}', '{Name}', '{weight}', '{kcal}', '{protein}', '{fat}', '{carbs}', '{DietType}')");
        }
Exemple #4
0
        public FastaSequence MakeFastaSequence(Protein protein)
        {
            List <ProteinMetadata> alternativeProteins = new List <ProteinMetadata>();

            foreach (var alternativeName in protein.AlternativeNames)
            {
                alternativeProteins.Add(alternativeName);
            }
            return(new FastaSequence(protein.ProteinMetadata.Name, protein.ProteinMetadata.Description, alternativeProteins, protein.Sequence));
        }
Exemple #5
0
        protected override IEnumerable <Peptide> SaveFileToEnumerable(System.IO.TextReader textReader, Dictionary <string, int> columnMapping)
        {
            var    peptides = new List <Peptide>();
            string line;

            while ((line = textReader.ReadLine()) != null)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var columns = line.Split('\t', '\n');

                var peptide = new Peptide();
                if (columnMapping.ContainsKey("Peptide.Scan"))
                {
                    peptide.Scan = Convert.ToInt32(columns[columnMapping["Peptide.Scan"]]);
                }
                if (columnMapping.ContainsKey("Peptide.Charge"))
                {
                    peptide.ChargeState = Convert.ToInt32(columns[columnMapping["Peptide.Charge"]]);
                }
                if (columnMapping.ContainsKey("Peptide.Protein"))
                {
                    var protein = new Protein
                    {
                        ProteinDescription = columns[columnMapping["Peptide.Protein"]]
                    };
                    peptide.ProteinList.Add(protein);
                }
                if (columnMapping.ContainsKey("Peptide.Sequence"))
                {
                    peptide.Sequence = columns[columnMapping["Peptide.Sequence"]];
                }
                if (columnMapping.ContainsKey("Peptide.Score"))
                {
                    peptide.Score = Convert.ToDouble(columns[columnMapping["Peptide.Score"]]);
                }
                if (columnMapping.ContainsKey("Peptide.ScorePRISM"))
                {
                    peptide.Score = Convert.ToDouble(columns[columnMapping["Peptide.ScorePRISM"]]);
                }
                if (columnMapping.ContainsKey("Peptide.evalue"))
                {
                    peptide.Score = Convert.ToDouble(columns[columnMapping["peptide.evalue"]]);
                }
                if (columnMapping.ContainsKey("Peptide.PrecursorMz"))
                {
                    peptide.Mz = Convert.ToDouble(columns[columnMapping["Peptide.PrecursorMz"]]);
                }
                peptides.Add(peptide);
            }
            return(peptides);
        }
Exemple #6
0
        public static void XlTestXlPosCal()
        {
            var      prot     = new Protein("MNNNKQQQQ", null);
            Protease protease = new Protease("New Custom Protease", new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("K", TerminusType.C)
            }, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            DigestionParams             digestionParams       = new DigestionParams(protease: protease.Name, minPeptideLength: 1, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <ModificationWithMass> variableModifications = new List <ModificationWithMass>();

            var ye = prot.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList();

            var pep = ye[0];

            Assert.AreEqual(pep.BaseSequence, "MNNNK");
            CrosslinkerTypeClass crosslinker = new CrosslinkerTypeClass();

            crosslinker.SelectCrosslinker(CrosslinkerType.DSS);
            Assert.AreEqual(crosslinker.CrosslinkerModSites, "K");
            Assert.AreEqual(Residue.GetResidue(crosslinker.CrosslinkerModSites).MonoisotopicMass, 128.09496301518999, 1e-9);
            var n = pep.CompactPeptide(TerminusType.None).NTerminalMasses;
            var c = pep.CompactPeptide(TerminusType.None).CTerminalMasses;

            Assert.AreEqual(n.Count(), 4);
            Assert.AreEqual(c.Count(), 4);
            Assert.AreEqual(c[0], 128.09496301518999, 1e-6);
            var x = PsmCross.XlPosCal(pep.CompactPeptide(TerminusType.None), crosslinker.CrosslinkerModSites).ToArray();

            Assert.AreEqual(x[0], 4);

            var pep2 = ye[2];

            Assert.AreEqual("MNNNKQQQQ", pep2.BaseSequence);
            var n2 = pep2.CompactPeptide(TerminusType.None).NTerminalMasses;
            var c2 = pep2.CompactPeptide(TerminusType.None).CTerminalMasses;

            Assert.AreEqual(n2.Count(), 8);
            Assert.AreEqual(c2.Count(), 8);
            Assert.AreEqual(n2[4] - n2[3], 128.09496301518999, 1e-6);
            var x2 = PsmCross.XlPosCal(pep2.CompactPeptide(TerminusType.None), crosslinker.CrosslinkerModSites).ToArray();

            Assert.AreEqual(x2[0], 4);

            //Test crosslinker with multiple types of mod
            var protSTC = new Protein("GASTACK", null);
            var peps    = protSTC.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList();
            var pepSTC  = peps[0];

            Assert.AreEqual(pepSTC.BaseSequence, "GASTACK");
            CrosslinkerTypeClass crosslinker2 = new CrosslinkerTypeClass("ST", "C", "crosslinkerSTC", false, -18.01056, 0, 0, 0, 0, 0, 0);
            string crosslinkerModSitesAll     = new string((crosslinker2.CrosslinkerModSites + crosslinker2.CrosslinkerModSites2).ToCharArray().Distinct().ToArray());

            Assert.AreEqual(crosslinkerModSitesAll, "STC");
        }
        /// <summary>
        /// Gets peptides for semispecific digestion of a protein
        ///
        /// semi-specific search enters here...
        /// </summary>
        /// <param name="protein"></param>
        /// <returns></returns>
        public IEnumerable <PeptideWithSetModifications> SemiSpecificDigestion(Protein protein)
        {
            List <ProteolyticPeptide> intervals     = new List <ProteolyticPeptide>();
            List <int> oneBasedIndicesToCleaveAfter = Protease.GetDigestionSiteIndices(protein.BaseSequence);

            for (int i = 0; i < oneBasedIndicesToCleaveAfter.Count - MaximumMissedCleavages - 1; i++)
            {
                if (Protease.Retain(i, InitiatorMethionineBehavior, protein[0]) &&
                    Protease.OkayLength(oneBasedIndicesToCleaveAfter[i + MaximumMissedCleavages + 1] - oneBasedIndicesToCleaveAfter[i], MinPeptidesLength, MaxPeptidesLength))
                {
                    intervals.Add(new ProteolyticPeptide(protein, oneBasedIndicesToCleaveAfter[i] + 1, oneBasedIndicesToCleaveAfter[i + MaximumMissedCleavages + 1],
                                                         oneBasedIndicesToCleaveAfter[i + MaximumMissedCleavages + 1] - oneBasedIndicesToCleaveAfter[i], "semi"));
                }

                if (Protease.Cleave(i, InitiatorMethionineBehavior, protein[0]) &&
                    Protease.OkayLength(oneBasedIndicesToCleaveAfter[i + MaximumMissedCleavages + 1] - 1, MinPeptidesLength, MaxPeptidesLength))
                {
                    intervals.Add(new ProteolyticPeptide(protein, 2, oneBasedIndicesToCleaveAfter[i + MaximumMissedCleavages + 1],
                                                         oneBasedIndicesToCleaveAfter[i + MaximumMissedCleavages + 1] - 1, "semi:M cleaved"));
                }
            }

            int lastIndex = oneBasedIndicesToCleaveAfter.Count - 1;
            int maxIndex  = MaximumMissedCleavages < lastIndex ? MaximumMissedCleavages : lastIndex;

            for (int i = 1; i <= maxIndex; i++)
            {
                if (DigestionParams.TerminusTypeSemiProtease == FragmentationTerminus.N) //tricky, it's N because we want the extra peptide at the C terminus |_
                {
                    if (Protease.OkayLength(oneBasedIndicesToCleaveAfter[lastIndex] - oneBasedIndicesToCleaveAfter[lastIndex - i], MinPeptidesLength, MaxPeptidesLength))
                    {
                        intervals.Add(new ProteolyticPeptide(protein, oneBasedIndicesToCleaveAfter[lastIndex - i] + 1, oneBasedIndicesToCleaveAfter[lastIndex],
                                                             oneBasedIndicesToCleaveAfter[lastIndex] - oneBasedIndicesToCleaveAfter[lastIndex - i], "semiN"));
                    }
                }
                else //TerminusType.C
                {
                    if (Protease.OkayLength(oneBasedIndicesToCleaveAfter[i] - oneBasedIndicesToCleaveAfter[0], MinPeptidesLength, MaxPeptidesLength))
                    {
                        intervals.Add(new ProteolyticPeptide(protein, oneBasedIndicesToCleaveAfter[0] + 1, oneBasedIndicesToCleaveAfter[i],
                                                             oneBasedIndicesToCleaveAfter[i] - oneBasedIndicesToCleaveAfter[0], "semiC"));
                    }
                }
            }

            // Also digest using the proteolysis product start/end indices
            intervals.AddRange(
                protein.ProteolysisProducts
                .Where(proteolysisProduct => proteolysisProduct.OneBasedEndPosition.HasValue && proteolysisProduct.OneBasedBeginPosition.HasValue &&
                       (proteolysisProduct.OneBasedBeginPosition != 1 || proteolysisProduct.OneBasedEndPosition != protein.Length))
                .Select(proteolysisProduct => new ProteolyticPeptide(protein, proteolysisProduct.OneBasedBeginPosition.Value, proteolysisProduct.OneBasedEndPosition.Value,
                                                                     0, proteolysisProduct.Type + " start")));

            return(intervals.SelectMany(peptide => peptide.GetModifiedPeptides(AllKnownFixedModifications, DigestionParams, VariableModifications)));
        }
        public static void TestUniProtGptmdConflict()
        {
            // this unit test checks to make sure GPTMD does not annotate mods at residues on
            // proteins where the equivalent uniprot mod already exists

            Modification uniProtPhospho = GlobalVariables.AllModsKnown.First(p => p.ModificationType == "UniProt" && p.IdWithMotif.Contains("Phosphoserine"));
            Modification mmPhospho      = GlobalVariables.AllModsKnown.First(p => p.ModificationType == "Common Biological" && p.IdWithMotif.Contains("Phosphorylation on S"));

            Protein protein = new Protein("PEPTIDESK", "test",
                                          oneBasedModifications: new Dictionary <int, List <Modification> >()
            {
                { 8, new List <Modification> {
                      uniProtPhospho
                  } }
            });

            PeptideWithSetModifications pep = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First(p => p.AllModsOneIsNterminus.Count == 0);

            // mod should not fit anywhere on the protein
            for (int i = 0; i < pep.Length; i++)
            {
                bool modFits = GptmdEngine.ModFits(mmPhospho, protein, i + 1, pep.Length, pep.OneBasedStartResidueInProtein + i);

                Assert.That(!modFits);
            }

            // the following code is just a control to make sure the phosphorylation actually does fit
            // at the given residue if the UniProt phosphorylation is not already present
            var someOtherSMod = GlobalVariables.AllModsKnown.Where(p => p.ModificationType == "Common Biological" && p.IdWithMotif.Contains("HexNAc on S")).First();

            protein = new Protein("PEPTIDESK", "test",
                                  oneBasedModifications: new Dictionary <int, List <Modification> >()
            {
                { 8, new List <Modification> {
                      someOtherSMod
                  } }
            });

            pep = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First(p => p.AllModsOneIsNterminus.Count == 0);

            // mod should fit at position 8
            for (int i = 0; i < pep.Length; i++)
            {
                bool modFits = GptmdEngine.ModFits(mmPhospho, protein, i + 1, pep.Length, pep.OneBasedStartResidueInProtein + i);

                if (i + 1 == 8)
                {
                    Assert.That(modFits);
                }
                else
                {
                    Assert.That(!modFits);
                }
            }
        }
        public static IProteinService CreateProteinService()
        {
            var service = new ProteinService();

            var protein = new Protein();

            protein.ProjectNumber = 6600;
            protein.WorkUnitName  = "WorkUnitName";
            protein.Core          = "GROGPU2";
            protein.Credit        = 450;
            protein.KFactor       = 0;
            protein.Frames        = 100;
            protein.NumberOfAtoms = 5000;
            protein.PreferredDays = 2;
            protein.MaximumDays   = 3;
            service.Add(protein);

            protein = new Protein();
            protein.ProjectNumber = 5797;
            protein.WorkUnitName  = "WorkUnitName2";
            protein.Core          = "GROGPU2";
            protein.Credit        = 675;
            protein.KFactor       = 2.3;
            protein.Frames        = 100;
            protein.NumberOfAtoms = 7000;
            protein.PreferredDays = 2;
            protein.MaximumDays   = 3;
            service.Add(protein);

            protein = new Protein();
            protein.ProjectNumber = 8011;
            protein.WorkUnitName  = "WorkUnitName3";
            protein.Core          = "GRO-A4";
            protein.Credit        = 106.6;
            protein.KFactor       = 0.75;
            protein.Frames        = 100;
            protein.NumberOfAtoms = 9000;
            protein.PreferredDays = 2.13;
            protein.MaximumDays   = 4.62;
            service.Add(protein);

            protein = new Protein();
            protein.ProjectNumber = 6903;
            protein.WorkUnitName  = "WorkUnitName4";
            protein.Core          = "GRO-A5";
            protein.Credit        = 22706;
            protein.KFactor       = 38.05;
            protein.Frames        = 100;
            protein.NumberOfAtoms = 11000;
            protein.PreferredDays = 5;
            protein.MaximumDays   = 12;
            service.Add(protein);

            return(service);
        }
Exemple #10
0
        public void Calculate()
        {
            Protein value = _proteinService.Get(SelectedProject);

            if (value == null)
            {
                return;
            }
            Protein protein = CopyProtein(value);

            if (PreferredDeadlineChecked)
            {
                protein.PreferredDays = PreferredDeadline;
            }
            if (FinalDeadlineChecked)
            {
                protein.MaximumDays = FinalDeadline;
            }
            if (KFactorChecked)
            {
                protein.KFactor = KFactor;
            }

            TimeSpan frameTime        = TimeSpan.FromMinutes(TpfMinutes).Add(TimeSpan.FromSeconds(TpfSeconds));
            TimeSpan totalTimeByFrame = TimeSpan.FromSeconds(frameTime.TotalSeconds * protein.Frames);
            TimeSpan totalTimeByUser  = totalTimeByFrame;

            if (TotalWuTimeEnabled)
            {
                totalTimeByUser = TimeSpan.FromMinutes(TotalWuTimeMinutes).Add(TimeSpan.FromSeconds(TotalWuTimeSeconds));
                // user time is less than total time by frame, not permitted
                if (totalTimeByUser < totalTimeByFrame)
                {
                    totalTimeByUser = totalTimeByFrame;
                }
            }

            var decimalPlaces = _prefs.Get <int>(Preference.DecimalPlaces);
            var noBonusValues = protein.GetProductionValues(frameTime, TimeSpan.Zero);
            var bonusByUserSpecifiedTimeValues = protein.GetProductionValues(frameTime, totalTimeByUser);
            var bonusByFrameTimeValues         = protein.GetProductionValues(frameTime, totalTimeByFrame);

            CoreName          = protein.Core;
            SlotType          = protein.Core.ToSlotType().ToString();
            NumberOfAtoms     = protein.NumberOfAtoms;
            CompletionTime    = Math.Round((TotalWuTimeEnabled ? totalTimeByUser.TotalDays : totalTimeByFrame.TotalDays), decimalPlaces);
            PreferredDeadline = protein.PreferredDays;
            FinalDeadline     = protein.MaximumDays;
            KFactor           = protein.KFactor;
            BonusMultiplier   = Math.Round((TotalWuTimeEnabled ? bonusByUserSpecifiedTimeValues.Multiplier : bonusByFrameTimeValues.Multiplier), decimalPlaces);
            BaseCredit        = noBonusValues.Credit;
            TotalCredit       = Math.Round((TotalWuTimeEnabled ? bonusByUserSpecifiedTimeValues.Credit : bonusByFrameTimeValues.Credit), decimalPlaces);
            BasePpd           = noBonusValues.PPD;
            TotalPpd          = Math.Round((TotalWuTimeEnabled ? bonusByUserSpecifiedTimeValues.PPD : bonusByFrameTimeValues.PPD), decimalPlaces);
        }
 /// <summary>
 /// Adds the protein to the target, and maps the target onto the protein
 /// </summary>
 /// <param name="p"></param>
 public void AddProtein(Protein p)
 {
     if (!m_proteinMap.ContainsKey(p.Reference))
     {
         m_proteinMap.Add(p.Reference, p);
     }
     else
     {
         m_proteinMap[p.Reference] = p;
     }
 }
 public ProteinForTreeView(Protein protein, string displayName, List <InSilicoPep> uniquePep,
                           List <InSilicoPep> sharedPep, List <InSilicoPep> allPep)
 {
     Protein        = protein;
     Expanded       = false;
     DisplayName    = displayName;
     UniquePeptides = uniquePep;
     SharedPeptides = sharedPep;
     AllPeptides    = allPep;
     Summary        = new ObservableCollection <SummaryForTreeView>();
 }
Exemple #13
0
        public void GetRandomItemFromCollectionTest()
        {
            Protein protein1       = new Protein("protein1");
            Protein protein2       = new Protein("protein2");
            var     listOfProteins = new List <Protein> {
                protein1, protein2
            };
            Protein protein = listOfProteins.GetRandomItem();

            CollectionAssert.Contains(listOfProteins, protein);
        }
Exemple #14
0
        //TODO: Generate all the proteolytic products as distinct proteins during XML reading and delete the ProteolysisProducts code
        public static List <Protein> LoadProteinXML(string proteinDbLocation, bool generateTargets, DecoyType decoyType, IEnumerable <Modification> allKnownModifications,
                                                    bool isContaminant, IEnumerable <string> modTypesToExclude, out Dictionary <string, Modification> unknownModifications, int maxThreads = -1,
                                                    int maxHeterozygousVariants = 4, int minAlleleDepth = 1)
        {
            List <Modification> prespecified = GetPtmListFromProteinXml(proteinDbLocation);

            allKnownModifications = allKnownModifications ?? new List <Modification>();
            modTypesToExclude     = modTypesToExclude ?? new List <string>();

            //Dictionary<string, IList<Modification>> modsDictionary = new Dictionary<string, IList<Modification>>();
            if (prespecified.Count > 0 || allKnownModifications.Count() > 0)
            {
                //modsDictionary = GetModificationDict(new HashSet<Modification>(prespecified.Concat(allKnownModifications)));
                IdToPossibleMods = GetModificationDict(new HashSet <Modification>(prespecified.Concat(allKnownModifications)));
                IdWithMotifToMod = GetModificationDictWithMotifs(new HashSet <Modification>(prespecified.Concat(allKnownModifications)));
            }
            List <Protein> targets = new List <Protein>();

            unknownModifications = new Dictionary <string, Modification>();
            using (var stream = new FileStream(proteinDbLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                Regex substituteWhitespace = new Regex(@"\s+");

                Stream uniprotXmlFileStream = proteinDbLocation.EndsWith("gz") ? // allow for .bgz and .tgz, which are (rarely) used
                                              (Stream)(new GZipStream(stream, CompressionMode.Decompress)) :
                                              stream;

                ProteinXmlEntry block = new ProteinXmlEntry();

                using (XmlReader xml = XmlReader.Create(uniprotXmlFileStream))
                {
                    while (xml.Read())
                    {
                        if (xml.NodeType == XmlNodeType.Element)
                        {
                            block.ParseElement(xml.Name, xml);
                        }
                        if (xml.NodeType == XmlNodeType.EndElement || xml.IsEmptyElement)
                        {
                            Protein newProtein = block.ParseEndElement(xml, modTypesToExclude, unknownModifications, isContaminant, proteinDbLocation);
                            if (newProtein != null)
                            {
                                targets.Add(newProtein);
                            }
                        }
                    }
                }
            }

            List <Protein>        decoys           = DecoyProteinGenerator.GenerateDecoys(targets, decoyType, maxThreads);
            IEnumerable <Protein> proteinsToExpand = generateTargets ? targets.Concat(decoys) : decoys;

            return(proteinsToExpand.SelectMany(p => p.GetVariantProteins(maxHeterozygousVariants, minAlleleDepth)).ToList());
        }
        private void GetProteinAfterDeserialization(Dictionary <string, Protein> idToProtein)
        {
            Protein protein = null;

            if (ProteinAccession != null && !idToProtein.TryGetValue(ProteinAccession, out protein))
            {
                throw new MzLibUtil.MzLibException("Could not find protein accession after deserialization! " + ProteinAccession);
            }

            Protein = protein;
        }
Exemple #16
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Peptide != null ? Peptide.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Protein != null ? Protein.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (LabelType != null ? LabelType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ MsLevel.GetHashCode();
         return(hashCode);
     }
 }
Exemple #17
0
 public FoldChangeRow(Protein protein, Model.Databinding.Entities.Peptide peptide, IsotopeLabelType labelType,
                      int?msLevel, GroupIdentifier group, int replicateCount, FoldChangeResult foldChangeResult)
 {
     Protein          = protein;
     Peptide          = peptide;
     IsotopeLabelType = labelType;
     MsLevel          = msLevel;
     ReplicateCount   = replicateCount;
     FoldChangeResult = foldChangeResult;
     Group            = group;
 }
Exemple #18
0
        public static void XlTestXlPosCal()
        {
            var prot = new Protein("MNNNKQQQQ", null);
            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("New Custom Protease", CleavageSpecificity.Full, null, null, motifs);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            DigestionParams     digestionParams       = new DigestionParams(protease: protease.Name, minPeptideLength: 1, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <Modification> variableModifications = new List <Modification>();

            var ye = prot.Digest(digestionParams, new List <Modification>(), variableModifications).ToList();

            var pep = ye[0];

            Assert.AreEqual(pep.BaseSequence, "MNNNK");
            Crosslinker crosslinker = GlobalVariables.Crosslinkers.Where(p => p.CrosslinkerName == "DSS").First();

            Assert.AreEqual(crosslinker.CrosslinkerModSites, "K");
            Assert.AreEqual(Residue.GetResidue(crosslinker.CrosslinkerModSites).MonoisotopicMass, 128.09496301518999, 1e-9);
            var n = pep.Fragment(DissociationType.HCD, FragmentationTerminus.N);
            var c = pep.Fragment(DissociationType.HCD, FragmentationTerminus.C);

            Assert.AreEqual(n.Count(), 4);
            Assert.AreEqual(c.Count(), 4);
            Assert.AreEqual(c.First().NeutralMass, 146.10552769899999, 1e-6);
            var x = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), pep).ToArray();

            Assert.AreEqual(x[0], 5);

            var pep2 = ye[2];

            Assert.AreEqual("MNNNKQQQQ", pep2.BaseSequence);
            var n2 = pep2.Fragment(DissociationType.HCD, FragmentationTerminus.N);
            var c2 = pep2.Fragment(DissociationType.HCD, FragmentationTerminus.C);

            Assert.AreEqual(n2.Count(), 8);
            Assert.AreEqual(c2.Count(), 8);
            var x2 = CrosslinkSpectralMatch.GetPossibleCrosslinkerModSites(crosslinker.CrosslinkerModSites.ToCharArray(), pep2).ToArray();

            Assert.AreEqual(x2[0], 5);

            //Test crosslinker with multiple types of mod
            var protSTC = new Protein("GASTACK", null);
            var peps    = protSTC.Digest(digestionParams, new List <Modification>(), variableModifications).ToList();
            var pepSTC  = peps[0];

            Assert.AreEqual(pepSTC.BaseSequence, "GASTACK");
            Crosslinker crosslinker2           = new Crosslinker("ST", "C", "crosslinkerSTC", false, -18.01056, 0, 0, 0, 0, 0, 0);
            string      crosslinkerModSitesAll = new string((crosslinker2.CrosslinkerModSites + crosslinker2.CrosslinkerModSites2).ToCharArray().Distinct().ToArray());

            Assert.AreEqual(crosslinkerModSitesAll, "STC");
        }
Exemple #19
0
        public static void TestNoCleavage()
        {
            List <Modification> fixedModifications = new List <Modification>();
            var prot = new Protein("MNNNKQQQQ", null, null, null, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(5, 6, "lala")
            });
            DigestionParams digestionParams = new DigestionParams(minPeptideLength: 5);
            var             ye = prot.Digest(digestionParams, fixedModifications, new List <Modification>()).ToList();

            Assert.AreEqual(3, ye.Count);
        }
        public ActionResult Create([Bind(Include = "ProteinId,Name,Price,NumberOfProductsInStock,Description,ImageURL")] Protein protein)
        {
            if (ModelState.IsValid)
            {
                db.Proteins.Add(protein);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(protein));
        }
Exemple #21
0
        public void WorkUnitModel_PreferredDeadlineTest1()
        {
            var protein = new Protein {
                ProjectNumber = 1, PreferredDays = 3
            };
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow
            };
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(workUnit.Assigned.AddDays(3).ToLocalTime(), workUnitModel.PreferredDeadline);
        }
Exemple #22
0
        private static WorkUnitModel CreateWorkUnitModel(Protein protein, WorkUnit workUnit, IProteinBenchmarkService benchmarkService = null)
        {
            var slotModel = new SlotModel(new NullClient(null, null, benchmarkService)
            {
                Settings = new ClientSettings()
            });

            return(new WorkUnitModel(slotModel, workUnit)
            {
                CurrentProtein = protein ?? new Protein()
            });
        }
Exemple #23
0
        public void WorkUnitModel_FinalDeadlineTest1()
        {
            var protein = new Protein {
                ProjectNumber = 1, MaximumDays = 6
            };
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow
            };
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(workUnit.Assigned.AddDays(6).ToLocalTime(), workUnitModel.FinalDeadline);
        }
Exemple #24
0
        private void LoadWeekProtein()
        {
            var protein = MainWindow.UserNutritionRepository.GetSumsOfProtein(MainWindow.UserId, 7);

            foreach (var i in protein)
            {
                Protein.Add(new GraphicPoint()
                {
                    Date = i.Key.ToShortDateString(), Number = i.Value
                });
            }
        }
        public static void TestGptmdEngine(string proteinSequence, string accession, string sequenceVariantDescription, int numModifiedResidues)
        {
            List <PeptideSpectralMatch> allResultingIdentifications = null;

            ModificationMotif.TryGetMotif("N", out ModificationMotif motifN);
            var gptmdModifications = new List <Modification> {
                new Modification(_originalId: "21", _modificationType: "mt", _target: motifN, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943)
            };
            IEnumerable <Tuple <double, double> > combos = new List <Tuple <double, double> >();
            Tolerance precursorMassTolerance             = new PpmTolerance(10);

            allResultingIdentifications = new List <PeptideSpectralMatch>();

            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp.Add(("", new CommonParameters()));

            var engine = new GptmdEngine(allResultingIdentifications, gptmdModifications, combos, new Dictionary <string, Tolerance> {
                { "filepath", precursorMassTolerance }
            }, new CommonParameters(), fsp, new List <string>());
            var res = (GptmdResults)engine.Run();

            Assert.AreEqual(0, res.Mods.Count);

            var parentProtein = new Protein(proteinSequence, accession, sequenceVariations: new List <SequenceVariation> {
                new SequenceVariation(1, "N", "A", sequenceVariantDescription)
            });
            var variantProteins = parentProtein.GetVariantProteins();
            CommonParameters commonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5));

            List <Modification> variableModifications = new List <Modification>();
            var modPep = variantProteins.SelectMany(p => p.Digest(commonParameters.DigestionParams, new List <Modification>(), variableModifications)).First();

            //PsmParent newPsm = new TestParentSpectrumMatch(588.22520189093 + 21.981943);
            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null), (new Proteomics.AminoAcidPolymer.Peptide(modPep.BaseSequence).MonoisotopicMass + 21.981943).ToMz(1), 1, "filepath", new CommonParameters());

            var peptidesWithSetModifications = new List <PeptideWithSetModifications> {
                modPep
            };
            PeptideSpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, commonParameters, new List <MatchedFragmentIon>());

            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            newPsm.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0);
            allResultingIdentifications.Add(newPsm);

            engine = new GptmdEngine(allResultingIdentifications, gptmdModifications, combos, new Dictionary <string, Tolerance> {
                { "filepath", precursorMassTolerance }
            }, new CommonParameters(), null, new List <string>());
            res = (GptmdResults)engine.Run();
            Assert.AreEqual(1, res.Mods.Count);
            Assert.AreEqual(numModifiedResidues, res.Mods["accession"].Count);
        }
        public static void TestLocalization()
        {
            Protein         parentProteinForMatch = new Protein("MEK", null);
            DigestionParams digestionParams       = new DigestionParams(minPeptideLength: 1);

            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            List <ModificationWithMass> variableModifications = new List <ModificationWithMass> {
                new ModificationWithMass("21", null, motif, TerminusLocalization.Any, 21.981943)
            };

            List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList();

            Assert.AreEqual(4, allPeptidesWithSetModifications.Count());
            PeptideWithSetModifications ps = allPeptidesWithSetModifications.First();

            List <ProductType> lp = new List <ProductType> {
                ProductType.BnoB1ions, ProductType.Y
            };

            PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1];
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetModsForSpectrum
            });
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            Ms2ScanWithSpecificMass scan   = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null);
            PeptideSpectralMatch    newPsm = new PeptideSpectralMatch(ps.CompactPeptide(TerminusType.None), 0, 0, 2, scan, digestionParams);

            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>();
            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                { ps.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> {
                      ps
                  } }
            };

            newPsm.MatchToProteinLinkedPeptides(matching);

            CommonParameters   commonParameters = new CommonParameters(productMassTolerance: fragmentTolerance);
            LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> {
                newPsm
            }, lp, myMsDataFile, commonParameters, new List <string>());

            f.Run();

            // Was single peak!!!
            Assert.AreEqual(0, newPsm.MatchedIonMassToChargeRatioDict[ProductType.BnoB1ions].Count(b => b > 0));
            Assert.AreEqual(1, newPsm.MatchedIonMassToChargeRatioDict[ProductType.Y].Count(b => b > 0));
            Assert.AreEqual(0, newPsm.MatchedIonIntensitiesDict[ProductType.BnoB1ions].Count(b => b > 0));
            Assert.AreEqual(1, newPsm.MatchedIonIntensitiesDict[ProductType.Y].Count(b => b > 0));
            // If localizing, three match!!!
            Assert.IsTrue(newPsm.LocalizedScores[1] > 3 && newPsm.LocalizedScores[1] < 4);
        }
Exemple #27
0
        public static void TestAmbiguousModFits(string proteinSequence, string motifString, bool result)
        {
            Protein protein = new Protein(proteinSequence, null);
            int     peptideOneBasedIndex = 1;
            int     peptideLength        = 1;
            int     proteinOneBasedIndex = 1;

            ModificationMotif.TryGetMotif(motifString, out ModificationMotif motif);
            Modification attemptToLocalize = new Modification(_target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: double.NaN);

            Assert.AreEqual(result, ModificationLocalization.ModFits(attemptToLocalize, protein.BaseSequence, peptideOneBasedIndex, peptideLength, proteinOneBasedIndex));
        }
Exemple #28
0
        public static void TestVeryCloseExperimentalsModern()
        {
            IDictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> >();

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif);
            var             prot            = new Protein("MMMM", null, null, null, mods);
            DigestionParams digestionParams = new DigestionParams
            {
                MinPeptideLength = 1,
            };
            var thePep = prot.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First();

            var massArray = thePep.CompactPeptide(TerminusType.None).ProductMassesMightHaveDuplicatesAndNaNs(new List <ProductType> {
                ProductType.B, ProductType.Y
            });

            Array.Sort(massArray);
            double[]       intensities  = new double[] { 1, 1, 1, 1 };
            double[]       mz           = new double[] { 1, 2, massArray[4].ToMz(1), massArray[4].ToMz(1) + 1e-9 };
            MzmlMzSpectrum massSpectrum = new MzmlMzSpectrum(mz, intensities, false);
            IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > scan = new MzmlScanWithPrecursor(1, massSpectrum, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, 0, null, null, 0, null, DissociationType.Unknown, 1, null, null, "scan=1");

            PeptideSpectralMatch[]    globalPsms            = new PeptideSpectralMatch[1];
            Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 600, 1, null) };
            CommonParameters          CommonParameters      = new CommonParameters
            {
                ProductMassTolerance = new PpmTolerance(5),
                DigestionParams      = new DigestionParams
                {
                    MaxMissedCleavages          = 0,
                    MinPeptideLength            = null,
                    MaxModificationIsoforms     = int.MaxValue,
                    InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain,
                },
                ConserveMemory = false,
                ScoreCutoff    = 1
            };
            var indexEngine = new IndexingEngine(new List <Protein> {
                prot
            }, new List <ModificationWithMass>(), new List <ModificationWithMass>(), new List <ProductType> {
                ProductType.B, ProductType.Y
            }, 1, DecoyType.Reverse, new List <IDigestionParams> {
                CommonParameters.DigestionParams
            }, CommonParameters, 30000, new List <string>());
            var indexResults = (IndexingResults)indexEngine.Run();
            var cse          = new ModernSearchEngine(globalPsms, arrayOfSortedMS2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, new List <ProductType> {
                ProductType.B, ProductType.Y
            }, 0, CommonParameters, false, new OpenSearchMode(), 0, new List <string>());

            cse.Run();
            Assert.Less(globalPsms[0].Score, 2);
            Assert.Greater(globalPsms[0].Score, 1);
        }
        private void SeedProductsIDs()
        {
            for (int i = 0; i < LoopIterations; i++)
            {
                var product = new Protein();

                product.Id = i == 0 ? ProductId : ProductId + i;
                this.context.Products.Add(product);
            }

            this.context.SaveChanges();
        }
        private readonly string ProteinAccession;     // used to get protein object after deserialization

        /// <summary>
        /// Creates a PeptideWithSetModifications object from a protein. Used when a Protein is digested.
        /// </summary>
        public PeptideWithSetModifications(Protein protein, DigestionParams digestionParams, int oneBasedStartResidueInProtein,
                                           int oneBasedEndResidueInProtein, string peptideDescription, int missedCleavages,
                                           Dictionary <int, Modification> allModsOneIsNterminus, int numFixedMods)
            : base(protein, oneBasedStartResidueInProtein, oneBasedEndResidueInProtein, missedCleavages, peptideDescription)
        {
            _allModsOneIsNterminus = allModsOneIsNterminus;
            NumFixedMods           = numFixedMods;
            _digestionParams       = digestionParams;
            DetermineFullSequence();
            ProteinAccession     = protein.Accession;
            DigestionParamString = digestionParams.ToString();
        }
        private readonly string ProteinAccession; // used to get protein object after deserialization

        /// <summary>
        /// Creates a PeptideWithSetModifications object from a protein. Used when a Protein is digested.
        /// </summary>
        public PeptideWithSetModifications(Protein protein, DigestionParams digestionParams, int oneBasedStartResidueInProtein,
                                           int oneBasedEndResidueInProtein, CleavageSpecificity cleavageSpecificity, string peptideDescription, int missedCleavages,
                                           Dictionary <int, Modification> allModsOneIsNterminus, int numFixedMods, string baseSequence = null)
            : base(protein, oneBasedStartResidueInProtein, oneBasedEndResidueInProtein, missedCleavages, cleavageSpecificity, peptideDescription, baseSequence)
        {
            _allModsOneIsNterminus = allModsOneIsNterminus;
            NumFixedMods           = numFixedMods;
            _digestionParams       = digestionParams;
            DetermineFullSequence();
            ProteinAccession = protein.Accession;
            UpdateCleavageSpecificity();
        }
        public static InteractionSet BuildInteractionSet(IEnumerable<Part> parts)
        {
            InteractionSet set = new InteractionSet();

            foreach (PartList.Part part in parts)
            {
                Protein protein = new Protein();
                protein.stringExternalID = part.stringID;
                protein.sequence = part;
                protein.name = part.data.ShortDesc;

                protein.attributes["length"] = part.data.Sequence.Length.ToString();
                protein.attributes["biobrick"] = part.data.Name;
                protein.attributes["url"] = BiobrickCache.PartRegistryLink(part.data.Name);

                set.startProteins.Add(protein);
                set.proteins[part.stringID] = protein;
            }
            return set;
        }
Exemple #33
0
 public Peptide(Protein parent, int startResidueNumber, int endResidueNumber, int missedCleavages)
     : base(parent.BaseSequence.Substring(startResidueNumber - 1, endResidueNumber - startResidueNumber + 1))
 {
     Parent = parent;
     StartResidueNumber = startResidueNumber;
     EndResidueNumber = endResidueNumber;
     MissedCleavages = missedCleavages;
     if(startResidueNumber - 1 - 1 >= 0)
     {
         PreviousAminoAcid = parent[startResidueNumber - 1 - 1];
     }
     else
     {
         PreviousAminoAcid = '-';
     }
     if(endResidueNumber - 1 + 1 < parent.Length)
     {
         NextAminoAcid = parent[endResidueNumber - 1 + 1];
     }
     else
     {
         NextAminoAcid = '-';
     }
     if(parent.KnownModifications != null && parent.KnownModifications.Count > 0)
     {
         for(int i = 0; i < endResidueNumber - startResidueNumber + 1; i++)
         {
             List<Modification> modifications;
             if(parent.KnownModifications.TryGetValue(startResidueNumber - 1 + i + 2, out modifications))
             {
                 if(KnownModifications == null)
                 {
                     KnownModifications = new Dictionary<int, List<Modification>>();
                 }
                 KnownModifications.Add(i + 2, modifications);
             }
         }
     }
 }
Exemple #34
0
 // public Peptide(Protein parent, int startResidueNumber, int endResidueNumber, int missedCleavages)
 //     : base(parent.BaseSequence.Substring(startResidueNumber - 1, endResidueNumber - startResidueNumber + 1), true)
 // {
 //     Parent = parent;
 //     StartResidueNumber = startResidueNumber;
 //     EndResidueNumber = endResidueNumber;
 //     MissedCleavages = missedCleavages;
 //     if(startResidueNumber - 1 - 1 >= 0)
 //     {
 //         PreviousAminoAcid = parent[startResidueNumber - 1 - 1];
 //     }
 //     else
 //     {
 //         PreviousAminoAcid = '-';
 //     }
 //     if(endResidueNumber - 1 + 1 < parent.Length)
 //     {
 //         NextAminoAcid = parent[endResidueNumber - 1 + 1];
 //     }
 //     else
 //     {
 //         NextAminoAcid = '-';
 //     }
 // }
 // private Peptide(Peptide peptide) : this(peptide.Parent, peptide.StartResidueNumber, peptide.EndResidueNumber, peptide.MissedCleavages) { }
 public void Init(Protein parent, int startResidueNumber, int endResidueNumber, int missedCleavages)
 {
     BaseInit(new FastSubstring(parent.BaseSequence, startResidueNumber - 1, endResidueNumber - startResidueNumber + 1));
     Parent = parent;
     StartResidueNumber = startResidueNumber;
     EndResidueNumber = endResidueNumber;
     MissedCleavages = missedCleavages;
     if(startResidueNumber - 1 - 1 >= 0)
     {
         PreviousAminoAcid = parent[startResidueNumber - 1 - 1];
     }
     else
     {
         PreviousAminoAcid = '-';
     }
     if(endResidueNumber - 1 + 1 < parent.Length)
     {
         NextAminoAcid = parent[endResidueNumber - 1 + 1];
     }
     else
     {
         NextAminoAcid = '-';
     }
 }
 public void AddNewProtein(Protein _in)
 {
     allSelectableTargets.Add(_in.gameObject);
     // selectedTargets.Add(_in.gameObject);
     CheckSelectedUnits();
 }
        private static IEnumerable<Protein> ReadUniProtXmlProteins(FileStream uniProtXmlProteomeDatabase, bool onTheFlyDecoys, IDictionary<string, Modification> knownVariableModifications)
        {
            XmlReader xml = XmlReader.Create(uniProtXmlProteomeDatabase);

            string[] nodes = new string[6];

            string dataset = null;
            string accession = null;
            string name = null;
            string full_name = null;
            bool fragment = false;
            string organism = null;
            string gene_name = null;
            string protein_existence = null;
            string sequence_version = null;
            string sequence = null;
            string feature_type = null;
            string feature_description = null;
            int feature_position = -1;
            Dictionary<int, List<Modification>> modifications = new Dictionary<int, List<Modification>>();
            while(xml.Read())
            {
                switch(xml.NodeType)
                {
                    case XmlNodeType.Element:
                        nodes[xml.Depth] = xml.Name;
                        switch(xml.Name)
                        {
                            case "entry":
                                dataset = xml.GetAttribute("dataset");
                                break;
                            case "accession":
                                if(accession == null)
                                {
                                    accession = xml.ReadElementString();
                                }
                                break;
                            case "name":
                                if(xml.Depth == 2)
                                {
                                    name = xml.ReadElementString();
                                }
                                else if(nodes[2] == "gene")
                                {
                                    if(gene_name == null)
                                    {
                                        gene_name = xml.ReadElementString();
                                    }
                                }
                                else if(nodes[2] == "organism")
                                {
                                    if(organism == null)
                                    {
                                        organism = xml.ReadElementString();
                                    }
                                }
                                break;
                            case "fullName":
                                if(full_name == null)
                                {
                                    full_name = xml.ReadElementString();
                                }
                                break;
                            case "proteinExistence":
                                protein_existence = xml.GetAttribute("type");
                                break;
                            case "feature":
                                feature_type = xml.GetAttribute("type");
                                feature_description = xml.GetAttribute("description");
                                break;
                            case "position":
                                feature_position = int.Parse(xml.GetAttribute("position")) - 1;
                                break;
                            case "sequence":
                                fragment = xml.GetAttribute("fragment") != null;
                                sequence_version = xml.GetAttribute("version");
                                sequence = xml.ReadElementString().Replace("\n", null);
                                break;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        switch(xml.Name)
                        {
                            case "feature":
                                if(feature_type == "modified residue" && knownVariableModifications != null && !feature_description.Contains("variant"))
                                {
                                    List<Modification> residue_modifications;
                                    if(!modifications.TryGetValue(feature_position + 2, out residue_modifications))
                                    {
                                        residue_modifications = new List<Modification>();
                                        modifications.Add(feature_position + 2, residue_modifications);
                                    }
                                    int semicolon_index = feature_description.IndexOf(';');
                                    if(semicolon_index >= 0)
                                    {
                                        feature_description = feature_description.Substring(0, semicolon_index);
                                    }
                                    Modification modification;
                                    if(knownVariableModifications.TryGetValue("UniProt: " + feature_description, out modification))
                                    {
                                        residue_modifications.Add(modification);
                                    }
                                }
                                break;
                            case "entry":
                                string dataset_abbreviation = dataset.Equals("Swiss-Prot", StringComparison.InvariantCultureIgnoreCase) ? "sp" : "tr";
                                string protein_existence_code = proteinExistenceCodes[protein_existence];
                                string description = dataset_abbreviation + '|' + accession + '|' + name + ' ' + full_name + (fragment ? " (Fragment)" : null) + " OS=" + organism + (gene_name != null ? " GN=" + gene_name : null) + " PE=" + protein_existence_code + " SV=" + sequence_version;
                                Protein protein;
                                if(modifications.Count > 0)
                                {
                                    protein = new Protein(sequence, description, modifications);
                                }
                                else
                                {
                                    protein = new Protein(sequence, description);
                                }

                                yield return protein;

                                if(onTheFlyDecoys)
                                {
                                    if(protein.Decoy)
                                    {
                                        throw new ArgumentException(uniProtXmlProteomeDatabase.Name + " contains decoy proteins; database should not contain decoy proteins when \"create target–decoy database on the fly\" option is enabled");
                                    }
                                    char[] sequence_array = sequence.ToCharArray();
                                    Dictionary<int, List<Modification>> decoy_modifications = null;
                                    if(sequence.StartsWith("M"))
                                    {
                                        Array.Reverse(sequence_array, 1, sequence.Length - 1);
                                        if(modifications != null)
                                        {
                                            decoy_modifications = new Dictionary<int, List<Modification>>(modifications.Count);
                                            foreach(KeyValuePair<int, List<Modification>> kvp in modifications)
                                            {
                                                if(kvp.Key == 2)
                                                {
                                                    decoy_modifications.Add(2, kvp.Value);
                                                }
                                                else if(kvp.Key > 2)
                                                {
                                                    decoy_modifications.Add(sequence.Length - (kvp.Key - 2) - 1 + 1 + 2, kvp.Value);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Array.Reverse(sequence_array);
                                        if(modifications != null)
                                        {
                                            decoy_modifications = new Dictionary<int, List<Modification>>(modifications.Count);
                                            foreach(KeyValuePair<int, List<Modification>> kvp in modifications)
                                            {
                                                decoy_modifications.Add(sequence.Length - (kvp.Key - 2) - 1 + 2, kvp.Value);
                                            }
                                        }
                                    }
                                    string reversed_sequence = new string(sequence_array);
                                    Protein decoy_protein = new Protein(reversed_sequence, description[2] == '|' ? description.Insert(3, Protein.DECOY_IDENTIFIER) : Protein.DECOY_IDENTIFIER + description, decoy_modifications);
                                    yield return decoy_protein;
                                }

                                dataset = null;
                                accession = null;
                                name = null;
                                full_name = null;
                                fragment = false;
                                organism = null;
                                gene_name = null;
                                protein_existence = null;
                                sequence_version = null;
                                sequence = null;
                                feature_type = null;
                                feature_description = null;
                                feature_position = -1;
                                modifications = new Dictionary<int, List<Modification>>();

                                break;
                        }
                        break;
                }
            }

            uniProtXmlProteomeDatabase.Seek(0, SeekOrigin.Begin);
        }
        private static IEnumerable<Protein> ReadFastaProteins(FileStream fastaProteomeDatabase, bool onTheFlyDecoys)
        {
            StreamReader fasta = new StreamReader(fastaProteomeDatabase);

            string description = null;
            string sequence = null;

            while(true)
            {
                string line = fasta.ReadLine();

                if(line.StartsWith(">"))
                {
                    description = line.Substring(1);
                }
                else
                {
                    sequence += line.Trim();
                }

                if(fasta.Peek() == '>' || fasta.Peek() == -1)
                {
                    Protein protein = new Protein(sequence, description);

                    yield return protein;

                    if(onTheFlyDecoys)
                    {
                        if(protein.Decoy)
                        {
                            throw new ArgumentException(fastaProteomeDatabase.Name + " contains decoy proteins; database should not contain decoy proteins when \"create target–decoy database on the fly\" option is enabled");
                        }
                        char[] sequence_array = sequence.ToCharArray();
                        if(sequence.StartsWith("M"))
                        {
                            Array.Reverse(sequence_array, 1, sequence.Length - 1);
                        }
                        else
                        {
                            Array.Reverse(sequence_array);
                        }
                        string reversed_sequence = new string(sequence_array);
                        Protein decoy_protein = new Protein(reversed_sequence, description[2] == '|' ? description.Insert(3, Protein.DECOY_IDENTIFIER) : Protein.DECOY_IDENTIFIER + description);
                        yield return decoy_protein;
                    }

                    description = null;
                    sequence = null;

                    if(fasta.Peek() == -1)
                    {
                        break;
                    }
                }
            }

            fastaProteomeDatabase.Seek(0, SeekOrigin.Begin);
        }
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();

            //Implement the loading / reading of the MTDB Framework objects.

            var reader          = new SqLiteTargetDatabaseReader();
            var mtdbDatabase    = reader.ReadDb(m_path);
            var massTags        = new List<MassTagLight>();

            // Mapping objects to create unique proteins and for the mass tag database to load only those proteins for
            // the given consensus targets/mass tags.
            var proteinMap          = new Dictionary<int, Protein>();
            var massTagProteinMap   = new Dictionary<int, List<Protein>>();

            if (mtdbDatabase == null)
                return database;

            foreach (var target in mtdbDatabase.ConsensusTargets)
            {
                // Copy the consensus data into a mass tag light.
                var tag = new MassTagLight
                {
                    Id = target.Id,
                    MassMonoisotopic = target.TheoreticalMonoIsotopicMass,
                    NetAverage = target.AverageNet,
                    NetPredicted = target.PredictedNet,
                    PeptideSequence = target.Sequence,
                    NetStandardDeviation = target.StdevNet
                };

                // Here we create unique proteins for the mass tag copying information from the consensus target proteins.
                var proteinsForMassTag = new List<Protein>();
                foreach (var targetProtein in target.Proteins)
                {
                    if (!proteinMap.ContainsKey(targetProtein.Id))
                    {
                        var newProtein = new Protein
                        {
                            Id = targetProtein.Id,
                            Name = targetProtein.ProteinName,
                            ResidueStartPosition = targetProtein.ResidueStart,
                            ResidueEndPosition = targetProtein.ResidueEnd
                        };
                        //TODO: Do something about the cleavage state and terminus state of a protein loaded from MTDBCreator database.
                        //protein.CleavageState = ??
                        //protein.TerminusState = ??

                        proteinMap.Add(newProtein.Id, newProtein);
                    }

                    var protein = proteinMap[targetProtein.Id];
                    proteinsForMassTag.Add(protein);
                }

                massTagProteinMap.Add(tag.Id, proteinsForMassTag);
                massTags.Add(tag);
            }

            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            return database;
        }
 public IEnumerable<DigestedPeptide> Digest(Protein protein)
 {
     if (string.IsNullOrEmpty(protein.Sequence))
     {
         yield break;
     }
     FastaSequence fastaSequence;
     try
     {
         fastaSequence = new FastaSequence("name", "description", new List<ProteinMetadata>(), protein.Sequence); // Not L10N
     }
     catch (InvalidDataException)
     {
         // It's possible that the peptide sequence in the fasta file was bogus, in which case we just don't digest it.
         yield break;
     }
     DigestSettings digestSettings = new DigestSettings(6, false);
     foreach (var digest in _enzyme.Digest(fastaSequence, digestSettings))
     {
         var digestedPeptide = new DigestedPeptide
         {
             Index = digest.Begin ?? 0,
             Sequence = digest.Sequence
         };
         yield return digestedPeptide;
     }
 }
Exemple #40
0
    static void Main( )
    {
        // Read proteins in FASTA format from the file.
        using( StreamReader sr = new StreamReader( fastaFile ) )
        {

           string id = null;
            string name = null;

            string line = sr.ReadLine();
            //while line not null
            while( line != null)
            {

                //set header to null
                string header = null;

                //while header null and line not null
                while ((line != null) && (header == null))
                {

                // if empty line, skip it (i.e., read next line)
                    if (string.IsNullOrWhiteSpace(line)== true)
                    {
                        line = sr.ReadLine();
                    }

                // else if header line, set header, read next line
                    else if (line.StartsWith(">"))
                    {
                        header = line;
                        //split the header into the id and the chemical name
                        id = header.Substring(1,10);
                        name = header.Substring(12);
                        line = sr.ReadLine();
                    }
                // else throw an exception (expected a header line)
                    else
                    {
                       throw new Exception("expected a header line");

                    }
                }

                //set sequence to null, not complete
                bool IsComplete = false;
                string sequence = null;

                // it's in a infinite loop right nowwwww

                //while sequence not complete and line not null
                while( (!IsComplete) && (line != null) )
                {

                //| if empty line, skip it (i.e., read next line)
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        line = sr.ReadLine();
                    }
             //else if not header line, concatenate to sequence, read next line
                    else if(!line.StartsWith(">"))
                    {
                        sequence = sequence + line.Trim();
                        line = sr.ReadLine();
                    }
              //else (is header line) if sequence not null, sequence is complete
                    else if (sequence != null)
                    {
                        // if(sequence != null)
                        // {
                            IsComplete = true;
                        // }
                    }
                //| else throw an exception (expected a sequence line)
                    else
                    {
                        throw new Exception
                            (" Expected sequence line");
                    }
                }

                //if header not null
                if (header != null)
                {
                    //| if sequence not null
                    if(sequence != null)
                    {
                    //| | add protein to collection
                    // This is how to create a new object
                    Protein p = new Protein( id, name, sequence);
                    proteins.Add(p);
                    }
                //| else throw an exception (header with missing sequence)
                    else
                    {
                         throw new Exception ("Header with missing sequence");
                    }
                }
        }

        // Report count of proteins loaded.
        Console.WriteLine( );
        Console.WriteLine( "Loaded {0} proteins from the {1} file.",
            proteins.Count, fastaFile );

        // Report proteins containing a specified sequence.
        Console.WriteLine( );
        Console.WriteLine( "Proteins containing sequence RILED:" );
        foreach( Protein p in proteins )
        {
            if( p.ContainsSubsequence( "RILED" ) )
            {
                Console.WriteLine( p.Name );
            }
        }

        // Report proteins containing a repeated sequence.
        Console.WriteLine( );
        Console.WriteLine(
            "Proteins containing sequence SNL more than 5 times:" );
        foreach( Protein p in proteins )
        {
            if( p.CountSubsequence( "SNL" ) > 5 )
            {
                Console.WriteLine( p.Name );
            }
        }

        // Locate the specified sequence in proteins containing it.
        Console.WriteLine( );
        Console.WriteLine( "Proteins containing sequence DEVGG:" );
        foreach( Protein p in proteins )
        {
            if( p.ContainsSubsequence( "DEVGG" ) )
            {
                Console.WriteLine( p.Name );
                Console.WriteLine( p.LocateSubsequence( "DEVGG" ) );
            }
        }

        // Show FASTA output for proteins containing a specified sequence.
        Console.WriteLine( );
        Console.WriteLine( "Proteins containing sequence DEVGG:" );
        foreach( Protein p in proteins )
        {
            if( p.ContainsSubsequence( "DEVGG" ) )
            {
                p.WriteFasta( Console.Out );
            }
        }

        }// done using file
    }
 public ProteinInfo(Protein protein)
 {
     ProteinMetadata = protein.ProteinMetadata;
     Sequence = protein.Sequence;
     Alternatives = ImmutableList.ValueOf(protein.AlternativeNames);
 }
Exemple #42
0
        public void Add (Protein pro)
        {
            insertRow(Table.Protein, new object[] {pro.Id, pro.Accession, pro.Length});
            insertRow(Table.ProteinMetadata, new object[] {pro.Id, pro.Description});
            insertRow(Table.ProteinData, new object[] {pro.Id, pro.Sequence});

            long length = pro.Sequence != null ? pro.Sequence.Length : 0;

            for (long i = currentMaxSequenceLength + 1; i <= length; ++i)
                insertRow(Table.IntegerSet, new object[] {i});
            currentMaxSequenceLength = Math.Max(length, currentMaxSequenceLength);
        }
Exemple #43
0
        private void button2_Click(object sender, EventArgs e)
        {
            readAll3Ngrams();

            StreamReader srNgram = new StreamReader("3grams1.csv");
            Stream myStream = null;
            //OpenFileDialog theDialog = new OpenFileDialog();
            //theDialog.Title = "Open Text File";
            //theDialog.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
            //theDialog.FilterIndex = 1;
            //// theDialog.Filter = "TXT files|*.txt";
            //theDialog.InitialDirectory = @"C:\";
            string folderSource = textBox1.Text;
            string[] fileNames = Directory.GetFiles(folderSource, "*.*", SearchOption.AllDirectories);
            SortedDictionary<Protein, string> protHash = new SortedDictionary<Protein, string>();
            StreamWriter sw = new StreamWriter("Protein_SVM_3Gm_Oct_5th.csv");
            /*string ngramLine = "";
            while ((ngramLine = srNgram.ReadLine()) != null)
            {
                sw.Write(ngramLine + ",");
            }
            srNgram.Close();
            sw.WriteLine(); */

            int size = -1;
            //  DialogResult result = theDialog.ShowDialog(); // Show the dialog.
            // if (result == DialogResult.OK) // Test result.
            //StreamWriter swn = new StreamWriter("bbb.csv");
            foreach (string file in fileNames)
            {
                //     string file = theDialog.FileName;
                string text = null;
                int nGramSize = 3;
                //try
                //{
                //    text = File.ReadAllText(file);

                //}
                //catch (IOException)
                //{
                //}

                string protein = "";

                string line1;
                //   sw.WriteLine("Protein_SVM" + "," + "Current subject file is  " + file);
                FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
                BufferedStream bs = new BufferedStream(fs);

                StreamReader sr = new StreamReader(fs);
                bool startProtFlag = false;
                string proteinString = "";
                int occurence = 0;
                int counter = 0;
                string protNameFinal = "";
                string proteinFinal = "";
                string ngramLine1 = "";
                string lastName = "";

                string className = "";
                string lastclassName = "";

                while (!sr.EndOfStream)// (line1 = sr.ReadLine()) != null)
                {
                    line1 = sr.ReadLine();
                    counter++;
                    lastclassName = className;
                    if (line1.Contains(">") && line1.Length < 15)
                    {

                        className = "";

                        if(line1.EndsWith(" C")){
                            className = "C";
                        }
                        else if(line1.EndsWith(" P")){
                            className = "P";
                        }
                        else if(line1.EndsWith(" N")){
                            className = "N";
                        }
                        else if(line1.EndsWith(" M")){
                            className = "M";
                        }
                        else {
                             className = "X";
                        }

              //          swn.WriteLine(line1);
                        lastName = file+","+protNameFinal;
                        startProtFlag = true;

                      //  protein = line1.Substring(1, line1.IndexOf('|') - 1);
                        line1 = line1.Remove(0, 1);
                        protein = line1;
                        protNameFinal = protein;
                        proteinFinal = proteinString;
                        proteinString = "";
                        occurence = 0;
                        if (counter > 2)
                        {
                            goto Analyse;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        proteinString += line1;
                        continue;
                    }
                Analyse:

                    Protein p1 = new Protein(lastclassName, lastName);
                //    protNameFinal=file+protNameFinal;
                    if (protHash.ContainsKey(p1) == false)
                    {

                        protHash.Add(p1, proteinFinal);
                        lastName = lastclassName+ file + protNameFinal;
                    }

                /*    occurence = 0;
                 *
                    StreamReader srNgram1 = new StreamReader("Ngrams.csv");
                    sw.Write(protNameFinal);
                    while ((ngramLine1 = srNgram1.ReadLine()) != null)
                    {

                        //   string SearchText = "7,true,NA,false:67,false,NA,false:5,false,NA,false:5,false,NA,false";
                        //      string Regex = @"\btrue\b";
                        int NumberOfTrues = Regex.Matches(proteinFinal, ngramLine1).Count;
                        sw.Write(NumberOfTrues + ",");
                        //if (proteinFinal.Contains(ngramLine1))
                        //{
                        //    occurence++;

                        //}

                        //  continue;
                    }
                    srNgram1.Close();
                    sw.WriteLine(); */
                    continue;
                    //    sw.WriteLine(protNameFinal + "," + occurence);
                }
                Protein p2 = new Protein(lastclassName, lastName);
                if (protHash.ContainsKey(p2) == false)
                {

                    protHash.Add(p2, proteinFinal);
                }

            }

            //swn.Close();
            sw.Write("3gram_Protein" + ",");

            //StreamWriter sw9 = new StreamWriter("izz.csv");
            //foreach (KeyValuePair<string,string> de in protHash)
            //{
            //    sw9.WriteLine(de.Key.ToString() + ",");
            //}

            //sw9.Close();

            foreach (KeyValuePair<string, int> kvp in nGramHash)
            {

                //if (!test11.Contains(kvp.Key.ToString()))
                //{
                sw.Write(kvp.Key +",");
                //   }

                //   test11 += kvp.Key;
            }

            sw.Write("Class");
            sw.WriteLine();
            string ngramLine = "";

            foreach (KeyValuePair<Protein,string> de in protHash)
            {
                srNgram = new StreamReader("3grams1.csv");
                Protein p = (Protein)de.Key;

                sw.Write(p.PClass + ","+p.PName+",");
            while ((ngramLine = srNgram.ReadLine()) != null)
            {

                int NumberOfTrues = Regex.Matches(de.Value.ToString(), ngramLine).Count;

                sw.Write(NumberOfTrues + ",");
                       }
             //   srNgram.Close();
              //  sw.Write(de.Key.ToString() + ",");
                sw.Write(de.Key.ToString());
            sw.WriteLine();
            }

            sw.Close();

            MessageBox.Show("Done");
        }
Exemple #44
0
 public ProteinViewModel(Protein p)
 {
     m_protein = p;
 }
Exemple #45
0
        private List<Protein> CompileResults(List<LocalizedHit> hits, string csvFile, string outputDirectory, bool breakProteinsApart = false)
        {
            Dictionary<string, LocalizedHit> hitsdict = new Dictionary<string, LocalizedHit>();

            // Group all the localized Hits into proteins
            Dictionary<string, Protein> proteins = new Dictionary<string, Protein>();

            foreach (LocalizedHit hit in hits)
            {
                hitsdict.Add(hit.PSM.Filename, hit);

                string defline = hit.PSM.Defline;

                if (breakProteinsApart)
                {
                    string[] groups = hit.PSM.ProteinGroup.Split('|');
                    foreach (string group in groups)
                    {
                        Protein prot;
                        if (!proteins.TryGetValue(group, out prot))
                        {
                            prot = new Protein(group, defline);
                            proteins.Add(group, prot);
                        }
                        prot.AddHit(hit);
                    }
                }
                else
                {
                    Protein prot;
                    if (!proteins.TryGetValue(hit.PSM.ProteinGroup, out prot))
                    {
                        prot = new Protein(hit.PSM.ProteinGroup, defline);
                        proteins.Add(hit.PSM.ProteinGroup, prot);
                    }
                    prot.AddHit(hit);
                }
            }
            using (StreamWriter writer = new StreamWriter(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(csvFile) + "_all.csv")),
                 localizedWriter = new StreamWriter(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(csvFile) + "_localized.csv")))
            {
                using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true))
                {
                    LocalizedHit hit = null;
                    headerInfo = reader.GetFieldHeaders();
                    bool tqFound = false;
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        if (headerInfo[i].EndsWith("NL)"))
                        {
                            if (!tqFound)
                            {
                                FirstQuantColumn = i;
                                tqFound = true;
                            }
                        }
                        if(headerInfo[i] == "Channels Detected")
                            LastQuantColumn = i-1;
                    }
                    string header = string.Join(",", headerInfo) + ",# Isoforms,# of Considered Fragments,Localized?,Delta Score,Best Isoform,Spectral Matches,% TIC,Second Best Isoform,Second Spectral Matches,Second % TIC";
                    writer.WriteLine(header);
                    localizedWriter.WriteLine(header);
                    while (reader.ReadNextRecord())
                    {
                        string mods = reader["Mods"];
                        if (string.IsNullOrEmpty(mods))
                            continue;

                        List<Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).OfType<Modification>().ToList();

                        // Only keep things with quantified Modifications
                        if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod)))
                            continue;

                        string filename = reader["Filename/id"];
                        if(!hitsdict.TryGetValue(filename, out hit))
                            continue;

                        string[] data = new string[reader.FieldCount];
                        reader.CopyCurrentRecordTo(data);

                        hit.omssapsm = data;

                        StringBuilder sb = new StringBuilder();

                        foreach (string datum in data)
                        {
                            if (datum.Contains(','))
                            {
                                sb.Append("\"");
                                sb.Append(datum);
                                sb.Append("\"");
                            }
                            else
                                sb.Append(datum);
                            sb.Append(',');
                        }
                        sb.Append(hit.PSM.Isoforms);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.Fragments.Count);
                        sb.Append(',');
                        sb.Append(hit.IsLocalized);
                        sb.Append(',');
                        sb.Append(hit.MatchDifference);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.SequenceWithModifications);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.SpectralMatch.Matches);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.SpectralMatch.PercentTIC);
                        if (hit.PSM.Isoforms > 1)
                        {
                            //sb.Append(',');
                            //sb.Append(hit.BestPeptideSDFCount);
                            sb.Append(',');
                            sb.Append(hit.SecondBestPeptideIsoform.SequenceWithModifications);
                            sb.Append(',');
                            sb.Append(hit.SecondBestPeptideIsoform.SpectralMatch.Matches);
                            sb.Append(',');
                            sb.Append(hit.SecondBestPeptideIsoform.SpectralMatch.PercentTIC);
                            //sb.Append(',');
                            //sb.Append(hit.SecondBestPeptideSDFCount);
                        }

                        if(hit.IsLocalized)
                            localizedWriter.WriteLine(sb.ToString());
                        writer.WriteLine(sb.ToString());
                    }
                }
            }

            return proteins.Values.ToList();
        }
Exemple #46
0
 public ProteinMatch(ProteinMatchSettings proteinMatchSettings, Protein protein)
 {
     Settings = proteinMatchSettings;
     Protein = protein;
     String ltext = proteinMatchSettings.SearchText.ToLower();
     for (int bit = 1; bit < (int)ProteinMatchType.all; bit <<= 1) // name, accession, gene, etc - case insenstive
     {
         ProteinMatchType matchType = (ProteinMatchType) bit;
         if ((0 != (proteinMatchSettings.MatchTypes & matchType)) && 
             (0==(matchType &(ProteinMatchType.sequence|ProteinMatchType.description)))) // handle sequence and description below
         {
             if (Matches(protein.ProteinMetadata, matchType, ltext))
             {
                 MatchType |= matchType;
             }
             else
             {
                 foreach (ProteinMetadata alternative in Protein.AlternativeNames)
                 {
                     if (Matches(alternative, matchType, ltext))
                     {
                         MatchType |= matchType;
                         AlternativeName = alternative;
                         break;
                     }
                 }
             }
         }
     }
     if ((MatchType == 0) && // Don't bother declaring a description match if we already have a more specific one (name, accession etc)
         (0 != (proteinMatchSettings.MatchTypes & ProteinMatchType.description))) 
     {
         if (ContainsLowerCase(protein.Description, ltext) ||
             ContainsLowerCase(protein.Name, ltext))
         {
                MatchType |= ProteinMatchType.description;
         }
         else
         {
             foreach (ProteinMetadata alternative in Protein.AlternativeNames)
             {
                 if (ContainsLowerCase(alternative.Name, ltext) ||
                     ContainsLowerCase(alternative.Description, ltext))
                 {
                     MatchType |= ProteinMatchType.description;
                     AlternativeDescription = alternative;
                 }
             }
         }
     }
     List<DigestedPeptide> digestedPeptides = new List<DigestedPeptide>();
     if (0 != (proteinMatchSettings.MatchTypes & ProteinMatchType.sequence))
     {
         if (proteinMatchSettings.Protease != null)
         {
             String lastPeptide = null;
             foreach (var peptide in proteinMatchSettings.Protease.Digest(protein))
             {
                 if (!peptide.Sequence.StartsWith(proteinMatchSettings.SearchText))
                 {
                     continue;
                 }
                 // If this peptide is just an extension of the previous peptide (i.e. with one
                 // more missed cleavage), then only include it if the user has typed the entire
                 // sequence of the previous peptide.
                 if (lastPeptide != null && peptide.Sequence.StartsWith(lastPeptide) 
                     && lastPeptide.Length > proteinMatchSettings.SearchText.Length)
                 {
                     continue;
                 }
                 lastPeptide = peptide.Sequence;
                 MatchType |= ProteinMatchType.sequence;
                 digestedPeptides.Add(peptide);
             }
         }
     }
     DigestedPeptides = digestedPeptides;
 }
 public FoldChangeRow(Protein protein, Model.Databinding.Entities.Peptide peptide, IsotopeLabelType labelType,
     int? msLevel, GroupIdentifier group, int replicateCount, FoldChangeResult foldChangeResult)
 {
     Protein = protein;
     Peptide = peptide;
     IsotopeLabelType = labelType;
     MsLevel = msLevel;
     ReplicateCount = replicateCount;
     FoldChangeResult = foldChangeResult;
     Group = group;
 }
Exemple #48
0
 public ProteinResult(Protein protein, ResultFile resultFile)
     : base(protein, resultFile)
 {
 }
Exemple #49
0
        public Digestion Digest(IProtease protease, ProgressMonitor progressMonitor)
        {
            using (ISession session = OpenWriteSession())
            {
                DbDigestion dbDigestion = GetDbDigestion(protease.Name);
                HashSet<string> existingSequences = new HashSet<string>();
                using (var transaction = session.BeginTransaction())
                {
                    if (dbDigestion != null)
                    {
                        if (dbDigestion.MaxSequenceLength >= MAX_SEQUENCE_LENGTH)
                        {
                            return new Digestion(this, dbDigestion);
                        }
                        if (!progressMonitor.Invoke(Resources.ProteomeDb_Digest_Listing_existing_peptides, 0))
                        {
                            return null;
                        }
                        IQuery query = session.CreateQuery("SELECT P.Sequence FROM " // Not L10N
                                                           + typeof(DbDigestedPeptide) + " P WHERE P.Digestion = :Digestion") // Not L10N
                            .SetParameter("Digestion", dbDigestion); // Not L10N
                        List<String> listSequences = new List<string>();
                        query.List(listSequences);
                        existingSequences.UnionWith(listSequences);
                        dbDigestion.MaxSequenceLength = MAX_SEQUENCE_LENGTH;
                        session.Update(dbDigestion);
                    }
                    else
                    {
                        dbDigestion = new DbDigestion
                        {
                            Name = protease.Name,
                            MinSequenceLength = MIN_SEQUENCE_LENGTH,
                            MaxSequenceLength = MAX_SEQUENCE_LENGTH,
                        };
                        session.Save(dbDigestion);
                    }
                    if (!progressMonitor.Invoke(Resources.ProteomeDb_Digest_Listing_proteins, 0)) 
                    {
                        return null;
                    }
                    List<DbProtein> proteins = new List<DbProtein>();
                    session.CreateCriteria(typeof(DbProtein)).List(proteins);
                    Dictionary<String, long> digestedPeptideIds
                        = new Dictionary<string, long>();
                    const String sqlPeptide =
                            "INSERT INTO ProteomeDbDigestedPeptide (Digestion, Sequence) VALUES(?,?);select last_insert_rowid();"; // Not L10N
                    using (var commandPeptide = session.Connection.CreateCommand())
                    using (var commandProtein = session.Connection.CreateCommand())
                    {
                        commandPeptide.CommandText = sqlPeptide;
                        commandPeptide.Parameters.Add(new SQLiteParameter());
                        commandPeptide.Parameters.Add(new SQLiteParameter());
                        const String sqlPeptideProtein =
                            "INSERT INTO ProteomeDbDigestedPeptideProtein (Peptide, Protein) VALUES(?,?);"; // Not L10N
                        commandProtein.CommandText = sqlPeptideProtein;
                        commandProtein.Parameters.Add(new SQLiteParameter());
                        commandProtein.Parameters.Add(new SQLiteParameter());
                        commandProtein.Parameters.Add(new SQLiteParameter());
                        for (int i = 0; i < proteins.Count; i++)
                        {
                            var proteinSequences = new HashSet<string>();
                            if (!progressMonitor.Invoke(string.Format(Resources.ProteomeDb_Digest_Digesting__0__proteins,proteins.Count), 100 * i / proteins.Count))
                            {
                                return null;
                            }
                            Protein protein = new Protein(ProteomeDbPath, proteins[i]);

                            foreach (DigestedPeptide digestedPeptide in protease.Digest(protein))
                            {
                                if (digestedPeptide.Sequence.Length < dbDigestion.MinSequenceLength)
                                {
                                    continue;
                                }
                                String truncatedSequence = digestedPeptide.Sequence.Substring(
                                    0, Math.Min(digestedPeptide.Sequence.Length, dbDigestion.MaxSequenceLength));
                                if (existingSequences.Contains(truncatedSequence))
                                {
                                    continue;
                                }
                                if (proteinSequences.Contains(truncatedSequence))
                                {
                                    continue;
                                }
                                proteinSequences.Add(truncatedSequence);
                                long digestedPeptideId;
                                if (!digestedPeptideIds.TryGetValue(truncatedSequence, out digestedPeptideId))
                                {
                                    ((SQLiteParameter)commandPeptide.Parameters[0]).Value = dbDigestion.Id;
                                    ((SQLiteParameter)commandPeptide.Parameters[1]).Value = truncatedSequence;
                                    digestedPeptideId = Convert.ToInt64(commandPeptide.ExecuteScalar());
                                    digestedPeptideIds.Add(truncatedSequence, digestedPeptideId);
                                }
                                ((SQLiteParameter)commandProtein.Parameters[0]).Value = digestedPeptideId;
                                ((SQLiteParameter)commandProtein.Parameters[1]).Value = protein.Id;
                                commandProtein.ExecuteNonQuery();
                            }
                        }
                    }
                    if (!progressMonitor.Invoke(Resources.ProteomeDb_AddFastaFile_Saving_changes, 99))
                    {
                        return null;
                    }
                    transaction.Commit();

                    AnalyzeDb(session);
                    progressMonitor.Invoke(
                        string.Format(Resources.ProteomeDb_Digest_Digested__0__proteins_into__1__unique_peptides,
                                      proteins.Count, digestedPeptideIds.Count),
                        100);
                }
                return new Digestion(this, dbDigestion);
            }
        }
 public ProteinColumn(int index, Protein protein)
 {
     Index = index;
     Protein = protein;
 }
 private TreeNode CreateProteinNode(Protein prot)
 {
     treeNodes[prot] = new TreeNode(prot.name);
     treeNodes[prot].Expand();
     return treeNodes[prot];
 }
        void TreeUpdateLogCallback(Protein org, Protein prot, string msg)
        {
            treeView.Invoke(new Action(delegate {
                if (treeNodes.ContainsKey(prot))
                    return;

                if (!treeNodes.ContainsKey(org))
                    treeView.Nodes.Add(CreateProteinNode(prot));

                string annotation = null;
                prot.attributes.TryGetValue("annotation", out annotation);
                treeNodes[prot] = treeNodes[org].Nodes.Add(prot.name + (annotation != null ? ": " + annotation : ""));
            }));
        }
        /// <summary>
        ///     Loads the protein information.
        /// </summary>
        protected virtual Dictionary<int, List<Protein>> LoadProteins()
        {
            var massTagToProtein = new Dictionary<int, List<Protein>>();
            using (var connection = CreateConnection(CreateConnectionString()))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    SetupProteinMassTagCommand(command);

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (reader["Mass_Tag_ID"] != DBNull.Value)
                            {
                                var id = Convert.ToInt32(reader["Mass_Tag_ID"]);
                                var refName = "";
                                var proteinId = -1;
                                var refID = -1;

                                if (reader["Ref_ID"] != DBNull.Value) refID = Convert.ToInt32(reader["Ref_ID"]);
                                if (reader["Reference"] != DBNull.Value) refName = reader["Reference"].ToString();
                                if (reader["Protein_ID"] != DBNull.Value)
                                    proteinId = Convert.ToInt32(reader["Protein_ID"]);

                                var protein = new Protein();
                                protein.Sequence = refName;
                                protein.RefId = refID;
                                protein.ProteinId = proteinId;

                                // Link to the Mass tags.
                                var hasMassTagID = massTagToProtein.ContainsKey(id);
                                if (!hasMassTagID)
                                {
                                    massTagToProtein.Add(id, new List<Protein>());
                                }
                                massTagToProtein[id].Add(protein);
                                ;
                            }
                        }
                        reader.Close();
                    }
                }
                connection.Close();
            }
            return massTagToProtein;
        }
 private void UpdateResults()
 {
     var results = GroupComparisonModel.Results;
     var rows = new List<FoldChangeRow>();
     if (null != results)
     {
         var groupComparisonDef = results.GroupComparer.ComparisonDef;
         var adjustedPValues = PValues.AdjustPValues(results.ResultRows.Select(
             row => row.LinearFitResult.PValue)).ToArray();
         for (int iRow = 0; iRow < results.ResultRows.Count; iRow++)
         {
             var resultRow = results.ResultRows[iRow];
             var protein = new Protein(_skylineDataSchema, new IdentityPath(resultRow.Selector.Protein.Id));
             Model.Databinding.Entities.Peptide peptide = null;
             if (null != resultRow.Selector.Peptide)
             {
                 peptide = new Model.Databinding.Entities.Peptide(_skylineDataSchema,
                     new IdentityPath(protein.IdentityPath, resultRow.Selector.Peptide.Id));
             }
             rows.Add(new FoldChangeRow(protein, peptide, resultRow.Selector.LabelType,
                 resultRow.Selector.MsLevel, resultRow.Selector.GroupIdentifier, resultRow.ReplicateCount,
                 new FoldChangeResult(groupComparisonDef.ConfidenceLevel,
                     adjustedPValues[iRow], resultRow.LinearFitResult)));
         }
     }
     var defaultViewSpec = GetDefaultViewSpec(rows);
     if (!Equals(defaultViewSpec, ViewContext.BuiltInViews.First()))
     {
         var viewInfo = new ViewInfo(_skylineDataSchema, typeof (FoldChangeRow), defaultViewSpec).ChangeViewGroup(ViewGroup.BUILT_IN);
         ViewContext.SetRowSources(new[]
         {
             new RowSourceInfo(
                 rows, viewInfo)
         });
         if (null != _bindingListSource.ViewSpec && _bindingListSource.ViewSpec.Name == defaultViewSpec.Name &&
             !_bindingListSource.ViewSpec.Equals(defaultViewSpec))
         {
             _bindingListSource.SetView(viewInfo, rows);
         }
     }
     _bindingListSource.RowSource = rows;
 }