Пример #1
0
        public void PrepDatabase(string rawFilePath, string outputDirectory)
        {
            var rawFile = new ThermoRawFile(rawFilePath);

            rawFile.Open();
            var path = outputDirectory + "\\" + rawFile.Name + "_ExtractedFeatures.gcfeat";
            var conn = new SQLiteConnection(@"Data Source=" + path);

            conn.Open();
            SQLiteIOMethods.CreateTablesInDatabase(conn);
            SQLiteIOMethods.AddRawFileEntry(rawFile, conn);
            SQLiteIOMethods.AddRawFileTICChroma(rawFile, conn);
            SQLiteIOMethods.CreateIndices(conn);
            conn.Close();
            conn.Dispose();
            rawFile.ClearCachedScans();
            rawFile.Dispose();
            OnFinish();
        }
Пример #2
0
        private void extractFeatures()
        {
            if (currIndex < allRawFileNames.Count)
            {
                var currRawFileString = allRawFileNames[currIndex];
                currRawFile = new ThermoRawFile(currRawFileString);
                currRawFile.Open();
                var path = outputTextBox.Text + "\\" + currRawFile.Name + "_ExtractedFeatures.gcfeat";
                conn = new SQLiteConnection(@"Data Source=" + path);
                conn.Open();
                rawFileListBox.ClearSelected();
                rawFileListBox.SelectedIndex = currIndex;
                this.Text = currIndex + "\\" + allRawFileNames.Count + " Deconvolved...";
                if (!SQLiteIOMethods.IsExtractionDone(conn))
                {
                    currFDM           = new FeatureDetectionMethods(currRawFile);
                    statusLabel.Text  = "Adding Features from " + currRawFile.Name + " to Database...";
                    currFDM.Progress += deconvolution_Progress;
                    currFDM.Finished += deconvolution_Finished;
                    currentThread     = new Thread(() => currFDM.StepwiseSetupFinalGroups(currRawFile, conn));
                    currentThread.Start();
                }
                else
                {
                    conn.Close();
                    conn.Dispose();
                    currRawFile.Dispose();
                    currIndex++;
                    extractFeatures();
                }
            }
            else
            {
                currIndex = 0;
                //statusBar.Value = 0;
                //statusLabel.Text = "Starting Feature Grouping...";
                //GroupFeatures();

                currRawFile.ClearCachedScans();
                currRawFile.Dispose();
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                }
                conn = null;
                if (currFDM != null)
                {
                    currFDM.Dispose();
                    currFDM = null;
                }
                GC.Collect();
                rawFileListBox.ClearSelected();
                foreach (Control control in this.Controls)
                {
                    control.Enabled = true;
                }
                statusBar.Value  = 100;
                statusLabel.Text = "Done!";
                this.Text        = "Deconvolution Engine";
            }
        }
Пример #3
0
        public IEnumerable <Feature> ExtractFeatures(IList <int> scans, double ppmTolerance, int minConsecutiveScans = 5)
        {
            List <Feature>      activeFeatures = new List <Feature>();
            List <ThermoMzPeak> outPeaks       = new List <ThermoMzPeak>();

            rawFile.GetLabeledSpectrum(scans[0]).TryGetPeaks(0, 1000, out outPeaks);
            double currRT = rawFile.GetRetentionTime(scans[0]);

            //MZPeak[] currentPeaks = currentScan.MassSpectrum.GetPeaks(0, 1000).ToArray();
            MZPeak[] currentPeaks = outPeaks.ToArray();
            activeFeatures.AddRange(currentPeaks.Select(p => new Feature(p, currRT)));
            int counter = 0;
            int percent = (scans.Count) / 100;

            for (int i = 1; i < scans.Count; i++)
            {
                rawFile.ClearCachedScans();
                if (i % percent == 0)
                {
                    counter++;
                    if (counter < 100)
                    {
                        OnProgressUpdate(0.01);
                    }
                }
                MSDataScan <ThermoSpectrum> currentScan = rawFile.GetMsScan(scans[i]);
                //currentScan = scans[i];

                // outPeaks = new List<ThermoMzPeak>();
                // double[,] peakArray = currentScan.MassSpectrum.ToArray();
                //for (int j = 0; j < peakArray.Length / 2; j++)
                //{
                //    outPeaks.Add(new MZPeak(peakArray[0, j], peakArray[1, j]));
                //}
                rawFile.GetLabeledSpectrum(currentScan.SpectrumNumber).TryGetPeaks(0, 1000, out outPeaks);
                outPeaks = outPeaks.OrderBy(x => x.MZ).ToList();
                //currentPeaks = currentScan.MassSpectrum.GetPeaks(0, 1000).ToArray();
                currentPeaks = outPeaks.ToArray();

                double rt = currentScan.RetentionTime;

                // Order features based on their average m/z which may change each round as new peaks are added
                activeFeatures = activeFeatures.OrderBy(feat => feat.AverageMZ).ToList();

                // Match all the active features to the current spectrum at a given ppm tolerance
                MatchPeaks(activeFeatures, currentPeaks, ppmTolerance, rt);

                // Find features that are finished and return them if they pass the filters
                int f = 0;
                while (f < activeFeatures.Count)
                {
                    var feature = activeFeatures[f];
                    //DJB
                    //if (feature.LastAddedTime < rt || feature.CurrentState == PeakState.Tailing)
                    //NWK
                    if (feature.MaxRT < rt)
                    {
                        //DJB
                        //if (feature.Count >= minConsecutiveScans && (feature.TotalStates & PeakState.Tailing) == PeakState.Tailing)
                        //NWK
                        if (feature.Count >= minConsecutiveScans && CheckPeakRise(feature))
                        {
                            yield return(feature);
                        }
                        activeFeatures.RemoveAt(f);
                    }
                    else
                    {
                        f++;
                    }
                }
            }

            //DJB
            //foreach (var feature in activeFeatures.Where(f => f.Count > minConsecutiveScans && f.CurrentState != PeakState.Random))
            //NWK
            foreach (var feature in activeFeatures.Where(f => f.Count > minConsecutiveScans))
            {
                if (CheckPeakRise(feature))
                {
                    yield return(feature);
                }
            }
        }