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
bs.single_image_from_filenames(
fnames=('scripts/raw_data.lp', 'scripts/compute_score.py', 'scripts/render_interactions.json'),
outfile='interactions.png',
dotfile='interactions.dot',
)
# We can also load all scripts in a given dir
scripts = list(bs.build_scripts_from_dir('scripts/'))
# Or from a single filename
scripts.extend(bs.build_scripts_from_file('myscripts/hello-world.json'))
# Now, we can choose any subset of these scripts to make a context describing a graph
final_context = bs.run(scripts[:3])
# this context (which is pure ASP) can be compiled to dot
print(final_context)
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/compute_score.py'))
print(f"Script {a_script.name} 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
gene(a,2).
gene(b,3).
gene(c,1).
{
"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