Exemplo n.º 1
0
        public static void AddFeatureGroupToDatabase(FeatureGroup group, int ID_Num, SQLiteConnection conn)
        {
            //(GroupID INT, NumPeaks INT, ApexRT DOUBLE, IncludedFeatures TEXT)
            var insertText = "INSERT INTO featureGroupTable (GroupID, NumPeaks, ApexRT, IncludedFeatures, PeakList)"
                             + " VALUES (@GroupID, @NumPeaks, @ApexRT, @IncludedFeatures, @PeakList)";
            var insertCommand = new SQLiteCommand(insertText, conn);

            insertCommand.Parameters.AddWithValue("@GroupID", ID_Num);
            insertCommand.Parameters.AddWithValue("@NumPeaks", group.allFeatures.Count);
            insertCommand.Parameters.AddWithValue("@ApexRT", group.ApexTime);
            var includedFeatures = "";

            foreach (var feat in group.allFeatures)
            {
                includedFeatures += feat.ID_Number + ";";
            }
            insertCommand.Parameters.AddWithValue("@IncludedFeatures", includedFeatures);
            var peakList = "";

            foreach (var peak in group.finalPeaks)
            {
                peakList += peak.MZ + "," + peak.Intensity + ";";
            }
            insertCommand.Parameters.AddWithValue("@PeakList", peakList);
            insertCommand.ExecuteNonQuery();
        }
Exemplo n.º 2
0
        public void GetMainSubgroup(FeatureGroup group)
        {
            FeatureGroup mainSubGroup = new FeatureGroup();
            double       startTime    = group.ApexTime - .005;
            double       stopTime     = group.ApexTime + .005;

            startTime = group.ApexTime;
            stopTime  = group.ApexTime;

            Tuple <double, double> apexWindow = GetApexTimeWindow(group.allFeatures.First(), GetRTPeakIndex(group.allFeatures.First(), group.allFeatures.First().MaxPeak));

            startTime = apexWindow.Item1;
            stopTime  = apexWindow.Item2;

            foreach (Feature feature in group.allFeatures)
            {
                if (ApexCheck(feature, startTime, stopTime))
                {
                    mainSubGroup.AddFeature(feature);
                }
            }
            mainSubGroup.ApexTime = group.ApexTime;
            mainSubGroup.DoApexCalculations();
            group.mainSubGroup = mainSubGroup;
            group.SubGroups.Add(mainSubGroup);
        }
Exemplo n.º 3
0
        private IEnumerable <FeatureGroup> GroupFeatures(IEnumerable <Feature> features, double time, int minNumberFragments = 5)
        {
            List <Feature> totalFeatures = features.OrderByDescending(f => f.MaxIntensity).ToList();

            while (totalFeatures.Count > 0)
            {
                Feature maxfeature = totalFeatures[0];
                totalFeatures.RemoveAt(0);
                double       maxFeatureApex = maxfeature.ApexTime;
                FeatureGroup group          = new FeatureGroup(maxfeature);
                group.ApexTime = maxFeatureApex;
                double minTime = maxFeatureApex - time / 2;
                double maxTime = maxFeatureApex + time / 2;
                int    i       = 0;
                while (i < totalFeatures.Count)
                {
                    var feature = totalFeatures[i];
                    if (minTime <= feature.ApexTime && feature.ApexTime <= maxTime)
                    {
                        group.AddFeature(feature);
                        totalFeatures.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
                if (group.Count >= minNumberFragments)
                {
                    yield return(group);
                }
            }
        }
Exemplo n.º 4
0
 public void GetFeatureSubGroups(FeatureGroup group)
 {
     group.allFeatures = group.allFeatures.OrderByDescending(x => x.MaxPeak.Intensity).ToList();
     foreach (Feature feature in group.allFeatures)
     {
         feature.includedInSubGroup = false;
     }
     group.maxFeature = group.allFeatures[0];
     GetFeatureSubGroups(group, 0, 0);
 }
Exemplo n.º 5
0
        public List <MZPeak> GetPeaksFromNearestSpectrum(FeatureGroup group, ThermoRawFile rawFile)
        {
            int              scanNum     = rawFile.GetSpectrumNumber(group.ApexTime);
            List <MZPeak>    returnPeaks = new List <MZPeak>();
            ThermoSpectrum   spectrum    = rawFile.GetLabeledSpectrum(scanNum);
            HashSet <double> peakMZs     = new HashSet <double>();

            foreach (Feature feature in group.allFeatures)
            {
                MZPeak outPeak = spectrum.GetClosestPeak(MassRange.FromPPM(feature.AverageMZ, 10));
                if (outPeak != null)
                {
                    if (!peakMZs.Contains(outPeak.Intensity))
                    {
                        returnPeaks.Add(new MZPeak(feature.AverageMZ, outPeak.Intensity));
                        peakMZs.Add(outPeak.Intensity);
                    }
                }
            }
            returnPeaks = returnPeaks.OrderBy(x => x.MZ).ToList();
            return(returnPeaks);
        }
Exemplo n.º 6
0
        public void GetFeatureSubGroups(FeatureGroup group, int nextSubGroupPointer, int numFeaturesInSubGroups)
        {
            bool nextSubGroupPointerFound = false;

            if (numFeaturesInSubGroups != group.allFeatures.Count)
            {
                Feature maxFeature = group.allFeatures[nextSubGroupPointer];
                // if (maxFeature.MaxPeak.Intensity < group.maxFeature.MaxPeak.Intensity * .06 || maxFeature.MaxPeak.Intensity < 100000 )
                if (maxFeature.MaxPeak.Intensity < group.maxFeature.MaxPeak.Intensity * .06)
                {
                    return;
                }
                //Binary search to the appropriate index (you'll need to store the actual RTPeak instead of just the intensity and time)
                int startIndex = GetRTPeakIndex(maxFeature, maxFeature.MaxPeak);
                //Get the apex time window for 93.5% intensity threshold
                Tuple <double, double> ApexTimeWindow = GetApexTimeWindow(maxFeature, startIndex);
                //Create a new subgroup, add the feature to the subgroup.
                FeatureGroup newSubGroup = new FeatureGroup(maxFeature);
                newSubGroup.ApexTime = maxFeature.ApexTime;
                //Check whether this has been included in a sub group. If not set that flag to true and increment numFeaturesInSubGroups.
                if (!maxFeature.includedInSubGroup)
                {
                    maxFeature.includedInSubGroup = true;
                    numFeaturesInSubGroups++;
                }
                maxFeature.numSubGroups++;
                //Iterate over all features in the group and see if their apexes align
                for (int i = 0; i < group.allFeatures.Count; i++)
                {
                    //Check whether there is an apex for the feature if (ApexCheck(feature, 93.5 start, 93.5 stop))... Add to subgroup, if Feature hasn't been in a subgroup yet
                    if (i != nextSubGroupPointer)
                    {
                        Feature currFeature = group.allFeatures[i];
                        if (ApexCheck(currFeature, ApexTimeWindow.Item1, ApexTimeWindow.Item2))
                        {
                            newSubGroup.AddFeature(currFeature);
                            if (!currFeature.includedInSubGroup)
                            {
                                currFeature.includedInSubGroup = true;
                                numFeaturesInSubGroups++;
                            }
                            currFeature.numSubGroups++;
                        }
                        else
                        {
                            if (i > nextSubGroupPointer && !nextSubGroupPointerFound && !currFeature.includedInSubGroup)
                            {
                                nextSubGroupPointer      = i;
                                nextSubGroupPointerFound = true;
                            }
                        }
                    }
                }
                newSubGroup.DoApexCalculations();
                if (newSubGroup.allFeatures.Count > 1)
                {
                    group.SubGroups.Add(newSubGroup);
                }
                GetFeatureSubGroups(group, nextSubGroupPointer, numFeaturesInSubGroups);
            }
        }