Example #1
0
        public QuantFile(List <QuantFile> quantFiles, Dictionary <string, string> fileNameAndHeadertoUniqueGroupName)
        {
            CombinedQuantEntryDict    = new Dictionary <string, QuantEntry>();
            CombinedHeadersToPrint    = new Dictionary <string, string>();
            CombinedGroupNamesToPrint = new Dictionary <string, string>();
            FileLocations             = new List <string>();
            Comparisons = new Dictionary <string, Comparison>();

            foreach (QuantFile quantFile in quantFiles)
            {
                //Add the file locations for all files
                FileLocations.Add(quantFile.FileLoaction);
                UniprotHeader = quantFile.UniprotHeader;

                //Add all of the headers to print to one dictionary - should all be the same headers
                foreach (KeyValuePair <string, string> kvp in quantFile.HeadersToPrint)
                {
                    string outString = null;
                    if (!CombinedHeadersToPrint.TryGetValue(kvp.Key, out outString))
                    {
                        CombinedHeadersToPrint.Add(kvp.Key, kvp.Value);
                    }
                }

                //Combine all of the unique group names to print out
                foreach (KeyValuePair <string, string> kvp in quantFile.UniqueGroupNamesToPrint)
                {
                    string outString = null;
                    if (!CombinedGroupNamesToPrint.TryGetValue(kvp.Key, out outString))
                    {
                        CombinedGroupNamesToPrint.Add(kvp.Key, kvp.Value);
                    }
                }

                //Combine the quantitation entries from each file
                foreach (QuantEntry quantEntry in quantFile.QuantEntries)
                {
                    QuantEntry outQuantEntry = null;
                    if (CombinedQuantEntryDict.TryGetValue(quantEntry.UniqueID, out outQuantEntry))
                    {
                        //If this entry already exsits simply add to the quant entry that exists
                        outQuantEntry.AddQuantEntry(quantEntry, fileNameAndHeadertoUniqueGroupName);
                    }
                    else
                    {
                        //Simply add the quant entry of it is the first time it is added
                        quantEntry.FillCombinedDictionary(fileNameAndHeadertoUniqueGroupName);
                        CombinedQuantEntryDict.Add(quantEntry.UniqueID, quantEntry);
                    }
                }
            }
        }
Example #2
0
        public void AddQuantEntry(QuantEntry addQuantEntry, Dictionary <string, string> fileNameAndHeadertoUniqueGroupName)
        {
            //Make a combined dictionary for Log2Normalized Values
            foreach (KeyValuePair <string, double> kvp in addQuantEntry.Log2NormalizedSampleValues)
            {
                string uniqueGroupNameKey = addQuantEntry.FileLocation + kvp.Key;
                CombinedLog2NormalizedSampleValues.Add(fileNameAndHeadertoUniqueGroupName[uniqueGroupNameKey], kvp.Value);
            }

            //Make a combined dictionary for Mean normalized Values
            foreach (KeyValuePair <string, double> kvp in addQuantEntry.MeanNormalizedSampleValues)
            {
                string uniqueGroupNameKey = addQuantEntry.FileLocation + kvp.Key;
                CombinedMeanNormalizedSampleValues.Add(fileNameAndHeadertoUniqueGroupName[uniqueGroupNameKey], kvp.Value);
            }

            //Add to the headers to print list - it will print out values from each file if they are not the same.
            foreach (KeyValuePair <string, string> kvp in addQuantEntry.HeadersToPrintDict)
            {
                List <string> outList = null;
                if (CombinedHeadersToPrintSampleValues.TryGetValue(kvp.Key, out outList))
                {
                    if (!outList.Contains(kvp.Value))
                    {
                        outList.Add(kvp.Value);
                    }
                }
                else
                {
                    List <string> addList = new List <string>();
                    addList.Add(kvp.Value);
                    CombinedHeadersToPrintSampleValues.Add(kvp.Key, addList);
                }
            }

            //Populate the Unique Header to Group Number Dictionary that will be used for Grouping the Quant Data
            foreach (KeyValuePair <string, string> uniqueGroupNameToNumber in addQuantEntry.UniqueHeaderToGroupString)
            {
                string outInt = null;
                if (!UniqueHeaderToGroupString.TryGetValue(uniqueGroupNameToNumber.Key, out outInt))
                {
                    UniqueHeaderToGroupString.Add(uniqueGroupNameToNumber.Key, uniqueGroupNameToNumber.Value);
                }
            }
        }
