def test_make_modifications_report(self):
        """
        Create a report object, do assertions on its properties, then assert that it gets written
        """
        h5 = os.path.join(self._data_dir, "basemods.h5")

        make_modifications_report(h5, "rpt.json", self._output_dir, 60)

        # deserialize report

        log.info("Deserializing report {r}".format(r=os.path.join(self._output_dir, "rpt.json")))
        s = None
        with open(os.path.join(self._output_dir, "rpt.json"), "r") as f:
            s = json.load(f)

        report = dict_to_report(s)

        validate_report_complete(self, report)

        self.assertEqual(1, len(report.plotGroups))
        self.assertEqual(2, len(report.plotGroups[0].plots))

        scatter = report.plotGroups[0].plots[0]
        histo = report.plotGroups[0].plots[1]

        self._assert_image_file(report.plotGroups[0].thumbnail)
        self._assert_image_file(scatter.image)
        self._assert_image_file(histo.image)
    def test_make_modifications_report(self):
        """
        Create a report object, do assertions on its properties, then assert that it gets written
        """
        csv = os.path.join(self._data_dir, 'modifications.csv.gz')

        make_modifications_report(csv, 'rpt.json', self._output_dir, 60, False)

        # deserialize report

        log.info("Deserializing report {r}".format(
            r=os.path.join(self._output_dir, 'rpt.json')))
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)

        self.assertEqual(1, len(report.plotGroups))
        self.assertEqual(2, len(report.plotGroups[0].plots))

        scatter = report.plotGroups[0].plots[0]
        histo = report.plotGroups[0].plots[1]

        self._assert_image_file(report.plotGroups[0].thumbnail)
        self._assert_image_file(scatter.image)
        self._assert_image_file(histo.image)
    def test_make_control_report(self):
        """
        Test that the report gets written proppa
        """
        cmph5 = os.path.join(self.DATA_DIR, 'control_reads.cmp.h5')
        csv = os.path.join(self.DATA_DIR, 'filtered_summary.csv')
        make_control_report(cmph5, csv, 'foo.json',
                            self._output_dir, 60, False)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'foo.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        validate_report_complete(self, report)
        self.assertEqual(7, len(report.attributes))

        for i in range(2):
            pg = report.plotGroups[i]
            self.assertFalse(os.path.isabs(pg.thumbnail))
            self.assertTrue(os.path.exists(
                os.path.join(self._output_dir, pg.thumbnail)))
            p = pg.plots[0]
            self.assertFalse(os.path.isabs(p.image))
            self.assertTrue(os.path.exists(
                os.path.join(self._output_dir, p.image)))
    def test_basic(self):
        output_dir = tempfile.mkdtemp(suffix="filter_subread_")
        t = tempfile.NamedTemporaryFile(delete=False, suffix=".json")
        t.close()
        report_json = t.name
        exe = "filter_subread"
        cmd = "{e} --debug -o {o} -r {r} {csv}".format(
            e=exe,
            csv=self.filtered_subread_summary_csv,
            r=report_json,
            o=output_dir)

        rcode = run_backticks(cmd)
        self.assertEqual(0, rcode)

        with open(report_json, 'r') as f:
            d = json.loads(f.read())

        report = dict_to_report(d)
        log.info("deserialized report:")
        log.info(pformat(report.to_dict()))

        self.assertIsNotNone(isinstance(report, Report))

        # Cleanup
        self.assertTrue(os.path.exists(report_json))
        os.remove(report_json)
    def test_basic(self):
        output_dir = tempfile.mkdtemp(suffix="filter_subread_")
        t = tempfile.NamedTemporaryFile(delete=False, suffix=".json")
        t.close()
        report_json = t.name
        exe = "filter_subread"
        cmd = "{e} --debug -o {o} -r {r} {csv}".format(
            e=exe, csv=self.filtered_subread_summary_csv, r=report_json, o=output_dir
        )

        rcode = run_backticks(cmd)
        self.assertEqual(0, rcode)

        with open(report_json, "r") as f:
            d = json.loads(f.read())

        report = dict_to_report(d)
        log.info("deserialized report:")
        log.info(pformat(report.to_dict()))

        self.assertIsNotNone(isinstance(report, Report))

        # Cleanup
        self.assertTrue(os.path.exists(report_json))
        os.remove(report_json)
