예제 #1
0
 public static LCTrace CreateTrace(LCMSGroup Group, MZData Start)
 {
     if (Group == null)
     {
         return(null);
     }
     if (Start == null)
     {
         Start = Group.Points[0];
         foreach (MZData P in Group.Points)
         {
             if (P.Intensity > Start.Intensity)
             {
                 Start = P;
             }
         }
     }
     return(new LCTrace(Group, Start));
 }
예제 #2
0
        private MZData TakeFreePoint(int Scan, double Mass, LCMSGroup Group)
        {
            MZData Point = RawFile.RawSpectra[Scan].FindNearestPeak(Mass, Program.MassError);

            if (Point.Mass != 0.0)
            {
                if (Point.Group == null)
                {
                    Point.Group = Group;
                    Group.Points.Add(Point);
                    return(Point);
                }
                else
                {
                    if (Point.Group != Group)
                    {
                        //Console.WriteLine("Warning: Group conflict {0}",ConflictCounter++);
                        ConflictCounter++;
                    }
                }
            }
            return(null);
        }
예제 #3
0
 LCTrace(LCMSGroup Group, MZData Start)
 {
     this.Group      = Group;
     this.StartPoint = Start;
 }
예제 #4
0
        static int Main(string[] args)
        {
            //Data Sources
            //args[0] - database
            //args[1] - Raw File Name
            //args[2] - ID for file
            try{
                Console.ReadLine();
                Console.WriteLine("Information: Loading...", args[1]);

                //Load Parameters

                string DBName = args[0];
                int    FileID = Convert.ToInt32(args[2]);
                //against database locking at start time

                int RepeatCount = 0;
                while (RepeatCount < 10)
                {
                    try{
                        DBInt = new DBInterface();
                        DBInt.InitDB(DBName);
                        LoadParameters();
                        break;
                    }catch (System.Data.SQLite.SQLiteException sqle) {
                        if (sqle.ErrorCode == System.Data.SQLite.SQLiteErrorCode.Busy && RepeatCount < 10)
                        {
                            //здесь возможна генерация идентичных features (- с точностью до границ пика)
                            Console.WriteLine("Warning: {0}", sqle.Message);
                            System.Threading.Thread.Sleep(10000);
                            RepeatCount++;
                        }
                        else
                        {
                            throw sqle;
                        }
                    }
                }

                RawFileService = new FileService(args[1]);

                Target T    = null;
                MZData P    = null;
                double MaxI = 0;

                Console.WriteLine("Information: Building data map");
                RawFileService.BuildDataMap();
                P    = RawFileService.BiggestUnused();
                T    = Target.TargetFromPoint(P, 0);
                MaxI = P.Intensity;

                Console.WriteLine("Information: Targets processing...", args[1]);

                List <Feature> ReadyFeatures = new List <Feature>();
                int            i             = 0;
                int            ICount        = 1;
                while (T != null)
                {
                    //Progress indicator
                    if ((int)Math.Pow(100, (Math.Log10(MaxI / DataThres) - Math.Log10(P.Intensity / DataThres)) / (Math.Log10(MaxI / DataThres))) > ICount)
                    {
                        Console.WriteLine("Information: Targets - {0}; Intensity - {1} ", i, P.Intensity);
                        Console.WriteLine("{0}%...", (int)Math.Pow(100, (Math.Log10(MaxI / DataThres) - Math.Log10(P.Intensity / DataThres)) / (Math.Log10(MaxI / DataThres))));
                        ICount++;
                    }
                    Feature F = FeatureForTarget(T, P);
                    if (F != null)
                    {
                        ReadyFeatures.Add(F);
                    }
                    i++;

                    //make a features from additional peaks
                    if (F != null)
                    {
                        for (int j = 0; j < F.TPeaks.Peaks.Count; j++)
                        {
                            if (F.TPeaks.TargetPeak != F.TPeaks.Peaks[j])
                            {
                                T = Target.TargetFromPeak(F.TPeaks.Peaks[j], i);
                                Feature NF = FeatureForTarget(T, P);
                                ReadyFeatures.Add(NF); //!!!!! ReadyFeatures.Add(F);
                                i++;
                            }
                        }
                    }
                    P = RawFileService.BiggestUnused();
                    if (P == null)
                    {
                        break;
                    }
                    T = Target.TargetFromPoint(P, i);
                }

                RepeatCount = 0;
                while (RepeatCount < 10000)
                {
                    try{
                        DBInt.tr = DBInt.con.BeginTransaction();
                        DBInt.SaveFile(args[1], FileID, RawFileService.RawFile.Mode);
                        LCMSGroup.GroupBase = DBInt.GetGroupBase();
                        foreach (Feature F in ReadyFeatures)
                        {
                            if (F != null && DBInt != null)
                            {
                                F.Write(DBInt.con, FileID);
                            }
                        }
                        RawFileService.SaveRTs(DBInt.con, FileID);
                        LCMSGroup.SaveGroups(DBInt.con, FileID);
                        DBInt.tr.Commit();
                        break;
                    }catch (System.Data.SQLite.SQLiteException sqle) {
                        if (sqle.ErrorCode == System.Data.SQLite.SQLiteErrorCode.Busy && RepeatCount < 1000)
                        {
                            Console.WriteLine("Warning: {0}", sqle.Message);
                            System.Threading.Thread.Sleep(1000);
                            RepeatCount++;
                        }
                        else
                        {
                            throw sqle;
                        }
                    }
                }
                Console.WriteLine("Completed");
                Console.ReadLine();
            }catch (Exception e) {
                Console.Write("Error:");
                Console.Write(e.Message);
                Console.WriteLine("STACKINFO:" + e.StackTrace);
                Console.WriteLine("Completed");
                Console.ReadLine();
                return(1);
            }
            return(0);
        }
