public ProteinScoringGraphFactory(IMassBinning comparer, AminoAcidSet aminoAcidSet)
        {
            _comparer = comparer;
            _adjList = new LinkedList<ScoringGraphEdge>[_comparer.NumberOfBins];

            for (var i = 0; i < _comparer.NumberOfBins; i++) _adjList[i] = new LinkedList<ScoringGraphEdge>();

            var terminalModifications = FilteredProteinMassBinning.GetTerminalModifications(aminoAcidSet);
            var aminoAcidArray = FilteredProteinMassBinning.GetExtendedAminoAcidArray(aminoAcidSet);

            for (var i = 0; i < _comparer.NumberOfBins; i++)
            {
                var mi = _comparer.GetMass(i);
                var fineNodeMass = mi;

                for (var a = 0; a < aminoAcidArray.Length; a++)
                {
                    var aa = aminoAcidArray[a];
                    var j = _comparer.GetBinNumber(fineNodeMass + aa.Mass);
                    if (j < 0 || j >= _comparer.NumberOfBins) continue;
                    _adjList[j].AddLast(new ScoringGraphEdge(i));

                    if (i == 0 && !(aa is ModifiedAminoAcid))
                    {
                        foreach (var terminalMod in terminalModifications)
                        {
                            var modifiedAa = new ModifiedAminoAcid(aa, terminalMod);
                            j = _comparer.GetBinNumber(fineNodeMass + modifiedAa.Mass);
                            if (j < 0 || j >= _comparer.NumberOfBins) continue;
                            _adjList[j].AddLast(new ScoringGraphEdge(i));
                        }                        
                    }
                }
            }
        }
Beispiel #2
0
 // Generate an amino acid map with Cys static modification
 public AminoAcidSet(Modification cysMod) : this()
 {
     foreach (var loc in AllSequenceLocations)
     {
         var residueMap = _locationSpecificResidueMap[loc];
         residueMap['C'] = new ModifiedAminoAcid(residueMap['C'], cysMod);
     }
 }