Example #6
0
    def test_make_control_report(self):
        """
        Test that the report gets written proppa
        """
        cmph5 = os.path.join(self.DATA_DIR, 'control_reads.cmp.h5')
        csv = os.path.join(self.DATA_DIR, 'filtered_summary.csv')
        make_control_report(cmph5, csv, 'foo.json', self._output_dir, 60,
                            False)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'foo.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        self.assertEqual(7, len(report.attributes))

        for i in range(2):
            pg = report.plotGroups[i]
            self.assertFalse(os.path.isabs(pg.thumbnail))
            self.assertTrue(
                os.path.exists(os.path.join(self._output_dir, pg.thumbnail)))
            p = pg.plots[0]
            self.assertFalse(os.path.isabs(p.image))
            self.assertTrue(
                os.path.exists(os.path.join(self._output_dir, p.image)))
    def test_make_modifications_report(self):
        """
        Create a report object, do assertions on its properties, then assert that it gets written
        """
        h5 = os.path.join(self._data_dir, "basemods.h5")

        make_modifications_report(h5, 'rpt.json', self._output_dir, 60)

        # deserialize report

        log.info("Deserializing report {r}".format(
            r=os.path.join(self._output_dir, 'rpt.json')))
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)

        self.assertEqual(1, len(report.plotGroups))
        self.assertEqual(2, len(report.plotGroups[0].plots))

        scatter = report.plotGroups[0].plots[0]
        histo = report.plotGroups[0].plots[1]

        self._assert_image_file(report.plotGroups[0].thumbnail)
        self._assert_image_file(scatter.image)
        self._assert_image_file(histo.image)
    def test_write_json(self):
        self.report.write_json(self.report_json)

        with open(self.report_json, 'r') as f:
            d = json.loads(f.read())

        report = dict_to_report(d)
        self.assertTrue(isinstance(report, Report))
Example #9
0
    def _deserialize_report(self, rptfile):
        """
        Read json report from file, return pbcommand.models.report.Report
        """
        s = None
        with open(os.path.join(rptfile), 'r') as f:
            s = json.load(f)

        return dict_to_report(s)
    def _deserialize_report(self, rptfile):
        """
        Read json report from file, return pbcommand.models.report.Report
        """
        s = None
        with open(os.path.join(rptfile), 'r') as f:
            s = json.load(f)

        return dict_to_report(s)
 def test_basic(self):
     cmd = _to_cmd(self.ALIGNMENTS, self.report_json)
     rcode = run_backticks(cmd)
     self.assertEqual(rcode, 0)
     with open(self.report_json, 'r') as f:
         s = json.load(f)
         log.info("JsonReport: ")
         log.info(pprint.pformat(s, indent=4))
     report = dict_to_report(s)
     self.assertIsNotNone(report)
     self.assertEqual(len(report.tables), 1)
     log.info(str(report.tables[0]))
     validate_report_metadata(self, report, meta_rpt)
 def test_basic(self):
     cmd = _to_cmd(self.ALIGNMENTS, self.report_json)
     rcode = run_backticks(cmd)
     self.assertEqual(rcode, 0)
     with open(self.report_json, 'r') as f:
         s = json.load(f)
         log.info("JsonReport: ")
         log.info(pprint.pformat(s, indent=4))
     report = dict_to_report(s)
     self.assertIsNotNone(report)
     self.assertEqual(len(report.tables), 1)
     log.info(str(report.tables[0]))
     validate_report_metadata(self, report, meta_rpt)
 def test_make_polished_assembly_report(self):
     """
     Test the attributes of the report
     """
     make_polished_assembly_report('rpt.json', self.GFF, self.FASTQ, self._output_dir)
     # deserialize report
     s = None
     with open(op.join(self._output_dir, 'rpt.json'), 'r') as f:
         s = json.load(f)
     self.report = dict_to_report(s)
     self._test_attribute("polished_contigs")
     self._test_attribute("max_contig_length")
     self._test_attribute("n_50_contig_length")
     self._test_attribute("sum_contig_lengths")
