Code Monkey home page Code Monkey logo

obographviz's Introduction

NPM version

Translate OBO Graphs into Dot/Graphviz

  • Input: a OBO Graph JSON object
  • Optional: a JSON ontology stylesheet
  • Output: a Dot-format / Graphviz file

Requirements

  • Node.js ≥ 14.16

Installation

The obographviz package can be installed via NPM either locally or globally. If you're not familiar with NPM, see the following to get started:

If you intend to primarily use the command line tool provided by this package or you're using a tool like Ontology Access Kit which depends on it, install globally:

npm install -g obographviz

Once installed globally, the og2dot executable will automatically be added to your PATH.

Otherwise, if you want to use the package in an existing Node.js project install it locally:

npm install obographviz

Quickstart

Command line

All examples in this README assume obographviz has been installed globally. If it was installed locally to a project, call og2dot via npx or an npm script.

See the examples directory in this repositories for sample OBO Graph JSON files and stylesheets.

og2dot simple-og.json > test.dot
dot test.dot -Tpng -Grankdir=BT > test.png

API

import { OboGraphViz } from "obographviz";

const obograph = { ... }

const compoundRelations = ['BFO:0000050']
const styleMap = {}
const gv = new OboGraphViz(obograph)
const dot = gv.renderDot(compoundRelations, styleMap)
console.log(dot)

Features

Nesting

One or more predicates can be designated as 'compound', i.e. used for nesting.

On the command line, use -c. In the API, use compoundRelations

Example:

og2dot -c is_a simple-og.json > test.dot

Generates:

img

Note only works for subgraphs that exhibit disjointness over this property, acyclicity

Use the -I option for inverting the containment relation (e.g. to use has part rather than part of).

Stylesheets

In the API can be passed using styleMap. On the command line, by using either -s (to pass a JSON file) or -S (to pass stringified JSON object directly on command line)

E.g.

og2dot -s example-style.json -c is_a simple-og.json > test.dot

Stylesheet Standard

This is now documented separately:

kgviz-model

Global stylemap properties

These go in the root of the stylemap object

{
    "style": "filled",
    "fillcolor": "green"
}

this sets all nodes to be filled green

Edge properties by relationship type

Each relationship type can have its own individual style, by passing relationProperties. This is keyed by the CURIE for the relation (or "is_a" for subClassOf):

{
    "relationProperties": {
        "is_a": {
            "color": "black",
            "penwith": 3,
            "arrowhead": "open",
            "label": ""
        },
        "BFO:0000050": {
            "arrowhead": "tee",
            "color": "blue"
        }
    }
}

Node properties by prefix

Pass in prefixProperties to be able to assign individual properties for ontology prefixes. This can be useful when visualization graphs that combine multiple ontologies

{
    "prefixProperties": {
        "SO": {
            "fillcolor": "yellow"
        },
        "RO": {
            "fillcolor": "pink"
        },
        "BFO": {
            "fillcolor": "cyan"
        }
    }
}

Conditional properties

Arbitrary conditions can be set using conditionalProperties for example:

{
    "conditionalProperties": [
        {
            "conditions": {
                "subset":"efo_slim"
            },
            "properties": {
                "fillcolor": "blue"
            }
        }
    ]
}

This will color any node in the efo_slim subset blue.

Combined Example

The following example uses all subclasses of digit in Uberon, plus their ancestors, which forms a complex lattic structure.

See digit.json for the underlying ontology. See examples/uberon-style.json for the stylesheet.

og2dot -s uberon-style.json digit.json -t png -o digit.png

Renders:

img

Nesting of Equivalence Sets

Optionally, cliques of classes interconnected with either equivalence axioms or xrefs will be clustered.

The file uberon-zfa-xref-example.json contains a subset of both UBERON, ZFA, and two Allen brain ontologies, with UBERON classes xref-ing equivalent ZFA classes.

og2dot -s uberon-zfa-style.json uberon-zfa-xref-example.json -t png -o uberon-zfa-xref-example.png

Renders:

img

(Uberon: yellow, ZFA:black, MBA: pink, HBA: grey, black lines = IS_A, blue lines = part_of, equivalence sets as bounding boxes)

The predicates used to build these can be configured in the json style file, e.g.:

"cliqueRelations": [
    "xref", "equivalent_to", "same_as"
]

Note: to style the bounding box in a stylesheet, the cliques are considered to be in the ID space %CLIQUE

"prefixProperties": {
    "%CLIQUE": {
        "fillcolor": "hotpink"
    },
    "GO": {
        "fillcolor": "yellow"
    },
}

Rendering anonymous and pseudo-anonymous individuals

E.g. GO-CAM models

{
    "nodeFilter" : {
        "type": "INDIVIDUAL"
    },
    "labelFrom": "type"
}
og2dot -c BFO:0000050 -c RO:0002333 -s gocam-style.json lego-example2.json

img

Integration with other components

Configuring individual nodes or edges

As well as configuring via style sheets, an individual node or edge can configure its display by using an annotation assertion with a property in https://w3id.org/kgviz/, e.g.:

{
    "sub": "GO:0031090",
    "pred": "BFO:0000050",
    "obj": "GO:0043227",
    "meta": {
        "basicPropertyValues": [
            {
                "pred": "https://w3id.org/kgviz/penwidth",
                "val": 10
            }
        ]
    }
}

Ontology Access Kit

This library is integrated into Ontology Access Kit (OAK) to support its viz subcommand. For example:

