/// <summary> /// Generate a plot of symbol count by position using Sho libraries. /// Also include GC count, if applicable. /// </summary> /// <param name="filename">Filename of the output image file</param> /// <param name="height">Height of the plot in pixels</param> /// <param name="width">Width of the plot in pixels</param> public void PlotSymbolCountByPosition(string filename, int height = ShoHelper.HeightDefault, int width = ShoHelper.WidthDefault) { if (this.Analyzer.SymbolCountByPositionTable == null) { throw new ArgumentNullException("SymbolCountByPositionTable"); } ShoChart f = ShoHelper.CreateBasicShoChart( true, height, width, "Percentage (%)", "Read position (bp)", "Base content by position " + titleBanner ); // Set additional ShoChart parameters f.SetYRange(0, 100); f.SetXRange(0, this.Analyzer.ReadLengthMax + 1); var xLabels = ShoHelper.CreateBins(1, (int)this.Analyzer.ReadLengthMax); f.SetXLabels(xLabels, null); // Calculate the total number of reads by position int[] totalCountByPosition = this.Analyzer.GetSumByPosition(); // Plot symbol content for each base (i.e. A, C, G, T) int seriesCount = 0; foreach (KeyValuePair <byte, int[]> pair in this.Analyzer.SymbolCountByPositionTable) { // convert counts to percentages double[] percentages = new double[this.Analyzer.ReadLengthMax]; for (int i = 0; i < this.Analyzer.ReadLengthMax; i++) { int countAtCurrentPosition = pair.Value.Sum(); percentages[i] = pair.Value[i] * 100 / totalCountByPosition[i]; } // plot the series f.Plot(xLabels, percentages, "-" + seriesColors[seriesCount]); f.DundasChart.Series[seriesCount].ChartType = SeriesChartType.StackedArea100; // set the series name (for legend display) f.SeriesNames[seriesCount] = System.Text.Encoding.UTF8.GetString(new byte[] { pair.Key }); seriesCount++; } //f.DundasChart.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn100; //f.DundasChart.AlignDataPointsByAxisLabel(); // If applicable, plot GC content by position as well if (this.Analyzer.Alphabet == Alphabets.DNA || this.Analyzer.Alphabet == Alphabets.AmbiguousDNA || this.Analyzer.Alphabet == Alphabets.RNA || this.Analyzer.Alphabet == Alphabets.AmbiguousRNA) { var gcContentByPosition = this.Analyzer.GCContentByPositionArray; f.Plot(xLabels, gcContentByPosition, ":ok"); f.SeriesNames[seriesCount] = "GC%"; f.DundasChart.Series[seriesCount].ChartType = SeriesChartType.Spline; } // save plot to image file f.SaveImage(filename); }