Skip to content

Commit

Permalink
Support flat config and table_id as a group. Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsavelyev committed Nov 20, 2023
1 parent 40d8ff1 commit 53e016c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
24 changes: 24 additions & 0 deletions docs/core/reports/customisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,27 @@ table_columns_visible:
Note that you can set these values to `True` to show columns that would otherwise be hidden
by default.

It can also be done for other module-specific tables in the report, where instead of
the _Group_, you'd need to specify the table ID. To get the table ID, click
_Configure Columns_ above the table, and look for the first line above the table contents.
It should say something like "Uncheck the tick box ... Table ID: `quast_table`".

For example, to hide the _# misassemblies_ column in the _Assembly Statistics_ table
from QUAST, you would use the following config:

```yaml
table_columns_visible:
quast_table:
"# misassemblies": false
```

Or you can pass the column ID directly:

```yaml
table_columns_visible:
"# misassemblies": false
```

### Column order

In the same way, you can force a column to appear at the start or end of the table, or
Expand Down Expand Up @@ -796,6 +817,9 @@ table_columns_name:
percent_gc: "Percent of bases that are GC"
```

It will also work for module-specific tables by using the table ID instead of the module name, and specifying the column ID directly.
See the [Hiding columns](#hiding-columns) section above for more details.

### Conditional formatting

It's possible to highlight values in tables based on their value. This is done using the `table_cond_formatting_rules` config setting.
Expand Down
1 change: 1 addition & 0 deletions multiqc/modules/quast/quast.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def quast_table(self):
config = {
"id": "quast_table",
"min": 0,
"namespace": "QUAST",
}
return table.plot(self.quast_data, headers, config)

Expand Down
60 changes: 34 additions & 26 deletions multiqc/plots/table_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,33 +156,41 @@ def __init__(self, data, headers=None, pconfig=None):
for cpc_k, cpc_v in config.custom_plot_config[pconfig["id"]].items():
headers[idx][k][cpc_k] = cpc_v

# Overwrite hidden if set in user config
for ns in config.table_columns_visible.keys():
# Make namespace key case-insensitive
if ns.lower() == headers[idx][k]["namespace"].lower():
# Overwrite "hidden" if set in user config
# Key can be a column ID, a table ID, or a namespace in the general stats table.
for key in config.table_columns_visible.keys():
# Case-insensitive check if the outer key is a table ID or a namespace.
if key.lower() == pconfig["id"].lower() or key.lower() == headers[idx][k]["namespace"].lower():
# First - if config value is a bool, set all module columns to that value
if isinstance(config.table_columns_visible[ns], bool):
headers[idx][k]["hidden"] = not config.table_columns_visible[ns]

# Not a bool, assume a dict of the specific column IDs
else:
try:
# Config has True = visibile, False = Hidden. Here we're setting "hidden" which is inverse
headers[idx][k]["hidden"] = not config.table_columns_visible[ns][k]
except KeyError:
pass

# Overwrite name if set in user config
for ns in config.table_columns_name.keys():
# Make namespace key case insensitive
if ns.lower() == headers[idx][k]["namespace"].lower():
# Assume a dict of the specific column IDs
try:
headers[idx][k]["title"] = config.table_columns_name[ns][k]
except KeyError:
pass

# Also overwite placement if set in config
if isinstance(config.table_columns_visible[key], bool):
# Config has True = visible, False = Hidden. Here we're setting "hidden" which is inverse
headers[idx][k]["hidden"] = not config.table_columns_visible[key]

# Not a bool, assume a dict of specific column IDs
elif k in config.table_columns_visible[key]:
# Config has True = visible, False = Hidden. Here we're setting "hidden" which is inverse
headers[idx][k]["hidden"] = not config.table_columns_visible[key][k]

# Case-insensitive check if the outer key is a column ID
elif key.lower() == k.lower():
if isinstance(config.table_columns_visible[key], bool):
# Config has True = visible, False = Hidden. Here we're setting "hidden" which is inverse
headers[idx][k]["hidden"] = not config.table_columns_visible[key]

# Overwrite "name" if set in user config
# Key can be a column ID, a table ID, or a namespace in the general stats table.
for key in config.table_columns_name.keys():
# Case-insensitive check if the outer key is a table ID or a namespace.
if key.lower() == pconfig["id"].lower() or key.lower() == headers[idx][k]["namespace"].lower():
# Assume a dict of specific column IDs
headers[idx][k]["title"] = config.table_columns_name[key][k]

# Case-insensitive check if the outer key is a column ID
elif key.lower() == k.lower():
if isinstance(config.table_columns_visible[key], bool):
headers[idx][k]["title"] = config.table_columns_visible[key]

# Also overwrite placement if set in config
try:
headers[idx][k]["placement"] = float(
config.table_columns_placement[headers[idx][k]["namespace"]][k]
Expand Down

0 comments on commit 53e016c

Please sign in to comment.