コード例 #1
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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        /// Plot the statistics at the quality score-level
        /// </summary>
        /// <param name="worker">Background working thread (used by GUI)</param>
        /// <param name="e">Worker event arguments</param>
        public void PlotQualityScoreLevelStats()
        {
            string tempDir         = this.OutputDirectory + "/";
            QualityScorePlotter qp = new QualityScorePlotter(QualityScoreQc, QualityScoreQc.Worker, QualityScoreQc.WorkerArgs);

            qp.PlotQualityScoreCountByPosition(tempDir + myFilenames.QualityScoreByPosition,
                                               width: ShoHelper.GetAutoPlotWidth(QualityScoreQc.ReadLengthMax));
            qp.PlotQualityScoreBySequence(tempDir + myFilenames.QualityScoreBySequence);

            HasPlottedQualityScoreStats = true;
        }
コード例 #5
0
        /// <summary>
        /// Plot the statistics at the sequence-level
        /// </summary>
        public void PlotSequenceLevelStats()
        {
            string          tempDir = this.OutputDirectory + @"\";
            SequencePlotter sp      = new SequencePlotter(SequenceQc);

            sp.PlotSymbolCountByPosition(tempDir + myFilenames.SymbolCountByPosition,
                                         width: ShoHelper.GetAutoPlotWidth(this.SequenceQc.ReadLengthMax));
            sp.PlotGCContentBySequence(tempDir + myFilenames.GCContentBySequence);
            sp.PlotSequenceLengthDistribution(tempDir + myFilenames.SequenceLengths);

            HasPlottedSequenceStats = true;
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
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);
        }