Exemplo n.º 1
0
        public double GetDemoninatorTerm(EISpectrum eiSpec)
        {
            double returnVal = 0;

            foreach (MZPeak peak in eiSpec.FinalNormalizedEIPeaks)
            {
                returnVal += (peak.MZ * peak.Intensity);
            }
            return(returnVal);
        }
Exemplo n.º 2
0
        public static void ReadInGCFeat(List <Feature> features, List <FeatureGroup> groups, List <EISpectrum> spectra, out Chromatogram chroma, out string name, SQLiteConnection conn)
        {
            var queryText    = "SELECT s.mz, s.ApexRT, s.ApexIntensity, s.SmoothFeatureString, s.RawFeatureString, s.ID_Number FROM featureTable s";
            var queryCommand = new SQLiteCommand(queryText, conn);
            var reader       = queryCommand.ExecuteReader();
            Dictionary <int, Feature> featDict = new Dictionary <int, Feature>();

            while (reader.Read())
            {
                var           mz            = double.Parse(reader["mz"].ToString());
                var           apexIntensity = double.Parse(reader["ApexIntensity"].ToString());
                var           apexRT        = double.Parse(reader["ApexRT"].ToString());
                var           smoothString  = reader["SmoothFeatureString"].ToString();
                var           rawString     = reader["RawFeatureString"].ToString();
                var           idNum         = int.Parse(reader["ID_Number"].ToString());
                List <RTPeak> rawPeaks      = ConvertFeatureStringToPeakList(rawString);
                List <RTPeak> smoothPeaks   = ConvertFeatureStringToPeakList(smoothString);
                var           feat          = new Feature();
                feat.ApexTime = apexRT;
                foreach (var peak in rawPeaks)
                {
                    feat.AddPeak(peak);
                }
                foreach (var peak in smoothPeaks)
                {
                    feat.AddSmoothPeak(peak);
                }
                feat.AverageMZ    = mz;
                feat.maxIntensity = apexIntensity;
                feat.ID_Number    = idNum;
                features.Add(feat);
                featDict.Add(idNum, feat);
            }
            reader.Close();

            queryText    = "SELECT s.ApexRT, s.IncludedFeatures, s.PeakList, s.GroupID FROM featureGroupTable s";
            queryCommand = new SQLiteCommand(queryText, conn);
            reader       = queryCommand.ExecuteReader();
            while (reader.Read())
            {
                var           apexRT           = double.Parse(reader["ApexRT"].ToString());
                var           includedString   = reader["IncludedFeatures"].ToString();
                var           peakList         = reader["PeakList"].ToString();
                var           groupID          = int.Parse(reader["GroupID"].ToString());
                List <MZPeak> peaks            = ConvertPeakListString(peakList);
                string[]      includedFeatures = includedString.Split(';');

                var featureGroup = new FeatureGroup();
                featureGroup.ApexTime   = apexRT;
                featureGroup.finalPeaks = peaks;
                featureGroup.groupID    = groupID;
                foreach (var feat in includedFeatures)
                {
                    if (!string.IsNullOrEmpty(feat))
                    {
                        int id = int.Parse(feat);
                        featureGroup.allFeatures.Add(featDict[id]);
                    }
                }
                var norm       = new Normalization();
                var eiSpectrum = new EISpectrum();
                eiSpectrum.FinalEIPeaks           = peaks;
                eiSpectrum.FinalNormalizedEIPeaks = peaks;
                eiSpectrum.FeatureGroup           = featureGroup;
                eiSpectrum.ApexTimeEI             = apexRT;
                groups.Add(featureGroup);
                spectra.Add(eiSpectrum);
            }

            queryText    = "SELECT s.TICChroma, s.Name FROM ticTable s";
            queryCommand = new SQLiteCommand(queryText, conn);
            reader       = queryCommand.ExecuteReader();
            List <double> rts         = new List <double>();
            List <double> intensities = new List <double>();

            name   = "";
            chroma = null;
            while (reader.Read())
            {
                var tic = reader["TICChroma"].ToString();
                name = reader["Name"].ToString();
                string[] parts = tic.Split(';');
                foreach (var part in parts)
                {
                    if (!string.IsNullOrEmpty(part))
                    {
                        string[] subparts  = part.Split(',');
                        double   rt        = double.Parse(subparts[0]);
                        double   intensity = double.Parse(subparts[1]);
                        rts.Add(rt);
                        intensities.Add(intensity);
                    }
                }
                chroma = new Chromatogram(rts.ToArray(), intensities.ToArray());
            }
            conn.Close();
        }
