Skip to content

Commit

Permalink
add_table_func
Browse files Browse the repository at this point in the history
  • Loading branch information
paulzierep committed Nov 1, 2023
1 parent 30cb077 commit f4ecf28
Show file tree
Hide file tree
Showing 7 changed files with 11,062 additions and 0 deletions.
89 changes: 89 additions & 0 deletions bin/create_interactive_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import argparse

import pandas as pd


def generate_table(
tsv_path: str,
template_path: str,
output_path: str,
) -> None:
df = pd.read_csv(tsv_path, sep="\t")

# need extra colum to allow expand
df["Expand"] = ""

df = df.fillna("")

# TODO maybe allow comunities to modify
columns = [
"Expand",
"Galaxy wrapper id",
"Galaxy wrapper version",
"Conda version",
"Conda id",
"Status",
"bio.tool id",
"bio.tool name",
"EDAM operation",
"EDAM topic",
"Description",
"bio.tool description",
"Status",
"Source",
"ToolShed categories",
"ToolShed id",
"Galaxy wrapper owner",
"Galaxy wrapper source",
]

df = df[df["To keep"]]

df = df.loc[:, columns]
df = df.reindex(columns=columns)

df.to_html("temp_tools_table.html",
border=0,
table_id="dataframe",
classes=["display", "nowrap"],
index=False)

with open(template_path, "r") as template_path:
template = template_path.read()

with open("temp_tools_table.html", "r") as table_path:
table = table_path.read()

final_html_output = template.replace("COMMUNITY_TABLE", table)

with open(output_path, "w") as output:
output.write(final_html_output)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Create interactive table from \
tsv using a template, where COMMUNITY_TABLE is replaced \
by the rendered table"
)
parser.add_argument(
"--table",
"-ta",
required=True,
help="Path to table",
)
parser.add_argument(
"--template",
"-te",
required=True,
help="Path to html template",
)
parser.add_argument(
"--output",
"-out",
required=True,
help="Path to html output",
)

args = parser.parse_args()
generate_table(args.table, args.template, args.output)
8 changes: 8 additions & 0 deletions bin/create_interactive_table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

mkdir -p 'results/microgalaxy'

python bin/create_interactive_table.py \
--table 'results/microgalaxy/tools.tsv' \
--template 'data/microgalaxy/datatable_template.html' \
--output 'results/microgalaxy/index.html'
58 changes: 58 additions & 0 deletions data/microgalaxy/datatable_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/searchbuilder/1.6.0/js/dataTables.searchBuilder.min.js"></script>
<script src="https://cdn.datatables.net/datetime/1.5.1/js/dataTables.dateTime.min.js"></script>

<script src="https://cdn.datatables.net/responsive/2.5.0/js/dataTables.responsive.min.js"></script>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.3/css/responsive.dataTables.min.css">

<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/searchbuilder/1.6.0/css/searchBuilder.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/datetime/1.5.1/css/dataTables.dateTime.min.css">

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

<style type="text/css">
.tooltip {
font-family: Georgia;
font-size: 18px;
}
.tooltip .tooltip-inner {
background-color: #00FFFF;
color: #000000;
min-width: 400px;
}
</style>

<script>
$(document).ready(function() {
$('#dataframe').DataTable( {
"sScrollX": "100%",
"dom": "Qlfrtip",

responsive: {
details: {
type: 'column'
}
},
"bAutoWidth": false,
columnDefs: [ {
className: 'control',
orderable: false,
targets: [ 0 ],
width: 100,
},
{ type: 'natural', targets: 1 } // allow normal sorting
],

});
});
</script>

<div class="display nowrap" style="width:80%" width="100%">

COMMUNITY_TABLE

</div>
Loading

0 comments on commit f4ecf28

Please sign in to comment.