Esempio n. 1
0
 protected FeatureNode(IsotopomerFeatures isotopomerFeatures, IonType ionType, Feature precursorFeature, GroupParameter groupParameter)
 {
     _isotopomerFeatures  = isotopomerFeatures;
     FragmentIonClassBase = ionType;
     PrecursorFeature     = precursorFeature;
     GroupParameter       = groupParameter;
     GetCorrelations();
 }
Esempio n. 2
0
 internal List <IonType> GetIonTypes(GroupParameter parameter)
 {
     if (_ionTypeDictionary.ContainsKey(parameter))
     {
         return(_ionTypeDictionary[parameter]);
     }
     return(new List <IonType>());
 }
Esempio n. 3
0
 internal double GetImsCorrelationScore(double imsCorr, GroupParameter parameter)
 {
     if (_imsCorrScoreDictionary.Count == 0)
     {
         return(CorrToIntForLcImsScore(imsCorr) / (double)MaxCorrIntScore * (HighScoreForLcImsScore - LowScoreForLcImsScore) + LowScoreForLcImsScore);
     }
     return(GetScoreFromDictionary(_imsCorrScoreDictionary, CorrToIntForLcImsScore(imsCorr), parameter, LowScoreForLcImsScore));
 }
Esempio n. 4
0
 protected FeatureNode(IsotopomerFeatures isotopomerFeatures, IonType ionType, Feature precursorFeature, GroupParameter groupParameter)
 {
     _isotopomerFeatures = isotopomerFeatures;
     FragmentIonClassBase = ionType;
     PrecursorFeature = precursorFeature;
     GroupParameter = groupParameter;
     GetCorrelations();
 }
Esempio n. 5
0
 public double GetCutScore(char nTermAA, char cTermAA, Composition cutComposition, Feature precursorFeature)
 {
     UpdatePrecursorFeatureNode(precursorFeature);
     var parameter = new GroupParameter(cutComposition, nTermAA, cTermAA, _precursorIon);
     _graph = new FragmentFeatureGraph(_imsData, PrecursorFeatureNode, precursorFeature, _precursorIon,
                                          cutComposition, parameter, _scoringParams);
     SupportingIonTypes = _graph.supportingIonTypes;
     return _graph.Score;
 }
Esempio n. 6
0
 private void UpdatePrecursorFeatureNode(Feature precursorFeature)
 {
     if (_previousPrecursorFeature != null && _previousPrecursorFeature == precursorFeature) return;
     var parameter = new GroupParameter(_precursorIon);
     PrecursorFeatureNode =
         new PrecursorFeatureNode(
             IsotopomerFeatures.GetPrecursorIsotopomerFeatures(_imsData, _precursorIon, precursorFeature),
             parameter, _scoringParams);
     _previousPrecursorFeature = precursorFeature;
 }
Esempio n. 7
0
 internal double GetIsotopeIntensityCorrelationScore(double isotopeCorr, GroupParameter groupParameter)
 {
     if (_isotopeIntensityCorrScoreDictionary.Count == 0)
     {
         var ret = CorrToIntForIsotopeScore(isotopeCorr) / (double)MaxCorrIntScore *
                   (HighScoreForIsotopeScore - LowScoreForIsotopeScore) + LowScoreForIsotopeScore;
         return(ret);
     }
     return(GetScoreFromDictionary(_isotopeIntensityCorrScoreDictionary, CorrToIntForIsotopeScore(isotopeCorr), groupParameter, LowScoreForIsotopeScore));
 }
Esempio n. 8
0
        public double GetCutScore(char nTermAA, char cTermAA, Composition cutComposition, Feature precursorFeature)
        {
            UpdatePrecursorFeatureNode(precursorFeature);
            var parameter = new GroupParameter(cutComposition, nTermAA, cTermAA, _precursorIon);

            _graph = new FragmentFeatureGraph(_imsData, PrecursorFeatureNode, precursorFeature, _precursorIon,
                                              cutComposition, parameter, _scoringParams);
            SupportingIonTypes = _graph.supportingIonTypes;
            return(_graph.Score);
        }
