Exemple #1
0
 public QuantMethods(Replicate replicate, Master master, SQLiteConnection quantDbConnection)
 {
     CurrentReplicate      = replicate;
     Master                = master;
     ReplicateDBConnection = new SQLiteConnection(@"Data Source=" + replicate.gcFeatFilePath);
     ReplicateDBConnection.Open();
     QuantDbConnection = quantDbConnection;
 }
        public static void NormalizeRepToRefExperimentLinear(Batch referenceBatch, Replicate rep)
        {
            List <Tuple <double, double, int> > bothVals = new List <Tuple <double, double, int> >();

            foreach (var key in rep.quantDictionary.Keys)
            {
                var lfqOne = referenceBatch.avgQuantDict[key].AvgIntensity;
                var lfqTwo = rep.quantDictionary[key].ApexIntensity_Normalized;

                //calculate m
                var m = (lfqOne / lfqTwo);
                m = Math.Log(m, 2);

                //calculate a
                var a = (lfqTwo * lfqOne);
                a  = Math.Log(a, 2);
                a /= 2;
                bothVals.Add(new Tuple <double, double, int>(a, m, key));
            }

            List <double> xVals = new List <double>();
            List <double> yVals = new List <double>();

            foreach (var val in bothVals)
            {
                xVals.Add(val.Item1);
                yVals.Add(val.Item2);
            }

            double slope;
            double yIntercept;
            double rSquared;

            Statistics.LinearRegression(xVals.ToArray(), yVals.ToArray(), 0, xVals.Count(), out rSquared, out yIntercept, out slope);
            foreach (var key in rep.quantDictionary.Keys)
            {
                var lfqOne = referenceBatch.avgQuantDict[key].AvgIntensity;
                var lfqTwo = rep.quantDictionary[key].ApexIntensity_Normalized;

                //calculate m
                var m = (lfqOne / lfqTwo);
                m = Math.Log(m, 2);

                //calculate a
                var a = (lfqTwo * lfqOne);
                a  = Math.Log(a, 2);
                a /= 2;


                //get predicted mi-star from
                var mistar     = (a * slope) + yIntercept;
                var corrFactor = m - mistar;

                rep.quantDictionary[key].ApexIntensity_Normalized = Math.Pow(2, -(corrFactor - (2 * a)) / 2);
                rep.quantDictionary[key].ApexIntensity            = Math.Pow(2, -(corrFactor - (2 * a)) / 2);
            }
        }
        public static void NormalizeRepToReferenceExperiment(Batch referenceBatch, Replicate rep)
        {
            List <Tuple <double, double, int> > bothVals = new List <Tuple <double, double, int> >();

            foreach (var key in rep.quantDictionary.Keys)
            {
                var lfqOne = referenceBatch.avgQuantDict[key].AvgIntensity;
                var lfqTwo = rep.quantDictionary[key].ApexIntensity_Normalized;

                //calculate m
                var m = (lfqOne / lfqTwo);
                m = Math.Log(m, 2);

                //calculate a
                var a = (lfqTwo * lfqOne);
                a  = Math.Log(a, 2);
                a /= 2;
                bothVals.Add(new Tuple <double, double, int>(a, m, key));
            }

            List <double> xVals = new List <double>();
            List <double> yVals = new List <double>();
            var           li    = new LowessInterpolator(.4, 0);

            bothVals = bothVals.OrderBy(t => t.Item1).ToList();
            foreach (var val in bothVals)
            {
                xVals.Add(val.Item1);
                yVals.Add(val.Item2);
            }
            var smoothed = li.smooth(xVals.ToArray(), yVals.ToArray());

            for (int q = 0; q < smoothed.Length; q++)
            {
                var residual = smoothed[q];
                var key      = bothVals[q].Item3;
                var lfqOne   = referenceBatch.avgQuantDict[key].AvgIntensity;
                var lfqTwo   = rep.quantDictionary[key].ApexIntensity_Normalized;

                //calculate m
                var m = (lfqOne / lfqTwo);
                m = Math.Log(m, 2);

                //calculate a
                var a = (lfqTwo * lfqOne);
                a  = Math.Log(a, 2);
                a /= 2;
                var corrFactor = -residual;
                //repAQuantDict[key].NormalizedIntensity = Math.Pow(2, (corrFactor + (2 * a)) / 2);
                rep.quantDictionary[key].ApexIntensity_Normalized = Math.Pow(2, -(corrFactor - (2 * a)) / 2);
                rep.quantDictionary[key].ApexIntensity            = Math.Pow(2, -(corrFactor - (2 * a)) / 2);
            }
        }
        public static Dictionary <int, Batch> GetBatchDictionary(SQLiteConnection conn)
        {
            Dictionary <int, Batch> batchDict = new Dictionary <int, Batch>();
            var queryText = "SELECT s.Name, s.Batch_ID FROM Batch_Table s";
            var command   = new SQLiteCommand(queryText, conn);
            var reader    = command.ExecuteReader();

            while (reader.Read())
            {
                var name     = reader["Name"].ToString();
                var id       = int.Parse(reader["Batch_ID"].ToString());
                var newBatch = new Batch();
                newBatch.batchID = id;
                newBatch.name    = name;
                batchDict.Add(id, newBatch);
            }
            reader.Close();

            queryText = "SELECT s.Name, s.Replicate_ID, s.GCFeatPath, s.BatchName, s.Batch_ID, s.ControlBatchName, s.ControlBatch_ID FROM Replicate_Table s";
            command   = new SQLiteCommand(queryText, conn);
            reader    = command.ExecuteReader();
            while (reader.Read())
            {
                var name        = reader["Name"].ToString();
                var id          = int.Parse(reader["Replicate_ID"].ToString());
                var path        = reader["GCFeatPath"].ToString();
                var batchName   = reader["BatchName"].ToString();
                var batchID     = int.Parse(reader["Batch_ID"].ToString());
                var controlName = reader["ControlBatchName"].ToString();
                var controlID   = reader["ControlBatch_ID"].ToString();
                var newRep      = new Replicate();
                newRep.batchID        = batchID;
                newRep.batchName      = batchName;
                newRep.gcFeatFilePath = path;
                newRep.name           = name;
                newRep.replicateID    = id;
                var currBatch = batchDict[batchID];
                currBatch.replicates.Add(newRep);
                if (!string.IsNullOrEmpty(controlID))
                {
                    var control_ID = int.Parse(controlID);
                    //var currBatch = batchDict[batchID];
                    //currBatch.replicates.Add(newRep);
                    newRep.controlName  = controlName;
                    newRep.control      = batchDict[control_ID];
                    currBatch.control   = batchDict[control_ID];
                    currBatch.controlID = control_ID;
                }
            }
            return(batchDict);
        }
