Ejemplo n.º 1
0
    def _repr_html_(self):
        """Output for the Jupyter notebook."""
        is_supergroup = self.__contains_groups()

        rsl = []
        rsl.append(
            v.tr(v.th("Pos.", style={"text-align": "right"}),
                 v.th("Bezeichnung", style={"text-align": "left"}),
                 v.th("Betrag", style={"text-align": "right"}),
                 v.th("Anmerkung", style={"text-align": "left"})), )
        rsl += self._vdom(is_supergroup)
        if is_supergroup:
            rsl.append(v.tr(v.td(), v.td(), v.td(), v.td()))
            rsl.append(
                v.tr(
                    v.td(),
                    v.td(v.u(v.b(f"Total {self.name}"))),
                    v.td(
                        v.u(
                            v.b(str(self.total())),
                            style={"text-align": "right"},
                        )),
                    v.td(),
                ), )
        layout = v.table(*rsl, )
        return layout.to_html()
Ejemplo n.º 2
0
    def _vdom(self, is_supergroup: bool):
        rsl = []
        if not is_supergroup:
            rsl.append(
                v.tr(
                    v.td(v.b(self.code), style={"text-align": "right"}),
                    v.td(v.b(self.name), style={"text-align": "left"}),
                    v.td(),
                    v.td(),
                ), )

        for item in self.items:
            # Blank line before new group.
            if isinstance(item, Group) and not is_supergroup:
                rsl.append(v.tr(v.td(), v.td(), v.td(), v.td()))
            if isinstance(item, Entry) and is_supergroup:
                # Render single entry in super-group.
                rsl.append(v.tr(v.td(), v.td(), v.td(), v.td()))
                rsl += self._from_entry(item)._vdom(False)
            else:
                # Render Group or Entry.
                rsl += item._vdom(False)

        if not is_supergroup:
            rsl.append(
                v.tr(
                    v.td(),
                    v.td(v.b("Total {}".format(self.name)),
                         style={"text-align": "left"}),
                    v.td(v.b(str(self.total())), style={"text-align":
                                                        "right"}),
                    v.td(),
                ))

        return rsl
Ejemplo n.º 3
0
def template_vdom_metacluster(name,
                              n_patterns,
                              n_seqlets,
                              important_for,
                              patterns,
                              is_open=False):
    return details(summary(
        b(name), f", # patterns: {n_patterns},"
        f" # seqlets: {n_seqlets}, "
        "important for: ", b(important_for)),
                   ul([li(pattern) for pattern in patterns], start=0),
                   id=name,
                   open=is_open)
Ejemplo n.º 4
0
def template_vdom_motif_pair(main_motif,
                             motif_pair,
                             lpdata,
                             dfab,
                             profile_mapping,
                             figures_dir,
                             figures_url,
                             cache=False,
                             **kwargs):

    motif_figs = []
    other = motif_pair[0] if motif_pair[0] != main_motif else motif_pair[1]
    # HACK - pass the tasks
    for task in ['Oct4', 'Sox2', 'Nanog', 'Klf4']:
        figs, dist_seq = motif_pair_figs(main_motif, task, motif_pair, lpdata,
                                         dfab, **kwargs)
        motif_figs += figs
        if task == profile_mapping[main_motif]:
            dist_seq_fig = dist_seq

    return details(
        summary(b(main_motif), f" (perturb {other})"), *[
            details(
                summary(k), *[
                    cache_fig(x,
                              figures_dir,
                              figures_url,
                              str(i) + "-" + main_motif + "<>" + other + "-" +
                              k,
                              width=840 if k is not "Distance" else 400,
                              cache=cache) for i, x in enumerate(v)
                ]) for k, v in dist_seq_fig + motif_figs
        ])
Ejemplo n.º 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())
Ejemplo n.º 6
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?'),
    ))