コード例 #1
0
ファイル: ProcyonForm.cs プロジェクト: dbaileychess/Compass
        private List<QuantFile> CombineQuantFiles(List<QuantFile> quantFiles)
        {
            List<QuantFile> retList = new List<QuantFile>();

            if (quantFiles.Count > 1)
            {
                UpdateLog("Combining Quant Files...");
            }

            QuantFile combinedQuantFile = new QuantFile(quantFiles, FileNameAndHeadertoUniqueGroupName);

            retList.Add(combinedQuantFile);

            return retList;
        }
コード例 #2
0
ファイル: ProcyonForm.cs プロジェクト: dbaileychess/Compass
        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;
        }