public static bool SaveToFile(string filename, PermutationArray PA) { try { PA.Version = typeof(Analyzer).Assembly.GetName().Version.ToString(); string json = JsonConvert.SerializeObject(PA); File.WriteAllText(filename, json); return(true); } catch { return(false); } }
public static PermutationArray ReadPermutationArrayQuantificationData(string fileName) { string[,] data = ReadArrayFromFile(fileName); bool permX = false, permY = false; PermutationArray.CheckPermutationAxis(data, ref permX, ref permY); if (!permX && !permY) { return(null); } Settings settings = Settings.Load("default.settings"); PermutationArray PA = new PermutationArray(data, permX, settings.WildTypeYAxisTopToBottom, out List <string> warnings, out string error); return(PA); }
public static PermutationArray ReadFromFile(string filename) { try { PermutationArray PA = null; if (File.Exists(filename)) { PA = JsonConvert.DeserializeObject <PermutationArray>(File.ReadAllText(filename)); if (PA.Version == "") { PA.Version = "Old version"; PA.Upgrade("NormalizedPeptideWeights"); PA.Upgrade("PositiveThreshold"); } if (PA.NormalizedMatrixMin == PA.NormalizedMatrixMax) { PA.Upgrade("NormalizedMatrixRange"); } } return(PA); } catch { return(null); } }
public Motif(PermutationArray PA) : this(PA.NormalizedPeptideWeights, PA.NormalizedWildtypeWeights, PA.WildTypePeptide, PA.GetPositiveThreshold(), PA.GetNegativeThreshold()) { }
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); } }