Пример #1
0
        public static void Run(bool removeNA, bool replaceNA, string missingValPercent, string missingValReplace,
                               ProgressWindow progressWindow, Dictionary <string, Dictionary <string, string> > dataMap,
                               IsotopeCalc isotopeCalc)
        {
            var excelPkg = new ExcelPackage();

            FormatToColumns(excelPkg, dataMap);

            if (removeNA)
            {
                progressWindow.progressTextBox.AppendLine("Removing NA");
                RemoveNA(excelPkg, missingValPercent, dataMap);
            }

            if (replaceNA)
            {
                progressWindow.progressTextBox.AppendLine($"Replacing NA with {missingValReplace}...");
                ReplaceNA(excelPkg, "Compounds Detected", missingValReplace);
            }

            if (isotopeCalc.isotopeToCompound.Count > 0)
            {
                progressWindow.progressTextBox.AppendLine("Calculating ratios");
                CalculateRatios(excelPkg, isotopeCalc, dataMap);
            }

            progressWindow.progressTextBox.AppendLine("Calculating concentrations");
            Concentration(excelPkg, isotopeCalc);
            // More WriteOutputFile....
            progressWindow.progressTextBox.AppendLine("Done");
            progressWindow.UseWaitCursor = false;
        }
Пример #2
0
        /// <summary>
        /// Calculates the ratio compound area / isotope area.
        /// </summary>
        /// <param name="excelPkg"></param>
        /// <param name="isotopeCalc"></param>
        /// <param name="detectedMap"></param>
        public static void CalculateRatios(ExcelPackage excelPkg, IsotopeCalc isotopeCalc,
                                           Dictionary <string, Dictionary <string, string> > detectedMap)
        {
            var compoundList = new List <string>(detectedMap.Keys);
            var sampleList   = new List <string>(detectedMap[compoundList[0]].Keys);
            int numSamples   = sampleList.Count;

            // Write data to new excel worksheet
            var isotopeRatioSheet = excelPkg.Workbook.Worksheets.Add("Isotope Ratio");

            isotopeRatioSheet.Cells[1, 1].Value = "Sample";

            // Fill in sample names
            for (int r = 2; r <= numSamples + 1; r++)
            {
                isotopeRatioSheet.Cells[r, 1].Value = sampleList[r - 2]; // Write sample name in first column
            }

            int col = 2;

            foreach (var isotope in isotopeCalc.isotopeToCompound.Keys)
            {
                foreach (var compound in isotopeCalc.isotopeToCompound[isotope].Where(compound => compoundList.Contains(compound)))
                {
                    isotopeRatioSheet.Cells[1, col].Value = compound; // Put compound name in first row
                    for (int row = 2; row <= numSamples + 1; row++)   // Fill in sample ratios
                    {
                        // Get area value from map with compound/sample match
                        var sampleName = isotopeRatioSheet.Cells[row, 1].Value.ToString();
                        detectedMap[compound].TryGetValue(sampleName, out var compoundArea);
                        if (double.TryParse(compoundArea, out var compoundAreaNum))
                        {
                            detectedMap[isotope].TryGetValue(sampleName, out var isotopeArea);
                            if (double.TryParse(isotopeArea, out var isotopeAreaNum))
                            {
                                isotopeRatioSheet.Cells[row, col].Value = compoundAreaNum / isotopeAreaNum;
                            }
                            else
                            {
                                isotopeRatioSheet.Cells[row, col].Value = "No Isotope";
                            }
                        }
                        else
                        {
                            isotopeRatioSheet.Cells[row, col].Value = 0.0;
                        }
                    }
                    col++;
                }
            }

            isotopeRatioSheet.Cells[2, 2, numSamples + 1, col - 1].Style.Numberformat.Format = "0.000000";
            isotopeRatioSheet.Cells.AutoFitColumns();
            SaveFile(excelPkg, outputFileName);
        }
