/// <summary> /// Generate a plot of quality score by position /// </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 PlotQualityScoreCountByPosition(string filename, int height = ShoHelper.HeightDefault, int width = ShoHelper.WidthDefault) { if (!this.Analyzer.HasRunContentByPosition) { throw new ArgumentException("Unable to plot. Need to process quality score data first."); } ShoChart f = ShoHelper.CreateBasicShoChart( false, height, width, "Phred quality score (" + this.Analyzer.FormatType.ToString() + ")", "Read position (bp)", "" ); // Set x- and y-axis ranges //f.SetXRange(1, this.Analyzer.ReadLengthMax); //f.SetYRange(Convert.ToDouble(QualitativeSequence.GetMinQualScore(this.Analyzer.FormatType)), // Convert.ToDouble(QualitativeSequence.GetMaxQualScore(this.Analyzer.FormatType))); var xLabels = ShoHelper.CreateBins(1, (int)this.Analyzer.ReadLengthMax); f.SetXLabels(xLabels, null); // Create a BoxPlot by reading data previously saved to file via FileStream. BoxPlot bp = new BoxPlot(f, (int)this.Analyzer.ReadLengthMax, this.Analyzer.Count, this.worker, this.workerArgs); // Update chart title f.Title = string.Format("Base quality score by position {0}", MakeTitleBanner(Path.GetFileName(this.Analyzer.FileName), bp.NumberOfProcessedReads)); // Build boxplot bp.BuildBoxPlot(xLabels, this.Analyzer.MemStream); f.SaveImage(filename); }
/// <summary> /// Plot mean quality scores at the sequence-level /// </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 PlotQualityScoreBySequence(string filename, int height = ShoHelper.HeightDefault, int width = ShoHelper.WidthDefault) { if (!this.Analyzer.HasRunContentBySequence) { throw new ArgumentException("Unable to plot. Need to process quality score data first."); } var bins = ShoHelper.CreateBins((int)this.Analyzer.BaseQualityScoreMin, (int)this.Analyzer.BaseQualityScoreMax, 2); var hist = new Histogram(this.Analyzer.QualityScoreBySequenceMeans, bins); ShoChart f = ShoHelper.CreateBasicShoChart( false, height, width, "Number of reads", "Mean quality score (" + this.Analyzer.FormatType.ToString() + ")", "Mean quality score by sequence " + titleBanner ); // set y-axis labels //f.SetYLabels(ShoHelper.GetIntegerAxisLabels(0, this.Analyzer.Count), null); f.Bar(bins, hist.Count); f.SaveImage(filename); }
/// <summary> /// Helper method to create a basic ShoChart object with common parameters pre-defined /// </summary> /// <param name="hasLegend">Specify if legend should be displayed</param> /// <param name="height">Height in pixels</param> /// <param name="width">Width in pixels</param> /// <param name="yTitle">y-axis title</param> /// <param name="xTitle">x-axis title</param> /// <param name="title">plot main title</param> /// <returns></returns> public static ShoChart CreateBasicShoChart(bool hasLegend, int height, int width, string yTitle, string xTitle, string title) { ShoChart f = new ShoChart(); f.Hold = true; f.HasLegend = hasLegend; // Set plot size f.Height = height; f.Width = width; // Set axis and plot titles f.XTitle = xTitle; f.YTitle = yTitle; f.Title = title; // Set major and minor gridlines //f.VerticalMajorGridlinesVisible = true; // Adjust font style and size var axisFont = new Font(FontFamily.GenericSansSerif, 10); f.XTitleFont = axisFont; f.YTitleFont = axisFont; f.TitleFont = new Font(FontFamily.GenericSansSerif, 12); return(f); }
/// <summary> /// Generate a histogram of GC content over all sequences. /// </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 PlotGCContentBySequence(string filename, int height = ShoHelper.HeightDefault, int width = ShoHelper.WidthDefault) { if (this.Analyzer.GCContentBySequenceArray == null) { throw new ArgumentNullException("this.analyzer.SymbolCountByPositionTable"); } int binSize = 5; var bins = ShoHelper.CreateBins(0, 100, binSize); var hist = new Histogram(this.Analyzer.GCContentBySequenceArray, bins); ShoChart f = ShoHelper.CreateBasicShoChart( false, height, width, "Number of reads", "GC content (%; bin size = " + binSize + ")", "GC content by sequence " + titleBanner ); var xLabelPositions = ShoHelper.CreateBins(1, 21); f.SetXLabels(xLabelPositions, bins); f.Bar(bins, hist.Count); //f.DundasChart.Series[0].ChartType = SeriesChartType.Spline; f.SaveImage(filename); }
public PeopleTab() { InitializeComponent(); _fateChart = new ShoChart(); _personalityChart = new Chart(); _personalityChartArea = new ChartArea(); _personalitySeries = new Series(); InitializeChart(); InitializePersonalityChart(); }
/// <summary> /// Create a BoxPlot object that sets all the required parameters /// </summary> /// <param name="chart">ShoChart to be used for plotting</param> /// <param name="length">Maximum length of the read</param> /// <param name="c">Number of reads</param> /// <param name="worker">Background working thread (used by GUI)</param> /// <param name="e">Worker event arguments</param> public BoxPlot(ShoChart chart, int length, long c, Stream s = null) { if (chart == null) { throw new ArgumentNullException("chart"); } this.chart = chart; this.readLength = length; this.count = c; //this.NumberOfProcessedReads = Math.Min(MaxNumberOfProcessedReads, (int)this.count); this.NumberOfProcessedReads = (int)this.count; }
/// <summary> /// Plot the distribution of sequence lengths /// </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 PlotSequenceLengthDistribution(string filename, int height = ShoHelper.HeightDefault, int width = ShoHelper.WidthDefault) { var hist = new Histogram(this.Analyzer.ReadLengths); ShoChart f = ShoHelper.CreateBasicShoChart( false, height, width, "Number of reads", "Length (bp)", "Sequence length distribution " + titleBanner ); f.HorizontalMinorGridlinesVisible = true; //f.SetYLabels(ShoHelper.CreateBins(0, (int)this.Analyzer.Count), null); f.Bar(hist.BinCenter, hist.Count); f.SaveImage(filename); }
public BoxPlot(ShoChart chart, int length, long c, BackgroundWorker worker, DoWorkEventArgs e) : this(chart, length, c) { this.worker = worker; this.workerArgs = e; }
/// <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); }