public frmBatchGenImg(List <string> argResultFiles, string argExportRootPath, enumGlycanLabelingMethod argLabelingMethod, bool argIndividualImg, bool argQuantImg) { InitializeComponent(); ResultFiles = argResultFiles; isIndividualImg = argIndividualImg; isQuantImg = argQuantImg; CompletedCount = 0; ExportFilePath = argExportRootPath; LabelingMethod = argLabelingMethod; bgWorkerGenerateImages.RunWorkerAsync(); }
public frmBatchGenImg(List<string> argResultFiles, string argExportRootPath, enumGlycanLabelingMethod argLabelingMethod, bool argIndividualImg, bool argQuantImg) { InitializeComponent(); ResultFiles = argResultFiles; isIndividualImg = argIndividualImg; isQuantImg = argQuantImg; CompletedCount = 0; ExportFilePath = argExportRootPath; LabelingMethod = argLabelingMethod; bgWorkerGenerateImages.RunWorkerAsync(); }
public static void GenQuantImg(string argQuantFile, enumGlycanLabelingMethod argLabelingMethod, string argExportFolder) { string Dir = argExportFolder + "\\Pic"; if (!Directory.Exists(Dir)) { Directory.CreateDirectory(Dir); } List <Color> LstColor = new List <Color>() { Color.DarkCyan, Color.DarkGoldenrod, Color.DarkGray, Color.DarkGreen, Color.DarkKhaki, Color.DarkMagenta, Color.DarkOliveGreen, Color.DarkOrchid, Color.DarkRed, Color.DarkSalmon, Color.DarkSeaGreen, Color.DarkSlateBlue, Color.DarkSlateGray, Color.DarkTurquoise, Color.DarkViolet, Color.DeepPink, Color.DeepSkyBlue }; //Get Title Dictionary <string, int> dictTitle = new Dictionary <string, int>(); StreamReader sr = new StreamReader(argQuantFile); string tmp = ""; //bool isLabeling = false; tmp = sr.ReadLine(); #region Read Title string[] tmpAry = tmp.Split(','); //string LabelTitle = ""; dictTitle.Add("Glycan", 0); List <string> lstLabelingTag = new List <string>(); if (argLabelingMethod == enumGlycanLabelingMethod.DRAG) { lstLabelingTag.Add("DRAG_Light(Adjusted 1)"); lstLabelingTag.Add("DRAG_Heavy(Adjusted 1)"); } else if (argLabelingMethod == enumGlycanLabelingMethod.MultiplexPermethylated) { lstLabelingTag.Add("MP_CH3"); lstLabelingTag.Add("MP_CH2D"); lstLabelingTag.Add("MP_CHD2"); lstLabelingTag.Add("MP_CD3"); lstLabelingTag.Add("MP_13CH3"); lstLabelingTag.Add("MP_13CH2D"); lstLabelingTag.Add("MP_13CHD2"); lstLabelingTag.Add("MP_13CD3"); } for (int i = 1; i < tmpAry.Length; i++) { if (argLabelingMethod == enumGlycanLabelingMethod.MultiplexPermethylated && tmpAry[i].StartsWith("MP")) { dictTitle.Add(tmpAry[i], i + 3); // MP_CH3 Normalization Factor Estimated Purity Normalizted and Adjusted Abundance (Adjusted Factor=1) } else if (argLabelingMethod == enumGlycanLabelingMethod.DRAG && tmpAry[i].Contains("DRAG_Light(Adjusted 1)") || tmpAry[i].Contains("DRAG_Heavy(Adjusted 1)")) { dictTitle.Add(tmpAry[i], i); } } #endregion #region Get Data Dictionary <string, Dictionary <string, double> > dictData = new Dictionary <string, Dictionary <string, double> >(); while (!sr.EndOfStream) { tmp = sr.ReadLine(); tmpAry = tmp.Split(','); string GlycanKey = tmpAry[dictTitle["Glycan"]]; if (!dictData.ContainsKey(GlycanKey)) { dictData.Add(GlycanKey, new Dictionary <string, double>()); } foreach (string LabelTag in lstLabelingTag) { if (!dictTitle.ContainsKey(LabelTag)) { continue; } if (tmpAry[dictTitle[LabelTag]] != "N/A") { double intensity = Convert.ToDouble(tmpAry[dictTitle[LabelTag]]); if (intensity < 0) { intensity = 0; } dictData[GlycanKey].Add(LabelTag, intensity); } } } sr.Close(); #endregion #region Generate Quant Images //foreach(string Gkey in dictData.Keys) //ZedGraph.ZedGraphControl zgcGlycan = null; Parallel.ForEach(dictData.Keys, new ParallelOptions() { MaxDegreeOfParallelism = MaxDegreeParallelism }, Gkey => { //ZedGraphControl zgcGlycan = null; try { Chart cht = new Chart(); cht.Size = new Size(2400, 1200); cht.ChartAreas.Add("Default"); cht.ChartAreas["Default"].AxisX.Title = "Labeling"; cht.ChartAreas["Default"].AxisX.TitleFont = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisX.LabelStyle.Format = "{F2}"; cht.ChartAreas["Default"].AxisX.LabelStyle.Font = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash; cht.ChartAreas["Default"].AxisY.Title = "Abundance(%)"; cht.ChartAreas["Default"].AxisY.TitleFont = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisY.LabelStyle.Format = "{0.#E+00}"; cht.ChartAreas["Default"].AxisY.LabelStyle.Font = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash; cht.Titles.Add("Default"); cht.Titles[0].Text = "Glycan: " + Gkey; cht.Titles[0].Font = new Font("Arial", 24, FontStyle.Bold); cht.Legends.Add("Default"); cht.Legends["Default"].Docking = Docking.Bottom; cht.Legends["Default"].Alignment = StringAlignment.Center; cht.Legends["Default"].LegendStyle = LegendStyle.Row; cht.Legends["Default"].Font = new Font("Arial", 24, FontStyle.Bold); Dictionary <enumLabelingTag, double> dictLabelIntensity = new Dictionary <enumLabelingTag, double>(); double YMax = dictData[Gkey].Values.Max(); List <string> labels = new List <string>(); List <LCPointPair> ppl = new List <LCPointPair>(); int i = 0; foreach (string labelTag in lstLabelingTag) { labels.Add(labelTag); if (!dictTitle.ContainsKey(labelTag) || !dictData[Gkey].ContainsKey(labelTag)) { ppl.Add(new LCPointPair(i, 0)); } else { ppl.Add(new LCPointPair(i, dictData[Gkey][labelTag] / YMax * 100)); } i++; } Series myBar = cht.Series.Add("Data"); myBar.ChartType = SeriesChartType.Bar; for (int j = 0; j < ppl.Count; j++) { myBar.Points.AddY(ppl[j].Intensity); myBar.Points[j].AxisLabel = lstLabelingTag[j]; } cht.SaveImage(Dir + "\\Quant-" + Gkey + ".png", ChartImageFormat.Png); } catch (Exception ex) { throw ex; } #endregion }); }
public static void GenQuantImg(string argQuantFile, enumGlycanLabelingMethod argLabelingMethod, string argExportFolder) { string Dir = argExportFolder + "\\Pic"; if (!Directory.Exists(Dir)) { Directory.CreateDirectory(Dir); } List<Color> LstColor = new List<Color>() { Color.DarkCyan, Color.DarkGoldenrod, Color.DarkGray, Color.DarkGreen, Color.DarkKhaki, Color.DarkMagenta, Color.DarkOliveGreen, Color.DarkOrchid, Color.DarkRed, Color.DarkSalmon, Color.DarkSeaGreen, Color.DarkSlateBlue, Color.DarkSlateGray, Color.DarkTurquoise, Color.DarkViolet, Color.DeepPink, Color.DeepSkyBlue }; //Get Title Dictionary<string, int> dictTitle = new Dictionary<string, int>(); StreamReader sr = new StreamReader(argQuantFile); string tmp = ""; bool isLabeling = false; tmp = sr.ReadLine(); #region Read Title string[] tmpAry = tmp.Split(','); string LabelTitle = ""; dictTitle.Add("Glycan", 0); List<string> lstLabelingTag = new List<string>(); if (argLabelingMethod == enumGlycanLabelingMethod.DRAG) { lstLabelingTag.Add("DRAG_Light(Adjusted 1)"); lstLabelingTag.Add("DRAG_Heavy(Adjusted 1)"); } else if (argLabelingMethod == enumGlycanLabelingMethod.MultiplexPermethylated) { lstLabelingTag.Add("MP_CH3"); lstLabelingTag.Add("MP_CH2D"); lstLabelingTag.Add("MP_CHD2"); lstLabelingTag.Add("MP_CD3"); lstLabelingTag.Add("MP_13CH3"); lstLabelingTag.Add("MP_13CHD2"); lstLabelingTag.Add("MP_13CD3"); } for (int i = 1; i < tmpAry.Length; i++) { if (argLabelingMethod == enumGlycanLabelingMethod.MultiplexPermethylated && tmpAry[i].StartsWith("MP")) { dictTitle.Add(tmpAry[i], i + 3); // MP_CH3 Normalization Factor Estimated Purity Normalizted and Adjusted Abundance (Adjusted Factor=1) } else if (argLabelingMethod == enumGlycanLabelingMethod.DRAG && tmpAry[i].Contains("DRAG_Light(Adjusted 1)") || tmpAry[i].Contains("DRAG_Heavy(Adjusted 1)")) { dictTitle.Add(tmpAry[i], i); } } #endregion #region Get Data Dictionary<string, Dictionary<string, double>> dictData = new Dictionary<string, Dictionary<string, double>>(); while(!sr.EndOfStream) { tmp = sr.ReadLine(); tmpAry = tmp.Split(','); string GlycanKey = tmpAry[dictTitle["Glycan"]]; if (!dictData.ContainsKey(GlycanKey)) { dictData.Add(GlycanKey, new Dictionary<string, double>()); } foreach (string LabelTag in lstLabelingTag) { if (!dictTitle.ContainsKey(LabelTag)) { continue; } if (tmpAry[dictTitle[LabelTag]] != "N/A") { double intensity = Convert.ToDouble(tmpAry[dictTitle[LabelTag]]); if (intensity < 0) { intensity = 0; } dictData[GlycanKey].Add(LabelTag, intensity); } } } sr.Close(); #endregion #region Generate Quant Images //foreach(string Gkey in dictData.Keys) //ZedGraph.ZedGraphControl zgcGlycan = null; Parallel.ForEach(dictData.Keys, new ParallelOptions() { MaxDegreeOfParallelism = MaxDegreeParallelism }, Gkey => { //ZedGraphControl zgcGlycan = null; try { Chart cht = new Chart(); cht.Size = new Size(2400, 1200); cht.ChartAreas.Add("Default"); cht.ChartAreas["Default"].AxisX.Title = "Labeling"; cht.ChartAreas["Default"].AxisX.TitleFont = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisX.LabelStyle.Format = "{F2}"; cht.ChartAreas["Default"].AxisX.LabelStyle.Font = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash; cht.ChartAreas["Default"].AxisY.Title = "Abundance(%)"; cht.ChartAreas["Default"].AxisY.TitleFont = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisY.LabelStyle.Format = "{0.#E+00}"; cht.ChartAreas["Default"].AxisY.LabelStyle.Font = new Font("Arial", 24, FontStyle.Bold); cht.ChartAreas["Default"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash; cht.Titles.Add("Default"); cht.Titles[0].Text = "Glycan: " + Gkey; cht.Titles[0].Font = new Font("Arial", 24, FontStyle.Bold); cht.Legends.Add("Default"); cht.Legends["Default"].Docking = Docking.Bottom; cht.Legends["Default"].Alignment = StringAlignment.Center; cht.Legends["Default"].LegendStyle = LegendStyle.Row; cht.Legends["Default"].Font = new Font("Arial", 24, FontStyle.Bold); Dictionary<enumLabelingTag, double> dictLabelIntensity = new Dictionary<enumLabelingTag, double>(); double YMax = dictData[Gkey].Values.Max(); List<string> labels = new List<string>(); List<LCPointPair> ppl = new List<LCPointPair>(); int i = 0; foreach (string labelTag in lstLabelingTag) { labels.Add(labelTag); if (!dictTitle.ContainsKey(labelTag) || !dictData[Gkey].ContainsKey(labelTag)) { ppl.Add(new LCPointPair(i, 0)); } else { ppl.Add(new LCPointPair(i, dictData[Gkey][labelTag] / YMax * 100)); } i++; } Series myBar = cht.Series.Add("Data"); myBar.ChartType = SeriesChartType.Bar; for(int j =0; j<ppl.Count;j++) { myBar.Points.AddY(ppl[j].Intensity); myBar.Points[j].AxisLabel = lstLabelingTag[j]; } cht.SaveImage(Dir + "\\Quant-" + Gkey + ".png",ChartImageFormat.Png); } catch (Exception ex) { throw ex; } #endregion }); }