Esempio n. 9
0
        private void UpdatePrecursorFeatureNode(Feature precursorFeature)
        {
            if (_previousPrecursorFeature != null && _previousPrecursorFeature == precursorFeature)
            {
                return;
            }
            var parameter = new GroupParameter(_precursorIon);

            PrecursorFeatureNode =
                new PrecursorFeatureNode(
                    IsotopomerFeatures.GetPrecursorIsotopomerFeatures(_imsData, _precursorIon, precursorFeature),
                    parameter, _scoringParams);
            _previousPrecursorFeature = precursorFeature;
        }
Esempio n. 10
0
        public FragmentFeatureGraph(ImsDataCached imsData, PrecursorFeatureNode precursorNode, Feature precursorFeature,
                                    Ion precursorIon, Composition cutComposition, GroupParameter parameter, SubScoreFactory scoringParams)
        {
            _scoringParams        = scoringParams;
            _precursorFeatureNode = precursorNode;

            Add(precursorNode, new List <FeatureEdge>());
            var fragmentNodes = GetFragmentNodes(imsData, precursorFeature, cutComposition, precursorIon, parameter);

            supportingIonTypes = new List <IonType>();
            foreach (var node in fragmentNodes)
            {
                if (node.Feature != null)
                {
                    supportingIonTypes.Add(node.FragmentIonClassBase);
                }
            }
            //var nn = fragmentNodes.Count(no => no.Feature != null);
            //Console.WriteLine(this + "Num features : " + nn);


            var usedNodes = new List <FeatureNode> {
                precursorNode
            };

            UpdateEdges(fragmentNodes, usedNodes); // from precursor to any of fragment nodes
            if (this[precursorNode].Count == 0)
            {
                NodeScore = RatioScore = -1; //TODO should be trained..
                Score     = NodeScore + RatioScore;
                return;
            }
            // usedNodes.Remove(precursorNode);// exclude precursorNode
            var primeNode   = (FragmentFeatureNode)this[precursorNode][0].RNode;
            var targetNodes = GetTargetNodes(primeNode, fragmentNodes, true, false);

            UpdateEdges(targetNodes, usedNodes); // to the nodes of different terminal ions
            targetNodes = GetTargetNodes(primeNode, fragmentNodes, false, false);

            UpdateEdges(targetNodes, usedNodes); // to the nodes of the same terminal ions
            targetNodes = GetTargetNodes(primeNode, fragmentNodes, true, true);
            UpdateEdges(targetNodes, usedNodes); // to the nodes of differently charged ions

            GetScore();
        }
Esempio n. 11
0
 internal double GetNoIonScore(GroupParameter parameter)
 {
     return(_noIonScore[parameter]);
 }
Esempio n. 12
0
 internal double GetNoIonScore(GroupParameter parameter)
 {
     return _noIonScore[parameter];
 }
Esempio n. 13
0
 internal double GetImsCorrelationScore(double imsCorr, GroupParameter parameter)
 {
     if (_imsCorrScoreDictionary.Count == 0)
         return CorrToIntForLcImsScore(imsCorr) / (double)MaxCorrIntScore * (HighScoreForLcImsScore - LowScoreForLcImsScore) + LowScoreForLcImsScore;
     return GetScoreFromDictionary(_imsCorrScoreDictionary, CorrToIntForLcImsScore(imsCorr), parameter, LowScoreForLcImsScore);
 }
Esempio n. 14
0
 internal double GetKLDivergence(IonType ionType, int ratio, GroupParameter groupParameter)
 {
     return(GetKLDivergence(ionType, ionType, ratio, groupParameter));
 }
Esempio n. 15
0
        private List <FragmentFeatureNode> GetFragmentNodes(ImsDataCached imsData, Feature precursorFeature, Composition cutComposition, Ion precursorIon, GroupParameter parameter)
        {
            var ionTypes = _scoringParams.GetIonTypes(parameter);

            var nodes             = new List <FragmentFeatureNode>();
            var suffixComposition = precursorIon.Composition - Composition.H2O - cutComposition;

            //Console.WriteLine(cutComposition.GetMass() + " " + suffixComposition.GetMass());

            foreach (var ionType in ionTypes)
            {
                var composition = ionType.IsPrefixIon ? cutComposition : suffixComposition;
                //Console.WriteLine("FragFeatureGraph\t" + ionType.Name + "\t" + composition.GetMass() + "\t" + ionType.GetIon(composition).GetMonoIsotopicMz());
                var node = new FragmentFeatureNode(IsotopomerFeatures.GetFramentIsotopomerFeatures(imsData, composition, ionType, precursorFeature), ionType, precursorFeature, parameter, _scoringParams);
                //if(node.Feature != null)
                //    if (20 * node.Feature.IntensityMax < precursorFeature.IntensityMax || node.Feature.IntensityMax > 20 * precursorFeature.IntensityMax) continue; //

                nodes.Add(node);
            }
            return(nodes);
        }
