Exemplo n.º 1
0
        public static List <Feature> GetAllFeaturesFromDatabase(SQLiteConnection conn)
        {
            List <Feature> returnFeatures = new List <Feature>();
            var            queryText      =
                "SELECT s.mz, s.ApexRT, s.ApexIntensity, s.ID_Number, s.SmoothFeatureString, s.RawFeatureString FROM featureTable s";
            var queryCommand = new SQLiteCommand(queryText, conn);
            var reader       = queryCommand.ExecuteReader();

            while (reader.Read())
            {
                var           apexRT       = double.Parse(reader["ApexRT"].ToString());
                var           mz           = double.Parse(reader["mz"].ToString());
                var           id           = int.Parse(reader["ID_Number"].ToString());
                var           smoothString = reader["SmoothFeatureString"].ToString();
                var           rawString    = reader["RawFeatureString"].ToString();
                List <RTPeak> smoothPeaks  = ConvertFeatureStringToPeakList(smoothString);
                List <RTPeak> rawPeaks     = ConvertFeatureStringToPeakList(rawString);
                var           feat         = new Feature();
                feat.ApexTime  = apexRT;
                feat.AverageMZ = mz;
                feat.ID_Number = id;
                foreach (var peak in rawPeaks)
                {
                    feat.AddPeak(peak);
                }
                foreach (var peak in smoothPeaks)
                {
                    feat.AddSmoothPeak(peak);
                }
                returnFeatures.Add(feat);
                //feat.ApexTime = apexRT;
                feat.AverageMZ = mz;
            }
            return(returnFeatures);
        }
Exemplo n.º 2
0
        private void MatchPeaks(List <Feature> features, MZPeak[] currentPeaks, double ppmTolerance, double rt, bool allowMultipleFeatureMatches = false)
        {
            if (features == null || currentPeaks == null)
            {
                return;
            }

            int fCount = features.Count;

            if (fCount == 0)
            {
                features.AddRange(currentPeaks.Select(p => new Feature(p, rt)));
                return;
            }

            int cCount = currentPeaks.Length;

            if (cCount == 0)
            {
                return;
            }

            int     c         = 0;
            int     f         = 0;
            Feature feature   = features[f];
            double  featureMZ = feature.AverageMZ;

            MZPeak cPeak = currentPeaks[c];

            ppmTolerance /= 2e6;

            double tolerance = cPeak.MZ * ppmTolerance;
            double lowmz     = cPeak.MZ - tolerance;

            List <Feature> featuresToAdd = new List <Feature>(cCount);

            while (true)
            {
                if (featureMZ < lowmz)
                {
                    if (++f == fCount) // Feature mz is to small, go to the next one
                    {
                        break;         // no more features, so just break out now
                    }
                    feature   = features[f];
                    featureMZ = feature.AverageMZ;
                    continue; // keep the current peak, so continue the loop right away
                }

                if (featureMZ < cPeak.MZ + tolerance)
                {
                    feature.AddPeak(cPeak, rt); // Peak matches feature, add it to the feature
                    if (!allowMultipleFeatureMatches)
                    {
                        if (++f == fCount) // Feature mz is to small, go to the next one
                        {
                            break;         // no more features, so just break out now
                        }
                        feature   = features[f];
                        featureMZ = feature.AverageMZ;
                    }
                }
                else
                {
                    // Peak didn't match any features, so save this peak to start a new feature
                    featuresToAdd.Add(new Feature(cPeak, rt));
                }

                if (++c == cCount)
                {
                    break; // no more current peaks, so just break out now
                }
                cPeak     = currentPeaks[c];
                tolerance = cPeak.MZ * ppmTolerance;
                lowmz     = cPeak.MZ - tolerance;
            }

            // Append unmatched peaks as new features
            features.AddRange(featuresToAdd);

            // Add left over peaks as new features
            while (c < cCount)
            {
                features.Add(new Feature(currentPeaks[c++], rt));
            }
        }