コード例 #1
0
ファイル: reports.py プロジェクト: reneebeardslee/hawc
 def printField(runs, heading, text):
     """
     Create a field-level run. The heading is bolded, the text is not-bolded.
     They will appear with no newline character between the two.
     """
     runs.append(TableMaker.new_run(heading, b=True, newline=False))
     runs.append(TableMaker.new_run(text))
コード例 #2
0
    def build_bias(self, bias, d):

        row = 0
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=0,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")
        rowspan = 1

        if len(bias) == 1:
            if bias[0] == "confounding":
                rowspan = len(d["confounders"])
                for i, cf in enumerate(d["confounders"]):
                    fields = d["biasFields"][bias[0]]
                    txt = dedent(f"""\
                        {cf[fields[0]]}: {cf[fields[1]]} {cf[fields[2]]}
                        {cf[fields[3]]}""")
                    tbl.new_td_txt(i, 1, txt, colspan=2)
            else:
                fields = d["biasFields"][bias[0]]
                txt = dedent(f"""\
                    {d[fields[0]]} {d[fields[1]]}
                    {d[fields[2]]}""")
                tbl.new_td_txt(row, 1, txt, colspan=2)
        else:
            for i, b in enumerate(bias):
                fields = d["biasFields"][b]
                txt = dedent(f"""\
                    {d[fields[0]]} {d[fields[1]]}
                    {d[fields[2]]}""")
                tbl.new_td_txt(row, i + 1, txt)

        tbl.new_td_txt(row, 0, d["reference"]["name"], rowspan=rowspan)

        return tbl
コード例 #3
0
ファイル: reports.py プロジェクト: reneebeardslee/hawc
    def getStudyDetailsRuns(self, ag, doses):

        runs = []

        txt = "({})".format(ag['experiment']['study']['short_citation'])
        runs.append(TableMaker.new_run(txt, b=True))

        self.printField(
            runs, "Species: ", ag["species"])
        self.printField(
            runs, "Strain (source): ", self.getStrainSource(ag))
        self.printField(
            runs, "Sex: ", ag["sex"])
        self.printField(
            runs, "Doses: ", self.getDoseText(doses))
        self.printField(
            runs, "Purity (source): ", self.getPurityText(ag["experiment"]))
        self.printField(
            runs, "Dosing period: ", strip_tags(ag["dosing_regime"]["description"]))
        self.printField(
            runs, "Route: ", ag["dosing_regime"]["route_of_exposure"])
        self.printField(
            runs, "Diet: ", ag["experiment"]["diet"])
        self.printField(
            runs, "Negative controls: ", ag["dosing_regime"]["negative_control"])
        self.printField(
            runs, "Funding source: ", ag["experiment"]["study"]["funding_source"])
        self.printField(
            runs, "Author conflict of interest: ", self.getCOItext(ag["experiment"]["study"]))
        self.printField(
            runs, "Comments: ", strip_tags(ag["experiment"]["description"]))

        return runs
コード例 #4
0
    def build_bias(self, bias, d):

        row = 0
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )
        rowspan = 1

        if len(bias) == 1:
            if bias[0] == "confounding":
                rowspan = len(d["confounders"])
                for i, cf in enumerate(d["confounders"]):
                    fields = d["biasFields"][bias[0]]
                    txt = dedent(
                        f"""\
                        {cf[fields[0]]}: {cf[fields[1]]} {cf[fields[2]]}
                        {cf[fields[3]]}"""
                    )
                    tbl.new_td_txt(i, 1, txt, colspan=2)
            else:
                fields = d["biasFields"][bias[0]]
                txt = dedent(
                    f"""\
                    {d[fields[0]]} {d[fields[1]]}
                    {d[fields[2]]}"""
                )
                tbl.new_td_txt(row, 1, txt, colspan=2)
        else:
            for i, b in enumerate(bias):
                fields = d["biasFields"][b]
                txt = dedent(
                    f"""\
                    {d[fields[0]]} {d[fields[1]]}
                    {d[fields[2]]}"""
                )
                tbl.new_td_txt(row, i + 1, txt)

        tbl.new_td_txt(row, 0, d["reference"]["name"], rowspan=rowspan)

        return tbl
コード例 #5
0
    def build_bias_table(self, biasNames, descriptions):
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=0,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")

        # write header
        tbl.new_th(0, 0, "Reference")
        for i, bias in enumerate(biasNames):
            tbl.new_th(0, i + 1, f"{self.convertCamelCase(bias)} rating")

        docx_tbl = tbl.render(self.doc)

        for desc in descriptions:
            inner_tbl = self.build_bias(biasNames, desc)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #6