runoak -i ontobee: viz HP:0000787

This proceeds by:

  1. Using the python oaklib library to extract a subgraph around the specified node
  2. Write as obographs-json
  3. Calls og2dot

Use from biolink-api REST

Go to http://api.monarchinitiative.org/api/

See the /ontol/subgraph/ route

This exports obographs which can be fed in to this js lib

TODO - link to demo site

Use with AmiGO

AmiGO uses bbop-graphs; these are similar enough that they can be passed in instead of obographs.

Development

Javascript and TypeScript files in the lib directory are compiled using tsc into the dist directory. To compile once use:

npm run build

To watch for file changes and compile incrementally use:

npm run dev

Before committing changes run the test suite with:

npm test

FAQ

Why Dot/GraphViz?

Why not D3, cytoscape js etc?

These are all very nice and pretty, but GraphViz has some powerful features that I have not found in any other framework (or have been too lazy to find out how to do). In particular:

  • Easy to run on command line
  • The ability to nest relationships (update: compound graphs in cytoscape.js)
  • simple control over box and edge visual attributes
  • embedding arbitrary HTML

This is intended to replace blipkit graphviz generation. For some examples, see mondo report

obographviz's People

Contributors

cmungall avatar dependabot[bot] avatar pkalita-lbl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obographviz's Issues

bounding box not drawn around clique

Define minimum requirements

the sequence

docker run  -v $PWD:/work -w /work -ti node bash
npm install -g obographviz
og2dot --help

works with latest node, but when I try with ODK:

✗ docker run  -v $PWD:/work -w /work -ti obolibrary/odkfull bash
root@19138ca8b3c3:/work# node --version
v10.19.0
root@19138ca8b3c3:/work# npm install -g obographviz
/usr/local/bin/og2dot -> /usr/local/lib/node_modules/obographviz/bin/og2dot.js
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=12"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":"^12.20.0 || >=14"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]

+ [email protected]
added 8 packages from 8 contributors in 1.598s
root@19138ca8b3c3:/work# og2dot --help
/usr/local/lib/node_modules/obographviz/bin/og2dot.js:3
import { readFileSync, existsSync, writeFileSync } from 'fs';
       ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

seems odd it perseveres and installs anyway - but we should document - in package.json the minimum reqs. 12 or 14?

tag 0.3.0?

Is there a tag missing for the latest release?

Add reduce operation to stylesheet

Add option for client to perform transitive reduction

Different modes:

  • ignore edge labels
  • perform TR on a per-label basis
  • inference based TR (will require some level of reasoning on client)

Visually nest equivalence cliques

We want to be able to show pairs, triads etc of equivalent classes as being grouped together. This is for the output of algorithms like kboom that find most likely equivalence axioms, and for general visualization of mappings.

An example can be seen here: monarch-initiative/monarch-disease-ontology-RETIRED#365 (comment)

I made a test file equivs.json

which currently renders as:

image

We would like all xs to be nested inside one box, all ys in one box, all zs in one box, based on:

https://github.com/cmungall/obographviz/blob/3ca5cd2404ac05a2d75189dd15171b8bc489c724/tests/equivs.json#L71-L89

The algorithm should be:

  1. find all equivalence cliques
    • e.g. using Tarjan's algorithm (convert each equivalence axiom to reciprocal DAG edges and find strongly connected components)
    • could also do this as a side-effect of reasoning, but that may be overkill here, but there may be other use cases for reasoning in this application
  2. for each clique, nest all members inside. This is probably easiest done by generating a new node for each clique, relating each clique member to the clique via an artificial cliqueMemberOf relation, and passing this in as a nested relation

@kltm - is the intent for bbop-graph to have algorithms such as Tarjan's implemented?

Or could just use https://www.npmjs.com/package/tarjan-graph

Or even the abandoned https://github.com/geneontology/noctua-reasoner

Or implement RETE/Arachne in node cc @balhoff

DeprecationWarning: Invalid 'main' field

When running in https://github.com/turbomam/deep-learning-ontology

robot convert -i deep-learning-ontology.owl -o deep-learning-ontology.json
npm i obographviz

(node:41034) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/MAM/Documents/gitrepos/deep-learning-ontology/node_modules/node-getopt/package.json' of './lib'. Please either fix that or report it to the module author
(Use node --trace-deprecation ... to show where the warning was created)

Style an edge based on an edge property

If we have an edge with a particular property value like this:

{
          "sub" : "RHEA:23719",
          "pred" : "is_a",
          "obj" : "RHEA:45900",
          "meta" : {
            "basicPropertyValues" : [
              {
                "pred" : "http://example.org/is_asserted",
                "val" : true
              }
            ]
          }
        }

Is there a way to give edges like that a particular color (or style like dashed or dotted)?

Bump depenency of bbop-graph to 0.21

Related to this berkeleybop/bbop-graph#6

The bbop-graph 0.19 that is the default requirement for obographviz has a bug that is described in the issue above affecting walker functions. E.g. when generating a descendant subgraph from a node, only the first-degree children were returned, and not all the grand-children, grand-grand, etc.

This error is fixed in bbop-graph 0.21

`og2dot` command line does not work with Node 14

Using Node 14.x running og2dot on the command line results in:

import { Graph } from "graphlib";
         ^^^^^
SyntaxError: The requested module 'graphlib' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from 'graphlib';
const { Graph } = pkg;
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:98:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:137:5)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.