From 75301af155f3d5d870d5ad32baf14701027a38b5 Mon Sep 17 00:00:00 2001 From: Anushya Muruganujan Date: Wed, 15 Nov 2023 16:16:35 -0800 Subject: [PATCH 1/4] For #1199 --- scripts/combined_assigned_by.py | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/scripts/combined_assigned_by.py b/scripts/combined_assigned_by.py index 3dc191f8..2a598449 100644 --- a/scripts/combined_assigned_by.py +++ b/scripts/combined_assigned_by.py @@ -238,7 +238,67 @@ def output_html(violations_info_list, path, rules_descriptions): ## Write out file fileName = path + '/assigned-by-' + id + '-report.html' ET.ElementTree(htmlObj).write(fileName, encoding='unicode', method='html') + +def output_aggregate_html(rules_to_violations, path, rules_descriptions): + htmlObj = ET.Element('html') + body = ET.Element('body') + htmlObj.append(body) + heading = ET.Element('h1') + body.append(heading) + heading.text = 'Aggregate GORULE violations' + body.append(ET.Element('br')) + + ## Create a section with the GORULE violation details + messageSection = ET.Element('h2') + body.append(messageSection) + messageSection.text = 'MESSAGES' + + rules = list(rules_to_violations.keys()) + rules.sort() + + tableSection = ET.Element('Table', attrib={'border': "1px solid black;"}) + body.append(tableSection) + tableHeaderRow = ET.Element('tr') + tableSection.append(tableHeaderRow) + + headerCellRule = ET.Element('th'); + tableHeaderRow.append(headerCellRule) + headerCellRule.text = 'Rule' + + headerCellDetails = ET.Element('th'); + tableHeaderRow.append(headerCellDetails) + headerCellDetails.text = 'Rule Violations' + + for rule in rules: + violations = rules_to_violations[rule] + if violations is None: + continue + + tableRow = ET.Element('tr') + tableHeaderRow.append(tableRow) + cellRuleDetails = ET.Element('td', attrib={'style':"white-space:nowrap;"}) + tableRow.append(cellRuleDetails) + + cellRuleDetails.text = html.escape(rule + ' - ' + str(len(violations)) + " violations - " + rules_descriptions[rule]["title"]) + + cellRuleViolations = ET.Element('td'); + tableRow.append(cellRuleViolations) + + unorderedList = ET.Element('ul') + cellRuleViolations.append(unorderedList) + for violation in violations: + violationItem = ET.Element('li') + unorderedList.append(violationItem) + violationItem.text = html.escape(violation['message'] + '--`' + violation['line']) + + # Indent + _pretty_print(htmlObj) + ## Write out file + fileName = path + '/aggregate-rule-violation-report.html' + ET.ElementTree(htmlObj).write(fileName, encoding='unicode', method='html') + + def main(): """The main runner of our script.""" @@ -254,6 +314,9 @@ def main(): rules_descriptions[rule_id] = { "title": rule["title"] } + + #Create a rule to all violations dictionary + rules_to_violations = dict() ## Deal with incoming. parser = argparse.ArgumentParser( @@ -405,8 +468,17 @@ def main(): if (len(violations) == 0): continue + #Add violations to the key_violations Lookup + if key in rules_to_violations: + cur_violations = rules_to_violations[key] + else: + cur_violations = [] + rules_to_violations[key] = cur_violations + + for violation in violations: gaf_line = violation['line'] + cur_violations.append(violation) gaf_contents = re.split('\t', gaf_line) ## Get assigned by information from GAF line. If it does not exist, attempt to get from group that created the GAF file @@ -472,6 +544,9 @@ def main(): ## Output html file for each assigned-by with GORULE violation details output_html(violator_list, os.path.dirname(args.output), rules_descriptions) + + ## Output aggregate violations file + output_aggregate_html(rules_to_violations, os.path.dirname(args.output), rules_descriptions) ## Final writeout of combined assigned-by json report with open(args.output, 'w+') as fhandle: From bf61874b5150ada1eaa980048692eab243fe5fb3 Mon Sep 17 00:00:00 2001 From: Anushya Muruganujan Date: Thu, 16 Nov 2023 11:27:03 -0800 Subject: [PATCH 2/4] For #1199 Updated to generate md instead of html --- scripts/combined_assigned_by.py | 70 +++++++++------------------------ 1 file changed, 18 insertions(+), 52 deletions(-) diff --git a/scripts/combined_assigned_by.py b/scripts/combined_assigned_by.py index 2a598449..6120f474 100644 --- a/scripts/combined_assigned_by.py +++ b/scripts/combined_assigned_by.py @@ -239,65 +239,31 @@ def output_html(violations_info_list, path, rules_descriptions): fileName = path + '/assigned-by-' + id + '-report.html' ET.ElementTree(htmlObj).write(fileName, encoding='unicode', method='html') -def output_aggregate_html(rules_to_violations, path, rules_descriptions): - htmlObj = ET.Element('html') - body = ET.Element('body') - htmlObj.append(body) - heading = ET.Element('h1') - body.append(heading) - heading.text = 'Aggregate GORULE violations' - body.append(ET.Element('br')) +def output_aggregate_md(rules_to_violations, path, rules_descriptions): + s = 'Aggregate GORULE violations' + s += '\n\n## SUMMARY' + s += '\n\nThis report generated on {}'.format(datetime.date.today()) + s += '\n\n## Rule Violations' - ## Create a section with the GORULE violation details - messageSection = ET.Element('h2') - body.append(messageSection) - messageSection.text = 'MESSAGES' - rules = list(rules_to_violations.keys()) + rules = list(rules_descriptions.keys()) rules.sort() - - tableSection = ET.Element('Table', attrib={'border': "1px solid black;"}) - body.append(tableSection) - tableHeaderRow = ET.Element('tr') - tableSection.append(tableHeaderRow) - - headerCellRule = ET.Element('th'); - tableHeaderRow.append(headerCellRule) - headerCellRule.text = 'Rule' - - headerCellDetails = ET.Element('th'); - tableHeaderRow.append(headerCellDetails) - headerCellDetails.text = 'Rule Violations' + for rule in rules: - violations = rules_to_violations[rule] - if violations is None: + if rule in rules_to_violations: + violations = rules_to_violations[rule] + s += '\n\n## ' + rule + ' - ' + str(len(violations)) + " violations - " + rules_descriptions[rule]["title"] + for violation in violations: + s+= '\n' + violation['message'] + '--`' + violation['line'].strip() + else: + s += '\n\n## ' + rule + ' - no violations - ' + rules_descriptions[rule]["title"] continue - - tableRow = ET.Element('tr') - tableHeaderRow.append(tableRow) - cellRuleDetails = ET.Element('td', attrib={'style':"white-space:nowrap;"}) - tableRow.append(cellRuleDetails) - - cellRuleDetails.text = html.escape(rule + ' - ' + str(len(violations)) + " violations - " + rules_descriptions[rule]["title"]) - - cellRuleViolations = ET.Element('td'); - tableRow.append(cellRuleViolations) - - unorderedList = ET.Element('ul') - cellRuleViolations.append(unorderedList) - for violation in violations: - violationItem = ET.Element('li') - unorderedList.append(violationItem) - violationItem.text = html.escape(violation['message'] + '--`' + violation['line']) - - # Indent - _pretty_print(htmlObj) + ## Write out file - fileName = path + '/aggregate-rule-violation-report.html' - ET.ElementTree(htmlObj).write(fileName, encoding='unicode', method='html') - + fileName = path + '/aggregate-rule-violation-report.md' + utils.write_text(fileName, s) def main(): @@ -546,7 +512,7 @@ def main(): output_html(violator_list, os.path.dirname(args.output), rules_descriptions) ## Output aggregate violations file - output_aggregate_html(rules_to_violations, os.path.dirname(args.output), rules_descriptions) + output_aggregate_md(rules_to_violations, os.path.dirname(args.output), rules_descriptions) ## Final writeout of combined assigned-by json report with open(args.output, 'w+') as fhandle: From 9ba3c5df4e51535a00533d08cedd50154e47babc Mon Sep 17 00:00:00 2001 From: Anushya Muruganujan Date: Wed, 22 Nov 2023 17:10:20 -0800 Subject: [PATCH 3/4] For #2093 update for latest version of ontobio --- pipeline/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/requirements.txt b/pipeline/requirements.txt index 318a81c4..31241892 100644 --- a/pipeline/requirements.txt +++ b/pipeline/requirements.txt @@ -1,5 +1,5 @@ PyYAML -ontobio==2.8.18 +ontobio==2.8.19 click pyparsing==2.4.7 antlr4-python3-runtime==4.9.3 From cfd0877945b5e065eaf8cdbea1d1a2cbc41d7ef4 Mon Sep 17 00:00:00 2001 From: Anushya Muruganujan Date: Fri, 1 Dec 2023 10:58:27 -0800 Subject: [PATCH 4/4] For #2093 updated to latest ontobio release --- pipeline/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/requirements.txt b/pipeline/requirements.txt index 31241892..b5dce23e 100644 --- a/pipeline/requirements.txt +++ b/pipeline/requirements.txt @@ -1,5 +1,5 @@ PyYAML -ontobio==2.8.19 +ontobio==2.8.20 click pyparsing==2.4.7 antlr4-python3-runtime==4.9.3