def generate_webpage(records: List[Record], results: List[Dict[str, module_results.ModuleResults]], options: ConfigType) -> None: """ Generates and writes the HTML itself """ generate_searchgtr_htmls(records, options) json_records = js.convert_records(records, results, options) js_domains = [] for i, record in enumerate(records): json_record = json_records[i] json_record['seq_id'] = "".join(char for char in json_record['seq_id'] if char in string.printable) for json_cluster in json_record['clusters']: # json clusters from antismash import get_analysis_modules # TODO break circular dependency handlers = find_plugins_for_cluster(get_analysis_modules(), json_cluster) for handler in handlers: # if there's no results for the module, don't let it try if handler.__name__ not in results[i]: continue if "generate_js_domains" in dir(handler): domains = handler.generate_js_domains( json_cluster, record, # type: ignore results[i][handler.__name__], options) if domains: js_domains.append(domains) write_geneclusters_js(json_records, options.output_dir, js_domains) with open(os.path.join(options.output_dir, 'index.html'), 'w') as result_file: env = Environment(autoescape=True, trim_blocks=True, lstrip_blocks=True, undefined=jinja2.StrictUndefined, loader=FileSystemLoader( path.get_full_path(__file__))) template = env.get_template('index.html') options_layer = OptionsLayer(options) record_layers = [] for record, record_results in zip(records, results): record_layers.append( RecordLayer(record, record_results, options_layer)) records_written = sum(len(record.get_clusters()) for record in records) aux = template.render(records=record_layers, options=options_layer, version=options.version, extra_data=js_domains, records_written=records_written, config=options) result_file.write(aux)
def generate_webpage(seq_records, results, options): generate_searchgtr_htmls(seq_records, options) json_records = js.convert_records(seq_records, results, options) extra_data = dict(js_domains=[]) for i, record in enumerate(seq_records): json_record = json_records[i] json_record['seq_id'] = "".join(char for char in json_record['seq_id'] if char in string.printable) for json_cluster in json_record['clusters']: # json clusters from antismash import get_analysis_modules # TODO break circular dependency handlers = find_plugins_for_cluster(get_analysis_modules(), json_cluster) for handler in handlers: # if there's no results for the module, don't let it try if handler.__name__ not in results[i]: continue if "generate_js_domains" in dir(handler): domains = handler.generate_js_domains( json_cluster, record, results[i][handler.__name__], options) if domains: extra_data['js_domains'].append(domains) write_geneclusters_js(json_records, options.output_dir, extra_data) # jinja with open(os.path.join(options.output_dir, 'index.html'), 'w') as result: env = Environment(autoescape=True, trim_blocks=True, lstrip_blocks=True, undefined=jinja2.StrictUndefined, loader=FileSystemLoader( path.get_full_path(__file__))) template = env.get_template('index.html') options_layered = OptionsLayer(options) records = [ RecordLayer(record, result, options_layered) for record, result in zip(seq_records, results) ] records_written = sum( [len(record.seq_record.get_clusters()) for record in records]) aux = template.render(records=records, options=options_layered, version=options.version, extra_data=extra_data, records_written=records_written, config=options) result.write(aux)
def build_json_data( records: List[Record], results: List[Dict[str, module_results.ModuleResults]], options: ConfigType ) -> Tuple[List[Dict[str, Any]], List[Dict[str, Union[str, List[JSONOrf]]]], Dict[str, Dict[str, Dict[str, Any]]]]: """ Builds JSON versions of records and domains for use in drawing SVGs with javascript. Arguments: records: a list of Records to convert results: a dictionary mapping record id to a list of ModuleResults to convert options: antiSMASH options Returns: a tuple of a list of JSON-friendly dicts representing records a list of JSON-friendly dicts representing domains """ from antismash import get_all_modules # TODO break circular dependency js_records = js.convert_records(records, results, options) js_domains: List[Dict[str, Union[str, List[JSONOrf]]]] = [] js_results = {} for i, record in enumerate(records): json_record = js_records[i] json_record['seq_id'] = "".join(char for char in json_record['seq_id'] if char in string.printable) for region, json_region in zip(record.get_regions(), json_record['regions']): handlers = find_plugins_for_cluster(get_all_modules(), json_region) region_results = {} for handler in handlers: # if there's no results for the module, don't let it try if handler.__name__ not in results[i]: continue if "generate_js_domains" in dir(handler): domains_by_region = handler.generate_js_domains( region, record) if domains_by_region: js_domains.append(domains_by_region) if hasattr(handler, "generate_javascript_data"): region_results[ handler.__name__] = handler.generate_javascript_data( record, region, results[i][handler.__name__]) if region_results: js_results[RegionLayer.build_anchor_id( region)] = region_results return js_records, js_domains, js_results