Example #3
0
        public void AddQuantEntry(QuantEntry addQuantEntry, Dictionary<string, string> fileNameAndHeadertoUniqueGroupName)
        {
            //Make a combined dictionary for Log2Normalized Values
            foreach (KeyValuePair<string, double> kvp in addQuantEntry.Log2NormalizedSampleValues)
            {
                string uniqueGroupNameKey = addQuantEntry.FileLocation + kvp.Key;
                CombinedLog2NormalizedSampleValues.Add(fileNameAndHeadertoUniqueGroupName[uniqueGroupNameKey], kvp.Value);
            }

            //Make a combined dictionary for Mean normalized Values
            foreach (KeyValuePair<string, double> kvp in addQuantEntry.MeanNormalizedSampleValues)
            {
                string uniqueGroupNameKey = addQuantEntry.FileLocation + kvp.Key;
                CombinedMeanNormalizedSampleValues.Add(fileNameAndHeadertoUniqueGroupName[uniqueGroupNameKey], kvp.Value);
            }

            //Add to the headers to print list - it will print out values from each file if they are not the same.
            foreach (KeyValuePair<string, string> kvp in addQuantEntry.HeadersToPrintDict)
            {
                List<string> outList = null;
                if (CombinedHeadersToPrintSampleValues.TryGetValue(kvp.Key, out outList))
                {
                    if(!outList.Contains(kvp.Value))
                    {
                        outList.Add(kvp.Value);
                    }
                }
                else
                {
                    List<string> addList = new List<string>();
                    addList.Add(kvp.Value);
                    CombinedHeadersToPrintSampleValues.Add(kvp.Key, addList);
                }
            }

            //Populate the Unique Header to Group Number Dictionary that will be used for Grouping the Quant Data
            foreach (KeyValuePair<string, string> uniqueGroupNameToNumber in addQuantEntry.UniqueHeaderToGroupString)
            {
                string outInt = null;
                if(!UniqueHeaderToGroupString.TryGetValue(uniqueGroupNameToNumber.Key, out outInt))
                {
                    UniqueHeaderToGroupString.Add(uniqueGroupNameToNumber.Key, uniqueGroupNameToNumber.Value);
                }
            }
        }