0
    def build_ROB_legend(self):
        widths = [1.5, 1.0, 0.4, 1.0, 0.4, 1.0, 0.4, 0.4, 1.0, 0.4]
        tbl = TableMaker(widths, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl")
        cells = [
           {"runs": [TableMaker.new_run("Risk of bias key:", b=True, newline=False)]},
           {"text": "Definitely Low"},
           {"text": "++", "shade": models.StudyQuality.SCORE_SHADES[4]},
           {"text": "Probably Low"},
           {"text": "+", "shade": models.StudyQuality.SCORE_SHADES[3]},
           {"text": "Probably High"},
           {"text": "-", "shade": models.StudyQuality.SCORE_SHADES[2]},
           {"text": "NR", "shade": models.StudyQuality.SCORE_SHADES[0]},
           {"text": "Definitely High"},
           {"text": "--", "shade": models.StudyQuality.SCORE_SHADES[1]},
        ]
        for i, cell in enumerate(cells):
            if "runs" in cell:
                tbl.new_td_run(0, i, cell["runs"], shade=cell.get("shade"))
            else:
                tbl.new_td_txt(0, i, cell["text"], shade=cell.get("shade"))

        return tbl.render(self.doc)
コード例 #7
0
    def build_bias_table(self, biasNames, descriptions):
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # write header
        tbl.new_th(0, 0, "Reference")
        for i, bias in enumerate(biasNames):
            tbl.new_th(0, i + 1, f"{self.convertCamelCase(bias)} rating")

        docx_tbl = tbl.render(self.doc)

        for desc in descriptions:
            inner_tbl = self.build_bias(biasNames, desc)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #8
0
ファイル: reports.py プロジェクト: JoshAddington/hawc
    def build_ROB_legend(self):
        widths = [1.5, 1.0, 0.4, 1.0, 0.4, 1.0, 0.4, 0.4, 1.0, 0.4]
        tbl = TableMaker(widths, numHeaders=0, firstRowCaption=False, tblStyle='ntpTbl')
        cells = [
           {'runs': [TableMaker.new_run('Risk of bias key:', b=True, newline=False)]},
           {'text': 'Definitely Low'},
           {'text': '++', 'shade': RiskOfBiasScore.SCORE_SHADES[4]},
           {'text': 'Probably Low'},
           {'text': '+', 'shade': RiskOfBiasScore.SCORE_SHADES[3]},
           {'text': 'Probably High'},
           {'text': '-', 'shade': RiskOfBiasScore.SCORE_SHADES[2]},
           {'text': 'NR', 'shade': RiskOfBiasScore.SCORE_SHADES[0]},
           {'text': 'Definitely High'},
           {'text': '--', 'shade': RiskOfBiasScore.SCORE_SHADES[1]},
        ]
        for i, cell in enumerate(cells):
            if 'runs' in cell:
                tbl.new_td_run(0, i, cell['runs'], shade=cell.get('shade'))
            else:
                tbl.new_td_txt(0, i, cell['text'], shade=cell.get('shade'))

        return tbl.render(self.doc)
コード例 #9
0
ファイル: ntp_html.py プロジェクト: shapiromatron/tblBuilder
    def _build_study(self, study):

        row = 0
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        sites = self.group_results_by_site(study["results"])
        study_rowspan = self.get_study_rowspan(sites)

        # Column A
        runs = [
            tbl.new_run(study["reference"]["name"], b=True),
            tbl.new_run("Animal:", b=True),
            tbl.new_run(f'{study["species"]} {study["strain"]}'),
            tbl.new_run(study["sex"]),
            tbl.new_run("Animal age at the beginning of exposure:", b=True),
            tbl.new_run(study["ageAtStart"]),
            tbl.new_run("Study duration:", b=True),
            tbl.new_run(study["duration"], newline=False),
        ]
        tbl.new_td_run(row, 0, runs, rowspan=study_rowspan)

        # Column B
        runs = [
            tbl.new_run("Agent and purity:", b=True),
            tbl.new_run(study["agent"]),
            tbl.new_run(study["purity"]),
            tbl.new_run("Exposure route:", b=True),
            tbl.new_run(study["dosingRoute"]),
            tbl.new_run("Exposure concentrations, frequency, and duration:", b=True),
            tbl.new_run(study["dosingRegimen"], newline=False),
        ]
        tbl.new_td_run(row, 1, runs, rowspan=study_rowspan)

        site_row = row
        for results in list(sites.values()):

            # Column C & D
            for result in results:

                # save significance footnotes
                notes = result.get("significanceNotes", "") or ""
                if notes and hash(notes) not in self.footnotes:
                    self.footnotes[hash(notes)] = notes

                # write histology (and footnote adjustment)
                txt = result["tumourSite"]
                histology = result.get("histology")
                if histology:
                    txt = f"{txt} – {histology}"

                if result["adjustedIncidence"]:
                    txt += "ᵃ"
                    fn = "ᵃ Adjusted percent incidence based on Poly-3 estimated neoplasm incidence after adjustment for intercurrent mortality."  # noqa
                    self.footnotes[hash(fn)] = fn

                runs = [tbl.new_run(txt, b=True, newline=False)]
                tbl.new_td_run(site_row, 2, runs, colspan=2)
                site_row += 1

                # write groups
                for group in result["endpointGroups"]:
                    dose = group["dose"]
                    tbl.new_td_txt(site_row, 2, dose)

                    txt = group.get("incidence", "")
                    val = group.get("incidenceSymbol", None)
                    if val:
                        txt += val
                    val = group.get("incidencePercent", "None")
                    if val:
                        txt += f" ({val}%)"
                    tbl.new_td_txt(site_row, 3, txt)

                    site_row += 1

                # write trend test
                txt = result.get("trendTest")
                if txt:
                    # italicize 'P' in 'P-value'
                    runs = [
                        tbl.new_run("Trend ", newline=False),
                        tbl.new_run("P", i=True, newline=False),
                        tbl.new_run(f"-value: {txt}"),
                    ]
                    tbl.new_td_run(site_row, 2, runs, colspan=2)
                    site_row += 1

        # Column E
        first_result = study["results"][0] if len(study["results"]) > 0 else {}

        # blank runs are extra newlines as requested by report writers
        runs = [
            tbl.new_run("Survival: ", b=True, newline=False),
            tbl.new_run(first_result["survivalNotes"] or ""),
            tbl.new_run(""),
            tbl.new_run("Body weight: ", b=True, newline=False),
            tbl.new_run(first_result["bodyWeightNotes"] or ""),
            tbl.new_run(""),
            tbl.new_run(
                "Significantly increased preneoplastic lesions: ", b=True, newline=False
            ),
            tbl.new_run(first_result["nonNeoplasticFindings"] or ""),
            tbl.new_run(""),
            tbl.new_run("Other comments: ", b=True, newline=False),
            tbl.new_run(first_result["comments"] or ""),
            tbl.new_run(""),
            tbl.new_run(
                f'Overall utility: [{study["overallUtility"]}] ', b=True, newline=False
            ),
            tbl.new_run(study["overallUtilityRationale"] or ""),
        ]
        tbl.new_td_run(row, 4, runs, rowspan=study_rowspan)

        return tbl
コード例 #10
0
    def _build_table(self, data):
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # write header
        tbl.new_th(0, 0, "Exposure assessment method")
        tbl.new_th(0, 1, "Description")
        tbl.new_th(0, 2, "Strengths")
        tbl.new_th(0, 3, "Limitations")
        tbl.new_th(0, 4, "Reference")
        tbl.new_th(0, 5, "Notes")

        # write data rows
        for i, d in enumerate(data["descriptions"]):
            r = i + 1

            txt = null_getter(d, "exposureAssessmentType")
            tbl.new_td_txt(r, 0, txt)

            txt = "\n".join(
                [
                    null_getter(d, "exposureAssessmentPopulationDetails"),
                    null_getter(d, "exposureAssessmentNotes"),
                ]
            )
            tbl.new_td_txt(r, 1, txt)

            txt = null_getter(d, "exposureAssessmentStrengths")
            tbl.new_td_txt(r, 2, txt)

            txt = null_getter(d, "exposureAssessmentLimitations")
            tbl.new_td_txt(r, 3, txt)

            txt = d["reference"]["name"]
            tbl.new_td_txt(r, 4, txt)

            txt = null_getter(d, "exposureAssessmentComments")
            tbl.new_td_txt(r, 5, txt)

        return tbl
コード例 #11
0
    def _build_description(self, desc, site):
        results = desc["organSiteResults"][site]
        row = 0
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=0,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")

        rowspan = self.get_desc_rowspan(results)
        # Column A
        runs = [
            tbl.new_run(desc["reference"]["name"]),
            tbl.new_run(desc["studyDesign"]),
            tbl.new_run(to_string(desc, "location")),
            tbl.new_run("Enrollment or follow-up:", b=True),
            tbl.new_run(to_string(desc, "enrollmentDates")),
        ]
        tbl.new_td_run(row, 0, runs, rowspan=rowspan)

        # Column B
        if desc["isCaseControl"]:
            txt = (f'Cases: {desc.get("populationSizeCases", "")};'
                   f' Controls: {desc.get("populationSizeControls", "")}')
            descriptors = desc.get("otherPopulationDescriptors")
            if descriptors is not None:
                txt = dedent(f"""\
                    {descriptors}
                    {txt}""")
            popD = tbl.new_run(txt)
        else:
            popD = tbl.new_run(
                dedent(f"""\
                {desc.get("otherPopulationDescriptors", "")}
                {desc.get("cohortPopulationSize", "")}"""))

        runs = [
            tbl.new_run("Population:", b=True),
            popD,
            tbl.new_run("Exposure assessment method: ", b=True, newline=False),
            tbl.new_run(desc["exposureAssessmentType"], newline=False),
        ]

        tbl.new_td_run(row, 1, runs, rowspan=rowspan)

        result_row = row
        for res in results:
            # Columns C,D
            result_rowspan = self.get_result_rowspan(res)
            risk_row = result_row
            if res.get("organSite") or res.get("effectMeasure"):
                txt = str(res["organSite"]) if res.get("organSite") else ""
                if res.get("effectMeasure"):
                    txt += ": " if len(txt) > 0 else ""
                    txt += res["effectMeasure"]

                if res.get("effectUnits") is not None:
                    txt += f' {res["effectUnits"]}'

                run = [tbl.new_run(txt, b=True, newline=False)]
                tbl.new_td_run(risk_row, 2, run, colspan=2)
                risk_row += 1

            for est in res["riskEstimates"]:
                tbl.new_td_txt(risk_row, 2, est["exposureCategory"])
                tbl.new_td_txt(risk_row, 3, est["riskFormatted"])
                risk_row += 1

            if res.get("trendTest"):
                run = [
                    tbl.new_run("Trend-test ", newline=False),
                    tbl.new_run("p", i=True, newline=False),
                    tbl.new_run("-value: ", newline=False),
                    tbl.new_run(res["trendTest"], newline=False),
                ]
                tbl.new_td_run(risk_row, 2, run, colspan=2)
                risk_row += 1

            # Column E
            tbl.new_td_txt(result_row,
                           4,
                           res["wrd_covariatesList"],
                           rowspan=result_rowspan)

            # update result_row
            result_row = result_row + result_rowspan

        # Column F
        runs = []
        wrd_notes = desc.get("wrd_notes")
        if wrd_notes is not None and wrd_notes != "":
            runs.append(tbl.new_run(wrd_notes))

        additional_results = "\n".join([
            res["additionalResults"] for res in results
            if ("additionalResults" in res and res["additionalResults"]
                is not None and res["additionalResults"] is not "")
        ])
        if additional_results is "":
            additional_results = "-"

        runs.extend([
            tbl.new_run("Exposure information:", b=True),
            tbl.new_run(to_string(desc, "exposureLevel")),
            tbl.new_run("Strengths:", b=True),
            tbl.new_run(to_string(desc, "strengths")),
            tbl.new_run("Limitations:", b=True),
            tbl.new_run(to_string(desc, "limitations")),
            tbl.new_run("Additional results:", b=True),
            tbl.new_run(additional_results),
            tbl.new_run("Confidence in evidence:", b=True),
            tbl.new_run(to_string(desc, "confidenceInEvidence"),
                        newline=False),
        ])
        tbl.new_td_run(row, 5, runs, rowspan=rowspan)

        return tbl
コード例 #12
0
    def _build_study(self, study):

        row = 0
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=0,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")

        sites = self.group_results_by_site(study["results"])
        study_rowspan = self.get_study_rowspan(sites)

        # Column A
        runs = [
            tbl.new_run(study["reference"]["name"], b=True),
            tbl.new_run("Animal:", b=True),
            tbl.new_run(f'{study["species"]} {study["strain"]}'),
            tbl.new_run(study["sex"]),
            tbl.new_run("Animal age at the beginning of exposure:", b=True),
            tbl.new_run(study["ageAtStart"]),
            tbl.new_run("Study duration:", b=True),
            tbl.new_run(study["duration"], newline=False),
        ]
        tbl.new_td_run(row, 0, runs, rowspan=study_rowspan)

        # Column B
        runs = [
            tbl.new_run("Agent and purity:", b=True),
            tbl.new_run(study["agent"]),
            tbl.new_run(study["purity"]),
            tbl.new_run("Exposure route:", b=True),
            tbl.new_run(study["dosingRoute"]),
            tbl.new_run("Exposure concentrations, frequency, and duration:",
                        b=True),
            tbl.new_run(study["dosingRegimen"], newline=False),
        ]
        tbl.new_td_run(row, 1, runs, rowspan=study_rowspan)

        site_row = row
        for results in list(sites.values()):

            # Column C & D
            for result in results:

                # save significance footnotes
                notes = result.get("significanceNotes", "") or ""
                if notes and hash(notes) not in self.footnotes:
                    self.footnotes[hash(notes)] = notes

                # write histology (and footnote adjustment)
                txt = result["tumourSite"]
                histology = result.get("histology")
                if histology:
                    txt = f"{txt} – {histology}"

                if result["adjustedIncidence"]:
                    txt += "ᵃ"
                    fn = "ᵃ Adjusted percent incidence based on Poly-3 estimated neoplasm incidence after adjustment for intercurrent mortality."  # noqa
                    self.footnotes[hash(fn)] = fn

                runs = [tbl.new_run(txt, b=True, newline=False)]
                tbl.new_td_run(site_row, 2, runs, colspan=2)
                site_row += 1

                # write groups
                for group in result["endpointGroups"]:
                    dose = group["dose"]
                    tbl.new_td_txt(site_row, 2, dose)

                    txt = group.get("incidence", "")
                    val = group.get("incidenceSymbol", None)
                    if val:
                        txt += val
                    val = group.get("incidencePercent", "None")
                    if val:
                        txt += f" ({val}%)"
                    tbl.new_td_txt(site_row, 3, txt)

                    site_row += 1

                # write trend test
                txt = result.get("trendTest")
                if txt:
                    # italicize 'P' in 'P-value'
                    runs = [
                        tbl.new_run("Trend ", newline=False),
                        tbl.new_run("P", i=True, newline=False),
                        tbl.new_run(f"-value: {txt}"),
                    ]
                    tbl.new_td_run(site_row, 2, runs, colspan=2)
                    site_row += 1

        # Column E
        first_result = study["results"][0] if len(study["results"]) > 0 else {}

        # blank runs are extra newlines as requested by report writers
        runs = [
            tbl.new_run("Survival: ", b=True, newline=False),
            tbl.new_run(first_result["survivalNotes"] or ""),
            tbl.new_run(""),
            tbl.new_run("Body weight: ", b=True, newline=False),
            tbl.new_run(first_result["bodyWeightNotes"] or ""),
            tbl.new_run(""),
            tbl.new_run("Significantly increased preneoplastic lesions: ",
                        b=True,
                        newline=False),
            tbl.new_run(first_result["nonNeoplasticFindings"] or ""),
            tbl.new_run(""),
            tbl.new_run("Other comments: ", b=True, newline=False),
            tbl.new_run(first_result["comments"] or ""),
            tbl.new_run(""),
            tbl.new_run(f'Overall utility: [{study["overallUtility"]}] ',
                        b=True,
                        newline=False),
            tbl.new_run(study["overallUtilityRationale"] or ""),
        ]
        tbl.new_td_run(row, 4, runs, rowspan=study_rowspan)

        return tbl
コード例 #13
0
    def buildHumanInVitro(self):
        colWidths = [1.0, 1.2, 1.4, 0.9, 0.9, 1.0, 1.6, 1.0]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = (
            f"Table 2 [Genotoxicity and related effects] of [{self.getAgent()}] in "
            "human cells in vitro"
        )
        tbl.new_th(0, 0, txt, colspan=8)

        # write header
        tbl.new_th(1, 0, "End-point")
        tbl.new_th(1, 1, "Test")
        tbl.new_th(1, 2, "Tissue, cell line")
        tbl.new_th(1, 3, "Results/\nResults without metabolic activation")
        tbl.new_th(1, 4, "Results with metabolic activation")
        tbl.new_th(1, 5, "Concentration (LEC or HIC)")
        tbl.new_th(1, 6, "Comments")
        tbl.new_th(1, 7, "Reference")

        row = 2
        for d in self.context["humanInVitro"]:

            tbl.new_td_txt(row, 0, d["endpoint"])
            tbl.new_td_txt(row, 1, d["endpointTest"])

            tbl.new_td_txt(row, 2, d["tissueCellLine"])

            tbl.new_td_txt(row, 3, d["wrd_resultA"])
            tbl.new_td_txt(row, 4, d["wrd_resultB"])

            txt = f'{d["wrd_led"]} {d["units"]}'
            tbl.new_td_txt(row, 5, txt)

            tbl.new_td_txt(row, 6, d["wrd_comments"])
            tbl.new_td_txt(row, 7, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(MAMMAL_VITRO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #14
0
    def buildEnviroMixedTables(self, exposures, title):
        colWidths = [2, 1.5, 1.5, 2, 2]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        tbl.new_th(0, 0, title, colspan=5)

        # write header
        tbl.new_th(1, 0, "Region, country (city)")
        tbl.new_th(1, 1, "Mean, agent")
        tbl.new_th(1, 2, "Range")
        tbl.new_th(1, 3, "Comments/\nadditional data")
        tbl.new_th(1, 4, "References")

        row = 2
        for exp in exposures:
            for res in exp["results"]:
                runs = [
                    tbl.new_run(exp["country"], newline=True, b=True),
                    tbl.new_run(
                        f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}',
                        newline=False,
                    ),
                ]
                tbl.new_td_run(row, 0, runs)

                txt = (
                    f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),'
                    f' {res["agent"]}')
                tbl.new_td_txt(row, 1, txt)

                txt = res["exposureRangePrint"]
                tbl.new_td_txt(row, 2, txt)

                txt = exp["comments"] or ""
                tbl.new_td_txt(row, 3, txt)

                txt = exp["reference"]["name"]
                tbl.new_td_txt(row, 4, txt)

                row += 1

        tbl.render(self.doc)
        self.doc.add_page_break()
コード例 #15
0
    def buildOccupationalTable(self, exposures):
        colWidths = [1.7, 1, 1.7, 1.3, 2.0, 1.3]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = "Occupational exposure data"
        tbl.new_th(0, 0, txt, colspan=6)

        # write header
        tbl.new_th(1, 0, "Industry, country, year")
        tbl.new_th(1, 1, "Job/process")
        tbl.new_th(1, 2, "Mean, agent")
        tbl.new_th(1, 3, "Range")
        tbl.new_th(1, 4, "Comments/\nadditional data")
        tbl.new_th(1, 5, "References")

        row = 2
        for exp in exposures:
            for res in exp["results"]:
                runs = [
                    tbl.new_run(exp["occupation"], newline=True, b=True),
                    tbl.new_run(
                        f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}',
                        newline=False,
                    ),
                ]
                tbl.new_td_run(row, 0, runs)

                txt = exp["occupationInfo"] or ""
                tbl.new_td_txt(row, 1, txt)

                txt = (
                    f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),'
                    f' {res["agent"]}'
                )
                tbl.new_td_txt(row, 2, txt)

                txt = res["exposureRangePrint"]
                tbl.new_td_txt(row, 3, txt)

                txt = exp["comments"] or ""
                tbl.new_td_txt(row, 4, txt)

                txt = exp["reference"]["name"]
                tbl.new_td_txt(row, 5, txt)

                row += 1

        tbl.render(self.doc)
        self.doc.add_page_break()
