ontodev/valve.py

Standardize function signatures and add "registry"

Closed this issue · 6 comments

I'd like to allow users to add their own functions. The main use case right now is the tetramer validator, where we want to be able to check modification types and positions against a sequence:

MHC Molecule Peptide Sequence Modification Type Modification Position
HLA-A*02:01 PKYVKQNTLKLAT OX M5
HLA-A*02:01 NLVPMVATV oxidation M5

To make this possible, I think we need a few changes to VALVE:

  1. Make all the functions use the same signature. It will have to include anything a function could need. My suggestion is: config dict, args list, table string, column string, row int. This should be enough to look up the current cell, but also get information from other cells in the row if needed. All functions should return a list of messages, which will be empty if the cell is valid.
  2. Extend the config with a dictionary of function name -> function pairs. Users will be able to add to this dictionary. I guess this needs to be specified before the datatype, field, and rule tables are checked. I'm thinking that an unknown function should be a WARN (and then skipped), which would allow you to use a function in Python that's not defined for JavaScript. But maybe it should be an ERROR.
  3. In run_function look for the function name in the dictionary from 2 and call the function with the standard arguments from 1.

I think run_function still needs to accept value instead of table, column, row_idx because of functions like concat, sub, and list. We need to be able to run any function over a different value than the cell value for these.

You're absolutely right!

How will users add functions? Will they pass in another python file?

They will write their own Python code and import ontodev-valve as a module, then call valve.validate() with some arguments -- exactly what arguments is the real question.

Correct