Example #14
0
    def test_make_minor_topvariants_report(self):
        """
        Call the main report generation method with minor kwarg==True. Deserialize report, check content.
        """
        ref = self.REFERENCE
        gff = self.RARE_VARIANTS_GFF
        make_topvariants_report(
            gff, ref, 100, 10000, 'rpt.json', self._output_dir, is_minor_variants_rpt=True)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
    def test_make_minor_topvariants_report(self):
        """
        Call the main report generation method with minor kwarg==True. Deserialize report, check content.
        """
        ref = self.REFERENCE
        gff = self.RARE_VARIANTS_GFF
        make_topvariants_report(gff, ref, 100, 10000, 'rpt.json', self._output_dir, is_minor_variants_rpt=True)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        self.assertEqual('Frequency', report.tables[0].columns[6].header)
 def test_make_polished_assembly_report(self):
     """
     Test the attributes of the report
     """
     make_polished_assembly_report(
         'rpt.json', self.GFF, self.FASTQ, self._output_dir)
     # deserialize report
     s = None
     with open(op.join(self._output_dir, 'rpt.json'), 'r') as f:
         s = json.load(f)
     self.report = dict_to_report(s)
     self._test_attribute("polished_contigs")
     self._test_attribute("max_contig_length")
     self._test_attribute("n_50_contig_length")
     self._test_attribute("sum_contig_lengths")
    def test_make_topvariants_report(self):
        """
        Call the main report generation method. Deserialize report, check content.
        """
        ref = self.REFERENCE
        gff = self.VARIANTS_GFF
        make_topvariants_report(gff, ref, 100, 10000,
                                'rpt.json', self._output_dir)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
Example #18
0
 def getReport(cls, report_id):
     if cls.service_access_layer is None:
         report_json = cls.datastore.get_report(report_id)
         assert report_json is not None, "Can't find %s" % report_id
         return load_report_from_json(report_json)
     else:
         # load report from services, not raw file
         for rpt_info in cls.service_access_layer.get_analysis_job_reports(
             cls.job_id):
             file_info = rpt_info['dataStoreFile']
             source_id = file_info.file_id.split("-")[0]
             if source_id == report_id:
                 report_d = cls.service_access_layer.get_analysis_job_report_details(cls.job_id, file_info.uuid)
                 return dict_to_report(report_d)
         raise RuntimeError("Can't find {i} report".format(i=report_id))
    def test_write_json(self):

        log.info(pformat(self.report.to_dict()))
        with open(self.report_json, 'w') as f:
            f.write(self.report.to_json())

        with open(self.report_json, 'r') as f:
            d = json.loads(f.read())

        report = dict_to_report(d)
        log.info("deserialized report:")
        log.info(pformat(report.to_dict()))
        self.assertIsNotNone(isinstance(report, Report))

        # Cleanup
        os.remove(self.report_json)
    def test_write_json(self):

        log.info(pformat(self.report.to_dict()))
        with open(self.report_json, "w") as f:
            f.write(self.report.to_json())

        with open(self.report_json, "r") as f:
            d = json.loads(f.read())

        report = dict_to_report(d)
        log.info("deserialized report:")
        log.info(pformat(report.to_dict()))
        self.assertIsNotNone(isinstance(report, Report))

        # Cleanup
        os.remove(self.report_json)
