rust-bio / rust-bio-tools

A set of command line utilities based on Rust-Bio.
MIT License
182 stars 24 forks source link

General grammar for even more flexible csv-reports #193

Closed johanneskoester closed 2 years ago

johanneskoester commented 3 years ago

This is a generalization of #192, also replacing other specialized functionality from before. We replace the CLI interface with a textual JS file definition like this (example with annotations):

{
    "tables": {
        "table-a": {
            "path": "table-a.tsv",
            "render-columns": {
              "x": {
                  "custom": function(value) {
                      return `<b>${value}</b>`; // applies the given function to render column content
                  },
              },
              "y": {
                  "link-to-url": "https://www.ensembl.org/Homo_sapiens/Gene/Summary?db=core;g={value}" // renders as <a href="https://www.ensembl.org/Homo_sapiens/Gene/Summary?db=core;g={value}">{value}</a>
              },
              "z": {
                  "link-to-table-row": "table-b/gene" // renders as link to the other table highlighting the row in which the gene column has the same value as here
              }
        },
        "table-b": {
            "path": "table-b.tsv"
            "render-columns": {
                "gene": {
                    "link-to-table": "gene-{value}" // renders as link to the given table, not a specific row
                }
            }
        },
        "gene-mycn": {
            "path": "genes/table-mycn.tsv"
            "render-columns": {
                "score": {
                    "plot": {
                        "type": "quantitative" // renders as vega-lite tick marks with a tooltip showing the value
                    },
                    "summary-plot": "hist" // shows a histogram at the top of the column
                },
                "type": {
                    "plot": {
                        "type": "nominal" // renders as colored cells (via vega-lite) with a tooltip showing the value and a global legend showing the color meanings
                    }
                },
                "length": {
                    "custom-plot": {
                        "data": function(value) { // a function to return the data needed for the schema below from the content of the column cell
                            return [{"length": value}]
                        },
                        "schema": { // a schema for a vega plot that is rendered into each cell of this column
                            "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
                            "encoding": { "y": { "field": "variety", "type": "ordinal" } },
                            "layer": [
                                {
                                    "mark": { "type": "point", "filled": true },
                                    "encoding": {
                                        "x": {
                                            "aggregate": "mean",
                                            "field": "yield",
                                            "type": "quantitative",
                                            "scale": { "zero": false },
                                            "title": "Barley Yield"
                                        },
                                        "color": { "value": "black" }
                                    }
                                },
                                {
                                    "mark": { "type": "errorbar", "extent": "stdev" },
                                    "encoding": {
                                        "x": { "field": "yield", "type": "quantitative", "title": "Barley Yield" }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        }
    }
}
fxwiegand commented 2 years ago

Closing in favor of koesterlab/datavzrd.