コード例 #16
0
    def buildNonMammInVitroTbl(self):
        colWidths = [0.8, 1.2, 0.9, 0.9, 0.7, 0.7, 1, 1.8, 1]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = (
            f"Table 5 [Genotoxicity and related effects] of [{self.getAgent()}] in non-mammalian"
            " species"
        )
        tbl.new_th(0, 0, txt, colspan=9)

        # write header
        tbl.new_th(1, 0, "Phylogenetic class")
        tbl.new_th(1, 1, "Test system\n(species, strain)")
        tbl.new_th(1, 2, "End-point")
        tbl.new_th(1, 3, "Test")
        tbl.new_th(1, 4, "Results/\nResults without metabolic activation")
        tbl.new_th(1, 5, "Results with metabolic activation")
        tbl.new_th(1, 6, "Agent, concentration (LEC or HIC)")
        tbl.new_th(1, 7, "Comments")
        tbl.new_th(1, 8, "Reference")

        row = 2
        for d in self.context["nonMammalianInVitro"]:
            tbl.new_td_txt(row, 0, d["phylogeneticClass"])
            tbl.new_td_txt(row, 1, d["wrd_testSystem"])
            tbl.new_td_txt(row, 2, d["endpoint"])
            tbl.new_td_txt(row, 3, d["endpointTest"])
            tbl.new_td_txt(row, 4, d["wrd_resultA"])
            tbl.new_td_txt(row, 5, d["wrd_resultB"])
            tbl.new_td_txt(row, 6, d["wrd_experimental"])
            tbl.new_td_txt(row, 7, d["wrd_comments"])
            tbl.new_td_txt(row, 8, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(NONMAMMAL_VITRO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #17
0
ファイル: html.py プロジェクト: shapiromatron/tblBuilder
    def _build_description(self, d):
        rows = 0
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        for res in d["results"]:
            res["_rowspan"] = max(len(res["riskEstimates"]), 1)
            effectUnits = res.get("effectUnits", None)
            if effectUnits and len(effectUnits) > 0:
                res["_rowspan"] += 1
            if res["hasTrendTest"]:
                res["_rowspan"] += 1

        st_rowspan = sum(res["_rowspan"] for res in d["results"])

        # Column A
        runs = [
            tbl.new_run(d["reference"]["name"]),
            tbl.new_run(d["location"]),
            tbl.new_run(d["enrollmentDates"]),
            tbl.new_run(d["studyDesign"]),
        ]
        tbl.new_td_run(rows, 0, runs, rowspan=st_rowspan)

        # Column B
        runs = self.getCol2(d, tbl)
        tbl.new_td_run(rows, 1, runs, rowspan=st_rowspan)

        # Columns C, D, E, F, G
        irows = rows
        for res in d["results"]:
            additionalRows = 0
            tbl.new_td_txt(irows, 2, res["printOrganSite"], rowspan=res["_rowspan"])
            tbl.new_td_txt(irows, 6, res["wrd_covariatesList"], rowspan=res["_rowspan"])

            effectUnits = res.get("effectUnits", None)
            if effectUnits and len(effectUnits) > 0:
                tbl.new_td_txt(irows, 3, effectUnits, colspan=3)
                additionalRows += 1

            stratum = res.get("stratum", None)
            for i, est in enumerate(res["riskEstimates"]):

                runs = []
                if i == 0 and stratum and len(stratum) > 0:
                    runs.append(tbl.new_run(f"{stratum}: ", b=True, newline=False))
                runs.append(tbl.new_run(est["exposureCategory"], newline=False))
                tbl.new_td_run(irows + additionalRows, 3, runs)

                tbl.new_td_txt(irows + additionalRows, 4, est["numberExposed"])
                tbl.new_td_txt(irows + additionalRows, 5, est["riskFormatted"])
                additionalRows += 1

            if res["hasTrendTest"]:
                txt = f'Trend-test p-value: {res["trendTest"]}'
                tbl.new_td_txt(irows + additionalRows, 3, txt, colspan=3)
                additionalRows += 1

            irows += additionalRows

        # Column H
        runs = [
            tbl.new_run(d["wrd_notes"]),
            tbl.new_run("Strengths: ", b=True, newline=False),
            tbl.new_run(d.get("strengths", "")),
            tbl.new_run("Limitations: ", b=True, newline=False),
            tbl.new_run(d.get("limitations", "")),
        ]
        tbl.new_td_run(rows, 7, runs, rowspan=st_rowspan)

        return tbl
コード例 #18
0
    def buildEnviroMixedTables(self, exposures, title):
        colWidths = [2, 1.5, 1.5, 2, 2]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        tbl.new_th(0, 0, title, colspan=5)

        # write header
        tbl.new_th(1, 0, "Region, country (city)")
        tbl.new_th(1, 1, "Mean, agent")
        tbl.new_th(1, 2, "Range")
        tbl.new_th(1, 3, "Comments/\nadditional data")
        tbl.new_th(1, 4, "References")

        row = 2
        for exp in exposures:
            for res in exp["results"]:
                runs = [
                    tbl.new_run(exp["country"], newline=True, b=True),
                    tbl.new_run(
                        f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}',
                        newline=False,
                    ),
                ]
                tbl.new_td_run(row, 0, runs)

                txt = (
                    f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),'
                    f' {res["agent"]}'
                )
                tbl.new_td_txt(row, 1, txt)

                txt = res["exposureRangePrint"]
                tbl.new_td_txt(row, 2, txt)

                txt = exp["comments"] or ""
                tbl.new_td_txt(row, 3, txt)

                txt = exp["reference"]["name"]
                tbl.new_td_txt(row, 4, txt)

                row += 1

        tbl.render(self.doc)
        self.doc.add_page_break()
コード例 #19
0
ファイル: html.py プロジェクト: shapiromatron/tblBuilder
    def build_tbl(self, data):
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=1, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # write header
        tbl.new_th(
            0, 0, "Reference, location follow-up/enrollment period, study-design"
        )  # noqa
        tbl.new_th(
            0, 1, "Population size, description, exposure assessment method"
        )  # noqa
        tbl.new_th(0, 2, "Organ site")
        tbl.new_th(0, 3, "Exposure category or level")
        tbl.new_th(0, 4, "Exposed cases/ deaths")
        tbl.new_th(0, 5, "Risk estimate (95% CI)")
        tbl.new_th(0, 6, "Covariates controlled")
        tbl.new_th(0, 7, "Comments")

        docx_tbl = tbl.render(self.doc)

        for d in data["descriptions"]:
            inner_tbl = self._build_description(d)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #20
0
ファイル: ntp_bias.py プロジェクト: shapiromatron/tblBuilder
    def build_tbl(self, study):
        colWidths = (2, 4.5)
        tbl = TableMaker(
            colWidths, numHeaders=1, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # Table caption
        txt = (
            f'Table X: {study["reference"]["name"]} ({study["sex"]} '
            f'{study["species"]}): {study["agent"]}: {study["dosingRoute"]}'
        )
        self.doc.add_heading(txt, level=2)

        # write header
        tbl.new_th(0, 0, "Study utility domain and question")
        tbl.new_th(0, 1, "Rating and rationale")

        # study design section
        self.add_rr_header(tbl, 1, "Study design")

        self.add_rr_row(
            tbl,
            2,
            "Randomization",
            study["randomizationRating"],
            study["randomizationRationale"],
        )

        self.add_rr_row(
            tbl,
            3,
            "Controls",
            study["concurrentControlsRating"],
            study["concurrentControlsRationale"],
        )

        tbl.new_td_txt(4, 0, "Historical data")
        response = "Yes" if study["historicalDataAvailable"] is True else "No"
        tbl.new_td_txt(4, 1, response)

        self.add_rr_row(
            tbl,
            5,
            "Animal model (sensitivity)",
            study["animalModelSensitivityRating"],
            study["animalModelSensitivityRationale"],
        )

        self.add_rr_row(
            tbl,
            6,
            "Statistical power (sensitivity)",
            study["statisticalPowerRating"],
            study["statisticalPowerRationale"],
        )

        # exposure section
        self.add_rr_header(tbl, 7, "Exposure")

        self.add_rr_row(
            tbl,
            8,
            "Chemical characterization",
            study["chemicalCharacterizationRating"],
            study["chemicalCharacterizationRationale"],
        )

        self.add_rr_row(
            tbl,
            9,
            "Dosing regimen",
            study["dosingRegimenRating"],
            study["dosingRegimenRationale"],
        )

        self.add_rr_row(
            tbl,
            10,
            "Exposure duration (sensitivity)",
            study["exposureDurationRating"],
            study["exposureDurationRationale"],
        )

        self.add_rr_row(
            tbl,
            11,
            "Dose-response (sensitivity)",
            study["doseResponseRating"],
            study["doseResponseRationale"],
        )

        # outcome section
        self.add_rr_header(tbl, 12, "Outcome")

        self.add_rr_row(
            tbl,
            13,
            "Pathology",
            study["outcomeMethodsRating"],
            study["outcomeMethodsRationale"],
        )

        self.add_rr_row(
            tbl,
            14,
            "Consistency between groups",
            study["groupConsistencyRating"],
            study["groupConsistencyRationale"],
        )

        self.add_rr_row(
            tbl,
            15,
            "Study duration (sensitivity)",
            study["durationRating"],
            study["durationRationale"],
        )

        # confounding section
        self.add_rr_header(tbl, 16, "Confounding")

        self.add_rr_row(
            tbl,
            17,
            "Confounding",
            study["confoundingRating"],
            study["confoundingRationale"],
        )

        # reporting & analysis section
        self.add_rr_header(tbl, 18, "Reporting and analysis")

        self.add_rr_row(
            tbl,
            19,
            "Reporting data and statistics",
            study["statisticalReportingRating"],
            study["statisticalReportingRationale"],
        )

        self.add_rr_row(
            tbl,
            20,
            "Combining lesions",
            study["tumorCombiningRating"],
            study["tumorCombiningRationale"],
        )

        # render table
        tbl.render(self.doc)

        # overall utility
        txt = f' {study["overallUtility"]}. {study["overallUtilityRationale"]}'
        p = self.doc.add_paragraph("")
        p.add_run("Overall utility: ").bold = True
        p.add_run(txt)

        self.doc.add_page_break()
コード例 #21
0
ファイル: html.py プロジェクト: shapiromatron/tblBuilder
    def build_tbl(self, data):
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=1, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # write header
        tbl.new_th(
            0,
            0,
            "Study design\nSpecies, strain (sex)\nAge at start\nDuration\nReference",
        )
        tbl.new_th(
            0,
            1,
            "Route\nAgent tested, purity\nVehicle\nDose(s)\n"
            "# animals at start\n# surviving animals",
        )
        tbl.new_th(0, 2, "Results")
        tbl.new_th(0, 3, "Significance")
        tbl.new_th(0, 4, "Comments")

        docx_tbl = tbl.render(self.doc)
        for d in data["studies"]:
            inner_tbl = self._build_study(d)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #22
0
ファイル: html.py プロジェクト: shapiromatron/tblBuilder
    def _build_study(self, d):

        rows = 0
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )
        rowspan = 0
        for ep in d["results"]:
            rowspan += 1
            if (
                len(ep["wrd_incidents"]) > 0
                or len(ep["wrd_incidence_significance"]) > 0
            ):
                rowspan += 1
            if (
                len(ep["wrd_multiplicities"]) > 0
                or len(ep["wrd_multiplicity_significance"]) > 0
            ):
                rowspan += 1
            if (
                len(ep["wrd_total_tumours"]) > 0
                or len(ep["wrd_total_tumours_significance"]) > 0
            ):
                rowspan += 1

        # Column A
        runs = [
            tbl.new_run(d["studyDesign"], b=True),
            tbl.new_run(d["species"], b=True, newline=False),
            tbl.new_run(f', {d["strain"]} {d["sex"]}'),
            tbl.new_run(d["ageAtStart"]),
            tbl.new_run(d["duration"]),
            tbl.new_run(d["reference"]["name"], newline=False),
        ]
        tbl.new_td_run(rows, 0, runs, rowspan=rowspan)

        # Column B
        txt = dedent(
            f"""\
            {d["dosingRoute"]}
            {d["agent"]}, {d["purity"]}
            {d["vehicle"]}
            {d["wrd_doses"]}
            {d["dosingRegimen"]}
            {d["wrd_nStarts"]}
            {d["wrd_nSurvivings"]}"""
        )
        tbl.new_td_txt(rows, 1, txt, rowspan=rowspan)

        # Columns C, D
        irows = rows
        for ep in d["results"]:

            txt = f'{ep["tumourSite"]}: {ep["histology"]}'
            runs = [tbl.new_run(txt, b=True, newline=False)]
            tbl.new_td_run(irows, 2, runs, colspan=2)
            irows += 1

            if (
                len(ep["wrd_incidents"]) > 0
                or len(ep["wrd_incidence_significance"]) > 0
            ):
                tbl.new_td_txt(irows, 2, ep["wrd_incidents"])
                tbl.new_td_txt(irows, 3, ep["wrd_incidence_significance"])
                irows += 1

            if (
                len(ep["wrd_multiplicities"]) > 0
                or len(ep["wrd_multiplicity_significance"]) > 0
            ):
                tbl.new_td_txt(irows, 2, ep["wrd_multiplicities"])
                tbl.new_td_txt(irows, 3, ep["wrd_multiplicity_significance"])
                irows += 1

            if (
                len(ep["wrd_total_tumours"]) > 0
                or len(ep["wrd_total_tumours_significance"]) > 0
            ):
                tbl.new_td_txt(irows, 2, ep["wrd_total_tumours"])
                tbl.new_td_txt(irows, 3, ep["wrd_total_tumours_significance"])
                irows += 1

        # Column E
        runs = [
            tbl.new_run("Principal strengths:", b=True),
            tbl.new_run(d["wrd_strengths"]),
            tbl.new_run("Principal limitations:", b=True),
            tbl.new_run(d["wrd_limitations"]),
            tbl.new_run("Other comments:", b=True),
            tbl.new_run(d["wrd_comments"], newline=False),
        ]
        tbl.new_td_run(rows, 4, runs, rowspan=rowspan)

        return tbl
コード例 #23
0
    def _build_table(self, data):
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # write header
        tbl.new_th(0, 0, "")
        tbl.new_th(0, 1, "Bias", colspan=6)
        tbl.new_th(0, 7, "Quality")
        tbl.new_th(0, 8, "Utility")

        tbl.new_th(1, 0, "Citation")
        tbl.new_th(1, 1, "Selection", vertical=True, height=0.5)
        tbl.new_th(1, 2, "Exposure", vertical=True)
        tbl.new_th(1, 3, "Outcome", vertical=True)
        tbl.new_th(1, 4, "Confounding methods", vertical=True)
        tbl.new_th(1, 5, "Adequacy of analysis", vertical=True)
        tbl.new_th(1, 6, "Selective reporting", vertical=True)
        tbl.new_th(1, 7, "Sensitivity", vertical=True)
        tbl.new_th(1, 8, "Integration", vertical=True)

        # write data rows
        for i, d in enumerate(data["descriptions"]):
            r = i + 2
            tbl.new_td_txt(r, 0, d["reference"]["name"])
            tbl.new_td_txt(r, 1, d["selectionBiasRating"])
            tbl.new_td_txt(r, 2, d["exposureAssessmentRating"])
            tbl.new_td_txt(r, 3, d["outcomeAssessmentRating"])
            confounders = [
                f'{conf["organSiteCategory"]}: {conf["confoundingRating"]}'
                for conf in d["confounders"]
            ]
            tbl.new_td_txt(r, 4, "\n".join(confounders))
            tbl.new_td_txt(r, 5, d["analysisRating"])
            tbl.new_td_txt(r, 6, d["selectiveReportingRating"])
            tbl.new_td_txt(r, 7, d["sensitivityRating"])
            tbl.new_td_txt(r, 8, d["overallUtility"])

        return tbl
コード例 #24
0
    def buildTable(self):
        colWidths = [1.35, 1.8, 1.35, 0.9, 0.9, 0.9, 1.8]
        tbl = TableMaker(colWidths,
                         numHeaders=1,
                         tblStyle="ntpTbl",
                         firstRowCaption=False)

        # write header
        tbl.new_th(0, 0, "Reference")
        tbl.new_th(0, 1, "Test system")
        tbl.new_th(0, 2, "Endpoint/\ntest")
        tbl.new_th(0, 3, "Results")
        tbl.new_th(0, 4, "Results (with metabolic activation)")
        tbl.new_th(0, 5, "Agent, LED/HID dose")
        tbl.new_th(0, 6, "Comments")

        row = 0
        for d in self.context["objects"]:
            row += 1

            txt = dedent(f"""\
                {d['reference']['name']}
                {d['dataClass']}""")
            tbl.new_td_txt(row, 0, txt)

            txt = d["col2"]
            tbl.new_td_txt(row, 1, txt)

            txt = d["col3"]
            tbl.new_td_txt(row, 2, txt)

            txt = d["col4"]
            tbl.new_td_txt(row, 3, txt)

            txt = d["col5"]
            tbl.new_td_txt(row, 4, txt)

            txt = d["col6"]
            tbl.new_td_txt(row, 5, txt)

            txt = d["wrd_comments"]
            tbl.new_td_txt(row, 6, txt)

        tbl.render(self.doc)
コード例 #25
0
    def buildAniVivoTbl(self):
        colWidths = [1.0, 1.0, 1.0, 1.0, 0.5, 0.7, 1.2, 1.6, 1]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = (
            f"Table 3 [Genotoxicity and related effects] of [{self.getAgent()}] in non-human "
            "mammals in vivo")
        tbl.new_th(0, 0, txt, colspan=9)

        # write header
        tbl.new_th(1, 0, "End-point")
        tbl.new_th(1, 1, "Test")
        tbl.new_th(1, 2, "Species, strain, sex")
        tbl.new_th(1, 3, "Tissue")
        tbl.new_th(1, 4, "Results")
        tbl.new_th(1, 5, "Agent, dose (LED or HID)")
        tbl.new_th(1, 6, "Route, duration, dosing regimen")
        tbl.new_th(1, 7, "Comments")
        tbl.new_th(1, 8, "Reference")

        row = 2
        for d in self.context["animalInVivo"]:

            tbl.new_td_txt(row, 0, d["endpoint"])

            tbl.new_td_txt(row, 1, d["endpointTest"])

            txt = f'{d["species"]} {d["strain"]} { d["sex"]}'
            tbl.new_td_txt(row, 2, txt)

            tbl.new_td_txt(row, 3, d["tissueAnimal"])

            tbl.new_td_txt(row, 4, d["result"])

            txt = dedent(f"""\
                {d["agent"]}
                LED/HID: {d["wrd_led"]} {d["units"]}""")
            tbl.new_td_txt(row, 5, txt)

            txt = dedent(f"""\
                {d["dosingRoute"]};
                {d["dosingDuration"]}""")
            tbl.new_td_txt(row, 6, txt)

            tbl.new_td_txt(row, 7, d["wrd_comments"])
            tbl.new_td_txt(row, 8, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(ANIMAL_VIVO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #26
0
    def buildHumanVivoTbl(self):
        colWidths = [0.9, 1.2, 1.2, 1.3, 1.4, 0.8, 1.4, 0.8]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = f"Table 1 [Genotoxicity and related effects] of [{self.getAgent()}] in humans in vivo"
        tbl.new_th(0, 0, txt, colspan=8)

        # write header
        tbl.new_th(1, 0, "End-point")
        tbl.new_th(1, 1, "Test")
        tbl.new_th(1, 2, "Tissue")
        tbl.new_th(1, 3, "Cell type\n(if specified)")
        tbl.new_th(1, 4, "Description of exposed and controls")
        tbl.new_th(1, 5, "Response/ significance*")
        tbl.new_th(1, 6, "Comments")
        tbl.new_th(1, 7, "Reference")

        row = 2
        for d in self.context["humanInVivo"]:
            tbl.new_td_txt(row, 0, d["endpoint"])
            tbl.new_td_txt(row, 1, d["endpointTest"])

            tbl.new_td_txt(row, 2, d["tissueHuman"])
            tbl.new_td_txt(row, 3, d["cellType"])
            tbl.new_td_txt(row, 4, d["exposureDescription"])

            txt = f'{d["result"]} {d["wrd_significance"]}'
            tbl.new_td_txt(row, 5, txt)

            tbl.new_td_txt(row, 6, d["wrd_comments"])
            tbl.new_td_txt(row, 7, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(HUMAN_VIVO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #27
0
    def buildNonMammInVitroTbl(self):
        colWidths = [0.8, 1.2, 0.9, 0.9, 0.7, 0.7, 1, 1.8, 1]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = (
            f"Table 5 [Genotoxicity and related effects] of [{self.getAgent()}] in non-mammalian"
            " species")
        tbl.new_th(0, 0, txt, colspan=9)

        # write header
        tbl.new_th(1, 0, "Phylogenetic class")
        tbl.new_th(1, 1, "Test system\n(species, strain)")
        tbl.new_th(1, 2, "End-point")
        tbl.new_th(1, 3, "Test")
        tbl.new_th(1, 4, "Results/\nResults without metabolic activation")
        tbl.new_th(1, 5, "Results with metabolic activation")
        tbl.new_th(1, 6, "Agent, concentration (LEC or HIC)")
        tbl.new_th(1, 7, "Comments")
        tbl.new_th(1, 8, "Reference")

        row = 2
        for d in self.context["nonMammalianInVitro"]:
            tbl.new_td_txt(row, 0, d["phylogeneticClass"])
            tbl.new_td_txt(row, 1, d["wrd_testSystem"])
            tbl.new_td_txt(row, 2, d["endpoint"])
            tbl.new_td_txt(row, 3, d["endpointTest"])
            tbl.new_td_txt(row, 4, d["wrd_resultA"])
            tbl.new_td_txt(row, 5, d["wrd_resultB"])
            tbl.new_td_txt(row, 6, d["wrd_experimental"])
            tbl.new_td_txt(row, 7, d["wrd_comments"])
            tbl.new_td_txt(row, 8, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(NONMAMMAL_VITRO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #28
0
    def buildOccupationalTable(self, exposures):
        colWidths = [1.7, 1, 1.7, 1.3, 2.0, 1.3]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = "Occupational exposure data"
        tbl.new_th(0, 0, txt, colspan=6)

        # write header
        tbl.new_th(1, 0, "Industry, country, year")
        tbl.new_th(1, 1, "Job/process")
        tbl.new_th(1, 2, "Mean, agent")
        tbl.new_th(1, 3, "Range")
        tbl.new_th(1, 4, "Comments/\nadditional data")
        tbl.new_th(1, 5, "References")

        row = 2
        for exp in exposures:
            for res in exp["results"]:
                runs = [
                    tbl.new_run(exp["occupation"], newline=True, b=True),
                    tbl.new_run(
                        f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}',
                        newline=False,
                    ),
                ]
                tbl.new_td_run(row, 0, runs)

                txt = exp["occupationInfo"] or ""
                tbl.new_td_txt(row, 1, txt)

                txt = (
                    f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),'
                    f' {res["agent"]}')
                tbl.new_td_txt(row, 2, txt)

                txt = res["exposureRangePrint"]
                tbl.new_td_txt(row, 3, txt)

                txt = exp["comments"] or ""
                tbl.new_td_txt(row, 4, txt)

                txt = exp["reference"]["name"]
                tbl.new_td_txt(row, 5, txt)

                row += 1

        tbl.render(self.doc)
        self.doc.add_page_break()
コード例 #29
0
    def buildTable(self):
        colWidths = [1.35, 1.8, 1.35, 0.9, 0.9, 0.9, 1.8]
        tbl = TableMaker(
            colWidths, numHeaders=1, tblStyle="ntpTbl", firstRowCaption=False
        )

        # write header
        tbl.new_th(0, 0, "Reference")
        tbl.new_th(0, 1, "Test system")
        tbl.new_th(0, 2, "Endpoint/\ntest")
        tbl.new_th(0, 3, "Results")
        tbl.new_th(0, 4, "Results (with metabolic activation)")
        tbl.new_th(0, 5, "Agent, LED/HID dose")
        tbl.new_th(0, 6, "Comments")

        row = 0
        for d in self.context["objects"]:
            row += 1

            txt = dedent(
                f"""\
                {d['reference']['name']}
                {d['dataClass']}"""
            )
            tbl.new_td_txt(row, 0, txt)

            txt = d["col2"]
            tbl.new_td_txt(row, 1, txt)

            txt = d["col3"]
            tbl.new_td_txt(row, 2, txt)

            txt = d["col4"]
            tbl.new_td_txt(row, 3, txt)

            txt = d["col5"]
            tbl.new_td_txt(row, 4, txt)

            txt = d["col6"]
            tbl.new_td_txt(row, 5, txt)

            txt = d["wrd_comments"]
            tbl.new_td_txt(row, 6, txt)

        tbl.render(self.doc)
コード例 #30
0
    def build_desc_tbl(self, caption, descriptions, site):
        tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=2, tblStyle="ntpTbl")

        # write title
        tbl.new_th(0, 0, caption, colspan=6)

        # write header
        tbl.new_th(1, 0, "Reference, study-design, location, and year")
        tbl.new_th(1, 1, "Population description & exposure assessment method")
        tbl.new_th(1, 2, "Exposure category or level")
        tbl.new_th(1, 3, "Risk estimate\n(95% CI); exposed cases")
        tbl.new_th(1, 4, "Co-variates controlled")
        tbl.new_th(1, 5, "Comments, strengths, and weaknesses")

        docx_tbl = tbl.render(self.doc)

        # write additional rows
        for desc in descriptions:
            inner_tbl = self._build_description(desc, site)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #31
0
    def build_table(self):
        tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = "Occupational exposure data"
        tbl.new_th(0, 0, txt, colspan=7)

        # write header
        tbl.new_th(1, 0, "Reference")
        tbl.new_th(1, 1, "Location,\ncollection date")
        tbl.new_th(1, 2, "Occupation description")
        tbl.new_th(1, 3, "Sampling matrix, approach,\nN, duration")
        tbl.new_th(1, 4, "Agent,\nexposure level")
        tbl.new_th(1, 5, "Exposure range")
        tbl.new_th(1, 6, "Comments/additional data")

        docx_tbl = tbl.render(self.doc)

        # write rows
        for d in self.context["exposures"]:
            inner_tbl = self.build_row(d)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #32
0
    def build_tbl(self, studies):
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=1,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")

        # write header
        tbl.new_th(0, 0, "Reference and study design")
        tbl.new_th(0, 1, "Exposure")
        tbl.new_th(0, 2, "Dose levels")
        tbl.new_th(0, 3, "Tumor incidence (n/N) (%)")
        tbl.new_th(0, 4, "Comments")

        docx_tbl = tbl.render(self.doc)

        # write body
        for study in studies:
            inner_tbl = self._build_study(study)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)

        self.doc.add_paragraph("\n".join(list(self.footnotes.values())))
コード例 #33
0
    def build_table(self):
        tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = "Occupational exposure data"
        tbl.new_th(0, 0, txt, colspan=7)

        # write header
        tbl.new_th(1, 0, "Reference")
        tbl.new_th(1, 1, "Location,\ncollection date")
        tbl.new_th(1, 2, "Occupation description")
        tbl.new_th(1, 3, "Sampling matrix, approach,\nN, duration")
        tbl.new_th(1, 4, "Agent,\nexposure level")
        tbl.new_th(1, 5, "Exposure range")
        tbl.new_th(1, 6, "Comments/additional data")

        docx_tbl = tbl.render(self.doc)

        # write rows
        for d in self.context["exposures"]:
            inner_tbl = self.build_row(d)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #34
0
ファイル: ntp_html.py プロジェクト: shapiromatron/tblBuilder
    def build_tbl(self, studies):
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=1, firstRowCaption=False, tblStyle="ntpTbl"
        )

        # write header
        tbl.new_th(0, 0, "Reference and study design")
        tbl.new_th(0, 1, "Exposure")
        tbl.new_th(0, 2, "Dose levels")
        tbl.new_th(0, 3, "Tumor incidence (n/N) (%)")
        tbl.new_th(0, 4, "Comments")

        docx_tbl = tbl.render(self.doc)

        # write body
        for study in studies:
            inner_tbl = self._build_study(study)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)

        self.doc.add_paragraph("\n".join(list(self.footnotes.values())))