Exemple #5
0
        public void CreateBatchDictionary()
        {
            BatchDictionary = new Dictionary <string, Batch>();
            var gcExpReader = new StreamReader(gcExpTextBox.Text);
            HashSet <string> batchNamesHashSet = new HashSet <string>();
            List <Replicate> replicates        = new List <Replicate>();
            List <Batch>     batches           = new List <Batch>();

            while (gcExpReader.Peek() > -1)
            {
                var currLine = gcExpReader.ReadLine();
                if (!currLine.Equals("\t\t\t\t") && !string.IsNullOrEmpty(currLine))
                {
                    string[] parts            = currLine.Split('\t');
                    var      gcFeatPath       = parts[0];
                    var      name             = parts[1];
                    var      batchName        = parts[2];
                    var      controlBatchName = parts[3];
                    if (string.IsNullOrEmpty(batchName))
                    {
                        batchName = name;
                    }
                    var newRep = new Replicate();
                    newRep.name           = name;
                    newRep.gcFeatFilePath = gcFeatPath;
                    batchNamesHashSet.Add(batchName);
                    batchNamesHashSet.Add(controlBatchName);
                    newRep.controlName = controlBatchName;
                    newRep.batchName   = batchName;
                    replicates.Add(newRep);
                }
            }
            foreach (var batch in batchNamesHashSet.ToList())
            {
                var newBatch = new Batch();
                newBatch.name = batch;
                batches.Add(newBatch);
                BatchDictionary.Add(newBatch.name, newBatch);
            }
            foreach (var rep in replicates)
            {
                var currBatch = BatchDictionary[rep.batchName];
                currBatch.replicates.Add(rep);
                rep.control = BatchDictionary[rep.controlName];
            }
            foreach (var batch in BatchDictionary.Where(x => x.Value.replicates.Count == 0).ToList())
            {
                BatchDictionary.Remove(batch.Key);
            }
            ReplicateList = new List <Replicate>();
            foreach (var batch in BatchDictionary.Values)
            {
                foreach (var rep in batch.replicates)
                {
                    if (!BatchDictionary.ContainsKey(rep.controlName))
                    {
                        rep.control     = null;
                        rep.controlName = null;
                    }
                    ReplicateList.Add(rep);
                }
            }
        }