public static InternalStandard GetClosestInternalStandard(QuantPoint qPt, List <InternalStandard> internalStandards)
 {
     if (internalStandards.Count == 0)
     {
         return(null);
     }
     if (internalStandards.Count == 1)
     {
         return(internalStandards.First());
     }
     if (internalStandards.Count > 1)
     {
         double           timeDiff     = double.MaxValue;
         InternalStandard holdStandard = null;
         foreach (var standard in internalStandards)
         {
             var currDiff = Math.Abs(standard.ApexRT - qPt.ApexRT);
             if (currDiff < timeDiff)
             {
                 timeDiff     = currDiff;
                 holdStandard = standard;
             }
         }
         return(holdStandard);
     }
     return(null);
 }
        public static void PopulateReplicateQuantDict(Dictionary <int, Batch> batchDict, SQLiteConnection conn)
        {
            foreach (var batch in batchDict.Values)
            {
                foreach (var rep in batch.replicates)
                {
                    var queryText = "SELECT s.GCMasterGroup_ID, s.QuantFeature_ID, s.ApexRT, s.QuantFeatureMZ, s.RTOffset, s.ApexIntensity FROM ReplicateQuant_Table s WHERE s.Replicate_ID=@ID";
                    var query     = new SQLiteCommand(queryText, conn);
                    query.Parameters.AddWithValue("@ID", rep.replicateID);
                    var reader = query.ExecuteReader();
                    while (reader.Read())
                    {
                        var quantFeatureString = reader["QuantFeature_ID"].ToString();
                        if (!string.IsNullOrEmpty(quantFeatureString))
                        {
                            var quantFeatureID = int.Parse(quantFeatureString);
                            var gcGroupId      = int.Parse(reader["GCMasterGroup_ID"].ToString());
                            var apexRT         = double.Parse(reader["ApexRT"].ToString());
                            var quantFeatureMZ = double.Parse(reader["QuantFeatureMZ"].ToString());
                            var offset         = double.Parse(reader["RTOffset"].ToString());
                            var apexIntensity  = double.Parse(reader["ApexIntensity"].ToString());
                            var groupID        = int.Parse(reader["GCMasterGroup_ID"].ToString());
                            //var name = reader["Name"].ToString();

                            var quantPt = new QuantPoint();
                            quantPt.ApexIntensity            = apexIntensity;
                            quantPt.ApexIntensity_Normalized = apexIntensity;
                            quantPt.ApexRT    = apexRT;
                            quantPt.BatchID   = batch.batchID;
                            quantPt.ControlID = batch.controlID;
                            quantPt.FeatureID = quantFeatureID;
                            //quantPt.Name = name;
                            quantPt.MZ          = quantFeatureMZ;
                            quantPt.ReplicateID = rep.replicateID;
                            rep.quantDictionary.Add(groupID, quantPt);
                        }
                    }
                }
            }
        }