コード例 #35
0
ファイル: html.py プロジェクト: shapiromatron/tblBuilder
    def build_tbl(self, data):
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=1,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")

        # write header
        tbl.new_th(
            0,
            0,
            "Study design\nSpecies, strain (sex)\nAge at start\nDuration\nReference",
        )
        tbl.new_th(
            0,
            1,
            "Route\nAgent tested, purity\nVehicle\nDose(s)\n"
            "# animals at start\n# surviving animals",
        )
        tbl.new_th(0, 2, "Results")
        tbl.new_th(0, 3, "Significance")
        tbl.new_th(0, 4, "Comments")

        docx_tbl = tbl.render(self.doc)
        for d in data["studies"]:
            inner_tbl = self._build_study(d)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #36
0
    def buildTable(self):
        colWidths = [1, 1, 1, 1, 1, 1, 1, .7, 1]
        tbl = TableMaker(
            colWidths, numHeaders=1, tblStyle="ntpTbl", firstRowCaption=False
        )

        # write header
        tbl.new_th(0, 0, "Reference,\nagent")
        tbl.new_th(0, 1, "Location,\ndate")
        tbl.new_th(0, 2, "Setting,\nscenario")
        tbl.new_th(0, 3, "Sampling\nmatrix")
        tbl.new_th(0, 4, "Number of\nsubjects")
        tbl.new_th(0, 5, "Mean,\nrange,\nunits")
        tbl.new_th(0, 6, "Endpoint &\nsignificance")
        tbl.new_th(0, 7, "Result")
        tbl.new_th(0, 8, "Covariates controlled")

        row = 1
        for ref in self.context["objects"]:

            rowspan = len(ref["results"])

            txt = f"{ref['reference']['name']}\n{ref['agent']}"
            tbl.new_td_txt(row, 0, txt, rowspan=rowspan)

            txt = f"{ref['location']}\n{ref['collectionDate']}"
            tbl.new_td_txt(row, 1, txt, rowspan=rowspan)

            for result in ref["results"]:

                txt = f"{result['exposureSetting']}\n{result['exposureScenario']}"
                tbl.new_td_txt(row, 2, txt)

                txt = result["samplingMatrix"]
                tbl.new_td_txt(row, 3, txt)

                txt = result["numberSubjects"]
                tbl.new_td_txt(row, 4, txt)

                txt = f"{result['exposureLevel']}\n{result['exposureLevelRange']}\n{result['units']}"
                tbl.new_td_txt(row, 5, txt)

                txt = f"{result['endpoint']}\n{result['significancePrint']}"
                tbl.new_td_txt(row, 6, txt)

                txt = result["result"]
                tbl.new_td_txt(row, 7, txt)

                txt = ",\n".join(result["covariates"])
                tbl.new_td_txt(row, 8, txt)

                row += 1

        tbl.render(self.doc)
コード例 #37
0
    def build_ROB_table(self, study):
        widths = [2.8, 0.7, 4.0]
        tbl = TableMaker(widths, numHeaders=2, firstRowCaption=True, tblStyle="ntpTbl")

        # add caption
        tbl.new_td_run(0, 0, self.getTableCaptionRuns(study), colspan=3)

        # add headers
        cells = ['Risk of Bias', 'Rating', 'Rating rationale']
        for i, cell in enumerate(cells):
            tbl.new_th(1, i, cell)

        # add body
        row = 2
        for d in study["qualities"]:
            tbl.new_td_txt(row, 0, d["metric"]["metric"])
            tbl.new_td_txt(row, 1, d["score_symbol"], shade=d["score_shade"])
            tbl.new_td_txt(row, 2, strip_tags(d["notes"]))
            row += 1

        return tbl.render(self.doc)