예제 #5
0
        public LCMSGroup GroupFromPoint(MZData Point)
        {
            if (Point.Group != null)
            {
                return(Point.Group as LCMSGroup);
            }

            LCMSGroup Group = new LCMSGroup();

            Point.Group = Group;
            Group.Points.Add(Point);
            Queue <MZData> QPoints = new Queue <MZData>();

            QPoints.Enqueue(Point);
            do
            {
                MZData CurrentPoint = QPoints.Dequeue();
                int    ForwardScan  = RawFile.IndexDir[CurrentPoint.Scan];
                int    BackwardScan = RawFile.IndexRev[CurrentPoint.Scan];
                for (int i = 0; i < Program.ZeroScans + 1; i++)
                {
                    if (ForwardScan > 0)
                    {
                        MZData NextPoint = TakeFreePoint(ForwardScan, CurrentPoint.Mass, Group);
                        if (NextPoint != null)
                        {
                            QPoints.Enqueue(NextPoint);
                        }
                        ForwardScan = RawFile.IndexDir[ForwardScan];
                    }
                    if (BackwardScan > 0)
                    {
                        MZData NextPoint = TakeFreePoint(BackwardScan, CurrentPoint.Mass, Group);
                        if (NextPoint != null)
                        {
                            QPoints.Enqueue(NextPoint);
                        }
                        BackwardScan = RawFile.IndexRev[BackwardScan];
                    }
                }
            } while(QPoints.Count > 0);

            Group.Points.Sort((p1, p2) => p1.Scan.CompareTo(p2.Scan));
            //Add zero points
            Group.Points.Add(MZData.CreateZero(RawFile.IndexDir[Group.Points[Group.Points.Count - 1].Scan]));
            Group.Points.Add(MZData.CreateZero(RawFile.IndexRev[Group.Points[0].Scan]));
            for (int i = Group.Points.Count - 3; i > 0; i--)
            {
                int CurrentScan = RawFile.IndexRev[Group.Points[i].Scan];
                while (CurrentScan > Group.Points[i - 1].Scan)
                {
                    Group.Points.Add(MZData.CreateZero(CurrentScan));
                    CurrentScan = RawFile.IndexRev[CurrentScan];
                }
            }
            Group.Points.Sort((p1, p2) => p1.Scan.CompareTo(p2.Scan));

            if (Group.Points[Group.Points.Count - 1].RT - Group.Points[0].RT < Program.PeakMinWidth)
            {
                return(null);
            }

            LCMSGroup.Global.Add(Group);
            return(Group);
        }
예제 #6
0
        public LCMSGroup GroupFromArea(double StartRT, double EndRT, double MZ, double MassError = 0.0)
        {
            LCMSGroup Group = new LCMSGroup();

            if (MassError == 0.0)
            {
                MassError = Program.MassError;
            }
            int StartScan = RawFile.ScanNumFromRT(StartRT);
            int EndScan   = RawFile.ScanNumFromRT(EndRT);

            for (int Scan = RawFile.IndexDir[StartScan]; Scan <= EndScan; Scan = RawFile.IndexDir[Scan])
            {
                if (Scan == -1)
                {
                    break;
                }
                MZData Next = RawFile.RawSpectra[Scan].FindBiggestPeak(MZ, MassError);
                Group.Points.Add(Next);
            }

            //Заполнение дыр
            //из начала в конец
            int LastIndex = -Program.ZeroScans - 1;

            for (int i = 0; i < Group.Points.Count; i++)
            {
                if (Group.Points[i].Intensity == 0.0)
                {
                    if (i - LastIndex < Program.ZeroScans)
                    {
                        double LastMZ = Group.Points[LastIndex].Mass;
                        MZData Next   = RawFile.RawSpectra[Group.Points[i].Scan].FindBiggestPeak(LastMZ, MassError);
                        Group.Points[i] = Next;
                        if (Next.Intensity != 0.0)
                        {
                            LastIndex = i;
                        }
                    }
                }
                else
                {
                    LastIndex = i;
                }
            }
            //из конца в начало
            LastIndex = Group.Points.Count + Program.ZeroScans + 1;
            for (int i = Group.Points.Count - 1; i >= 0; i--)
            {
                if (Group.Points[i].Intensity == 0.0)
                {
                    if (LastIndex - i < Program.ZeroScans)
                    {
                        double LastMZ = Group.Points[LastIndex].Mass;
                        MZData Next   = RawFile.RawSpectra[Group.Points[i].Scan].FindBiggestPeak(LastMZ, MassError);
                        Group.Points[i] = Next;
                        if (Next.Intensity != 0.0)
                        {
                            LastIndex = i;
                        }
                    }
                }
                else
                {
                    LastIndex = i;
                }
            }

            //leading and tailing zeros (except one)
            while (Group.Points.Count > 1 &&
                   Group.Points[0].Intensity == 0.0 &&
                   Group.Points[1].Intensity == 0.0)
            {
                Group.Points.RemoveAt(0);
            }
            while (Group.Points.Count > 1 &&
                   Group.Points[Group.Points.Count - 1].Intensity == 0.0 &&
                   Group.Points[Group.Points.Count - 2].Intensity == 0.0)
            {
                Group.Points.RemoveAt(Group.Points.Count - 1);
            }

            if (Group.Points.Count <= 1)
            {
                return(null);
            }

            LCMSGroup.Global.Add(Group);
            return(Group);
        }