1. References

1.1. Reports

Base classes to create HTML reports easily

class Report(searchpath=None, filename='index.html', directory='report', overwrite=True, verbose=True, template_filename='index.html', extra_css_list=[], extra_js_list=[], init_report=True)[source]

A base class to create HTML pages

The Report is used to

  1. fetch Jinja templates and css from a user directory (by default a generic set of files is provided as an example
  2. fetch the CSS and images
  3. hold variables and contents within a dictionary (jinja)
  4. Create the HTML document in a local directory.
from report import Report
r = Report()
r.create_report(onweb=True)

The next step is for you to copy the templates in a new directory, edit them and fill the jinja attribute to fulfil your needs:

from report import Report
r = Report("myreport_templates")
r.jinja["section1"] = "<h1></h1>" 
r.create_report() 

Constructor

Parameters:
  • searchpath – where to find the jina templates. If not provided, uses the generic template
  • filename – output filename (default to index.html)
  • directory – defaults to report
  • overwrite – default to True
  • verbose – default to True
  • template_filename – entry point of the jinja code
  • extra_css_list – where to find the extra css
  • extra_js_list – where to find the extra css
  • init_report (bool) – init the report that is create the directories to store css and JS.
abspath

The absolute path of the document (read only)

add_dependencies = None

flag to add dependencies

create_report(onweb=True)[source]
directory

The directory where to save the HTML document

filename

The filename of the HTML document

get_table_dependencies(package='reports')[source]

Returns dependencies of the pipeline as an HTML/XML table

The dependencies are the python dependencies as returned by pkg_resource module.

get_time_now()[source]

Returns a time stamp

onweb()[source]

Open the HTML document in a browser

to_html()[source]
write()[source]

1.2. HTMLTable

Base classes to create HTML reports easily

class HTMLTable(df, name=None, **kargs)[source]

Handler to export dataframe into HTML table.

Dataframe in Pandas already have a to_html method to export the dataframe into a HTML formatted table. However, we provide here a few handy features:

  • Takes each cell in a given column and creates an HTML reference in each cell. See add_href() method.
  • add an HTML background into cells (numeric content) of a given column using different methods (e.g., normalise). See add_bgcolor()
import pandas as pd
df = pd.DataFrame({'A':[1,2,10], 'B':[1,10,2]})
from gdsctools import HTMLTable
html = HTMLTable(df)

Note

similar project exists such as prettytable but could not do exactly what we wanted at the time gdsctools was developed.

Note

Could be moved to biokit or easydev package.

Constructor

Parameters:
  • df (dataframe) – a pandas dataframe to transform into a table
  • name (str) – not used yet

There is an pd_options attribute to reduce the max column width or the precision of the numerical values.

add_bgcolor(colname, cmap='copper', mode='absmax', threshold=2)[source]

Change column content into HTML paragraph with background color

Parameters:
  • colname
  • cmap – a colormap (matplotlib) or created using colormap package (from pypi).
  • mode – type of normalisation in ‘absmax’, ‘max’, ‘clip’ (see details below)
  • threshold – used if mode is set to ‘clip’

Colormap have values between 0 and 1 so we need to normalised the data between 0 and 1. There are 3 mode to normalise the data so far.

If mode is set to ‘absmax’, negatives and positives values are expected to be found in a range from -inf to inf. Values are scaled in between [0,1] X’ = (X / M +1) /2. where m is the absolute maximum. Ideally a colormap should be made of 3 colors, the first color used for negative values, the second for zeros and third color for positive values.

If mode is set to ‘clip’, values are clipped to a max value (parameter threshold and values are normalised by that same threshold.

If mode is set to ‘max’, values are normalised by the max.

add_href(colname, url=None, newtab=False, suffix=None)[source]

default behaviour: takes column content and put into:

<a href={content}.html>content</a>

This is used to link to local files. If url is provided, you typically want to link to an external url where the content is an identifier:

<a href={url}{content}>content</a>

Note that in the first case, .html is appended but not in the second case, which means cell’s content should already have the .html Also in the second case, a new tab is open whereas in the first case the url is open in the current tab.

Note

this api may change in the future.

sort(name, ascending=True)[source]
to_html(index=False, escape=False, header=True, collapse_table=True, class_outer='table_outer', **kargs)[source]

Return HTML version of the table

This is a wrapper of the to_html method of the pandas dataframe.

Parameters:
  • index (bool) – do not include the index
  • escape (bool) – do not escape special characters
  • header (bool) – include header
  • collapse_table (bool) – long tables are shorten with a scroll bar
  • kargs – any parameter accepted by pandas.DataFrame.to_html()