コード例 #1
0
ファイル: SubScoreFactory.cs プロジェクト: javamng/GitHUB
        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();
        }