public static bool SaveToFile(string filename, OPALArray OA) { try { OA.Version = typeof(Analyzer).Assembly.GetName().Version.ToString(); string json = JsonConvert.SerializeObject(OA); File.WriteAllText(filename, json); return(true); } catch { return(false); } }
public static OPALArray ReadOPALArrayQuantificationData(string fileName) { string[,] data = ReadArrayFromFile(fileName); bool permX = false, permY = false; OPALArray.CheckPermutationAxis(data, ref permX, ref permY); if (!permX && !permY) { return(null); } Settings settings = Settings.Load("default.settings"); OPALArray OA = new OPALArray(data, permX, settings.WildTypeYAxisTopToBottom, out string error); return(OA); }
public static OPALArray ReadFromFile(string filename) { try { OPALArray OA = null; if (File.Exists(filename)) { OA = JsonConvert.DeserializeObject <OPALArray>(File.ReadAllText(filename)); if (OA.Version == "") { OA.Version = "Old version"; OA.Upgrade("PositiveThreshold"); OA.Upgrade("NormalizedMatrixRange"); } } return(OA); } catch { return(null); } }
public Motif(OPALArray OA) : this(OA.NormalizedPeptideWeights, null, OA.WildTypePeptide, OA.PositiveThreshold, OA.NegativeThreshold) { }
public static bool ExportOPALArrayToExcel(string fileName, OPALArray OA, 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 (OA.PermutationXAxis) { headercolumn = OA.PositionCaptions.ToList().ConvertAll(c => c.ToString()); headerrow = OA.Permutation.ToList().ConvertAll(c => c.ToString()); } else { headerrow = OA.PositionCaptions.ToList().ConvertAll(c => c.ToString()); headercolumn = OA.Permutation.ToList().ConvertAll(c => c.ToString()); } int startrow = 1; int lastrow = MatrixToExcel(worksheet, startrow, "Quantification Matrix", OA.QuantificationMatrix); if (lastrow < 0) { return(false); } ListToExcelRow(worksheet, startrow + 1, 1, "", headerrow); ListToExcelColumn(worksheet, startrow + 1, 1, "", headercolumn); //put the normalization values if (OA.NormMode == NormalizationMode.Max) { worksheet.Cells[++lastrow, 1].Value = "Norm By:"; worksheet.Cells[lastrow, 2].Value = OA.NormalizationValue; } else if (OA.PermutationXAxis) { ListToExcelColumn(worksheet, startrow + 1, OA.QuantificationMatrix.GetLength(1) + 2, "Norm By", OA.NormBy.ToList()); } else { ListToExcelRow(worksheet, lastrow + 1, 1, "Norm By", OA.NormBy.ToList()); } startrow = lastrow + 3; lastrow = MatrixToExcel(worksheet, startrow, "Normalized Matrix", OA.NormalizedMatrix); ListToExcelRow(worksheet, startrow + 1, 1, "", headerrow); ListToExcelColumn(worksheet, startrow + 1, 1, "", headercolumn); WriteToSheetMotif(package, new Motif(OA)); WriteToSheetReferenceInfo(package, OA); 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); } }