Esempio n. 16
0
 private double GetScoreFromDictionary(Dictionary<GroupParameter, Dictionary<int, double>> scoreDictionary, int rawScore, GroupParameter parameter, double lowScore)
 {
     var key = parameter.GetPrecursorGroupParameter();
     if (!scoreDictionary.ContainsKey(key)) return lowScore;
     var l1 = scoreDictionary[key];
     return !l1.ContainsKey(rawScore) ? lowScore : l1[rawScore];
 }
Esempio n. 17
0
 private double GetScoreFromDictionary(Dictionary<GroupParameter, Dictionary<Tuple<int, int>, Dictionary<int, double>>> scoreDictionary, IonType ionType1, IonType ionType2, int rawScore, GroupParameter groupParameter, double lowScore)
 {
     if (!scoreDictionary.ContainsKey(groupParameter)) return lowScore;
     var l1 = scoreDictionary[groupParameter];
     var si = _ionTypeIndexDictionary[groupParameter];
     var key = new Tuple<int, int> ( si[ionType1], si[ionType2] );
     if (!l1.ContainsKey(key)) return lowScore;
     var l2 = l1[key];
     return !l2.ContainsKey(rawScore) ? lowScore : l2[rawScore];
 }
Esempio n. 18
0
 internal double GetKLDivergence(IonType ionType, int ratio, GroupParameter groupParameter)
 {
     return GetKLDivergence(ionType, ionType, ratio, groupParameter);
 }
Esempio n. 19
0
 internal double GetKLDivergence(IonType ionType, IonType ionType1, int ratio, GroupParameter groupParameter)
 {
     double prob1 = 1, prob2 = 1;
     var si = _ionTypeIndexDictionary[groupParameter];
     var ionTypeIndices = new Tuple<int, int> ( si[ionType], si[ionType1]); 
     if(_ratioTargetProbDictionary.ContainsKey(groupParameter))
     {
         prob1 = prob1 * _ratioTargetProbDictionary[groupParameter][ionTypeIndices][ratio];
         prob2 = prob2 * _ratioDecoyProbDictionary[groupParameter][ionTypeIndices][ratio];
     }
    
     return GetKLDivergence(prob1, prob2);
 }
Esempio n. 20
0
 internal double GetIsotopeIntensityCorrelationScoreForPrecursor(double isotopeCorr, GroupParameter groupParameter)
 {
     if (_isotopeIntensityCorrScoreDictionary.Count == 0)
     {
         var ret = CorrToIntForIsotopeScoreForPrecursor(isotopeCorr) / (double)MaxCorrIntScore *
                (HighScoreForIsotopeScore - LowScoreForIsotopeScore) + LowScoreForIsotopeScore;
         return ret;
     }
     return GetScoreFromDictionary(_isotopeIntensityCorrScoreDictionary, CorrToIntForIsotopeScoreForPrecursor(isotopeCorr), groupParameter, LowScoreForIsotopeScore);
 }
Esempio n. 21
0
 internal double GetRatioScore(IonType ionType, int ratio, GroupParameter parameter)  // between precursor and frag ion
 {
     return GetRatioScore(ionType, ionType, ratio, parameter);
 }
Esempio n. 22
0
 internal double GetRatioScore(IonType ionType1, IonType ionType2, int ratio, GroupParameter parameter)
 {
     return(GetScoreFromDictionary(_ratioScoreDictionary, ionType1, ionType2, ratio, parameter, LowScoreForIsotopeScore));
 }
