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_domains = build_json_data(records, results, options) write_regions_js(json_records, options.output_dir, js_domains) with open(os.path.join(options.output_dir, 'index.html'), 'w') as result_file: template = FileTemplate( path.get_full_path(__file__, "templates", "overview.html")) options_layer = OptionsLayer(options) record_layers_with_regions = [] record_layers_without_regions = [] results_by_record_id = { } # type: Dict[str, Dict[str, module_results.ModuleResults]] for record, record_results in zip(records, results): if record.get_regions(): record_layers_with_regions.append( RecordLayer(record, None, options_layer)) else: record_layers_without_regions.append( RecordLayer(record, None, options_layer)) results_by_record_id[record.id] = record_results regions_written = sum(len(record.get_regions()) for record in records) job_id = os.path.basename(options.output_dir) page_title = "" if options.html_title: page_title = options.html_title elif options.sequences: page_title, _ = os.path.splitext( os.path.basename(options.sequences[0])) elif options.reuse_results: page_title, _ = os.path.splitext( os.path.basename(options.reuse_results)) html_sections = generate_html_sections(record_layers_with_regions, results_by_record_id, options) aux = template.render( records=record_layers_with_regions, options=options_layer, version=options.version, extra_data=js_domains, regions_written=regions_written, sections=html_sections, results_by_record_id=results_by_record_id, config=options, job_id=job_id, page_title=page_title, records_without_regions=record_layers_without_regions) result_file.write(aux)
def generate_html(region_layer: RegionLayer, results: NRPS_PKS_Results, record_layer: RecordLayer, options_layer: OptionsLayer) -> HTMLSections: """ Generate the sidepanel HTML with results from the NRPS/PKS module """ html = HTMLSections("nrps_pks") nrps_layer = NrpspksLayer(results, region_layer.region_feature, record_layer) features_with_domain_predictions: Dict[str, List[str]] = {} for domain_name, consensus in results.consensus.items(): if not consensus: continue domain = record_layer.get_domain_by_name(domain_name) features_with_domain_predictions[domain.locus_tag] = [] for feature_name, monomers in features_with_domain_predictions.items(): for domain in record_layer.get_cds_by_name( feature_name).nrps_pks.domains: monomer = results.consensus.get(domain.feature_name) if monomer: monomers.append(monomer) prod_tt = ( "Shows estimated product structure and polymer for each candidate cluster in the region. " "To show the product, click on the expander or the candidate cluster feature drawn in the overview. " ) mon_tt = ( "Shows the predicted monomers for each adynelation domain and acyltransferase within genes. " "Each gene prediction can be expanded to view detailed predictions of each domain. " "Each prediction can be expanded to view the predictions by tool " " (and, for some tools, further expanded for extra details). ") if not nrps_layer.has_any_polymer(): return html for filename, name, class_name, tooltip in [ ("products.html", "NRPS/PKS products", "nrps_pks_products", prod_tt), ("monomers.html", "NRPS/PKS monomers", "", mon_tt) ]: template = FileTemplate( path.get_full_path(__file__, "templates", filename)) section = template.render( record=record_layer, region=nrps_layer, results=results, relevant_features=features_with_domain_predictions, options=options_layer, tooltip=tooltip) html.add_sidepanel_section(name, section, class_name) return html
def generate_js_domains(cluster, record, results, options ) -> Optional[Dict[str, Union[str, List[JSONDomain]]]]: """ Generate """ assert isinstance(results, NRPS_PKS_Results), type(results) cluster_feature = record.get_cluster(cluster['idx']) cluster = NrpspksLayer(results, cluster_feature, RecordLayer(record, results, OptionsLayer(options))) return cluster.get_domain_details()
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 __init__(self, results: NRPS_PKS_Results, region_feature: Region, record: RecordLayer) -> None: self.url_strict = {} # type: Dict[str, str] # gene name -> url self.url_relaxed = {} # type: Dict[str, str] # gene name -> url self._build_urls(region_feature.cds_children) super().__init__(record, region_feature) assert isinstance(results, NRPS_PKS_Results), type(results) self.results = results region_number = region_feature.get_region_number() self.candidate_clusters = [] # type: List[CandidateClusterLayer] for candidate_cluster_pred in results.region_predictions.get(region_number, []): candidate_cluster = record.get_candidate_cluster(candidate_cluster_pred.candidate_cluster_number) self.candidate_clusters.append(CandidateClusterLayer(candidate_cluster, candidate_cluster_pred))
def generate_html(region_layer: RegionLayer, results: NRPS_PKS_Results, record_layer: RecordLayer, options_layer: OptionsLayer) -> HTMLSections: """ Generate the sidepanel HTML with results from the NRPS/PKS module """ html = HTMLSections("nrps_pks") nrps_layer = NrpspksLayer(results, region_layer.region_feature, record_layer) features_with_domain_predictions = {} # type: Dict[str, List[str]] for domain_name, consensus in results.consensus.items(): if not consensus: continue domain = record_layer.get_domain_by_name(domain_name) features_with_domain_predictions[domain.locus_tag] = [] for feature_name, monomers in features_with_domain_predictions.items(): for domain in record_layer.get_cds_by_name( feature_name).nrps_pks.domains: monomer = results.consensus.get(domain.feature_name) if monomer: monomers.append(monomer) for filename, name, class_name in [ ("products.html", "NRPS/PKS products", "nrps_pks_products"), ("monomers.html", "NRPS/PKS monomers", "") ]: template = FileTemplate( path.get_full_path(__file__, "templates", filename)) section = template.render( record=record_layer, region=nrps_layer, results=results, relevant_features=features_with_domain_predictions, options=options_layer) html.add_sidepanel_section(name, section, class_name) return html
def generate_html(region_layer: RegionLayer, results: LassoResults, record_layer: RecordLayer, _options_layer: OptionsLayer) -> HTMLSections: """ Generates HTML for the module """ html = HTMLSections("lassopeptides") motifs_in_region = {} for locus in results.motifs_by_locus: if record_layer.get_cds_by_name(locus).is_contained_by(region_layer.region_feature): motifs_in_region[locus] = results.motifs_by_locus[locus] detail_tooltip = ("Lists the possible core peptides for each biosynthetic enzyme, including the predicted class. " "Each core peptide shows the leader and core peptide sequences, separated by a dash.") template = FileTemplate(path.get_full_path(__file__, "templates", "details.html")) html.add_detail_section("Lasso peptides", template.render(results=motifs_in_region, tooltip=detail_tooltip)) side_tooltip = ("Lists the possible core peptides in the region. " "Each core peptide lists the number of disulfide bridges, possible molecular weights, " "and the scores for cleavage site prediction and RODEO.") template = FileTemplate(path.get_full_path(__file__, "templates", "sidepanel.html")) html.add_sidepanel_section("Lasso peptides", template.render(results=motifs_in_region, tooltip=side_tooltip)) return html
def generate_html(region_layer: RegionLayer, results: LassoResults, record_layer: RecordLayer, _options_layer: OptionsLayer) -> HTMLSections: """ Generates HTML for the module """ html = HTMLSections("lassopeptides") motifs_in_region = {} for locus in results.motifs_by_locus: if record_layer.get_cds_by_name(locus).is_contained_by( region_layer.region_feature): motifs_in_region[locus] = results.motifs_by_locus[locus] template = FileTemplate( path.get_full_path(__file__, "templates", "details.html")) html.add_detail_section("Lasso peptides", template.render(results=motifs_in_region)) template = FileTemplate( path.get_full_path(__file__, "templates", "sidepanel.html")) html.add_sidepanel_section("Lasso peptides", template.render(results=motifs_in_region)) return html
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_domains = build_json_data(records, results, options) write_regions_js(json_records, options.output_dir, js_domains) with open(os.path.join(options.output_dir, 'index.html'), 'w') as result_file: template = FileTemplate( path.get_full_path(__file__, "templates", "overview.html")) options_layer = OptionsLayer(options) record_layers_with_regions = [] record_layers_without_regions = [] results_by_record_id = { } # type: Dict[str, Dict[str, module_results.ModuleResults]] for record, record_results in zip(records, results): if record.get_regions(): record_layers_with_regions.append( RecordLayer(record, None, options_layer)) else: record_layers_without_regions.append( RecordLayer(record, None, options_layer)) results_by_record_id[record.id] = record_results regions_written = sum(len(record.get_regions()) for record in records) job_id = os.path.basename(options.output_dir) page_title = "" if options.html_title: page_title = options.html_title elif options.sequences: page_title, _ = os.path.splitext( os.path.basename(options.sequences[0])) elif options.reuse_results: page_title, _ = os.path.splitext( os.path.basename(options.reuse_results)) html_sections = generate_html_sections(record_layers_with_regions, results_by_record_id, options) doc_url = options.urls.docs_baseurl + "understanding_output/#the-antismash-5-region-concept" svg_tooltip = ( "Shows the layout of the region, marking coding sequences and areas of interest. " "Clicking a gene will select it and show any relevant details. " "Clicking an area feature (e.g. a candidate cluster) will select all coding " "sequences within that area. Double clicking an area feature will zoom to that area. " "Multiple genes and area features can be selected by clicking them while holding the Ctrl key." ) svg_tooltip += "<br>More detailed help is available <a href='%s' target='_blank'>here</a>." % doc_url aux = template.render( records=record_layers_with_regions, options=options_layer, version=options.version, extra_data=js_domains, regions_written=regions_written, sections=html_sections, results_by_record_id=results_by_record_id, config=options, job_id=job_id, page_title=page_title, records_without_regions=record_layers_without_regions, svg_tooltip=svg_tooltip) result_file.write(aux)