Beispiel #3
0
 // Generate an amino acid map with Cys static modification
 public AminoAcidSet(Modification cysMod): this()
 {
     foreach (var loc in AllSequenceLocations)
     {
         var residueMap = _locationSpecificResidueMap[loc];
         residueMap['C'] = new ModifiedAminoAcid(residueMap['C'], cysMod);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Create a sequence using the supplied character sequence, modifications, and amino acid set
        /// </summary>
        /// <param name="sequence"></param>
        /// <param name="modStr">E.g. Acetyl 0,Oxidation 1,Oxidation 20,Oxidation 27</param>
        /// <param name="aminoAcidSet"></param>
        /// <returns></returns>
        public static Sequence CreateSequence(string sequence, string modStr, AminoAcidSet aminoAcidSet)
        {
            if (string.IsNullOrEmpty(modStr))
            {
                return(new Sequence(sequence, aminoAcidSet));
            }

            var indexModMap = new Dictionary <int, Modification>();

            foreach (var modIns in modStr.Split(','))
            {
                var token = modIns.Split(' ');
                if (token.Length != 2)
                {
                    return(null);                   // invalid modStr
                }
                var mod = Modification.Get(token[0]);
                if (mod == null)
                {
                    return(null);
                }
                var index = Convert.ToInt32(token[1]) - 1;
                indexModMap.Add(index, mod);
            }

            var aaList = new List <AminoAcid>();

            for (var i = 0; i < sequence.Length; i++)
            {
                var residue = sequence[i];
                var aa      = aminoAcidSet.GetAminoAcid(residue);
                if (i == 0 && indexModMap.ContainsKey(-1))  // N-term modification
                {
                    var nTermMod = indexModMap[-1];
                    aa = new ModifiedAminoAcid(aa, nTermMod);
                }

                if (indexModMap.TryGetValue(i, out var mod))
                {
                    var modifiedAa = new ModifiedAminoAcid(aa, mod);
                    aaList.Add(modifiedAa);
                }
                else
                {
                    aaList.Add(aa);
                }
            }

            return(new Sequence(aaList));
        }
Beispiel #5
0
        public Composition.Composition[] GetUniqueCompositions()
        {
            //var aaList = AminoAcid.StandardAminoAcidArr.ToList();
            var uniqueCompositionList = new List <Composition.Composition>();
            var tempModTable          = new List <Composition.Composition> [AminoAcid.StandardAminoAcidArr.Length];

            for (var i = 0; i < AminoAcid.StandardAminoAcidArr.Length; i++)
            {
                tempModTable[i] = new List <Composition.Composition>();
                uniqueCompositionList.Add(AminoAcid.StandardAminoAcidArr[i].Composition);
            }

            foreach (var location in AllSequenceLocations)
            {
                //var keys = _locationSpecificResidueMap[location].Keys.ToArray();
                for (var i = 0; i < AminoAcid.StandardAminoAcidArr.Length; i++)
                {
                    var residue = AminoAcid.StandardAminoAcidArr[i].Residue;
                    var aa      = GetAminoAcid(residue, location);

                    foreach (var modIndex in GetModificationIndices(residue, location))
                    {
                        var mAa = new ModifiedAminoAcid(aa, _modificationParams.GetModification(modIndex));
                        if (tempModTable[i].Contains(mAa.Composition))
                        {
                            continue;
                        }
                        tempModTable[i].Add(mAa.Composition);
                        uniqueCompositionList.Add(mAa.Composition);
                        //aaList.Add(mAa);
                    }
                    //Console.WriteLine();
                }
            }

            return(uniqueCompositionList.ToArray());
        }
        public FilteredProteinMassBinning(AminoAcidSet aaSet, double maxProteinMass = 50000, int numBits = 27)
        {
            _aminoAcidSet = aaSet;
            var terminalModifications = GetTerminalModifications(aaSet);
            var extendedAminoAcidArray = GetExtendedAminoAcidArray(aaSet);

            MaxMass = maxProteinMass;
            MinMass = MaxMass;
            foreach (var aa in extendedAminoAcidArray)
            {
                if (aa.Mass < MinMass) MinMass = aa.Mass;
                foreach (var mod in terminalModifications)
                {
                    var modAa = new ModifiedAminoAcid(aa, mod);
                    if (modAa.Mass < MinMass) MinMass = modAa.Mass;
                }
            }

            _mzComparer = new MzComparerWithBinning(numBits);

            _minMzBinIndex = _mzComparer.GetBinNumber(MinMass);
            _maxMzBinIndex = _mzComparer.GetBinNumber(MaxMass);

            var numberOfMzBins = _maxMzBinIndex - _minMzBinIndex + 2; // pad zero mass bin
            _mzBinToFilteredBinMap = new int[numberOfMzBins];
            for (var i = 0; i < numberOfMzBins; i++) _mzBinToFilteredBinMap[i] = -1;

            var tempMap = new int[numberOfMzBins];
            var fineNodes = new BitArray(Constants.GetBinNumHighPrecision(MaxMass));
            fineNodes[0] = true;

            var effectiveBinCounter = 0;
            for (var fineBinIdx = 0; fineBinIdx < fineNodes.Length; fineBinIdx++)
            {
                if (!fineNodes[fineBinIdx]) continue;

                var fineNodeMass = fineBinIdx / Constants.RescalingConstantHighPrecision;

                foreach (var aa in extendedAminoAcidArray)
                {
                    var validFineNodeIndex = Constants.GetBinNumHighPrecision(fineNodeMass + aa.Mass);
                    if (validFineNodeIndex >= fineNodes.Length) break;
                    fineNodes[validFineNodeIndex] = true;

                    if (fineBinIdx == 0 && !(aa is ModifiedAminoAcid)) // include terminal modifications 
                    {
                        foreach (var terminalMod in terminalModifications)
                        {
                            var modifiedAa = new ModifiedAminoAcid(aa, terminalMod);
                            validFineNodeIndex = Constants.GetBinNumHighPrecision(fineNodeMass + modifiedAa.Mass);
                            if (validFineNodeIndex >= fineNodes.Length) break;
                            fineNodes[validFineNodeIndex] = true;                            
                        }                         
                    }
                }
                
                /*foreach (var m in massList)
                {
                    var validFineNodeIndex = Constants.GetBinNumHighPrecision(fineNodeMass + m);
                    if (validFineNodeIndex >= fineNodes.Length) break;
                    fineNodes[validFineNodeIndex] = true;
                }*/

                var binNum = _mzComparer.GetBinNumber(fineNodeMass);
                if (fineBinIdx == 0 || (binNum >= _minMzBinIndex && binNum <= _maxMzBinIndex && _mzBinToFilteredBinMap[binNum - _minMzBinIndex + 1] < 0))
                {
                    _mzBinToFilteredBinMap[binNum == 0 ? 0 : binNum - _minMzBinIndex + 1] = effectiveBinCounter;
                    tempMap[effectiveBinCounter] = binNum;
                    effectiveBinCounter++;
                }
            }
            _filteredBinToMzBinMap = new int[effectiveBinCounter];
            Array.Copy(tempMap, _filteredBinToMzBinMap, effectiveBinCounter);            
        }
        public static AminoAcid[] GetExtendedAminoAcidArray(AminoAcidSet aaSet)
        {
            var ret = new List<AminoAcid>();
            var modParam = aaSet.GetModificationParams();
            var aminoAcidArray = AminoAcid.StandardAminoAcidArr;

            foreach (var aa in aminoAcidArray)
            {
                ret.Add(aa);
                foreach (var modIndex in aaSet.GetModificationIndices(aa.Residue, SequenceLocation.Everywhere))
                {
                    var aa2 = new ModifiedAminoAcid(aa, modParam.GetModification(modIndex));
                    ret.Add(aa2);
                }
            }
            return ret.ToArray();
        }
Beispiel #8
0
        public AminoAcidSet(IEnumerable <SearchModification> searchModifications, int maxNumModsPerSequence) : this()
        {
            if (searchModifications == null)
            {
                return;
            }

            var modifications = searchModifications as SearchModification[] ?? searchModifications.ToArray();

            // apply fixed modifications
            foreach (var searchModification in modifications)
            {
                if (!searchModification.IsFixedModification)
                {
                    continue;
                }

                var location      = searchModification.Location;
                var targetResidue = searchModification.TargetResidue;

                foreach (var loc in AffectedLocations[location])
                {
                    var appliedResidue = targetResidue != '*' ? targetResidue : SequenceLocationToLocationResidue[loc];
                    var residueMap     = _locationSpecificResidueMap[loc];
                    residueMap[appliedResidue] = new ModifiedAminoAcid(residueMap[appliedResidue], searchModification.Modification);
                }
            }

            if (maxNumModsPerSequence <= 0)
            {
                return;
            }

            // apply dynamic modifications
            var dynamicModifications = new HashSet <Modification>();
            var locationSpecificResidueVariableModMap = new Dictionary <SequenceLocation, Dictionary <char, List <Modification> > >();

            foreach (var loc in AllSequenceLocations)
            {
                locationSpecificResidueVariableModMap[loc] = new Dictionary <char, List <Modification> >();
            }

            foreach (var searchModification in modifications)
            {
                if (searchModification.IsFixedModification)
                {
                    continue;
                }

                dynamicModifications.Add(searchModification.Modification);
                var location      = searchModification.Location;
                var targetResidue = searchModification.TargetResidue;

                foreach (var loc in AffectedLocations[location])
                {
                    var residueModMap  = locationSpecificResidueVariableModMap[loc];
                    var appliedResidue = targetResidue != '*' ? targetResidue : SequenceLocationToLocationResidue[loc];
                    List <Modification> modList;
                    if (residueModMap.TryGetValue(appliedResidue, out modList))
                    {
                        modList.Add(searchModification.Modification);
                    }
                    else
                    {
                        residueModMap.Add(appliedResidue, new List <Modification> {
                            searchModification.Modification
                        });
                    }
                }
            }

            var dynModArray = dynamicModifications.ToArray();

            _modificationParams = new ModificationParams(dynModArray, maxNumModsPerSequence);

            foreach (var loc in AllSequenceLocations)
            {
                var residueModMap = locationSpecificResidueVariableModMap[loc];
                foreach (var entry in residueModMap)
                {
                    var residue = entry.Key;
                    var modList = entry.Value;

                    var modIndexArr = new int[modList.Count];
                    var index       = -1;
                    foreach (var mod in modList)
                    {
                        var modIndex = Array.IndexOf(dynModArray, mod);
                        modIndexArr[++index] = modIndex;
                    }
                    _locationSpecificResidueModMap[loc].Add(residue, modIndexArr);
                }
            }
        }
Beispiel #9
0
        public AminoAcidSet(IEnumerable<SearchModification> searchModifications, int maxNumModsPerSequence): this()
        {
            if (searchModifications == null) return;

            var modifications = searchModifications as SearchModification[] ?? searchModifications.ToArray();

            // apply fixed modifications
            foreach (var searchModification in modifications)
            {
                if (!searchModification.IsFixedModification) continue;

                var location = searchModification.Location;
                var targetResidue = searchModification.TargetResidue;

                foreach (var loc in AffectedLocations[location])
                {
                    var appliedResidue = targetResidue != '*' ? targetResidue : SequenceLocationToLocationResidue[loc];
                    var residueMap = _locationSpecificResidueMap[loc];
                    residueMap[appliedResidue] = new ModifiedAminoAcid(residueMap[appliedResidue], searchModification.Modification);
                }
            }

            if (maxNumModsPerSequence <= 0) return;

            // apply dynamic modifications
            var dynamicModifications = new HashSet<Modification>();
            var locationSpecificResidueVariableModMap = new Dictionary<SequenceLocation,Dictionary<char, List<Modification>>>();
            foreach (var loc in AllSequenceLocations)
            {
                locationSpecificResidueVariableModMap[loc] = new Dictionary<char, List<Modification>>();
            }

            foreach (var searchModification in modifications)
            {
                if (searchModification.IsFixedModification) continue;

                dynamicModifications.Add(searchModification.Modification);
                var location = searchModification.Location;
                var targetResidue = searchModification.TargetResidue;

                foreach (var loc in AffectedLocations[location])
                {
                    var residueModMap = locationSpecificResidueVariableModMap[loc];
                    var appliedResidue = targetResidue != '*' ? targetResidue : SequenceLocationToLocationResidue[loc];
                    List<Modification> modList;
                    if (residueModMap.TryGetValue(appliedResidue, out modList))
                    {
                        modList.Add(searchModification.Modification);
                    }
                    else
                    {
                        residueModMap.Add(appliedResidue, new List<Modification> { searchModification.Modification });
                    }
                }
            }

            var dynModArray = dynamicModifications.ToArray();
            _modificationParams = new ModificationParams(dynModArray, maxNumModsPerSequence);

            foreach (var loc in AllSequenceLocations)
            {
                var residueModMap = locationSpecificResidueVariableModMap[loc];
                foreach (var entry in residueModMap)
                {
                    var residue = entry.Key;
                    var modList = entry.Value;

                    var modIndexArr = new int[modList.Count];
                    var index = -1;
                    foreach (var mod in modList)
                    {
                        var modIndex = Array.IndexOf(dynModArray, mod);
                        modIndexArr[++index] = modIndex;
                    }
                    _locationSpecificResidueModMap[loc].Add(residue, modIndexArr);
                }
            }

        }
Beispiel #10
0
        public Composition.Composition[] GetUniqueCompositions()
        {
            //var aaList = AminoAcid.StandardAminoAcidArr.ToList();
            var uniqueCompositionList = new List<Composition.Composition>();
            var tempModTable = new List<Composition.Composition>[AminoAcid.StandardAminoAcidArr.Length];
            for (var i = 0; i < AminoAcid.StandardAminoAcidArr.Length; i++)
            {
                tempModTable[i] = new List<Composition.Composition>();
                uniqueCompositionList.Add(AminoAcid.StandardAminoAcidArr[i].Composition);
            }

            foreach (var location in AllSequenceLocations)
            {
                //var keys = _locationSpecificResidueMap[location].Keys.ToArray();
                for(var i =0; i < AminoAcid.StandardAminoAcidArr.Length; i++)
                {
                    var residue = AminoAcid.StandardAminoAcidArr[i].Residue;
                    var aa = GetAminoAcid(residue, location);

                    foreach (var modIndex in GetModificationIndices(residue, location))
                    {
                        var mAa = new ModifiedAminoAcid(aa, _modificationParams.GetModification(modIndex));
                        if (tempModTable[i].Contains(mAa.Composition)) continue;
                        tempModTable[i].Add(mAa.Composition);
                        uniqueCompositionList.Add(mAa.Composition);
                        //aaList.Add(mAa);
                    }
                    //Console.WriteLine();
                }
            }

            return uniqueCompositionList.ToArray();
        }