Commit 47b26814 authored by Lucas Bourneuf's avatar Lucas Bourneuf

example of api usage

parent 8c12165e
"""Basic example of API usage"""
import biseau as bs
# straightforward way : just use default options for all scripts
fnames=('scripts/raw_data.lp', 'scripts/', 'scripts/render_interactions.json'),
# We can also load all scripts in a given dir
scripts = list(bs.build_scripts_from_dir('scripts/'))
# Or from a single filename
# Now, we can choose any subset of these scripts to make a context describing a graph
final_context =[:3])
# this context (which is pure ASP) can be compiled to dot
bs.compile_to_single_image(final_context, outfile='example.png')
# note that scripts are complex objects, that have options :
a_script = next(bs.build_scripts_from_file('scripts/'))
print(f"Script {} have options:", a_script.options)
print(" Current values are:", a_script.options_values)
print(" Changing values… ")
a_script.options_values['multiplier'] = 3
print(" Now values are:", a_script.options_values)
"name": "JSON Example 1",
"description": "example of JSON module",
"ASP": "color(A,B,C) :- triplet(A,B,C,_).",
"tags": ["json example"],
"inputs": ["triplet/4"],
"outputs": ["color/3"]
"name": "JSON Example 2",
"description": "example of JSON module",
"ASP": "p(X) :- q(X,Y). yolande(C) :- michel(C).",
"tags": ["json example"],
"inputs": ["q/2", "michel/1"],
"outputs": ["p/1", "yolande/1"]
from itertools import combinations
NAME = "Ranker"
OUTPUTS = "score/3"
def run_on(models, *, multiplier:float=2):
for model in models:
for (geneA, valA), (geneB, valB) in combinations(model.get('gene', ()), r=2):
score = abs(float(valA) - float(valB)) * float(multiplier)
yield f'score({geneA},{geneB},"{score}").'
% raw data
"name": "Interactions renderer",
"description": "Render score/3 as a graph",
"ASP": "link(A,B) :- score(A,B,_).\nlabel(A,B,L) :- score(A,B,L).",
"inputs": ["score/3"],
"outputs": ["link/2", "label/3"]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment