예제 #1
0
def figure_to_vdom_image(figure):
    buf = io.BytesIO()
    figure.savefig(buf, format='png')
    buf.seek(0)
    string = base64.b64encode(buf.read())

    return vdomh.div(vdomh.img(src='data:image/png;base64,' +
                               urllib.parse.quote(string)),
                     style={"display": "inline-block"})
예제 #2
0
async def get_dashboard():
    example = div(
        span(img(src=image_url, style=dict(width='100', heigth='100')),
             h1('Smart 311 Dashboard')),
        p('Written in Python, 100%'),
        topten(),
        p('Top ten complaint types'),
    ).to_html()

    return HTMLResponse(content=example)
예제 #3
0
def vdom_modisco(mr, figdir, total_counts, dfp=None, is_open=True, **kwargs):
    return div([
        vdom_metacluster(mr,
                         metacluster,
                         figdir,
                         total_counts,
                         dfp=dfp,
                         is_open=is_open,
                         **kwargs) for metacluster in mr.metaclusters()
        if len(mr.patterns(metacluster)) > 0
    ])
예제 #4
0
def vdm_heatmaps(seqlets,
                 d,
                 included_samples,
                 tasks,
                 pattern,
                 top_n=None,
                 pssm_fig=None,
                 opened=False,
                 resize_width=200):
    ex_signal, ex_contrib_profile, ex_contrib_counts, ex_seq, sort_idx = get_signal(
        seqlets, d, included_samples, tasks, resize_width=resize_width)

    if top_n is not None:
        sort_idx = sort_idx[:top_n]
    return div(
        details(summary("Sequence:"),
                pssm_fig,
                br(),
                fig2vdom(
                    heatmap_sequence(ex_seq,
                                     sort_idx=sort_idx,
                                     figsize_tmpl=(10, 15),
                                     aspect='auto')),
                open=opened),
        details(
            summary("ChIP-nexus counts:"),
            fig2vdom(
                multiple_plot_stranded_profile(
                    ex_signal, figsize_tmpl=(20 / len(ex_signal), 3))),
            # TODO - change
            fig2vdom(
                multiple_heatmap_stranded_profile(ex_signal,
                                                  sort_idx=sort_idx,
                                                  figsize=(20, 20))),
            open=opened),
        details(summary("Contribution scores (profile)"),
                fig2vdom(
                    multiple_heatmap_contribution_profile(ex_contrib_profile,
                                                          sort_idx=sort_idx,
                                                          figsize=(20, 20))),
                open=opened),
        details(summary("Contribution scores (counts)"),
                fig2vdom(
                    multiple_heatmap_contribution_profile(ex_contrib_counts,
                                                          sort_idx=sort_idx,
                                                          figsize=(20, 20))),
                open=opened))
예제 #5
0
def write_modisco_table(df,
                        output_dir,
                        report_url=None,
                        prefix='pattern_table',
                        exclude_when_writing=["logo pwm", "logo imp"],
                        doc=DOC,
                        write_csv=True):
    """Write the pattern table to as .html and .csv
    """
    from vdom.helpers import h2, h3, p, ul, ol, li, div, b
    output_dir = Path(output_dir)
    df = df.copy()

    if write_csv:
        cols_for_csv = [c for c in df.columns if c not in exclude_when_writing]
        df[cols_for_csv].to_csv(output_dir / f'{prefix}.csv', index=False)

    if report_url is not None:
        df.pattern = [pattern_url(p, report_url) for p in df.pattern]
    df.columns = [c.replace(" ", "<br>") for c in df.columns]
    # Add instructions
    instructions = div(
        h2("Column description"),
        ul([li(b(k), ": ", v) for k, v in doc.items()]),
        h2("Table interaction options"),
        ul([
            li(b("Re-order columns: "),
               "Drag column headers using the mouse pointer"),
            li(
                b("Sort w.r.t single column: "),
                "Click on the column header to sort the table with respect two that "
                "column in an ascending order and click again to sort in a descending order."
            ),
            li(
                b("Sort w.r.t multiple columns: "),
                "Hold shift and click multiple column headers to sort w.r.t. multiple columns"
            ),
            li(b("View logo images: "),
               "Right-click on the images and choose 'Open image in new tab'"),
            li(b("Select muliple rows: "),
               "Click on the row to select/de-select it."),
            li(b("Get more information about the pattern: "),
               "Follow the link in the pattern column."),
        ]))
    write_datatable_html(df, output_dir / f"{prefix}.html",
                         instructions.to_html())
예제 #6
0
def vdom_motif_pair(motif_pair_lpdata,
                    dfab,
                    profile_mapping,
                    figures_dir,
                    figures_url,
                    profile_width=200,
                    cache=False,
                    **kwargs):
    from basepair.exp.chipnexus.spacing import remove_edge_instances
    out = []
    os.makedirs(figures_dir, exist_ok=True)
    for motif_pair_name, lpdata in tqdm(motif_pair_lpdata.items()):

        motif_pair = list(motif_pair_name.split("<>"))
        dfab_subset = remove_edge_instances(
            dfab[dfab.motif_pair == motif_pair_name],
            profile_width=profile_width)
        out.append(
            template_vdom_motif_pair(motif_pair[0],
                                     motif_pair,
                                     lpdata,
                                     dfab_subset,
                                     profile_mapping,
                                     figures_dir=figures_dir,
                                     figures_url=figures_url,
                                     cache=cache,
                                     **kwargs))
        if motif_pair[0] != motif_pair[1]:
            out.append(
                template_vdom_motif_pair(motif_pair[1],
                                         motif_pair,
                                         lpdata,
                                         dfab_subset,
                                         profile_mapping,
                                         figures_dir=figures_dir,
                                         figures_url=figures_url,
                                         cache=True,
                                         **kwargs))
        # break
    return div(ul([li(elem) for elem in out], start=0))
예제 #7
0
def dashboard():
    return div(
        span(img(src=image_url, style=dict(width='100', heigth='100')),
             h1('Smart 311 Dashboard')), img(width='400', src=barplot_url),
        p('Written in Python, 100%'))
예제 #8
0
def _badHTML(data):
    # TODO: use xml.dom.minidom as dangerouslySetInnerHTML should be blocklisted in frontend
    return div(dangerouslySetInnerHTML={'__html': data})
예제 #9
0
from IPython.display import display
from vdom.helpers import h1, p, img, div, b

display(
    div(
        h1('Our Incredibly Declarative Example'),
        p('Can you believe we wrote this ', b('in Python'), '?'),
        img(src="https://media.giphy.com/media/xUPGcguWZHRC2HyBRS/giphy.gif"),
        p('What will ', b('you'), ' create next?'),
    ))