Exemple #1
0
    def test_get_consensus_table(self):
        """
        Test the data in the table object and the attributes
        """
        top_contigs = get_top_contigs_from_ref_entry(
            self._get_reference_entry(), 2)

        ref_data = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY,
                                                top_contigs)[0]
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(0, results[ERR])

        _append_variants_gff_data(ref_data, self.VARIANTS_GFF)

        table, attributes = _get_consensus_table_and_attributes(
            ref_data, self._get_reference_entry())
        self.assertEqual(5, len(table.columns))
        self.assertEqual(self.CONTIG_ID, table.columns[0].values[0])
        self.assertEqual(self.TEST_VALUES["contig_len"],
                         table.columns[1].values[0])
        self.assertEqual(1, table.columns[2].values[0])
        self.assertAlmostEqual(self.TEST_VALUES["concordance"],
                               table.columns[3].values[0],
                               places=4)
        self.assertAlmostEqual(self.TEST_VALUES["coverage"],
                               table.columns[4].values[0],
                               places=2)
    def test_get_consensus_table(self):
        """
        Test the data in the table object and the attributes
        """
        top_contigs = get_top_contigs_from_ref_entry(self._get_reference_entry(), 2)

        ref_data = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY, top_contigs)[0]
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(0, results[ERR])

        _append_variants_gff_data(ref_data, self.VARIANTS_GFF)

        table, attributes = _get_consensus_table_and_attributes(ref_data, self._get_reference_entry())
        self.assertEqual(5, len(table.columns))
        self.assertEqual(self.CONTIG_ID, table.columns[0].values[0])
        self.assertEqual(self.TEST_VALUES["contig_len"],
                         table.columns[1].values[0])
        self.assertEqual(1, table.columns[2].values[0])
        self.assertAlmostEqual(self.TEST_VALUES["concordance"],
                               table.columns[3].values[0], places=4)
        self.assertAlmostEqual(self.TEST_VALUES["coverage"],
                               table.columns[4].values[0], places=2)
    def test_get_consensus_attributes(self):
        """
        Test the data in the table object and the attributes
        """
        top_contigs = get_top_contigs_from_ref_entry(self._get_reference_entry(), 2)

        ref_data = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY, top_contigs)[0]
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(0, results[ERR])

        _append_variants_gff_data(ref_data, self.VARIANTS_GFF)

        table, attributes = _get_consensus_table_and_attributes(ref_data, self._get_reference_entry())
        self.assertEqual(5, len(attributes))

        def __get_att_val(_id, atts):
            for a in atts:
                if a.id == _id:
                    return a.value

        self.assertEqual(self.TEST_VALUES["contig_len"], __get_att_val("mean_contig_length", attributes))
        self.assertAlmostEqual(
            self.TEST_VALUES["bases_called"], __get_att_val("weighted_mean_bases_called", attributes), places=4
        )
        self.assertAlmostEqual(
            self.TEST_VALUES["concordance"], __get_att_val("weighted_mean_concordance", attributes), places=4
        )
        self.assertAlmostEqual(
            self.TEST_VALUES["coverage"], __get_att_val("weighted_mean_coverage", attributes), places=2
        )
        self.assertEqual(self.CONTIG_ID, __get_att_val("longest_contig_name", attributes))
    def test_create_variants_plot_grp(self):
        """
        Test that plotGroup of variants plots is created as expected
        """
        top_contigs = get_top_contigs_from_ref_entry(self._get_reference_entry(), 25)
        ref_data, contig_variants = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY, top_contigs)

        plot_group = _create_variants_plot_grp(top_contigs, contig_variants, self._output_dir)
        self.assertEqual(1, len(plot_group.plots))

        self._assert_image_file(plot_group.thumbnail)

        for plot in plot_group.plots:
            self._assert_image_file(plot.image)
        self._assert_image_file(plot_group.legend)
    def test_extract_alignment_summ_data(self):
        """
        Test the dicts returned from parsing the alignment_summary gff
        """
#        top_contigs = get_top_contigs(ref, 2)

        top_contigs = get_top_contigs_from_ref_entry(self._get_reference_entry(), 2)

        ref_data, contig_variants = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY, top_contigs)
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(0, results[ERR])

        self.assertEqual(1, len(contig_variants))
    def test_legend(self):
        """
        Create the legend png
        """
        top_contigs = get_top_contigs_from_ref_entry(self._get_reference_entry(), 25)
        contig_variants = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY, top_contigs)[1]
        ctgvar = None
        for t in top_contigs:
            ctgvar = contig_variants[t.header]

        bars = _create_bars(ctgvar)
        self.assertEqual(3, len(bars))

        leg = _get_legend_file(bars, self._output_dir)
        leg_path = op.join(self._output_dir, leg)

        log.info('legend path: {l}'.format(l=leg_path))
        self.assertTrue(op.exists(leg_path))
    def test_append_variants_gff_data(self):
        """
        Test that ERR information gets added to the ref_data dict
        """
#        top_contigs = get_top_contigs(ref, 2)

        top_contigs = get_top_contigs_from_ref_entry(self._get_reference_entry(), 2)

        ref_data = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY, top_contigs)[0]
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(self.TEST_VALUES["n_gff_err_1"], results[ERR])

        _append_variants_gff_data(ref_data, self.VARIANTS_GFF)
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(self.TEST_VALUES["n_gff_err_2"], results[ERR])
Exemple #8
0
    def test_extract_alignment_summ_data(self):
        """
        Test the dicts returned from parsing the alignment_summary gff
        """
        #        top_contigs = get_top_contigs(ref, 2)

        top_contigs = get_top_contigs_from_ref_entry(
            self._get_reference_entry(), 2)

        ref_data, contig_variants = _extract_alignment_summ_data(
            self.ALIGNMENT_SUMMARY, top_contigs)
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(0, results[ERR])

        self.assertEqual(1, len(contig_variants))
Exemple #9
0
    def test_create_variants_plot_grp(self):
        """
        Test that plotGroup of variants plots is created as expected
        """
        top_contigs = get_top_contigs_from_ref_entry(
            self._get_reference_entry(), 25)
        ref_data, contig_variants = _extract_alignment_summ_data(
            self.ALIGNMENT_SUMMARY, top_contigs)

        plot_group = _create_variants_plot_grp(top_contigs, contig_variants,
                                               self._output_dir)
        self.assertEqual(1, len(plot_group.plots))

        self._assert_image_file(plot_group.thumbnail)

        for plot in plot_group.plots:
            self._assert_image_file(plot.image)
        self._assert_image_file(plot_group.legend)
Exemple #10
0
    def test_get_consensus_attributes(self):
        """
        Test the data in the table object and the attributes
        """
        top_contigs = get_top_contigs_from_ref_entry(
            self._get_reference_entry(), 2)

        ref_data = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY,
                                                top_contigs)[0]
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(0, results[ERR])

        _append_variants_gff_data(ref_data, self.VARIANTS_GFF)

        table, attributes = _get_consensus_table_and_attributes(
            ref_data, self._get_reference_entry())
        self.assertEqual(5, len(attributes))

        def __get_att_val(_id, atts):
            for a in atts:
                if a.id == _id:
                    return a.value

        self.assertEqual(self.TEST_VALUES["contig_len"],
                         __get_att_val('mean_contig_length', attributes))
        self.assertAlmostEqual(self.TEST_VALUES["bases_called"],
                               __get_att_val('weighted_mean_bases_called',
                                             attributes),
                               places=4)
        self.assertAlmostEqual(self.TEST_VALUES["concordance"],
                               __get_att_val('weighted_mean_concordance',
                                             attributes),
                               places=4)
        self.assertAlmostEqual(self.TEST_VALUES["coverage"],
                               __get_att_val('weighted_mean_coverage',
                                             attributes),
                               places=2)
        self.assertEqual(self.CONTIG_ID,
                         __get_att_val('longest_contig_name', attributes))
Exemple #11
0
    def test_legend(self):
        """
        Create the legend png
        """
        top_contigs = get_top_contigs_from_ref_entry(
            self._get_reference_entry(), 25)
        contig_variants = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY,
                                                       top_contigs)[1]
        ctgvar = None
        for t in top_contigs:
            ctgvar = contig_variants[t.header]

        bars = _create_bars(ctgvar)
        self.assertEqual(3, len(bars))

        leg = _get_legend_file(bars, self._output_dir)
        leg_path = op.join(self._output_dir, leg)

        log.info('legend path: {l}'.format(l=leg_path))
        self.assertTrue(op.exists(leg_path))
Exemple #12
0
    def test_append_variants_gff_data(self):
        """
        Test that ERR information gets added to the ref_data dict
        """
        #        top_contigs = get_top_contigs(ref, 2)

        top_contigs = get_top_contigs_from_ref_entry(
            self._get_reference_entry(), 2)

        ref_data = _extract_alignment_summ_data(self.ALIGNMENT_SUMMARY,
                                                top_contigs)[0]
        self.assertEqual(1, len(ref_data))

        results = ref_data[self.CONTIG_ID]
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(self.TEST_VALUES["n_gff_err_1"], results[ERR])

        _append_variants_gff_data(ref_data, self.VARIANTS_GFF)
        self.assertEqual(self.TEST_VALUES["contig_len"], results[LENGTH])
        self.assertEqual(self.TEST_VALUES["n_gff_err_2"], results[ERR])