Example #4
0
        private List<QuantFile> ImportQuantFiles()
        {
            UpdateLog("Importing Quant Files...");

            //This will be the list of Quant Files
            List<QuantFile> retList = new List<QuantFile>();

            //Load the headers that you will want to print in the final document.
            String[] headersToPrintArray = new string[headersToPrintListBox.CheckedItems.Count];
            headersToPrintListBox.CheckedItems.CopyTo(headersToPrintArray, 0);
            List<String> headersToPrintList = headersToPrintArray.ToList();

            if (!headersToPrintList.Contains(UniprotHeader))
            {
                headersToPrintList.Add(UniprotHeader);
            }

            //Load the two strings that you will use to determine a unique group when combining files
            string uniqueIDString = headerComboBox.SelectedItem.ToString();
            string uniqueIDString2 = headerComboBox2.SelectedItem.ToString();

            //Create Quant Files for each loaded CSV - Files will not be combined at this time
            foreach (KeyValuePair<string, List<string>> kvp in FileNametoHeadersToQuantify)
            {
                //Open the CSV file
                using (CsvReader reader = new CsvReader(new StreamReader(kvp.Key), true))
                {
                    //Create the Quant File that you will populate
                    QuantFile quantFile = new QuantFile(kvp.Key, kvp.Value);

                    //Set the UniprotHeader
                    quantFile.UniprotHeader = UniprotHeader;

                    //Read in each line and make a Quant Entry
                    while (reader.ReadNextRecord())
                    {
                        //Make sure that there is quantitative data for all measurements in the file
                        bool addQuantData = true;

                        //Do this check if you are mean normalizing
                        if (ValueForComparison == ValueType.MeanNormalizedFoldChange || ValueForComparison == ValueType.MeanNormalizedLog2Change || medianNorm.Checked || sumNorm.Checked)
                        {
                            //Check all of the headers in the file regardless of if they are in a comparison
                            foreach (string header in kvp.Value)
                            {
                                string parseThis = reader[header];
                                double outDouble = 0;
                                if (!double.TryParse(parseThis, out outDouble) || outDouble == 0)
                                {
                                    addQuantData = false;
                                }
                            }
                        }
                        else
                        {
                            //Only check the headers that are involved in a comparison HeadersToIncludeByFile
                            foreach (string header in HeadersToIncludeByFile[kvp.Key])
                            {
                                string parseThis = reader[header];
                                double outDouble = 0;
                                if (!double.TryParse(parseThis, out outDouble) || outDouble == 0)
                                {
                                    addQuantData = false;
                                }
                            }
                        }

                        //If there are not "0" or "-" values then add this Quant Entry
                        if (addQuantData)
                        {
                            //Make a new Quant Entry
                            QuantEntry quantEntry = new QuantEntry(quantFile.FileLoaction, reader[uniqueIDString], reader[uniqueIDString2], UniqueGroupNametoGroupString);

                            //Load up the data in the columns that you will want to print at the end.
                            foreach (string header in headersToPrintList)
                            {
                                string outString = null;
                                if (!quantFile.HeadersToPrint.TryGetValue(header, out outString))
                                {
                                    quantFile.HeadersToPrint.Add(header, header);
                                }

                                quantEntry.HeadersToPrintDict.Add(header, reader[header]);
                            }

                            //Load up the data from each of the columns that you want to quantify.
                            foreach (string header in kvp.Value)
                            {
                                //Get the Quant Value to Parse
                                string testit = reader[header];

                                double a = double.Parse(reader[header]);

                                quantFile.HeadertoValueDict[header].Add(double.Parse(reader[header]));
                                quantEntry.SampleValues.Add(header, double.Parse(reader[header]));

                                //Get the file name + header and create a unique hash code that you will map the unique header name
                                string fileAndHeader = quantFile.FileLoaction + header;
                                long fileAndHeaderHash = fileAndHeader.GetHashCode();

                                //Only add these once - this will map the File Location + Header code to the unique name given by the user
                                string outString = null;
                                if (!quantFile.UniqueGroupNamesToPrint.TryGetValue(fileAndHeader, out outString))
                                {
                                    quantFile.UniqueGroupNamesToPrint.Add(fileAndHeader, FileNameAndHeadertoUniqueGroupName[fileAndHeader]);
                                }
                            }

                            //Add that Quant Entry to the List within the Quant File
                            quantFile.QuantEntries.Add(quantEntry);
                        }
                    }

                    retList.Add(quantFile);
                }
            }

            return retList;
        }
Example #5
0
        public void NormalizeDataSet(bool noNormalize, bool sumNormalize, bool medianNormalize, string uniprotHeader, string normalizationString, List <string> uniprotListForNormalization)
        {
            if (uniprotListForNormalization.Count == 0)
            {
                if (noNormalize)
                {
                    DoNotNormalizeDataSet(HeadertoValueDict);
                }
                else if (medianNormalize)
                {
                    MedianNormalizeDataSet(HeadertoValueDict);
                }
                else if (sumNormalize)
                {
                    SumNormalizeDataSet(HeadertoValueDict);
                }
            }
            else
            {
                //this will be a normalization based on a subset of proteins
                Dictionary <string, List <double> > subsetDictionary = new Dictionary <string, List <double> >();
                foreach (QuantEntry entry in QuantEntries)
                {
                    entry.PopulateUniprotList(uniprotHeader);

                    foreach (string uniprotID in entry.UniprotIDList)
                    {
                        if (uniprotListForNormalization.Contains(uniprotID))
                        {
                            QuantEntry outEntry = null;
                            if (!QuantEntriesForNorm.TryGetValue(entry.UniqueID, out outEntry))
                            {
                                QuantEntriesForNorm.Add(entry.UniqueID, entry);
                            }

                            foreach (KeyValuePair <string, double> kvp in entry.SampleValues)
                            {
                                List <double> outDouble = null;
                                if (subsetDictionary.TryGetValue(kvp.Key, out outDouble))
                                {
                                    outDouble.Add(kvp.Value);
                                }
                                else
                                {
                                    List <double> addList = new List <double>();
                                    addList.Add(kvp.Value);
                                    subsetDictionary.Add(kvp.Key, addList);
                                }
                            }
                        }
                    }
                }

                if (noNormalize)
                {
                    DoNotNormalizeDataSet(subsetDictionary);
                }
                else if (medianNormalize)
                {
                    MedianNormalizeDataSet(subsetDictionary);
                }
                else if (sumNormalize)
                {
                    SumNormalizeDataSet(subsetDictionary);
                }
            }
        }