Skip to content

Instantly share code, notes, and snippets.

@remram44
Created July 30, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remram44/8512903a5def704dbc42 to your computer and use it in GitHub Desktop.
Save remram44/8512903a5def704dbc42 to your computer and use it in GitHub Desktop.
Example of VisTrails API usage (planned)
import vistrails.api as vt
# No initialization, no application creation
# Opens a vistrail
# Vistrail wraps the Vistrail and VistrailController
vistrail = vt.load_vistrail("terminator.vt")
assert isinstance(vistrail, vt.Vistrail)
# We can get pipelines from the vistrail
pipeline = vistrail.get_pipeline(3)
pipeline = vistrail.get_pipeline("some_tag")
assert isinstance(vistrail, vt.Pipeline)
# or change the "current" one, from which new versions are derived
vistrail.set_current_pipeline("some_tag")
assert isinstance(vistrail.current_pipeline, vt.Pipeline)
# Wrappers should do sanity checks and raise exceptions for problems (don't
# show popups...)
try:
vistrail.get_pipeline(object())
except TypeError:
pass
try:
vistrail.get_pipeline(108)
except vt.NoSuchVersion:
pass
# Loading packages should be done when requested, NOT from the configuration
# file. It should not update the user's preferences either...
urlpkg = vt.load_package("org.vistrails.vistrails.url")
assert isinstance(urlpkg, vt.Package)
try:
vt.load_package("org.vistrails.nonexistent.nonexistentpkg")
except vt.NoSuchPackage:
pass
# Alias for basic_modules? This is probably a good idea
bmods = vt.basic_modules
# Easy execution of a (sub)workflow as a Python function (requested by Claudio)
bound = vistrail.current_pipeline.get_module("higher_bound") # InputPort module
target = vistrail.current_pipeline.get_module("target_file")
sinkmodule = vistrail.current_pipeline.get_module("passes")
vistrail.execute(
sinkmodule, # "run this module" function: run part of a pipeline
bound == vt.Function(bmods.Integer, 10), # explicit typing
target == "/tmp/vt_output") # implicit typing (if 'target' is a File...)
results = vistrail.execute(higher_bound=10, target_file="/tmp/vt_output)
assert isinstance(results, vt.Results)
print results.output_port['passes'] - 1 # value passed to OutputPort module
results.module(4).outputs['value'] # access to ports of executed modules
# OutputModules support?
with vt.output_mode('ImageOutput', 'file',
directory='/tmp/', prefix='apitest_image', format='png'):
pipeline.execute()
# IPython support
vistrail.get_pipeline('ipython_test').execute()
# <visualization embedded in qtconsole / notebook>
# Workflow changes? (create new versions, change current vistrail)
# (similarities with ORMs here...)
mod = visturlpkg.DownloadFile(url="http://www.vistrails.org/skins/vistrails/vistrails_logo.png")
vistrail.add_module(mod) # single version created, that adds module with 'url' function set
mod.url = "http://www.google.com/"
mod.insecure = True
bound.name = 'high_bound'
vistrail.add_modules([mod, bound], desc="Params 2.0") # single version created, that sets 3 parameters
vistrail.tag("Revised version")
vistrail.save("/tmp/new_terminator.vt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment