def test_top_contigs(self): """ Test top contigs from ref """ ref = op.join(LOCAL_DATA, "coverage", 'simple3', "sequence", "simple3.fasta") self.assertEqual(2, len(get_top_contigs(ref, 2)))
def test_top_contigs(self): """ Test top contigs from ref """ ref = op.join(LOCAL_DATA, "coverage", 'simple3', "sequence", "simple3.fasta") self.assertEqual(2, len(get_top_contigs(ref, 2)))
def test_get_coverage_stats(self): """ Test the coverage stats object (needs more) """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) self.assertEqual(485, len(stats.means))
def test_create_histogram(self): """ Simple (non null) test of histogram """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) stats = _get_reference_coverage_stats(pls.values()) fig, ax = _create_histogram(stats) self.assertIsNotNone(fig) self.assertIsNotNone(ax)
def test_create_histogram(self): """ Simple (non null) test of histogram """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) stats = _get_reference_coverage_stats(pls.values()) fig, ax = CoverageReport()._create_histogram(stats) self.assertIsNotNone(fig) self.assertIsNotNone(ax)
def test_get_coverage_stats(self): """ Test the coverage stats object (needs more) """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) self.assertEqual(485, len(stats.means))
def test_create_contig_plot(self): """ Simple non-null test of single contig fig,ax """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] fig, ax = _create_contig_plot(c_cov) self.assertIsNotNone(fig) self.assertIsNotNone(ax)
def test_get_coverage_stats(self): """ Test the coverage stats object (needs more) """ ref = os.path.join(self._data_dir, 'references', 'lambda') tcs = get_top_contigs(ref, 25) als = os.path.join(self._data_dir, 'alignment_summary.lambda.gff') pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) self.assertEqual(485, len(stats.means))
def test_create_contig_plot(self): """ Simple non-null test of single contig fig,ax """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] fig, ax = CoverageReport()._create_contig_plot(c_cov) self.assertIsNotNone(fig) self.assertIsNotNone(ax)
def test_contigs_to_plot(self): """ Test top contigs from ref """ tcs = get_top_contigs(self.REFERENCE, 25) self.assertEqual(1, len(tcs)) # op.join(self._data_dir, 'alignment_summary.lambda.gff') als = self.GFF pls = _get_contigs_to_plot(als, tcs) self.assertEqual(len(pls), len(tcs)) contig = tcs[0] c_cov = pls[contig.header] self.assertEqual(self.CONTIG_ID, c_cov._name) self.assertEqual(self.PLOT_FILE_NAME, op.basename(c_cov.file_name))
def test_contigs_to_plot(self): """ Test top contigs from ref """ ref = os.path.join(self._data_dir, 'references', 'lambda') tcs = get_top_contigs(ref, 25) self.assertEqual(1, len(tcs)) als = os.path.join(self._data_dir, 'alignment_summary.lambda.gff') pls = _get_contigs_to_plot(als, tcs) self.assertEqual(len(pls), len(tcs)) contig = tcs[0] c_cov = pls[contig.header] self.assertEqual('lambda_NEB3011', c_cov._name)
def test_create_contig_plot(self): """ Simple non-null test of single contig fig,ax """ ref = os.path.join(self._data_dir, 'references', 'lambda') tcs = get_top_contigs(ref, 25) als = os.path.join(self._data_dir, 'alignment_summary.lambda.gff') pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] fig, ax = _create_contig_plot(c_cov) self.assertIsNotNone(fig) self.assertIsNotNone(ax)
def test_attributes_high_coverage(self): tcs = get_top_contigs(self.REFERENCE, 25) als = op.join(self._data_dir, "alignment_summary.lambda.gff") pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) att = _get_att_mean_coverage(stats) # This was in coverage.xml for the alignment summary gff used # attribute hidden="true" id="depth_coverage_mean" name="Coverage" # value="2958.16">2958.16</attribute> self.assertEqual(2958, int(att.value)) att = _get_att_percent_missing(stats) self.assertEqual(0, att.value)
def test_contigs_to_plot(self): """ Test top contigs from ref """ tcs = get_top_contigs(self.REFERENCE, 25) self.assertEqual(1, len(tcs)) # op.join(self._data_dir, 'alignment_summary.lambda.gff') als = self.GFF pls = _get_contigs_to_plot(als, tcs) self.assertEqual(len(pls), len(tcs)) contig = tcs[0] c_cov = pls[contig.header] self.assertEqual(self.CONTIG_ID, c_cov._name) self.assertEqual(self.PLOT_FILE_NAME, op.basename(c_cov.file_name))
def test_create_coverage_histo_plot_grp(self): """ Test that plotGroup of the histogram is created as expected """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) stats = _get_reference_coverage_stats(pls.values()) plot_group = _create_coverage_histo_plot_grp(stats, self._output_dir) # only 1 histo 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)
def test_attributes_high_coverage(self): tcs = get_top_contigs(self.REFERENCE, 25) als = op.join(self._data_dir, "alignment_summary.lambda.gff") pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) att = _get_att_mean_coverage(stats) # This was in coverage.xml for the alignment summary gff used # attribute hidden="true" id="depth_coverage_mean" name="Coverage" # value="2958.16">2958.16</attribute> self.assertAlmostEqual(2958.16, att.value, places=2) att = _get_att_percent_missing(stats) self.assertEqual(0, att.value)
def test_create_histogram(self): """ Simple (non null) test of histogram """ ref = os.path.join(self._data_dir, 'references', 'lambda') tcs = get_top_contigs(ref, 25) als = os.path.join(self._data_dir, 'alignment_summary.lambda.gff') pls = _get_contigs_to_plot(als, tcs) stats = _get_reference_coverage_stats(pls.values()) fig, ax = _create_histogram(stats) self.assertIsNotNone(fig) self.assertIsNotNone(ax)
def test_create_coverage_plot_grp(self): """ Test that plotGroup of coverage plots is created as expected """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) plot_group = _create_coverage_plot_grp(tcs, pls, self._output_dir) # only 1 contig in lambda 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)
def test_create_coverage_plot_grp(self): """ Test that plotGroup of coverage plots is created as expected """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) plot_group = CoverageReport()._create_coverage_plot_grp( tcs, pls, self._output_dir) # only 1 contig in lambda 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)
def test_create_coverage_histo_plot_grp(self): """ Test that plotGroup of the histogram is created as expected """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) stats = _get_reference_coverage_stats(pls.values()) plot_group = CoverageReport()._create_coverage_histo_plot_grp( stats, self._output_dir) # only 1 histo 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)
def test_attributes(self): """ Test that attribute values match expected """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) att = _get_att_mean_coverage(stats) # This was in coverage.xml for the alignment summary gff used # attribute hidden="true" id="depth_coverage_mean" name="Coverage" # value="2958.16">2958.16</attribute> self.assertEqual(1, int(att.value)) att = _get_att_percent_missing(stats) self.assertAlmostEqual(0.584, att.value, places=3)
def test_create_coverage_plot_grp(self): """ Test that plotGroup of coverage plots is created as expected """ ref = os.path.join(self._data_dir, 'references', 'lambda') tcs = get_top_contigs(ref, 25) als = os.path.join(self._data_dir, 'alignment_summary.lambda.gff') pls = _get_contigs_to_plot(als, tcs) plot_group = _create_coverage_plot_grp(tcs, pls, self._output_dir) # only 1 contig in lambda 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)
def test_attributes(self): """ Test that attribute values match expected """ tcs = get_top_contigs(self.REFERENCE, 25) als = self.GFF pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) att = _get_att_mean_coverage(stats) # This was in coverage.xml for the alignment summary gff used # attribute hidden="true" id="depth_coverage_mean" name="Coverage" # value="2958.16">2958.16</attribute> self.assertAlmostEqual(1.228, att.value, places=3) att = _get_att_percent_missing(stats) self.assertAlmostEqual(58.4, att.value, places=1)
def make_report(self, gff, reference, max_contigs_to_plot, report, output_dir): """ Entry to report. :param gff: (str) path to alignment_summary.gff :param reference: (str) path to reference_dir :param max_contigs_to_plot: (int) max number of contigs to plot """ _validate_inputs(gff, reference) top_contigs = get_top_contigs(reference, max_contigs_to_plot) cov_map = _get_contigs_to_plot(gff, top_contigs) # stats may be None stats = _get_reference_coverage_stats(cov_map.values()) a1 = _get_att_mean_coverage(stats) a2 = _get_att_percent_missing(stats) plot_grp_coverage = self._create_coverage_plot_grp( top_contigs, cov_map, output_dir) plot_grp_histogram = None if stats is not None: plot_grp_histogram = self._create_coverage_histo_plot_grp( stats, output_dir) plotgroups = [] # Don't add the Plot Group if no plots are added if plot_grp_coverage.plots: plotgroups.append(plot_grp_coverage) if plot_grp_histogram is not None: # Don't add the Plot Group if no plots are added if plot_grp_histogram.plots: plotgroups.append(plot_grp_histogram) rpt = Report(self.spec.id, plotgroups=plotgroups, attributes=[a1, a2], dataset_uuids=(ReferenceSet(reference).uuid,)) rpt = self.spec.apply_view(rpt) rpt.write_json(os.path.join(output_dir, report)) return rpt
def test_attributes(self): """ Test that attribute values match expected """ ref = os.path.join(self._data_dir, 'references', 'lambda') tcs = get_top_contigs(ref, 25) als = os.path.join(self._data_dir, 'alignment_summary.lambda.gff') pls = _get_contigs_to_plot(als, tcs) contig = tcs[0] c_cov = pls[contig.header] stats = _get_reference_coverage_stats(pls.values()) att = _get_att_mean_coverage(stats) # This was in coverage.xml for the alignment summary gff used # attribute hidden="true" id="depth_coverage_mean" name="Coverage" value="2958.16">2958.16</attribute> self.assertEqual(2958.1640346377467, att.value) att = _get_att_percent_missing(stats) self.assertEqual(0, att.value)
def make_coverage_report(gff, reference, max_contigs_to_plot, report, output_dir): """ Entry to report. :param gff: (str) path to alignment_summary.gff :param reference: (str) path to reference_dir :param max_contigs_to_plot: (int) max number of contigs to plot """ _validate_inputs(gff, reference) top_contigs = get_top_contigs(reference, max_contigs_to_plot) cov_map = _get_contigs_to_plot(gff, top_contigs) # stats may be None stats = _get_reference_coverage_stats(cov_map.values()) a1 = _get_att_mean_coverage(stats) a2 = _get_att_percent_missing(stats) plot_grp_coverage = _create_coverage_plot_grp( top_contigs, cov_map, output_dir) plot_grp_histogram = None if stats is not None: plot_grp_histogram = _create_coverage_histo_plot_grp(stats, output_dir) plotgroups = [] # Don't add the Plot Group if no plots are added if plot_grp_coverage.plots: plotgroups.append(plot_grp_coverage) if plot_grp_histogram is not None: # Don't add the Plot Group if no plots are added if plot_grp_histogram.plots: plotgroups.append(plot_grp_histogram) rpt = Report('coverage', title="Coverage", plotgroups=plotgroups, attributes=[a1, a2], dataset_uuids=(ReferenceSet(reference).uuid,)) rpt.write_json(os.path.join(output_dir, report)) return rpt
def test_get_top_contigs(self): top_contigs = get_top_contigs(self.REFERENCE, 25) self.assertTrue(len(top_contigs), 25)
def test__get_contigs_to_plot(self): top_contigs = get_top_contigs(self.REFERENCE, 25) cov_map = _get_contigs_to_plot(self.GFF, top_contigs) self.assertNotEqual(len(cov_map), 0)
def test_top_contigs(self): """ Test top contigs from ref """ ref = os.path.join(self._data_dir, 'references', 'simple3') self.assertEqual(2, len(get_top_contigs(ref, 2)))
def test_get_top_contigs(self): top_contigs = get_top_contigs(self.REFERENCE, 25) self.assertTrue(len(top_contigs), 25)
def test__get_contigs_to_plot(self): top_contigs = get_top_contigs(self.REFERENCE, 25) cov_map = _get_contigs_to_plot(self.GFF, top_contigs) self.assertNotEqual(len(cov_map), 0)