public static Batch GetMedianReferenceExperiment(Dictionary <int, Batch> batchDictionary)
        {
            Batch         returnBatch = new Batch();
            HashSet <int> allIds      = new HashSet <int>();

            foreach (var batch in batchDictionary.Values)
            {
                foreach (var rep in batch.replicates)
                {
                    foreach (var key in rep.quantDictionary.Keys)
                    {
                        allIds.Add(key);
                    }
                }
            }
            foreach (var key in allIds.ToList())
            {
                List <double> allMeasurements = new List <double>();
                foreach (var batch in batchDictionary.Values)
                {
                    foreach (var rep in batch.replicates)
                    {
                        if (rep.quantDictionary.ContainsKey(key))
                        {
                            allMeasurements.Add(rep.quantDictionary[key].ApexIntensity_Normalized);
                        }
                    }
                }
                var avgIntensity = allMeasurements.Median();
                var avgPoint     = new AvgQuantPoint();
                avgPoint.AvgIntensity = avgIntensity;
                returnBatch.avgQuantDict.Add(key, avgPoint);
            }
            return(returnBatch);
        }
 public static void GetAveragedIntensityValues(Dictionary <int, Batch> batchDict)
 {
     foreach (var batch in batchDict.Values)
     {
         HashSet <int> keys = new HashSet <int>();
         foreach (var rep in batch.replicates)
         {
             foreach (var key in rep.quantDictionary.Keys)
             {
                 keys.Add(key);
             }
         }
         foreach (var key in keys)
         {
             var avgQuantPt = new AvgQuantPoint();
             avgQuantPt.GCMasterGroupID = key;
             foreach (var rep in batch.replicates)
             {
                 if (rep.quantDictionary.ContainsKey(key))
                 {
                     avgQuantPt.AllIntensities.Add(rep.quantDictionary[key].ApexIntensity);
                     avgQuantPt.BatchID              = batch.batchID;
                     avgQuantPt.ControlID            = batch.controlID;
                     avgQuantPt.GCMasterGroup_ApexRT = rep.quantDictionary[key].ApexRT;
                     avgQuantPt.Name          = rep.quantDictionary[key].Name;
                     avgQuantPt.ChEBI_ID      = rep.quantDictionary[key].ChEBI_ID;
                     avgQuantPt.PreferredName = "";
                     if (!string.IsNullOrEmpty(avgQuantPt.Name))
                     {
                         avgQuantPt.PreferredName = avgQuantPt.Name + " | ";
                     }
                     if (avgQuantPt.ChEBI_ID != 0)
                     {
                         avgQuantPt.PreferredName += "ChEBI ID: " + avgQuantPt.ChEBI_ID + " | ";
                     }
                     avgQuantPt.PreferredName += "Apex RT: " + Math.Round(avgQuantPt.GCMasterGroup_ApexRT, 4);
                 }
             }
             avgQuantPt.AvgIntensity                   = avgQuantPt.AllIntensities.Average();
             avgQuantPt.AvgIntensity_StdDev            = avgQuantPt.AllIntensities.StandardDeviation();
             avgQuantPt.AvgIntensity_Normalized_StdDev = avgQuantPt.AllIntensities.StandardDeviation();
             avgQuantPt.AvgIntensity_Normalized        = avgQuantPt.AllIntensities.Average();
             batch.avgQuantDict.Add(key, avgQuantPt);
         }
     }
 }