Пример #3
0
        public static void Concentration(ExcelPackage excelPkg, IsotopeCalc isotopeCalc)
        {
            // Copy ratios data to new sheet to do calculation
            var concentrationSheet = excelPkg.Workbook.Worksheets.Copy("Isotope Ratio", "Concentrations");
            var rows = concentrationSheet.Dimension.Rows;
            var cols = concentrationSheet.Dimension.Columns;

            // Iterate through compounds
            int col = 2;

            for (int c = 2; c <= cols; c++)
            {
                var compound = concentrationSheet.Cells[1, c].Text;
                // Get slope and intercept for compound
                var slopeIntercept = isotopeCalc.SlopeIntercept("filePath", compound);

                // Calculate for each sample
                for (int r = 2; r <= rows; r++)
                {
                    var ratio = concentrationSheet.Cells[r, c].Text;
                    if (double.TryParse(ratio, out var ratioNum))
                    {
                        if (ratioNum == 0.0)
                        {
                            concentrationSheet.Cells[r, c].Value = 0.0;
                        }
                        else
                        {
                            concentrationSheet.Cells[r, c].Value = (ratioNum - slopeIntercept[1]) / slopeIntercept[0];
                        }
                    }
                }
            }

            //isotopeRatioSheet.Cells[2, 2, numSamples + 1, numCompounds + 1].Style.Numberformat.Format = "0.000000";
            concentrationSheet.Cells.AutoFitColumns();
            SaveFile(excelPkg, outputFileName);
        }
Пример #4
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            if (filePath == string.Empty)
            {
                return;
            }

            var progressWindow = new ProgressWindow();

            progressWindow.Show();

            // Create isotope map
            Dictionary <string, List <string> > isotopeMap = null;
            IsotopeCalc isotopeCalc = new IsotopeCalc();
            //isotopeMap = isotopeCalc.IsotopeMap(filePath);

            // Read data to map
            Dictionary <string, Dictionary <string, string> > dataMap = null;

            if (skylineRadioButton.Checked)
            {
                dataMap = ProcessSkyline.ReadDataToMap(filePath);
                if (dataMap.Count == 0)
                {
                    return;
                }

                // Create isotope map
                isotopeMap = isotopeCalc.IsotopeMap(filePath);
            }
            else if (sciexRadioButton.Checked)
            {
                dataMap = ProcessSciex.ReadDataToMap(filePath);
                if (dataMap.Count == 0)
                {
                    return;
                }
            }
            else if (NormQcRadioButton.Checked)
            {
                dataMap = ProcessSciex.ReadDataToMap(filePath);
                //Normalize.NormalizeToQC(filePath, dataMap);
            }
            else if (multiquantTxtRadioButton.Checked)
            {
                dataMap = ReadInput.ReadMultiQuantTxt(filePaths);
                var templatePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
                                   $"\\DataProcessor\\targeted_300_template-serum-mrm.xlsx";
                WriteOutputFile.WriteMapToSheetCompoundsInRows(progressWindow, dataMap, templatePath, "Relative Quant Data", 1);
                //WriteOutputFile.WriteMapToSheetCompoundsInRows(progressWindow, dataMap, templatePath, "Data Reproducibility", 2);
            }
            if (dataMap == null)
            {
                progressWindow.progressTextBox.AppendLine("Error reading file.");
                return;
            }

            progressWindow.progressTextBox.AppendLine("Finished reading data.\r\nWriting data");

            bool removeNA          = removeMissingCheckBox.Checked;
            var  missingValPercent = string.IsNullOrEmpty(missingValueBox.Text)
                ? missingValueBox.PlaceholderText
                : missingValueBox.Text;

            bool replaceNA         = replaceMissingValueCheckBox.Checked;
            var  missingValReplace = string.IsNullOrEmpty(replaceMissingValueTextBox.Text)
                ? replaceMissingValueTextBox.PlaceholderText
                : replaceMissingValueTextBox.Text;

            //WriteOutputFile.WriteSciex(replaceNA, missingValReplace, progressWindow, dataMap, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\DataProcessor\\targeted_300_template-tissue.xlsx");

            WriteOutputFile.Run(removeNA, replaceNA, missingValPercent, missingValReplace, progressWindow, dataMap, isotopeCalc);
        }