コード例 #38
0
    def buildHumanVivoTbl(self):
        colWidths = [0.9, 1.2, 1.2, 1.3, 1.4, 0.8, 1.4, 0.8]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = f"Table 1 [Genotoxicity and related effects] of [{self.getAgent()}] in humans in vivo"
        tbl.new_th(0, 0, txt, colspan=8)

        # write header
        tbl.new_th(1, 0, "End-point")
        tbl.new_th(1, 1, "Test")
        tbl.new_th(1, 2, "Tissue")
        tbl.new_th(1, 3, "Cell type\n(if specified)")
        tbl.new_th(1, 4, "Description of exposed and controls")
        tbl.new_th(1, 5, "Response/ significance*")
        tbl.new_th(1, 6, "Comments")
        tbl.new_th(1, 7, "Reference")

        row = 2
        for d in self.context["humanInVivo"]:
            tbl.new_td_txt(row, 0, d["endpoint"])
            tbl.new_td_txt(row, 1, d["endpointTest"])

            tbl.new_td_txt(row, 2, d["tissueHuman"])
            tbl.new_td_txt(row, 3, d["cellType"])
            tbl.new_td_txt(row, 4, d["exposureDescription"])

            txt = f'{d["result"]} {d["wrd_significance"]}'
            tbl.new_td_txt(row, 5, txt)

            tbl.new_td_txt(row, 6, d["wrd_comments"])
            tbl.new_td_txt(row, 7, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(HUMAN_VIVO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #39
0
ファイル: reports.py プロジェクト: reneebeardslee/hawc
    def build_summary_table(self, ag):
        widths = [2.5, 2.7, 1.5, 0.5, 1.2, 1.6]
        tbl = TableMaker(widths, numHeaders=3, firstRowCaption=True, tblStyle="ntpTbl")

        doses = self.getDoses(ag)
        firstDose = doses.keys()[0]

        # add caption
        tbl.new_td_txt(0, 0, ag['name'], colspan=6)

        # add headers
        tbl.new_th(1, 0, r'Reference, Animal Model, and Dosing', rowspan=2)
        tbl.new_th(1, 1, r'Health outcome', rowspan=2)
        tbl.new_th(1, 2, r'Results', colspan=4)

        tbl.new_th(2, 2, u'Dose ({0})'.format(firstDose))
        tbl.new_th(2, 3, r'N')
        tbl.new_th(2, 4, u'Mean \u00B1 SD',)
        tbl.new_th(2, 5, r'% control (95% CI)')

        # build endpoint rows
        rows = 3
        for ep in ag["eps"]:

            if ep["data_extracted"] == False:
                continue

            # add endpoint-name as first-row
            tbl.new_td_run(
                rows, 2,
                [TableMaker.new_run(ep["name"], i=True, newline=False)],
                colspan=4
            )
            rows += 1

            # build column-header table
            data_type = ep["data_type"]
            for i, eg in enumerate(ep["groups"]):

                ci = []
                resp = u"-"

                if data_type == "C":
                    resp = unicode(eg.get("response", "-"))
                    if eg.get('stdev') is not None:
                        resp += u' \u00B1 {0:.2f}'.format(eg["stdev"])
                elif data_type in ["D", "DC"]:
                    if eg.get("incidence") is not None:
                        resp = u'{0}/{1}'.format(eg["incidence"], eg["n"])
                    ci.append(u"NR")
                else:  # ["P"]
                    resp = u'NR'

                if i != 0 and eg.get("percentControlMean") is not None:
                    ci.append("{0:.1f}".format(eg["percentControlMean"]))
                if eg.get("percentControlLow") is not None and eg.get("percentControlHigh") is not None:
                    ci.append(u'({0:.1f}, {1:.1f})'.format(eg["percentControlLow"], eg["percentControlHigh"]))
                ci = u" ".join(ci)

                tbl.new_td_txt(rows, 2, unicode(doses[firstDose][i]))
                tbl.new_td_txt(rows, 3, unicode(eg.get("n", "-")))
                tbl.new_td_txt(rows, 4, resp)
                tbl.new_td_txt(rows, 5, ci)
                rows += 1
        else:
            # add blank cells if none-exist
            tbl.new_td_txt(3, 2, "")
            tbl.new_td_txt(3, 3, "")
            tbl.new_td_txt(3, 4, "")
            tbl.new_td_txt(3, 5, "")

        # adjust rowspans for summary rows
        rowspan = rows - 3
        tbl.new_td_run(3, 0, self.getStudyDetailsRuns(ag, doses), rowspan=rowspan)
        tbl.new_td_run(3, 1, self.getHealthOutcomes(ag), rowspan=rowspan)

        tbl.render(self.doc)
        self.doc.add_paragraph("\n")
コード例 #40
0
    def build_row(self, d):

        row = 0
        rowspan = max(len(d["results"]), 1)
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        txt = d["reference"]["name"]
        tbl.new_td_txt(row, 0, txt, rowspan=rowspan)

        txt = dedent(
            f"""\
            {d["country"]}
            {d["collectionDate"]}"""
        )
        tbl.new_td_txt(row, 1, txt, rowspan=rowspan)

        occ = (
            dedent(
                f"""
                {d["occupationInfo"]}"""
            )
            if d["occupationInfo"]
            else ""
        )
        txt = f'{d["occupation"]}{occ}' if d["isOccupational"] else "N/A"
        tbl.new_td_txt(row, 2, txt, rowspan=rowspan)

        if len(d["results"]) == 0:
            tbl.new_td_txt(row, 3, "-")
            tbl.new_td_txt(row, 4, "-")
            tbl.new_td_txt(row, 5, "-")
        else:
            for i, d2 in enumerate(d["results"]):
                txt = dedent(
                    f"""\
                    {d2["samplingMatrix"]};
                    {d2["samplingApproach"]};
                    {d2["numberMeasurements"]};
                    {d2["measurementDuration"]}"""
                )
                tbl.new_td_txt(i, 3, txt)

                txt = dedent(
                    f"""\
                    {d2["agent"]}
                    {d2["exposureLevel"]} {d2["units"]}
                    {d2["exposureLevelDescription"]}"""
                )
                tbl.new_td_txt(i, 4, txt)

                txt = d2["exposureRangePrint"]
                tbl.new_td_txt(i, 5, txt)

        txt = d["comments"] or ""
        tbl.new_td_txt(row, 6, txt, rowspan=rowspan)

        return tbl
コード例 #41
0
    def buildHumanInVitro(self):
        colWidths = [1.0, 1.2, 1.4, 0.9, 0.9, 1.0, 1.6, 1.0]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = (
            f"Table 2 [Genotoxicity and related effects] of [{self.getAgent()}] in "
            "human cells in vitro")
        tbl.new_th(0, 0, txt, colspan=8)

        # write header
        tbl.new_th(1, 0, "End-point")
        tbl.new_th(1, 1, "Test")
        tbl.new_th(1, 2, "Tissue, cell line")
        tbl.new_th(1, 3, "Results/\nResults without metabolic activation")
        tbl.new_th(1, 4, "Results with metabolic activation")
        tbl.new_th(1, 5, "Concentration (LEC or HIC)")
        tbl.new_th(1, 6, "Comments")
        tbl.new_th(1, 7, "Reference")

        row = 2
        for d in self.context["humanInVitro"]:

            tbl.new_td_txt(row, 0, d["endpoint"])
            tbl.new_td_txt(row, 1, d["endpointTest"])

            tbl.new_td_txt(row, 2, d["tissueCellLine"])

            tbl.new_td_txt(row, 3, d["wrd_resultA"])
            tbl.new_td_txt(row, 4, d["wrd_resultB"])

            txt = f'{d["wrd_led"]} {d["units"]}'
            tbl.new_td_txt(row, 5, txt)

            tbl.new_td_txt(row, 6, d["wrd_comments"])
            tbl.new_td_txt(row, 7, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(MAMMAL_VITRO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #42
0
    def build_row(self, d):

        row = 0
        rowspan = max(len(d["results"]), 1)
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=0,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")

        txt = d["reference"]["name"]
        tbl.new_td_txt(row, 0, txt, rowspan=rowspan)

        txt = dedent(f"""\
            {d["country"]}
            {d["collectionDate"]}""")
        tbl.new_td_txt(row, 1, txt, rowspan=rowspan)

        occ = (dedent(f"""
                {d["occupationInfo"]}""") if d["occupationInfo"] else "")
        txt = f'{d["occupation"]}{occ}' if d["isOccupational"] else "N/A"
        tbl.new_td_txt(row, 2, txt, rowspan=rowspan)

        if len(d["results"]) == 0:
            tbl.new_td_txt(row, 3, "-")
            tbl.new_td_txt(row, 4, "-")
            tbl.new_td_txt(row, 5, "-")
        else:
            for i, d2 in enumerate(d["results"]):
                txt = dedent(f"""\
                    {d2["samplingMatrix"]};
                    {d2["samplingApproach"]};
                    {d2["numberMeasurements"]};
                    {d2["measurementDuration"]}""")
                tbl.new_td_txt(i, 3, txt)

                txt = dedent(f"""\
                    {d2["agent"]}
                    {d2["exposureLevel"]} {d2["units"]}
                    {d2["exposureLevelDescription"]}""")
                tbl.new_td_txt(i, 4, txt)

                txt = d2["exposureRangePrint"]
                tbl.new_td_txt(i, 5, txt)

        txt = d["comments"] or ""
        tbl.new_td_txt(row, 6, txt, rowspan=rowspan)

        return tbl
コード例 #43
0
    def _build_result(self, res):

        rows = 0
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        rowspan = len(res["riskEstimates"])

        # Column A
        txt = dedent(
            f"""\
            {res["descriptive"]["reference"]["name"]}
            {res["descriptive"]["studyDesign"]}
            {res["descriptive"]["location"]}
            {res["descriptive"]["enrollmentDates"]}"""
        )
        tbl.new_td_txt(rows, 0, txt, rowspan=rowspan)

        # Column B
        if res["descriptive"]["isCaseControl"]:
            popD = tbl.new_run(
                dedent(
                    f"""\
                {res["descriptive"].get("eligibilityCriteria", "")}
                Cases: {res["descriptive"].get("populationSizeCase", "")}
                Controls: {res["descriptive"].get("populationSizeControl", "")}"""
                )
            )
        else:
            popD = tbl.new_run(
                dedent(
                    f"""\
                {res["descriptive"].get("eligibilityCriteria", "")}
                {res["descriptive"].get("populationSize", "")}"""
                )
            )

        runs = [
            popD,
            tbl.new_run("Exposure assessment method: ", b=True, newline=False),
            tbl.new_run(res["descriptive"]["exposureAssessmentType"], newline=False),
        ]

        if res.get("organSite"):
            runs.insert(0, tbl.new_run(res["organSite"], b=True))

        tbl.new_td_run(rows, 1, runs, rowspan=rowspan)

        # Columns C,D,E
        for i, est in enumerate(res["riskEstimates"]):
            tbl.new_td_txt(rows + i, 2, est["exposureCategory"])
            tbl.new_td_txt(rows + i, 3, est["numberExposed"])
            tbl.new_td_txt(rows + i, 4, est["riskFormatted"])

        # Column F
        txt = res["wrd_covariatesList"]
        runs = [tbl.new_run(res["wrd_covariatesList"])]
        if res["hasTrendTest"]:
            runs.extend(
                [
                    tbl.new_run("Trend-test ", newline=False),
                    tbl.new_run("P", i=True, newline=False),
                    tbl.new_run(f'-value: {res["trendTest"]}', newline=False),
                ]
            )
        tbl.new_td_run(rows, 5, runs, rowspan=rowspan)

        # Column G
        runs = [
            tbl.new_run(res["descriptive"]["wrd_notes"]),
            tbl.new_run("Strengths:", b=True),
            tbl.new_run(res["descriptive"]["strengths"]),
            tbl.new_run("Limitations:", b=True),
            tbl.new_run(res["descriptive"]["limitations"], newline=False),
        ]
        tbl.new_td_run(rows, 6, runs, rowspan=rowspan)

        return tbl
コード例 #44
0
ファイル: html.py プロジェクト: shapiromatron/tblBuilder
    def _build_study(self, d):

        rows = 0
        tbl = TableMaker(self.COLUMN_WIDTHS,
                         numHeaders=0,
                         firstRowCaption=False,
                         tblStyle="ntpTbl")
        rowspan = 0
        for ep in d["results"]:
            rowspan += 1
            if (len(ep["wrd_incidents"]) > 0
                    or len(ep["wrd_incidence_significance"]) > 0):
                rowspan += 1
            if (len(ep["wrd_multiplicities"]) > 0
                    or len(ep["wrd_multiplicity_significance"]) > 0):
                rowspan += 1
            if (len(ep["wrd_total_tumours"]) > 0
                    or len(ep["wrd_total_tumours_significance"]) > 0):
                rowspan += 1

        # Column A
        runs = [
            tbl.new_run(d["studyDesign"], b=True),
            tbl.new_run(d["species"], b=True, newline=False),
            tbl.new_run(f', {d["strain"]} {d["sex"]}'),
            tbl.new_run(d["ageAtStart"]),
            tbl.new_run(d["duration"]),
            tbl.new_run(d["reference"]["name"], newline=False),
        ]
        tbl.new_td_run(rows, 0, runs, rowspan=rowspan)

        # Column B
        txt = dedent(f"""\
            {d["dosingRoute"]}
            {d["agent"]}, {d["purity"]}
            {d["vehicle"]}
            {d["wrd_doses"]}
            {d["dosingRegimen"]}
            {d["wrd_nStarts"]}
            {d["wrd_nSurvivings"]}""")
        tbl.new_td_txt(rows, 1, txt, rowspan=rowspan)

        # Columns C, D
        irows = rows
        for ep in d["results"]:

            txt = f'{ep["tumourSite"]}: {ep["histology"]}'
            runs = [tbl.new_run(txt, b=True, newline=False)]
            tbl.new_td_run(irows, 2, runs, colspan=2)
            irows += 1

            if (len(ep["wrd_incidents"]) > 0
                    or len(ep["wrd_incidence_significance"]) > 0):
                tbl.new_td_txt(irows, 2, ep["wrd_incidents"])
                tbl.new_td_txt(irows, 3, ep["wrd_incidence_significance"])
                irows += 1

            if (len(ep["wrd_multiplicities"]) > 0
                    or len(ep["wrd_multiplicity_significance"]) > 0):
                tbl.new_td_txt(irows, 2, ep["wrd_multiplicities"])
                tbl.new_td_txt(irows, 3, ep["wrd_multiplicity_significance"])
                irows += 1

            if (len(ep["wrd_total_tumours"]) > 0
                    or len(ep["wrd_total_tumours_significance"]) > 0):
                tbl.new_td_txt(irows, 2, ep["wrd_total_tumours"])
                tbl.new_td_txt(irows, 3, ep["wrd_total_tumours_significance"])
                irows += 1

        # Column E
        runs = [
            tbl.new_run("Principal strengths:", b=True),
            tbl.new_run(d["wrd_strengths"]),
            tbl.new_run("Principal limitations:", b=True),
            tbl.new_run(d["wrd_limitations"]),
            tbl.new_run("Other comments:", b=True),
            tbl.new_run(d["wrd_comments"], newline=False),
        ]
        tbl.new_td_run(rows, 4, runs, rowspan=rowspan)

        return tbl
コード例 #45
0
    def build_desc_tbl(self, caption, descriptions, site):
        tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=2, tblStyle="ntpTbl")

        # write title
        tbl.new_th(0, 0, caption, colspan=6)

        # write header
        tbl.new_th(1, 0, "Reference, study-design, location, and year")
        tbl.new_th(1, 1, "Population description & exposure assessment method")
        tbl.new_th(1, 2, "Exposure category or level")
        tbl.new_th(1, 3, "Risk estimate\n(95% CI); exposed cases")
        tbl.new_th(1, 4, "Co-variates controlled")
        tbl.new_th(1, 5, "Comments, strengths, and weaknesses")

        docx_tbl = tbl.render(self.doc)

        # write additional rows
        for desc in descriptions:
            inner_tbl = self._build_description(desc, site)
            docx_tbl_inner = inner_tbl.render(self.doc)
            docx_tbl._cells.extend(docx_tbl_inner._cells)
コード例 #46
0
 def getTableCaptionRuns(self, study):
     return [
         TableMaker.new_run(u'{0}: '.format(study["short_citation"]), b=True, newline=False),
         TableMaker.new_run(study["full_citation"], newline=False)
     ]
コード例 #47
0
    def _build_description(self, desc, site):
        results = desc["organSiteResults"][site]
        row = 0
        tbl = TableMaker(
            self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl"
        )

        rowspan = self.get_desc_rowspan(results)
        # Column A
        runs = [
            tbl.new_run(desc["reference"]["name"]),
            tbl.new_run(desc["studyDesign"]),
            tbl.new_run(to_string(desc, "location")),
            tbl.new_run("Enrollment or follow-up:", b=True),
            tbl.new_run(to_string(desc, "enrollmentDates")),
        ]
        tbl.new_td_run(row, 0, runs, rowspan=rowspan)

        # Column B
        if desc["isCaseControl"]:
            txt = (
                f'Cases: {desc.get("populationSizeCases", "")};'
                f' Controls: {desc.get("populationSizeControls", "")}'
            )
            descriptors = desc.get("otherPopulationDescriptors")
            if descriptors is not None:
                txt = dedent(
                    f"""\
                    {descriptors}
                    {txt}"""
                )
            popD = tbl.new_run(txt)
        else:
            popD = tbl.new_run(
                dedent(
                    f"""\
                {desc.get("otherPopulationDescriptors", "")}
                {desc.get("cohortPopulationSize", "")}"""
                )
            )

        runs = [
            tbl.new_run("Population:", b=True),
            popD,
            tbl.new_run("Exposure assessment method: ", b=True, newline=False),
            tbl.new_run(desc["exposureAssessmentType"], newline=False),
        ]

        tbl.new_td_run(row, 1, runs, rowspan=rowspan)

        result_row = row
        for res in results:
            # Columns C,D
            result_rowspan = self.get_result_rowspan(res)
            risk_row = result_row
            if res.get("organSite") or res.get("effectMeasure"):
                txt = str(res["organSite"]) if res.get("organSite") else ""
                if res.get("effectMeasure"):
                    txt += ": " if len(txt) > 0 else ""
                    txt += res["effectMeasure"]

                if res.get("effectUnits") is not None:
                    txt += f' {res["effectUnits"]}'

                run = [tbl.new_run(txt, b=True, newline=False)]
                tbl.new_td_run(risk_row, 2, run, colspan=2)
                risk_row += 1

            for est in res["riskEstimates"]:
                tbl.new_td_txt(risk_row, 2, est["exposureCategory"])
                tbl.new_td_txt(risk_row, 3, est["riskFormatted"])
                risk_row += 1

            if res.get("trendTest"):
                run = [
                    tbl.new_run("Trend-test ", newline=False),
                    tbl.new_run("p", i=True, newline=False),
                    tbl.new_run("-value: ", newline=False),
                    tbl.new_run(res["trendTest"], newline=False),
                ]
                tbl.new_td_run(risk_row, 2, run, colspan=2)
                risk_row += 1

            # Column E
            tbl.new_td_txt(
                result_row, 4, res["wrd_covariatesList"], rowspan=result_rowspan
            )

            # update result_row
            result_row = result_row + result_rowspan

        # Column F
        runs = []
        wrd_notes = desc.get("wrd_notes")
        if wrd_notes is not None and wrd_notes != "":
            runs.append(tbl.new_run(wrd_notes))

        additional_results = "\n".join(
            [
                res["additionalResults"]
                for res in results
                if (
                    "additionalResults" in res
                    and res["additionalResults"] is not None
                    and res["additionalResults"] is not ""
                )
            ]
        )
        if additional_results is "":
            additional_results = "-"

        runs.extend(
            [
                tbl.new_run("Exposure information:", b=True),
                tbl.new_run(to_string(desc, "exposureLevel")),
                tbl.new_run("Strengths:", b=True),
                tbl.new_run(to_string(desc, "strengths")),
                tbl.new_run("Limitations:", b=True),
                tbl.new_run(to_string(desc, "limitations")),
                tbl.new_run("Additional results:", b=True),
                tbl.new_run(additional_results),
                tbl.new_run("Confidence in evidence:", b=True),
                tbl.new_run(to_string(desc, "confidenceInEvidence"), newline=False),
            ]
        )
        tbl.new_td_run(row, 5, runs, rowspan=rowspan)

        return tbl
コード例 #48
0
    def buildAniVivoTbl(self):
        colWidths = [1.0, 1.0, 1.0, 1.0, 0.5, 0.7, 1.2, 1.6, 1]
        tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl")

        # write title
        txt = (
            f"Table 3 [Genotoxicity and related effects] of [{self.getAgent()}] in non-human "
            "mammals in vivo"
        )
        tbl.new_th(0, 0, txt, colspan=9)

        # write header
        tbl.new_th(1, 0, "End-point")
        tbl.new_th(1, 1, "Test")
        tbl.new_th(1, 2, "Species, strain, sex")
        tbl.new_th(1, 3, "Tissue")
        tbl.new_th(1, 4, "Results")
        tbl.new_th(1, 5, "Agent, dose (LED or HID)")
        tbl.new_th(1, 6, "Route, duration, dosing regimen")
        tbl.new_th(1, 7, "Comments")
        tbl.new_th(1, 8, "Reference")

        row = 2
        for d in self.context["animalInVivo"]:

            tbl.new_td_txt(row, 0, d["endpoint"])

            tbl.new_td_txt(row, 1, d["endpointTest"])

            txt = f'{d["species"]} {d["strain"]} { d["sex"]}'
            tbl.new_td_txt(row, 2, txt)

            tbl.new_td_txt(row, 3, d["tissueAnimal"])

            tbl.new_td_txt(row, 4, d["result"])

            txt = dedent(
                f"""\
                {d["agent"]}
                LED/HID: {d["wrd_led"]} {d["units"]}"""
            )
            tbl.new_td_txt(row, 5, txt)

            txt = dedent(
                f"""\
                {d["dosingRoute"]};
                {d["dosingDuration"]}"""
            )
            tbl.new_td_txt(row, 6, txt)

            tbl.new_td_txt(row, 7, d["wrd_comments"])
            tbl.new_td_txt(row, 8, d["reference"]["name"])
            row += 1

        tbl.render(self.doc)
        self.doc.add_paragraph(ANIMAL_VIVO_FOOTNOTE)
        self.doc.add_page_break()
コード例 #49
0
    def buildTable(self):
        colWidths = [1, 1, 1, 1, 1, 1, 1, .7, 1]
        tbl = TableMaker(colWidths,
                         numHeaders=1,
                         tblStyle="ntpTbl",
                         firstRowCaption=False)

        # write header
        tbl.new_th(0, 0, "Reference,\nagent")
        tbl.new_th(0, 1, "Location,\ndate")
        tbl.new_th(0, 2, "Setting,\nscenario")
        tbl.new_th(0, 3, "Sampling\nmatrix")
        tbl.new_th(0, 4, "Number of\nsubjects")
        tbl.new_th(0, 5, "Mean,\nrange,\nunits")
        tbl.new_th(0, 6, "Endpoint &\nsignificance")
        tbl.new_th(0, 7, "Result")
        tbl.new_th(0, 8, "Covariates controlled")

        row = 1
        for ref in self.context["objects"]:

            rowspan = len(ref["results"])

            txt = f"{ref['reference']['name']}\n{ref['agent']}"
            tbl.new_td_txt(row, 0, txt, rowspan=rowspan)

            txt = f"{ref['location']}\n{ref['collectionDate']}"
            tbl.new_td_txt(row, 1, txt, rowspan=rowspan)

            for result in ref["results"]:

                txt = f"{result['exposureSetting']}\n{result['exposureScenario']}"
                tbl.new_td_txt(row, 2, txt)

                txt = result["samplingMatrix"]
                tbl.new_td_txt(row, 3, txt)

                txt = result["numberSubjects"]
                tbl.new_td_txt(row, 4, txt)

                txt = f"{result['exposureLevel']}\n{result['exposureLevelRange']}\n{result['units']}"
                tbl.new_td_txt(row, 5, txt)

                txt = f"{result['endpoint']}\n{result['significancePrint']}"
                tbl.new_td_txt(row, 6, txt)

                txt = result["result"]
                tbl.new_td_txt(row, 7, txt)

                txt = ",\n".join(result["covariates"])
                tbl.new_td_txt(row, 8, txt)

                row += 1

        tbl.render(self.doc)