Esempio n. 23
0
        private double GetScoreFromDictionary(Dictionary <GroupParameter, Dictionary <int, double> > scoreDictionary, int rawScore, GroupParameter parameter, double lowScore)
        {
            var key = parameter.GetPrecursorGroupParameter();

            if (!scoreDictionary.ContainsKey(key))
            {
                return(lowScore);
            }
            var l1 = scoreDictionary[key];

            return(!l1.ContainsKey(rawScore) ? lowScore : l1[rawScore]);
        }
Esempio n. 24
0
 internal double GetRatioScore(IonType ionType, int ratio, GroupParameter parameter)  // between precursor and frag ion
 {
     return(GetRatioScore(ionType, ionType, ratio, parameter));
 }
Esempio n. 25
0
 public FragmentFeatureNode(IsotopomerFeatures isotopomerFeatures, IonType fragmentIonClassBase, Feature precursorFeature,
                            GroupParameter parameter, SubScoreFactory scoringParams)
     : base(isotopomerFeatures, fragmentIonClassBase, precursorFeature, parameter)
 {
     _scoringParams = scoringParams;
 }
Esempio n. 26
0
        internal double GetKLDivergence(IonType ionType, IonType ionType1, int ratio, GroupParameter groupParameter)
        {
            double prob1 = 1, prob2 = 1;
            var    si             = _ionTypeIndexDictionary[groupParameter];
            var    ionTypeIndices = new Tuple <int, int> (si[ionType], si[ionType1]);

            if (_ratioTargetProbDictionary.ContainsKey(groupParameter))
            {
                prob1 = prob1 * _ratioTargetProbDictionary[groupParameter][ionTypeIndices][ratio];
                prob2 = prob2 * _ratioDecoyProbDictionary[groupParameter][ionTypeIndices][ratio];
            }

            return(GetKLDivergence(prob1, prob2));
        }
Esempio n. 27
0
 internal List<IonType> GetIonTypes(GroupParameter parameter)
 {
     if(_ionTypeDictionary.ContainsKey(parameter))
         return _ionTypeDictionary[parameter];
     return new List<IonType>();
 }
Esempio n. 28
0
        private double GetScoreFromDictionary(Dictionary <GroupParameter, Dictionary <Tuple <int, int>, Dictionary <int, double> > > scoreDictionary, IonType ionType1, IonType ionType2, int rawScore, GroupParameter groupParameter, double lowScore)
        {
            if (!scoreDictionary.ContainsKey(groupParameter))
            {
                return(lowScore);
            }
            var l1  = scoreDictionary[groupParameter];
            var si  = _ionTypeIndexDictionary[groupParameter];
            var key = new Tuple <int, int> (si[ionType1], si[ionType2]);

            if (!l1.ContainsKey(key))
            {
                return(lowScore);
            }
            var l2 = l1[key];

            return(!l2.ContainsKey(rawScore) ? lowScore : l2[rawScore]);
        }
Esempio n. 29
0
 internal double GetRatioScore(IonType ionType1, IonType ionType2, int ratio, GroupParameter parameter)
 {
     return GetScoreFromDictionary(_ratioScoreDictionary, ionType1, ionType2, ratio, parameter, LowScoreForIsotopeScore);
 }
