Пример #1
0
 def test_accuracy_as_phred_qv(self):
     qv = accuracy_as_phred_qv(0.999)
     self.assertEquals(int(round(qv)), 30)
     qv = accuracy_as_phred_qv(1.0, max_qv=60)
     self.assertEquals(int(round(qv)), 60)
     qv = accuracy_as_phred_qv([0.95, 1.0, 0.99999])
     qvs = [int(round(x)) for x in qv]
     self.assertEqual(qvs, [13, 70, 50])
Пример #2
0
 def test_accuracy_as_phred_qv(self):
     qv = accuracy_as_phred_qv(0.999)
     self.assertEquals(int(round(qv)), 30)
     qv = accuracy_as_phred_qv(1.0, max_qv=60)
     self.assertEquals(int(round(qv)), 60)
     qv = accuracy_as_phred_qv([0.95, 1.0, 0.99999])
     qvs = [ int(round(x)) for x in qv ]
     self.assertEqual(qvs, [13, 70, 50])
Пример #3
0
def _movie_results_to_attributes(movie_results):
    """Create the necessary attributes for the CCS report"""
    rs = [m.read_lengths for m in movie_results]
    read_lengths = np.concatenate(rs)
    ac = [m.accuracies for m in movie_results]
    accuracies = np.concatenate(ac)
    npass = [m.num_passes for m in movie_results]
    num_passes = np.concatenate(npass)

    m_readlength = int(read_lengths.mean()) if read_lengths.size > 0 else 0.0
    m_accuracy = np.round(
        accuracies.mean(), decimals=4) if accuracies.size > 0 else 0.0
    m_npasses = np.round(num_passes.mean()) if num_passes.size > 0 else 0.0
    m_qv = int(round(accuracy_as_phred_qv(float(m_accuracy))))

    n_reads_at = Attribute(
        Constants.A_NREADS, read_lengths.shape[0], name=Constants.ATTR_LABELS[
            Constants.A_NREADS])
    t_bases_at = Attribute(
        Constants.A_TOTAL_BASES, read_lengths.sum(), name=Constants.ATTR_LABELS[Constants.A_TOTAL_BASES])
    m_readlength_at = Attribute(
        Constants.A_MEAN_READLENGTH, m_readlength, name=Constants.ATTR_LABELS[Constants.A_MEAN_READLENGTH])
    m_accuracy_at = Attribute(
        Constants.A_MEAN_ACCURACY, m_accuracy, name=Constants.ATTR_LABELS[Constants.A_MEAN_ACCURACY])
    m_qv = Attribute(
        Constants.A_MEAN_QV, m_qv, name=Constants.ATTR_LABELS[Constants.A_MEAN_QV])

    m_npasses_at = Attribute(
        Constants.A_MEAN_NPASSES, m_npasses, name=Constants.ATTR_LABELS[Constants.A_MEAN_NPASSES])

    attributes = [n_reads_at, t_bases_at,
                  m_readlength_at, m_accuracy_at, m_qv, m_npasses_at]

    return attributes
Пример #4
0
def _movie_results_to_table(movie_results):
    """Group movie results by movie name and build a report table.

    Table has movie name, # of CCS bases, Total CCS bases,
    mean CCS readlength and mean CCS accuracy.
    """
    columns = [Column(Constants.C_MOVIE_NAME, header="Movie"),
               Column(Constants.A_NREADS, header="Consensus reads"),
               Column(Constants.A_TOTAL_BASES,
                      header="Number of consensus bases"),
               Column(Constants.A_MEAN_READLENGTH,
                      header="Mean Consensus Read Length"),
               Column(Constants.A_MEAN_ACCURACY,
                      header="Mean Consensus Predicted Accuracy"),
               Column(Constants.A_MEAN_QV,
                      header="Mean Consensus Predicted QV"),
               Column(Constants.A_MEAN_NPASSES, header="Mean Number of Passes")]

    table = Table(Constants.T_ID, title="Consensus reads", columns=columns)

    movie_names = {m.movie_name for m in movie_results}

    for movie_name in movie_names:
        rs = [
            m.read_lengths for m in movie_results if m.movie_name == movie_name]
        read_lengths = np.concatenate(rs)
        ac = [
            m.accuracies for m in movie_results if m.movie_name == movie_name]
        accuracies = np.concatenate(ac)
        npass = [
            m.num_passes for m in movie_results if m.movie_name == movie_name]
        num_passes = np.concatenate(npass)

        m_readlength = int(
            read_lengths.mean()) if read_lengths.size > 0 else 0.0
        m_accuracy = np.round(
            accuracies.mean(), decimals=4) if accuracies.size > 0 else 0.0
        m_npasses = np.round(
            num_passes.mean(), decimals=3) if num_passes.size > 0 else 0.0
        m_qv = int(round(accuracy_as_phred_qv(float(accuracies.mean()))))

        table.add_data_by_column_id(Constants.C_MOVIE_NAME, movie_name)
        table.add_data_by_column_id(Constants.A_NREADS, read_lengths.shape[0])
        table.add_data_by_column_id(
            Constants.A_TOTAL_BASES, read_lengths.sum())
        table.add_data_by_column_id(Constants.A_MEAN_READLENGTH, m_readlength)
        table.add_data_by_column_id(Constants.A_MEAN_ACCURACY, m_accuracy)
        table.add_data_by_column_id(Constants.A_MEAN_QV, m_qv)
        table.add_data_by_column_id(Constants.A_MEAN_NPASSES, m_npasses)

    return table
Пример #5
0
def scatter_plot_accuracy_vs_numpasses(data,
        axis_labels=("Number of passes", "Predicted accuracy (Phred QV)"),
        nbins=None, barcolor=None):
    """
    """
    npasses, accuracy = data
    qvs = accuracy_as_phred_qv(accuracy)
    fig, ax = get_fig_axes_lpr()
    data = [Line(xData=npasses,
                yData=qvs,
                style='o')]
    apply_line_data(
        ax=ax,
        line_models=data,
        axis_labels=axis_labels,
        only_whole_ticks=False)
    return fig, ax
Пример #6
0
def scatter_plot_accuracy_vs_numpasses(
    data,
    axis_labels=(
        get_plot_xlabel(spec, Constants.PG_SCATTER, Constants.P_SCATTER),
        get_plot_ylabel(spec, Constants.PG_SCATTER, Constants.P_SCATTER),
    ),
    nbins=None,
    barcolor=None,
):
    """
    """
    npasses, accuracy = data
    qvs = accuracy_as_phred_qv(accuracy)
    fig, ax = get_fig_axes_lpr()
    data = [Line(xData=npasses, yData=qvs, style="o")]
    apply_line_data(ax=ax, line_models=data, axis_labels=axis_labels, only_whole_ticks=False)
    return fig, ax
Пример #7
0
def scatter_plot_accuracy_vs_numpasses(
        data,
        axis_labels=(get_plot_xlabel(spec, Constants.PG_SCATTER,
                                     Constants.P_SCATTER),
                     get_plot_ylabel(spec, Constants.PG_SCATTER,
                                     Constants.P_SCATTER)),
        nbins=None,
        barcolor=None):
    """
    """
    npasses, accuracy = data
    qvs = accuracy_as_phred_qv(accuracy)
    fig, ax = get_fig_axes_lpr()
    data = [Line(xData=npasses, yData=qvs, style='o')]
    apply_line_data(ax=ax,
                    line_models=data,
                    axis_labels=axis_labels,
                    only_whole_ticks=False)
    return fig, ax
Пример #8
0
def scatter_plot_accuracy_vs_numpasses(data,
                                       axis_labels=(
                                           meta_rpt.get_meta_plotgroup(Constants.PG_SCATTER).get_meta_plot(Constants.P_SCATTER).xlabel,
                                           meta_rpt.get_meta_plotgroup(Constants.PG_SCATTER).get_meta_plot(Constants.P_SCATTER).ylabel),
                                       nbins=None, barcolor=None):
    """
    """
    npasses, accuracy = data
    qvs = accuracy_as_phred_qv(accuracy)
    fig, ax = get_fig_axes_lpr()
    data = [Line(xData=npasses,
                 yData=qvs,
                 style='o')]
    apply_line_data(
        ax=ax,
        line_models=data,
        axis_labels=axis_labels,
        only_whole_ticks=False)
    return fig, ax