예제 #1
0
 public void ReadInMasterFile()
 {
     UpdateText("Reading GC Master File...");
     master = new Master(gcMastTextBox.Text);
     master.ReadInMaster();
     UpdateText("Preparing GC Results Database...");
     SQLiteIOMethods.CreateQuantDatabase(outputDirectoryTextBox.Text, out conn);
     SQLiteIOMethods.AddBatchStructure(BatchDictionary, conn);
     SQLiteIOMethods.AddMasterInformationToDatabase(conn, gcMastTextBox.Text);
     UpdateText("Starting Quantitation...");
     MasterReadInFinished();
 }
        public static void ProcessData(SQLiteConnection conn)
        {
            Dictionary <int, Batch> batchDict = GetBatchDictionary(conn);

            PopulateReplicateQuantDict(batchDict, conn);
            //NEW
            var refBatch = GetMedianReferenceExperiment(batchDict);

            foreach (var batch in batchDict.Values)
            {
                foreach (var rep in batch.replicates)
                {
                    //NormalizeRepToReferenceExperiment(refBatch, rep);
                    NormalizeRepToRefExperimentLinear(refBatch, rep);
                }
            }
            GetAveragedIntensityValues(batchDict);
            GetBatchLessControlValues(batchDict);
            SQLiteIOMethods.AddBarChartInfoToDatabase(batchDict, conn);
            SQLiteIOMethods.AddBatchQuantDataToDatabase(batchDict, conn);
            SQLiteIOMethods.AddBatchBatchCorrelationsToDatabase(batchDict, conn);
            //OLD
            //GetAveragedIntensityValues(batchDict);
            //GetBatchLessControlValues(batchDict);
            //GetInternalStandards(batchDict, conn);
            //List<InternalStandard> standards = new List<InternalStandard>();
            //foreach (var batch in batchDict.Values)
            //{
            //    foreach (var rep in batch.replicates)
            //    {
            //        foreach (var standard in rep.internalStandards)
            //        {
            //            standards.Add(standard);
            //        }
            //    }
            //}
            //SQLiteIOMethods.AddInternalStandardsToDatabase(standards, conn);
            //SQLiteIOMethods.AddBatchQuantDataToDatabase(batchDict, conn);
        }
예제 #3
0
        public void Quantify()
        {
            List <EISpectrum> curatedSpectra = Master.allSpectra.Where(x => x.isValid).ToList();
            List <RTPeak>     replicateTIC   = SQLiteIOMethods.GetTicChromaFromGCFeat(ReplicateDBConnection);

            ClippedMasterTicChroma    = RemoveSolventFrontFromTIC(Master.chroma);
            ClippedReplicateTicChroma = RemoveSolventFrontFromTIC(replicateTIC, replicateTIC.First().RT);
            int completed = 0;

            using (var transaction = QuantDbConnection.BeginTransaction())
            {
                foreach (var currentSpectrum in curatedSpectra)
                {
                    if (!SQLiteIOMethods.IsQuantified(CurrentReplicate.replicateID, QuantDbConnection))
                    {
                        double apexTime  = currentSpectrum.ApexTimeEI;
                        double startTime = apexTime - .15;
                        double stopTime  = apexTime + .15;
                        GetValidTICSegment(startTime, stopTime);
                        CurrentTICStartTime = startTime;
                        CurrentTICStopTime  = stopTime;
                        var ticMaster =
                            ClippedMasterTicChroma.Where(x => x.RT >= CurrentTICStartTime && x.RT <= CurrentTICStopTime)
                            .ToList();
                        var ticReplicate =
                            ClippedReplicateTicChroma.Where(x => x.RT >= CurrentTICStartTime && x.RT <= CurrentTICStopTime)
                            .ToList();
                        var ticMasterArray    = GetExpandedChromatogram(ticMaster, CurrentTICStartTime, CurrentTICStopTime);
                        var ticReplicateArray = GetExpandedChromatogram(ticReplicate, CurrentTICStartTime,
                                                                        CurrentTICStopTime);
                        double      offset     = GetAdjustedChromatogramOffset(ticMasterArray, ticReplicateArray);
                        DoubleRange quantRange = new DoubleRange(currentSpectrum.ApexTimeEI - offset - .15,
                                                                 currentSpectrum.ApexTimeEI - offset + .15);
                        List <Feature> replicateRangeFeatures = SQLiteIOMethods.GetFeatures(quantRange.Minimum,
                                                                                            quantRange.Maximum, ReplicateDBConnection);
                        List <Feature> currSpecQuantFeatures = new List <Feature>();
                        foreach (var ion in currentSpectrum.quantIons)
                        {
                            var ppmRange = DoubleRange.FromPPM(ion.MZ, 5);
                            currSpecQuantFeatures.AddRange(replicateRangeFeatures.Where(x => ppmRange.Contains(x.AverageMZ)));
                        }
                        foreach (var ion in currentSpectrum.quantIons)
                        {
                            var     ppmRange       = DoubleRange.FromPPM(ion.MZ, 5);
                            Feature quantFeature   = null;
                            double  timeDifference = double.MaxValue;
                            foreach (var feature in currSpecQuantFeatures)
                            {
                                if (ppmRange.Contains(feature.AverageMZ))
                                {
                                    var currTimeDiff = Math.Abs(feature.apexTime - currentSpectrum.ApexTimeEI - offset);
                                    if (currTimeDiff < timeDifference)
                                    {
                                        timeDifference = currTimeDiff;
                                        quantFeature   = feature;
                                    }
                                }
                            }
                            if (quantFeature != null)
                            {
                                if (CurrentReplicate.control != null)
                                {
                                    SQLiteIOMethods.AddReplicateQuantPointToDatabase(CurrentReplicate.replicateID, CurrentReplicate.name, CurrentReplicate.batchID, CurrentReplicate.control.batchID,
                                                                                     currentSpectrum.FeatureGroup.groupID, offset, quantFeature, QuantDbConnection);
                                }
                                else
                                {
                                    SQLiteIOMethods.AddReplicateQuantPointToDatabase(CurrentReplicate.replicateID, CurrentReplicate.name, CurrentReplicate.batchID, 0, currentSpectrum.FeatureGroup.groupID,
                                                                                     offset, quantFeature, QuantDbConnection);
                                }
                            }
                            else
                            {
                                if (CurrentReplicate.control != null)
                                {
                                    SQLiteIOMethods.AddNullReplicateQuantPointToDatabase(CurrentReplicate.replicateID, CurrentReplicate.name, CurrentReplicate.batchID, CurrentReplicate.control.batchID,
                                                                                         currentSpectrum.FeatureGroup.groupID, offset, QuantDbConnection);
                                }
                                else
                                {
                                    SQLiteIOMethods.AddNullReplicateQuantPointToDatabase(CurrentReplicate.replicateID, CurrentReplicate.name, CurrentReplicate.batchID, 0,
                                                                                         currentSpectrum.FeatureGroup.groupID, offset, QuantDbConnection);
                                }
                            }
                        }
                        completed++;
                        double percent = ((double)completed) / ((double)curatedSpectra.Count) * 200;
                        OnProgressUpdate(percent);
                    }
                }
                SQLiteIOMethods.SetReplicateToQuantified(CurrentReplicate.replicateID, QuantDbConnection);
                transaction.Commit();
                transaction.Dispose();
            }
            OnFinish();
        }