Esempio n. 30
0
        private void Read(string filePath)
        {
            var ratioProbDictionary = _ratioTargetProbDictionary;
            var isotopeIntensityCorrTargetProbDictionary = new Dictionary <GroupParameter, Dictionary <int, Dictionary <int, double> > >();
            var isotopeIntensityCorrDecoyProbDictionary  = new Dictionary <GroupParameter, Dictionary <int, Dictionary <int, double> > >();
            var isotopeIntensityCorrProbDictionary       = isotopeIntensityCorrTargetProbDictionary;

            var noIonTargetProbDictionary = new Dictionary <GroupParameter, double>();
            var noIonDecoyProbDictionary  = new Dictionary <GroupParameter, double>();
            var noIonProbDictionary       = noIonTargetProbDictionary;

            var            stremaReader = new StreamReader(filePath);
            string         s;
            var            mode           = -1;
            GroupParameter groupParameter = null;
            List <int>     ionTypeIndices = null;

            while ((s = stremaReader.ReadLine()) != null)
            {
                if (s.StartsWith("###DECOY"))
                {
                    ratioProbDictionary = _ratioDecoyProbDictionary;
                    isotopeIntensityCorrProbDictionary = isotopeIntensityCorrDecoyProbDictionary;
                    noIonProbDictionary = noIonDecoyProbDictionary;
                    continue;
                }
                if (s.StartsWith("##IONTYPES"))
                {
                    mode = 1;
                    continue;
                }
                if (s.StartsWith("##ISOTOPE"))
                {
                    mode = 2;
                    continue;
                }
                if (s.StartsWith("##RATIO"))
                {
                    mode = 3;
                    continue;
                }
                if (s.StartsWith("##NOION"))
                {
                    mode = 4;
                    continue;
                }

                var token = s.Split('\t');
                if (s.StartsWith("#G"))
                {
                    groupParameter = GroupParameter.Parse(token[1]);
                    continue;
                }

                if (s.StartsWith("#I"))
                {
                    if (mode == 1)
                    {
                        var ionType = IonType.Parse(token[1]);
                        if (groupParameter == null || ionType == null)
                        {
                            continue;
                        }
                        if (!_ionTypeDictionary.ContainsKey(groupParameter))
                        {
                            _ionTypeDictionary[groupParameter] = new List <IonType>();
                        }
                        _ionTypeDictionary[groupParameter].Add(ionType);
                    }
                    else
                    {
                        ionTypeIndices = new List <int>();
                        for (var i = 1; i < token.Length; i++)
                        {
                            ionTypeIndices.Add(int.Parse(token[i]));
                        }
                    }
                    continue;
                }
                if (!s.StartsWith("#") && token.Length > 0)
                {
                    if (mode == 2)
                    {
                        if (groupParameter == null || ionTypeIndices == null || ionTypeIndices.Count == 0)
                        {
                            continue;
                        }
                        if (!isotopeIntensityCorrProbDictionary.ContainsKey(groupParameter))
                        {
                            isotopeIntensityCorrProbDictionary[groupParameter] = new Dictionary <int, Dictionary <int, double> >();
                        }
                        var si = isotopeIntensityCorrProbDictionary[groupParameter];
                        if (!si.ContainsKey(ionTypeIndices[0]))
                        {
                            si[ionTypeIndices[0]] = new Dictionary <int, double>();
                        }
                        var ssi = si[ionTypeIndices[0]];
                        foreach (var scoreStr in token)
                        {
                            var st = scoreStr.Split(',');
                            if (st.Length == 2)
                            {
                                ssi[int.Parse(st[0])] = double.Parse(st[1]);
                            }
                        }
                    }
                    else if (mode == 3)
                    {
                        if (groupParameter == null || ionTypeIndices == null || ionTypeIndices.Count < 2)
                        {
                            continue;
                        }
                        if (!ratioProbDictionary.ContainsKey(groupParameter))
                        {
                            ratioProbDictionary[groupParameter] = new Dictionary <Tuple <int, int>, Dictionary <int, double> >();
                        }
                        var sr  = ratioProbDictionary[groupParameter];
                        var key = new Tuple <int, int>(ionTypeIndices[0], ionTypeIndices[1]);
                        if (!sr.ContainsKey(key))
                        {
                            sr[key] = new Dictionary <int, double>();
                        }
                        var ssr = sr[key];
                        foreach (var scoreStr in token)
                        {
                            var st = scoreStr.Split(',');
                            if (st.Length == 2)
                            {
                                ssr[int.Parse(st[0])] = double.Parse(st[1]);
                            }
                        }
                    }
                    else if (mode == 4)
                    {
                        if (groupParameter == null)
                        {
                            continue;
                        }
                        noIonProbDictionary[groupParameter] = double.Parse(s);
                    }
                }
            }

            foreach (var k in noIonTargetProbDictionary.Keys)
            {
                _noIonScore[k] = GetLogLRScore(noIonTargetProbDictionary[k], noIonDecoyProbDictionary[k]);
            }

            GetScoreDictionariesFromProbDictionaries();
        }
Esempio n. 31
0
 public FragmentFeatureNode(IsotopomerFeatures isotopomerFeatures, IonType fragmentIonClassBase, Feature precursorFeature,
     GroupParameter parameter, SubScoreFactory scoringParams)
     : base(isotopomerFeatures, fragmentIonClassBase, precursorFeature, parameter)
 {
     _scoringParams = scoringParams;
 }