private void GroupFeatures() { 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; if (!SQLiteIOMethods.IsGroupingDone(conn)) { currFDM = new FeatureDetectionMethods(currRawFile); statusLabel.Text = "Grouping Features from " + currRawFile.Name + "..."; currFDM.Finished += grouping_Finished; //currentThread = new Thread(() => currFDM.GroupFeatures(conn)); //currentThread.Start(); } else { currIndex++; double percent = ((double)currIndex) / ((double)allRawFileNames.Count) * 100; statusBar.Value = (int)percent; GroupFeatures(); } } else { 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!"; } }
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(); }
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"; } }
public void StepwiseSetupFinalGroups(ThermoRawFile rawfile, SQLiteConnection conn) { List <int> list = new List <int>(); foreach (var scan in rawFile.GetMsScans()) { if (scan.MsnOrder == 1) { list.Add(scan.SpectrumNumber); } } var extractedFeatures = ExtractFeatures(list, 10).ToList(); //Features have been extracted //Check which features are valid and which are not based on how their max intensity changes //nwk temp code var tmpFeatures = extractedFeatures.Where(x => x.ApexTime > 13.55 && x.apexTime <13.70 && x.AverageMZ> 267.082 && x.averageMZ < 267.095).ToList(); var q = ""; CheckPeakRise(extractedFeatures); //Smooth features now foreach (Feature feature in extractedFeatures) { feature.SmoothRTPeaks = GetRollingAveragePeaks(feature.RawRTPeaks, 9); } CheckPeakRiseSmooth(extractedFeatures); List <Feature> finalFeatures = GetFinalFeatures(extractedFeatures); extractedFeatures.Clear(); CheckPeakRiseSmooth(finalFeatures); int count = 1; foreach (var feat in finalFeatures) { feat.ID_Number = count; count++; } //push features to database PushFeaturesToDatabase(rawfile, finalFeatures, conn); List <FeatureGroup> groups = GroupFeatures(finalFeatures, .04, 2).ToList(); DoubleBack(groups, finalFeatures); finalFeatures.Clear(); List <FeatureGroup> allSubGroups = new List <FeatureGroup>(); foreach (FeatureGroup group in groups) { GetMainSubgroup(group); GetFeatureSubGroups(group); if (group.mainSubGroup.allFeatures.Count > 1) { allSubGroups.Add(group.mainSubGroup); } foreach (FeatureGroup subGroup in group.SubGroups) { allSubGroups.Add(subGroup); } } this.finalGroups = GetFinalFeatures(allSubGroups); foreach (FeatureGroup group in this.finalGroups) { group.finalPeaks = GetPeaksFromNearestSpectrum(group, rawFile); } foreach (FeatureGroup group in this.finalGroups) { EISpectrum spec = new EISpectrum(); spec.ApexTimeEI = group.ApexTime; spec.FeatureGroup = group; spec.FinalEIPeaks = group.finalPeaks; spec.FinalEIPeaks = spec.FinalEIPeaks.OrderByDescending(x => x.Intensity).ToList(); if (group.finalPeaks.Count >= 2) //here as well (changed to remove num feature restriction) { spec.BasePeak = spec.FinalEIPeaks[0]; this.eiSpectra.Add(spec); } spec.FinalNormalizedEIPeaks.AddRange(spec.FinalEIPeaks); spec.FinalNormalizedEIPeaks = spec.FinalNormalizedEIPeaks.OrderBy(x => x.MZ).ToList(); norm.CombineLikeMZPeaks(spec.FinalNormalizedEIPeaks); spec.AdjustedPeaks.AddRange(spec.FinalNormalizedEIPeaks); norm.GetAdjustedPeaks(spec.AdjustedPeaks); spec.DenominatorTerm = norm.GetDemoninatorTerm(spec.AdjustedPeaks); } //this.eiSpectra = CleanUpSpectra(eiSpectra); this.eiSpectra = eiSpectra.Where(x => x.FinalEIPeaks.Count >= 2).ToList(); AddFeatureGroupsToDatabase(this.eiSpectra, conn); SQLiteIOMethods.ExtractionComplete(conn); SQLiteIOMethods.GroupingComplete(conn); OnFinish(); }