Пример #1
0
 public static void AddQuantPointToDatabase(EISpectrum masterSpecies, double quantIonMZ, double apexIntensity, double offset, Feature quantFeature, string rawName, SQLiteConnection conn)
 {
     if (!ContainsQuantFeature(masterSpecies.ApexTimeEI, rawName, conn))
     {
         int id = GetRawFileID(rawName, conn);
         //(ID INT, Name TEXT, FeatureRT DOUBLE, QuantIonMZ DOUBLE, ApexIntensity DOUBLE, OffsetRT DOUBLE, FeatureString TEXT)
         var insertText = "INSERT INTO rawFileQuantTable (ID, Name, FeatureRT, QuantIonMZ, ApexIntensity, OffsetRT, FeatureString)" +
                          " VALUES (@ID, @Name, @FeatureRT, @QuantIonMZ, @ApexIntensity, @OffsetRT, @FeatureString)";
         var insertCommand = new SQLiteCommand(insertText, conn);
         insertCommand.Parameters.AddWithValue("@ID", id);
         insertCommand.Parameters.AddWithValue("@Name", rawName);
         insertCommand.Parameters.AddWithValue("@QuantIonMZ", quantIonMZ);
         insertCommand.Parameters.AddWithValue("@ApexIntensity", apexIntensity);
         insertCommand.Parameters.AddWithValue("@OffsetRT", offset);
         insertCommand.Parameters.AddWithValue("@FeatureRT", masterSpecies.ApexTimeEI);
         var featString = "";
         if (quantFeature != null)
         {
             foreach (var peak in quantFeature.smoothRTPeaks)
             {
                 featString += peak.RT + "," + peak.Intensity + ";";
             }
         }
         insertCommand.Parameters.AddWithValue("@FeatureString", featString);
         insertCommand.ExecuteNonQuery();
     }
 }
Пример #2
0
        public double GetDemoninatorTerm(EISpectrum eiSpec)
        {
            double returnVal = 0;

            foreach (MZPeak peak in eiSpec.FinalNormalizedEIPeaks)
            {
                returnVal += (peak.MZ * peak.Intensity);
            }
            return(returnVal);
        }
Пример #3
0
        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();
        }
Пример #4
0
        private void StepwiseSetupFinalGroups(ThermoRawFile rawFile)
        {
            List <int> list = new List <int>();

            foreach (var scan in rawFile.GetMsScans())
            {
                if (scan.RetentionTime < 7)
                {
                    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
            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);
            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 > 6) //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);
            }

            OnFinish();
        }