Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <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);
        }