Exemple #1
0
        public static List <OffsetEntry> ReadFromFile(string fileName)
        {
            var result = new List <OffsetEntry>();
            var lines  = File.ReadAllLines(fileName);

            for (int i = 1; i < lines.Length; i++)
            {
                var parts = lines[i].Split('\t');
                if (parts.Length < 6)
                {
                    break;
                }

                OffsetEntry entry = new OffsetEntry(int.Parse(parts[0]), double.Parse(parts[2]), double.Parse(parts[4]), int.Parse(parts[3]));
                entry.InitValue.MedianInWindow = double.Parse(parts[5]);

                if (parts.Length > 6)
                {
                    entry.RefineValue.Count          = int.Parse(parts[6]);
                    entry.RefineValue.IonOffset      = int.Parse(parts[7]);
                    entry.RefineValue.MedianInWindow = int.Parse(parts[8]);
                }

                result.Add(entry);
            }
            return(result);
        }
Exemple #2
0
        protected void CalculateOffset(List <OffsetEntry> offsets, Func <OffsetEntry, OffsetValue> func)
        {
            for (int i = 0; i < offsets.Count; i++)
            {
                List <OffsetEntry> window = new List <OffsetEntry>();
                for (int j = i; j >= 0; j--)
                {
                    if (offsets[i].RetentionTime - offsets[j].RetentionTime < rtWindow)
                    {
                        if (func(offsets[j]).Count > 0)
                        {
                            window.Add(offsets[j]);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                for (int j = i + 1; j < offsets.Count; j++)
                {
                    if (offsets[j].RetentionTime - offsets[i].RetentionTime < rtWindow)
                    {
                        if (func(offsets[j]).Count > 0)
                        {
                            window.Add(offsets[j]);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                if (window.Count > 0)
                {
                    func(offsets[i]).MedianInWindow = Statistics.Median(from w in window select func(w).IonOffset);
                }
                else
                {
                    func(offsets[i]).MedianInWindow = -1;
                }
            }

            for (int i = 0; i < offsets.Count; i++)
            {
                if (func(offsets[i]).MedianInWindow == -1)
                {
                    OffsetEntry before = null;
                    OffsetEntry after  = null;

                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (func(offsets[j]).Count > 0)
                        {
                            before = offsets[j];
                            break;
                        }
                    }

                    for (int j = i + 1; j < offsets.Count; j++)
                    {
                        if (func(offsets[j]).Count > 0)
                        {
                            after = offsets[j];
                            break;
                        }
                    }

                    if (before == null || after == null)
                    {
                        continue;
                    }

                    func(offsets[i]).IonOffset      = (func(before).IonOffset + func(after).IonOffset) / 2;
                    func(offsets[i]).MedianInWindow = (func(before).MedianInWindow + func(after).MedianInWindow) / 2;
                }
            }
        }