Exemplo n.º 3
0
        //Input method
        public void ReadInMaster()
        {
            conn = new SQLiteConnection(@"Data Source=" + parentFile);
            conn.Open();
            var queryText =
                "SELECT s.Name, 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();
            Dictionary <int, Feature> tmpFeatureDict = new Dictionary <int, Feature>();

            while (reader.Read())
            {
                name = reader["Name"].ToString();
                var           mz                  = double.Parse(reader["mz"].ToString());
                var           apexRT              = double.Parse(reader["ApexRT"].ToString());
                var           apexIntensity       = double.Parse(reader["ApexIntensity"].ToString());
                var           ID_Number           = int.Parse(reader["ID_Number"].ToString());
                var           smoothFeatureString = reader["SmoothFeatureString"].ToString();
                List <RTPeak> smoothPeaks         = ConvertFeatureStringToPeakList(smoothFeatureString);
                var           rawFeatureString    = reader["RawFeatureString"].ToString();
                List <RTPeak> rawPeaks            = ConvertFeatureStringToPeakList(rawFeatureString);
                var           feat                = new Feature();
                feat.AverageMZ = mz;
                feat.ApexTime  = apexRT;
                feat.ID_Number = ID_Number;
                foreach (var peak in rawPeaks)
                {
                    feat.AddPeak(peak);
                }
                foreach (var peak in smoothPeaks)
                {
                    feat.AddSmoothPeak(peak);
                }
                feat.AverageMZ    = mz;
                feat.maxIntensity = apexIntensity;
                tmpFeatureDict.Add(ID_Number, feat);
            }

            queryText =
                "SELECT s.GroupID, s.IsValid, s.NumPeaks, s.ApexRT, s.NIST_ID, s.Name, s.ChEBI_ID, s.IncludedFeatures, s.IsInternalStandard, s.QuantIons, s.PeakList FROM featureGroupTable s";
            queryCommand = new SQLiteCommand(queryText, conn);
            reader       = queryCommand.ExecuteReader();
            while (reader.Read())
            {
                var groupID = int.Parse(reader["GroupID"].ToString());
                var isValid = bool.Parse(reader["IsValid"].ToString());
                //var isValid = false;
                //var isValidString = reader["IsValid"].ToString();
                //if (isValidString.Equals("1"))
                //{
                //    isValid = true;
                //}

                var numPeaks = int.Parse(reader["NumPeaks"].ToString());
                var apexRT   = double.Parse(reader["ApexRT"].ToString());
                var chebiID  = reader["ChEBI_ID"].ToString();
                var NISTID   = reader["NIST_ID"].ToString();
                var userName = reader["Name"].ToString();
                //var isInternalStandard = bool.Parse(reader["IsInternalStandard"].ToString());
                var isInternalStandard       = false;
                var isInternalStandardString = reader["IsInternalStandard"].ToString();
                if (isInternalStandardString.Equals("1"))
                {
                    isInternalStandard = true;
                }
                var           includedFeatureString = reader["IncludedFeatures"].ToString();
                var           quantIonString        = reader["QuantIons"].ToString();
                List <MZPeak> quantIons             = ConvertPeakListString(quantIonString);
                var           peakListString        = reader["PeakList"].ToString();
                List <MZPeak> peakList     = ConvertPeakListString(peakListString);
                var           featureGroup = new FeatureGroup();
                featureGroup.groupID    = groupID;
                featureGroup.ApexTime   = apexRT;
                featureGroup.finalPeaks = peakList;

                foreach (var feat in includedFeatureString.Split(';'))
                {
                    if (!string.IsNullOrEmpty(feat))
                    {
                        int id = int.Parse(feat);
                        featureGroup.allFeatures.Add(tmpFeatureDict[id]);
                    }
                }

                var eiSpectrum = new EISpectrum();
                //if (isInternalStandard==1)
                //{
                //    eiSpectrum.isInternalStandard = true;
                //}
                //else
                //{
                //    eiSpectrum.isInternalStandard = false;
                //}
                eiSpectrum.isInternalStandard = isInternalStandard;
                eiSpectrum.FinalEIPeaks.AddRange(peakList);
                eiSpectrum.FinalNormalizedEIPeaks.AddRange(peakList);
                var norm = new Normalization();
                norm.CombineLikeMZPeaks(eiSpectrum.FinalNormalizedEIPeaks);
                eiSpectrum.FeatureGroup = featureGroup;
                eiSpectrum.ApexTimeEI   = apexRT;
                eiSpectrum.NISTName     = NISTID;
                eiSpectrum.UserName     = userName;
                eiSpectrum.chebiID      = chebiID;
                //if (isValid == 1)
                //{
                //    eiSpectrum.isValid = true;
                //}

                //else
                //{
                //    eiSpectrum.isValid = false;
                //}
                eiSpectrum.isValid    = isValid;
                eiSpectrum.spectrumID = groupID;
                eiSpectrum.quantIons  = quantIons;
                allSpectra.Add(eiSpectrum);
            }

            queryText    = "SELECT s.TICChroma, s.Name FROM rawFileTable s";
            queryCommand = new SQLiteCommand(queryText, conn);
            reader       = queryCommand.ExecuteReader();
            List <double> rts         = new List <double>();
            List <double> intensities = new List <double>();

            name   = "";
            chroma = null;
            while (reader.Read())
            {
                var tic = reader["TICChroma"].ToString();
                name = reader["Name"].ToString();
                string[] parts = tic.Split(';');
                foreach (var part in parts)
                {
                    if (!string.IsNullOrEmpty(part))
                    {
                        string[] subparts  = part.Split(',');
                        double   rt        = double.Parse(subparts[0]);
                        double   intensity = double.Parse(subparts[1]);
                        rts.Add(rt);
                        intensities.Add(intensity);
                    }
                }
                chroma = new Chromatogram(rts.ToArray(), intensities.ToArray());
            }
            allFeatures = tmpFeatureDict.Values.ToList();
            foreach (var spec in allSpectra)
            {
                foreach (var feat in spec.FeatureGroup.allFeatures)
                {
                    spec.FeatureGroup.includedFeatureIDs.Add(feat.ID_Number);
                }
            }
        }