Example #21
0
 def getReport(cls, report_id):
     if cls.service_access_layer is None:
         report_json = cls.datastore.get_report(report_id)
         assert report_json is not None, "Can't find %s" % report_id
         return load_report_from_json(report_json)
     else:
         # load report from services, not raw file
         for rpt_info in cls.service_access_layer.get_analysis_job_reports(
                 cls.job_id):
             file_info = rpt_info['dataStoreFile']
             source_id = file_info.file_id.split("-")[0]
             if source_id == report_id:
                 report_d = cls.service_access_layer.get_analysis_job_report_details(
                     cls.job_id, file_info.uuid)
                 return dict_to_report(report_d)
         raise RuntimeError("Can't find {i} report".format(i=report_id))
    def test_make_topvariants_report(self):
        """
        Call the main report generation method. Deserialize report, check content.
        """
        ref = self.REFERENCE
        gff = self.VARIANTS_GFF
        make_topvariants_report(gff, ref, 100, 10000, 'rpt.json',
                                self._output_dir)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        validate_report_complete(self, report)
    def test_make_minor_topvariants_report(self):
        """
        Call the main report generation method with minor kwarg==True. Deserialize report, check content.
        """
        ref = self.REFERENCE
        gff = self.RARE_VARIANTS_GFF
        make_topvariants_report(
            gff, ref, 100, 10000, 'rpt.json', self._output_dir, is_minor_variants_rpt=True)

        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        validate_report_complete(self, report)
 def test_exit_code_0(self):
     """
     Like a cram test. Assert exits with 0.
     """
     r = op.join(self._output_dir, 'rpt.json')
     cmd = 'python -m pbreports.report.polished_assembly {g} {f} {r}'.format(g=self.GFF, f=self.FASTQ, r=r)
     log.info(cmd)
     o, c, m = backticks(cmd)
     if c is not 0:
         log.error(m)
         log.error(o)
         sys.stderr.write(str(m))
         print(m)
     s = None
     with open(op.join(self._output_dir, 'rpt.json'), 'r') as f:
         s = json.load(f)
     report = dict_to_report(s)
     self.assertEqual(4, len(report.attributes))
 def test_exit_code_0(self):
     """
     Like a cram test. Assert exits with 0.
     """
     r = op.join(self._output_dir, 'rpt.json')
     cmd = 'python -m pbreports.report.polished_assembly {g} {f} {r}'.format(
         g=self.GFF, f=self.FASTQ, r=r)
     log.info(cmd)
     o, c, m = backticks(cmd)
     if c is not 0:
         log.error(m)
         log.error(o)
         sys.stderr.write(str(m))
         print(m)
     s = None
     with open(op.join(self._output_dir, 'rpt.json'), 'r') as f:
         s = json.load(f)
     report = dict_to_report(s)
     self.assertEqual(4, len(report.attributes))
Example #26
0
    def test_exit_code_0_minor(self):
        """
        Like a cram test. Create the minor report in a subprocess. Assert that the report is correct.
        """
        ref = self.REFERENCE
        gff = self.RARE_VARIANTS_GFF
        cmd = 'pbreport minor-topvariants {o} rpt.json {g} {r}'.format(o=self._output_dir,
                                                                       g=gff, r=ref)
        log.info(cmd)
        o, c, m = backticks(cmd)
        if c is not 0:
            log.error(m)
            log.error(o)
            print(m)
        self.assertEquals(0, c)
        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        self.assertEqual('Frequency', report.tables[0].columns[6].header)
    def test_exit_code_0_minor(self):
        """
        Like a cram test. Create the minor report in a subprocess. Assert that the report is correct.
        """
        ref = self.REFERENCE
        gff = self.RARE_VARIANTS_GFF
        cmd = 'pbreport minor-topvariants {o} rpt.json {g} {r}'.format(o=self._output_dir,
                                                                       g=gff, r=ref)
        log.info(cmd)
        o, c, m = backticks(cmd)
        if c is not 0:
            log.error(m)
            log.error(o)
            print(m)
        self.assertEquals(0, c)
        # deserialize report
        s = None
        with open(os.path.join(self._output_dir, 'rpt.json'), 'r') as f:
            s = json.load(f)

        report = dict_to_report(s)
        self.assertEqual('Frequency', report.tables[0].columns[6].header)