def render(self): if len(self.highlights) == 0 \ and len(self.notes) == 0 \ and len(self.bookmarks) == 0: return with div(): h2(self.title) if self.authors is not None: p(f'Authors: {self.authors}') p(f'File: {self.file_name}') if len(self.bookmarks) > 0: h3('Bookmarks') with ol(): for bookmark in self.bookmarks: with li(): bookmark.render() if len(self.highlights) > 0: h3('Highlights') with ol(): for highlight in self.highlights: with li(): highlight.render() if len(self.notes) > 0: h3('Notes') with ol(): for note in self.notes: with li(): note.render()
def close_html_doc(html_doc): with html_doc.body.children[-1]: assert html_doc.body.children[-1]['class'] == 'container-fluid' with tags.div(id="search_modal"): tags.attr(cls="modal fade") with html_doc: # add footnotes content of this section: with tags.ol(id="footnotes"): for (id) in html_doc.footnote_ids_of_this_html_doc: footnote = word_doc_footnotes.footnotes_part.notes[id + 1] assert footnote.id == id htmler.add_footnote_to_output(footnote.paragraphs) # add placeholder for searching tags.comment("search_placeholder") place_holder = "<!--search_placeholder-->" with open("input_web/stub_search.html", 'r') as file: search_html = file.read() html_doc_name = html_doc.index name = "debug_%s.html" % html_doc_name with open("output/" + name, 'w') as f: f.write(html_doc.render(pretty=True).encode('utf8')) replace_in_file("output/" + name, place_holder, search_html) name = "%s.html" % html_doc_name with open("output/" + name, 'w') as f: f.write(html_doc.render(pretty=False).encode('utf8')) print "Created ", name replace_in_file("output/" + name, place_holder, search_html)
def makeHtml(path, fileName, sitename, authorname, usecss, usejs): doc = dominate.document(title=sitename) with doc.head: if (usecss.lower() == "y"): link(rel='stylesheet', href='style.css') if (usejs.lower() == "y"): script(type='text/javascript', src='script.js') with meta(): attr(author=authorname) with doc: with div(id='header').add(ol()): for i in ['home', 'about', 'contact']: li(a(i.title(), href='/%s.html' % i)) with div(): attr(cls='body') p('Lorem ipsum..') if not os.path.exists("./" + path): os.makedirs("./" + path) f = open("./" + path + "/" + fileName, 'w+') f.write(str(doc)) f.close() if (usejs.lower() == "y"): if not os.path.exists("./" + sitename + "/js"): os.makedirs("./" + sitename + "/js") if (usecss.lower() == "y"): if not os.path.exists("./" + sitename + "/css"): os.makedirs("./" + sitename + "/css")
def close_html_doc(html_doc): with html_doc.body.children[-1]: assert html_doc.body.children[-1]['class'] == 'container-fluid' with tags.div(id="search_modal"): tags.attr(cls="modal fade") with html_doc: # add footnotes content of this section: with tags.ol(id="footnotes"): for (id) in html_doc.footnote_ids_of_this_html_doc: footnote = word_doc_footnotes.footnotes_part.notes[id + 1] assert footnote.id == id htmler.add_footnote_to_output(footnote.paragraphs) # add placeholder for searching tags.comment("search_placeholder") place_holder = "<!--search_placeholder-->" with open("input_web/stub_search.html", 'r') as file: search_html = file.read() html_doc_name = html_doc.index name = "debug_%s.html" % html_doc_name with open("output/" + name, 'w') as f: f.write(html_doc.render(inline=False).encode('utf8')) replace_in_file("output/" + name, place_holder, search_html) name = "%s.html" % html_doc_name with open("output/" + name, 'w') as f: f.write(html_doc.render(inline=True).encode('utf8')) print "Created ", name replace_in_file("output/" + name, place_holder, search_html)
def new_user(form, ws_url, errors=None): title = 'New User' d = _doc(title) with d: with t.form(action=form.action, method='post'): with t.fieldset(): t.legend(title) _errors(errors) with t.ol(cls='step_numbers'): with t.li(): t.p('First, create a one-word username for yourself (lowercase, no spaces)...' ) _text_input( *form.nv('new_username'), ('required', 'autofocus'), { 'pattern': valid.re_username, 'oninput': 'check_username(this.value)' }, 'Type new username here', _invalid(valid.inv_username, form.invalid('new_username'))) _invalid(valid.inv_username_exists, False, 'username_exists_message') with t.li(): t.p("Next, invent a password; type it in twice to make sure you've got it..." ) _text_input('password', None, ('required', ), {'pattern': valid.re_password}, 'Type new password here', _invalid(valid.inv_password, form.invalid('password')), type_='password') _text_input('password_confirmation', None, ('required', ), None, 'Type password again for confirmation', _invalid( valid.inv_password_confirmation, form.invalid('password_confirmation'), 'password_match_message'), type_='password') with t.li(): t.p("Finally, type in an email address that can be used if you ever need a password reset (optional, but this may be very useful someday!)..." ) _text_input( *form.nv('email'), None, {'pattern': valid.re_email}, 'Type email address here', _invalid(valid.inv_email, form.invalid('email'))) t.input_(type="submit", value="Done!") t.script(_js_validate_new_user_fields()) t.script(_js_check_username(ws_url)) return d.render()
def generateHtml(): with open(path.join(current_dir, '../changelog/', 'storage.json'), 'r') as f: data = json.load(f)[::-1] doc = document(title='Changelog - lkellar.org') articles = [] with doc.head: tags.link(rel='stylesheet', href='style.css') tags.meta(charset="UTF-8") tags.meta(name="description", content="A log of all changes made on lkellar.org") tags.meta(name="viewport", content="width=device-width, initial-scale=1") tags.link(rel="alternate", title="Changelog Feed", type="application/json", href="https://lkellar.org/changelog/feed.json") with doc: with tags.nav().add(tags.ol()): with tags.li(): tags.a("Home", href="../") tags.li("Changelog") with tags.main(): tags.h1('Changelog') for entry in data: tags.hr() article_content = tags.article() with article_content: tags.h2( f'{entry["title"]} - {entry["date"].split("T")[0]}', id=f'{entry["title"]} - {entry["date"]}'.replace( ' ', ''.lower())) list_content = tags.ul() with list_content: for line in entry['items']: line = urls.sub(r'<a href="\2">\1</a>', line) tags.li(raw(line)) articles.append((f'{entry["title"]} - {entry["date"]}'.replace( ' ', ''.lower()), list_content.render(), entry["date"], entry['title'])) with open(path.join(current_dir, '../changelog/', 'index.html'), 'w') as f: f.write(doc.render()) generateFeed(articles)
def slide_indicator(num): """ Helper function that controls how image slide count works """ with tag.ol(_class="carousel-indicators") as o: for cnt in range(num): if cnt == 0: tag.li(data_target="#carousel_controls", data_slide_to="0", _class="active") else: tag.li(data_target="#carousel_controls", data_slide_to="%s" % str(cnt)) return o
def dict_html(container, query, dict_, source, target): container.add(div(query, cls='word')) container.add(div(raw( f'{langs[source]} -> {langs[target[0]]}'), cls='lang')) for w in dict_: def_box = container.add(div()).add(ul()) defin = dict_[w] def_box.add(li(f'{w} ({defin["word_type"]})'.lower(), cls='definition')) synonyms = def_box.add(ol()) for syn in defin['variants']: if not syn[1]: synonyms.add(li(syn[0], cls='synonyms')) else: syn_word = synonyms.add(li(f'{syn[0]} ', cls='synonyms has_example')) syn_word.add(sup(syn[1]))
def create_html_summary(n_genomes, n_clusters, n_big_clusters): doc = dominate.document(title='Genomes mapping summary') with doc.head: tags.style(""" body { background-color: #e1f5fe; font-family: sans-serif; font-size: 18px; } .container { width: 80%; margin: 0 auto; background-color: white; padding: 15px 30px; } span { font-weight: 600; } cite { border-left: solid black 3px; font-size: 12px; } .big_img { width: 100%; } """) with doc.body: with tags.div(cls='container'): tags.h1('Creating the total list of genes for {}'.format(ORGANISM)) tags.p( raw('Total list has <span>{} genomes</span>'.format(n_genomes) + ' and <span>{} clusters</span>.'.format(n_clusters))) tags.img(src='../plots/clusters_sizes.png', alt='clusters sizes') tags.p( raw('There are <span>{} clusters</span>'.format(n_big_clusters) + ' of <span>size > 5</span>.')) tags.img(src='../plots/n_clusters_by_threshold.png', alt='N clusters by threshold') tags.p( raw('Check the <i>results/</i> folder for files, which you can use for the following analysis:' )) with tags.ul(): tags.li( raw('<i><b>proteome.faa</b></i> — fasta file with all the protein coding genes from' + 'all the genomes. Gene names are concatenated with their genome ID. There is also' + 'some extra information in brackets. Example of the header:<br> ' + '<cite>>WP_000002298.1[genome:GCF_002741575.1_ASM274157v1_] MULTISPECIES: alpha-D-ribose' + ' 1-methylphosphonate 5-phosphate C-P-lyase [Enterobacteriaceae]' + ' [start:4548948] [end:4549793] [genome:GCF_002741575.1_ASM274157v1_]</cite>' )) tags.li( raw('<i><b>genes_info.tsv</b></i> — tab separated table with 2 columns: <b>gene</b> and' + ' <b>info</b>. Contains information for each gene in the proteome. Information' + ' is extracted from fasta header.')) tags.li( raw('<i><b>cluster_info.json</b></i> — contains counted information about the genes in' + ' each cluster. You can use it to take a look at what genes the cluster consists of' + ', and to set a name for the cluster. Here is the example of visualisation' + ' of this information for 1 cluster:')) tags.img(src='../images/cluster_names.png') tags.li( raw('<i><b>total_list.csv</b></i> — table with clusters in rows and genomes in columns. Number' + ' on the intersection means, how many genes from this cluster the genome contains.' )) with tags.li( raw('<i><b>clusters.csv</b></i> — data frame with following columns:' )): with tags.ol(): tags.li(raw('<i>cluster</i> — cluster of a sequence')) tags.li( raw('<i>representative</i> — boolean variable, which indicates, if the given' + ' sequence is representative')) tags.li( raw('<i>gene</i> — name of the sequence from fasta header with appended genome ID' )) tags.li( raw('<i>length</i> — length of the gene\'s sequence' )) tags.li( raw('<i>identity</i> — identity of a sequence to representative sequence' + ' of its cluster')) tags.li( raw('<i>name</i> — name of the sequence from fasta header without appended genome ID' )) tags.li( raw('<i>genome</i> — genome id from fasta header')) tags.li( raw('<i>info</i> — information about gene from its fasta header' )) tags.p( raw('Visualisation of the total list of genes. Each row represents a genome. Each column' + ' represents a cluster (only clusters with <b>size > 5</b> included).' + ' If the genome has the gene, there is a white dot on the intersection.' + ' Otherwise — a black dot.')) tags.img(src='../plots/genes_presence.png', alt='genes presence', cls='big_img') tags.p( raw('Clustering of genes. These illustrations are for you to take a look at the data.' + ' For higher quality illustrations, and the following analysis it is recommended to perform ' + 'these operations in <a href="https://software.broadinstitute.org/morpheus/">Morpheus tool</a>' + ' (also avialable as <a href="https://github.com/cmap/morpheus.R">R package</a>).' )) tags.img(src='../plots/genes_presence_clustering.png', alt='genes presence clustering') tags.p( raw('If you had any problems during the work of the program, or have any notes, please contact' + ' <a href="mailto:[email protected]">[email protected]</a>' )) with open('./results/summary.html', 'w') as f: f.write(str(doc))
import dominate from dominate import tags as dtags doc = dominate.document(title="TKP") with doc.head: dtags.link(rel="stylesheet", href="style.css", type="text/css") with open("gtag.html", "r") as gtag: content = gtag.read() # print(content) dominate.util.raw(content) with doc: with dtags.div(id='header').add(dtags.ol()): for i in ['home', 'about', 'contact']: dtags.li(dtags.a(i.title(), href='/%s.html' % i)) with dtags.div(): dtags.attr(cls='body') dtags.p('Lorem ipsum..') print(doc)
def generate_html_document(trackers: List[Tracker], sequences: List[Sequence], results, storage: Storage): def insert_figure(figure): buffer = io.StringIO() figure.save(buffer, "SVG") raw(buffer.getvalue()) def insert_mplfigure(figure): buffer = io.StringIO() figure.savefig(buffer, format="SVG", bbox_inches='tight', pad_inches=0.01, dpi=200) raw(buffer.getvalue()) def add_style(name, linked=False): if linked: link(rel='stylesheet', href='file://' + os.path.join(os.path.dirname(__file__), name)) else: style(read_resource(name)) def add_script(name, linked=False): if linked: script(type='text/javascript', src='file://' + os.path.join(os.path.dirname(__file__), name)) else: with script(type='text/javascript'): raw("//<![CDATA[\n" + read_resource(name) + "\n//]]>") logger = logging.getLogger("vot") table_header, table_data, table_order = extract_measures_table( trackers, results) plots = extract_plots(trackers, results) legend = StyleManager.default().legend(Tracker) doc = dominate.document(title='VOT report') linked = check_debug() with doc.head: add_style("pure.css", linked) add_style("report.css", linked) add_script("jquery.js", linked) add_script("table.js", linked) add_script("report.js", linked) with doc: h1("VOT report") with ol(cls="metadata"): li('Toolkit version: ' + toolkit_version()) li('Created: ' + datetime.datetime.now().isoformat()) if len(table_header[2]) == 0: logger.debug("No measures found, skipping table") else: with table( cls= "overview-table pure-table pure-table-horizontal pure-table-striped" ): with thead(): with tr(): th() [ th(c[0].identifier, colspan=c[1]) for c in merge_repeats(table_header[0]) ] with tr(): th() [ th(c[0].title, colspan=c[1]) for c in merge_repeats(table_header[1]) ] with tr(): th("Trackers") [ th(c.abbreviation, data_sort="int" if order else "") for c, order in zip(table_header[2], table_order) ] with tbody(): for tracker, data in table_data.items(): with tr(data_tracker=tracker.reference): with td(): insert_mplfigure(legend.figure(tracker)) span(tracker.label) for value, order in zip(data, table_order): insert_cell( value, order[tracker] if not order is None else None) for experiment, experiment_plots in plots.items(): if len(experiment_plots) == 0: continue h2("Experiment {}".format(experiment.identifier), cls="experiment") with div(cls="plots"): for title, plot in experiment_plots: with div(cls="plot"): p(title) insert_figure(plot) with storage.write("report.html") as filehandle: filehandle.write(doc.render())
def generate_html_document(trackers: List[Tracker], sequences: List[Sequence], results, storage: Storage): import io import dominate from dominate.tags import h1, h2, table, thead, tbody, tr, th, td, div, p, li, ol, span, style, link, script from dominate.util import raw order_classes = {1: "first", 2: "second", 3: "third"} def insert_figure(): buffer = io.StringIO() plt.savefig(buffer, format="SVG", bbox_inches='tight', transparent=True) raw(buffer.getvalue()) plt.close() def insert_cell(value, order): attrs = dict(data_sort_value=order, data_value=value) if order in order_classes: attrs["cls"] = order_classes[order] td(_format_value(value), **attrs) def add_style(name, linked=False): if linked: link(rel='stylesheet', href='file://' + os.path.join(os.path.dirname(__file__), name)) else: style(_read_resource(name)) def add_script(name, linked=False): if linked: script(type='text/javascript', src='file://' + os.path.join(os.path.dirname(__file__), name)) else: with script(type='text/javascript'): raw("//<![CDATA[\n" + _read_resource(name) + "\n//]]>") logger = logging.getLogger("vot") legend = Legend() table_header, table_data, table_order = _extract_measures_table(trackers, results) graphs = _extract_graphs(trackers ,results, legend) doc = dominate.document(title='VOT report') linked = check_debug() with doc.head: add_style("pure.css", linked) add_style("report.css", linked) add_script("jquery.js", linked) add_script("table.js", linked) add_script("report.js", linked) with doc: h1("VOT report") with ol(cls="metadata"): li('Toolkit version: ' + version) li('Created: ' + datetime.datetime.now().isoformat()) if len(table_header[2]) == 0: logger.debug("No measures found, skipping table") else: with table(cls="measures pure-table pure-table-horizontal pure-table-striped"): with thead(): with tr(): th() [th(c[0].identifier, colspan=c[1]) for c in _merge_repeats(table_header[0])] with tr(): th() [th(c[0].name, colspan=c[1]) for c in _merge_repeats(table_header[1])] with tr(): th("Trackers") [th(c.abbreviation, data_sort="int" if order else "") for c, order in zip(table_header[2], table_order)] with tbody(): for tracker, data in table_data.items(): with tr(): number = legend.number(tracker.identifier) with td(id="legend_%d" % number): legend.figure(tracker.identifier) insert_figure() span(tracker.label) for value, order in zip(data, table_order): insert_cell(value, order[tracker] if not order is None else None) for experiment, experiment_graphs in graphs.items(): if len(experiment_graphs) == 0: continue h2("Experiment {}".format(experiment.identifier), cls="experiment") with div(cls="graphs"): for title, graph in experiment_graphs: with graph, div(cls="graph"): p(title) insert_figure() with storage.write("report.html") as filehandle: filehandle.write(doc.render())