Example #1
0
 public Motif(PermutationArray PA)
     : this(PA.NormalizedPeptideWeights, PA.NormalizedWildtypeWeights, PA.WildTypePeptide, PA.GetPositiveThreshold(), PA.GetNegativeThreshold())
 {
 }
Example #2
0
        public static bool ExportPermutationArrayToExcel(string fileName, PermutationArray PA, bool overwrite, out string errormsg)
        {
            try
            {
                errormsg = "";
                FileInfo existingFile = new FileInfo(fileName);
                if (existingFile.Exists && !overwrite)
                {
                    return(false);
                }
                using (ExcelPackage package = new ExcelPackage(existingFile))
                {
                    if (existingFile.Exists)
                    {
                        while (package.Workbook.Worksheets.Count > 0)
                        {
                            package.Workbook.Worksheets.Delete(1);
                        }
                    }
                    ExcelWorksheet worksheet = GetWorksheetBlank(package, "Arrays");

                    List <string> headerrow    = new List <string>();
                    List <string> headercolumn = new List <string>();
                    if (PA.PermutationXAxis)
                    {
                        headercolumn = PA.WildTypePeptide.ToCharArray().ToList().ConvertAll(c => c.ToString());
                        if (!PA.WildTypeYAxisTopToBottom)
                        {
                            headercolumn.Reverse();
                        }
                        headerrow = PA.Permutation.ToList().ConvertAll(c => c.ToString());
                    }
                    else
                    {
                        headerrow    = PA.WildTypePeptide.ToCharArray().ToList().ConvertAll(c => c.ToString());
                        headercolumn = PA.Permutation.ToList().ConvertAll(c => c.ToString());
                    }

                    int startrow = 2;
                    int lastrow  = MatrixToExcel(worksheet, 1, "Peptide Matrix", PA.PeptideMatrix);
                    if (lastrow < 0)
                    {
                        return(false);
                    }
                    ListToExcelRow(worksheet, startrow, 1, "", headerrow);
                    ListToExcelColumn(worksheet, startrow, 1, "", headercolumn);


                    startrow = lastrow + 3;
                    lastrow  = MatrixToExcel(worksheet, lastrow + 3, "Quantification Matrix", PA.QuantificationMatrix);
                    if (lastrow < 0)
                    {
                        return(false);
                    }
                    ListToExcelRow(worksheet, startrow + 1, 1, "", headerrow);
                    ListToExcelColumn(worksheet, startrow + 1, 1, "", headercolumn);
                    //put the normalization values
                    if (PA.NormMode == NormalizationMode.Mean)
                    {
                        worksheet.Cells[++lastrow, 1].Value = "Norm By:";
                        worksheet.Cells[lastrow, 2].Value   = PA.NormalizationValue;
                    }
                    else if (PA.PermutationXAxis)
                    {
                        ListToExcelColumn(worksheet, startrow + 1, PA.QuantificationMatrix.GetLength(1) + 2, "Norm By", PA.NormBy.ToList());
                    }
                    else
                    {
                        ListToExcelRow(worksheet, lastrow + 1, 1, "Norm By", PA.NormBy.ToList());
                    }

                    startrow = lastrow + 3;
                    lastrow  = MatrixToExcel(worksheet, lastrow + 3, "Normalized Matrix", PA.NormalizedMatrix);
                    ListToExcelRow(worksheet, startrow + 1, 1, "", headerrow);
                    ListToExcelColumn(worksheet, startrow + 1, 1, "", headercolumn);

                    worksheet.Cells[lastrow + 2, 1].Value = "Positive Threshold: ";
                    worksheet.Cells[lastrow + 2, 2].Value = PA.GetPositiveThreshold();

                    worksheet.Cells[lastrow + 3, 1].Value = "Negative Threshold: ";
                    worksheet.Cells[lastrow + 3, 2].Value = PA.GetNegativeThreshold();

                    WriteToSheetWeighedPeptideList(package, PA.NormalizedPeptideWeights, PA.GetPositiveThreshold(), PA.GetNegativeThreshold(), PA.WildTypePeptide);
                    WriteToSheetMotif(package, new Motif(PA));
                    WriteToSheetReferenceInfo(package, PA);
                    try
                    {
                        package.Save();
                    }
                    catch
                    {
                        errormsg = "There is a problem with saving the export file. Please make sure the file is not open and you have writing rights to the specific folder.";
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                errormsg = "There is a problem with creating the export file. Please try again.";
                return(false);
            }
        }