def constructor( ctx, libctx, package_dirdict, package_name, package, ): mod = ctx.analyze_dependencies = Module() mod.code = libctx.code.analyze_dependencies.value tf = ctx.build_package = Transformer() tf.code = libctx.code.build_package.value ctx.package_dirdict = Cell("plain") tf.package_dirdict = ctx.package_dirdict package_dirdict.connect(ctx.package_dirdict) tf.analyze_dependencies = mod tf.package_name = package_name ctx.package = tf ctx.package.celltype = "plain" package.connect_from(ctx.package)
from seamless.highlevel import Context, Transformer, Cell from functools import partial ctx2 = Context() ctx2.share_namespace = "status" ctx2.graph = {} ctx2.graph.celltype = "plain" ctx2.graph.share() ctx2.graph_rt = {} ctx2.graph_rt.celltype = "plain" ctx2.status_ = {} ctx2.status_data = ctx2.status_ ctx2.status_data.celltype = "plain" gvs = ctx2.gen_vis_status = Transformer() gvs.graph = ctx2.graph_rt gvs.status_ = ctx2.status_ gvs.code.mount("gen_vis_status.py", authority="file") ctx2.vis_status = ctx2.gen_vis_status ctx2.vis_status.celltype = "plain" ctx2.vis_status.share(readonly=True) c = ctx2.html = Cell() c.set(open("status-visualization.html").read()) c.celltype = "text" c.mimetype = "text/html" c.share(path="index.html") import seamless, os seamless_dir = os.path.dirname(seamless.__file__) c = ctx2.seamless_client_js = Cell()
from seamless.highlevel import Context, Cell, Transformer ctx = Context() ctx.seq1 = Cell("text") ctx.seq1.mount("seq1.txt") ctx.seq1.share(readonly=False) ctx.seq2 = Cell("text") ctx.seq2.mount("seq2.txt") ctx.seq2.share(readonly=False) ctx.align = Transformer() ctx.align.language = "docker" ctx.align.docker_image = "pegi3s/emboss" ctx.align.seq1 = ctx.seq1 ctx.align.seq2 = ctx.seq2 ctx.align.code.mount("align.bash") ctx.alignment = ctx.align ctx.alignment.celltype = "text" ctx.alignment.mount("alignment.water", "w") ctx.scramble_code = Cell("text") ctx.scramble_code.mount("scramble.py") ctx.scramble1 = Transformer() ctx.scramble1.seq = ctx.seq1 ctx.scramble1.code = ctx.scramble_code ctx.scrambled1 = ctx.scramble1 ctx.scrambled1.celltype = "text"
from seamless.highlevel import Context, Cell, Module, Transformer from seamless.highlevel import set_resource ctx = Context() mod = ctx.analyze_dependencies = Module() mod.code = set_resource("analyze_dependencies.py") tf = ctx.build_package = Transformer() tf.code = set_resource("build_package.py") ctx.package_dirdict = Cell("plain") ctx.package_dirdict.mount("testpackage", as_directory=True, mode="r") ctx.package_dirdict_value = ctx.package_dirdict ctx.package_dirdict_value.celltype = "plain" ctx.package_dirdict_value.mount("package_dirdict.json", mode="w") tf.package_dirdict = ctx.package_dirdict tf.package_name = "testpackage" tf.analyze_dependencies = mod ctx.package = tf ctx.package.celltype = "plain" ctx.package.mount("package.json", mode="w") ctx.compute() ctx.testpackage = Module() ctx.testpackage.code = ctx.package def func(): print(testpackage, dir(testpackage)) from .testpackage import testvalue from .testpackage.sub.mod1 import func from .testpackage.sub.mod2 import func as func2 print(testvalue) print(func is func2)
from seamless.highlevel import Context, Transformer ctx = Context() ctx.a = 12 ipycode = """ %%timeit def triple_it(a): return 3 * a result = _ """ ctx.transform = Transformer() ctx.transform.language = "ipython" ctx.transform.code = ipycode ctx.transform.a = ctx.a ctx.transform.debug = True ctx.myresult = ctx.transform ctx.compute() print(ctx.myresult.value) # None ctx.a = 13 ctx.compute() print(ctx.myresult.value) # None print(ctx.transform.status)
jobname += "_" + clean(wildcard) jobname += "_" + clean(wildcard_value) return jobname for job in dag.jobs: rule = job.rule jobname = get_jobname(job) if not len(job.output): print("Skipped job '%s', as it has no outputs" % jobname) continue print("Creating job:", jobname) indummies, outdummies, wildcard_dummies = rule_dummies[rule] pins = indummies._tf_params() tf = Transformer(pins=pins) setattr(ctx.jobs, jobname, tf) docker_image = job.singularity_img_url if docker_image is not None: if not docker_image.startswith("docker://"): raise Exception( "Docker image '%s' (rule %s) does not start with docker://" % (docker_image, rule.name)) tf.language = "docker" tf.docker_image = docker_image[len("docker://"):] else: tf.language = "bash" tf.code = getattr(ctx.rules, rule.name) if not len(job.input.keys()):
tf_code = ''' print(__name__) print(testmodule) print(testmodule.q) from .testmodule import q print(q) import sys print([m for m in sys.modules if m.find("testmodule") > -1]) result = a + b ''' from seamless.highlevel import Transformer, Cell, Context ctx = Context() ctx.testmodule = Cell("plain").set({ "type": "interpreted", "language": "python", "code": "q = 10" }) ctx.tf = Transformer(code=tf_code) ctx.tf.a = 10 ctx.tf.b = 20 ctx.tf.testmodule = ctx.testmodule ctx.tf.pins.testmodule.celltype = "plain" ctx.tf.pins.testmodule.subcelltype = "module" ctx.c = ctx.tf ctx.compute() print(ctx.testmodule.status) print(ctx.tf.status) print(ctx.tf.exception) print(ctx.c.value)
from seamless.highlevel import Context, Transformer, Cell ctx = Context() ctx.pdb0 = open("1crn.pdb").read() ctx.pdb0.celltype = "text" ctx.pdb0.share("pdb0.pdb", readonly=False) ctx.filter_pdb = Transformer() ctx.filter_pdb.language = "bash" ctx.filter_pdb.code = 'grep ATOM pdb0 | awk \'$3 == "CA" || $3 == "C" || $3 == "O" || $3 == "N"\' > RESULT' ctx.filter_pdb.pdb0 = ctx.pdb0 ctx.filtered_pdb = ctx.filter_pdb ctx.filtered_pdb.celltype = "text" ctx.filtered_pdb.share("filtered_pdb.pdb") ctx.fix_pdb = Transformer() ctx.fix_pdb.language = "bash" ctx.fix_pdb.code = 'head -20 filtered_pdb > RESULT' ctx.fix_pdb.filtered_pdb = ctx.filtered_pdb ctx.pdb = ctx.fix_pdb ctx.pdb.celltype = "text" ctx.pdb.share("pdb.pdb") ctx.filter_code = ctx.filter_pdb.code.pull() ctx.filter_code.share("filter_code.bash", readonly=False) ctx.filter_code.mount("/tmp/filter_code.bash") ctx.code = ctx.fix_pdb.code.pull()
"""Another example on how to modify the Seamless environment, adding Go support via "go build" """ import traceback from seamless.highlevel import Context, Cell, Transformer ctx = Context() env = ctx.environment # Define a transformer with signature # (a: int, b: int) -> int # and a=13, b=16 ctx.tf = Transformer() ctx.tf.a = 13 ctx.tf.b = 16 ctx.compute() ctx.tf.example.a = 0 ctx.tf.example.b = 0 ctx.tf.result.example = 0 print(ctx.tf.schema) print(ctx.tf.result.schema) print(ctx.tf.a.value) # Set the language as Go # => fail, unknown language try: ctx.tf.language = "go" except KeyError as exc: traceback.print_exc(limit=0)
from seamless.highlevel import Context, Cell, Transformer, Link, load_graph from seamless import stdlib import os, json ctx = Context() ctx.include(stdlib.merge) ctx.initial_graph = Cell("plain").mount("initial-graph.seamless", "r") ctx.seamless2webform = Cell("code").mount("../seamless2webform.py", "r") ctx.gen_webform = Transformer() ctx.gen_webform.graph = ctx.initial_graph ctx.gen_webform.pins.graph.celltype = "plain" ctx.gen_webform.code = ctx.seamless2webform ctx.initial_webform = ctx.gen_webform ctx.initial_webform.celltype = "plain" ctx.initial_webform.mount("initial-webform.json", "w") ctx.initial_webform0 = Cell("text") ctx.initial_webform0 = ctx.initial_webform ctx.compute() ctx.webform = Cell("plain").mount("webform.json") ctx.webform0 = Cell("text") ctx.link(ctx.webform, ctx.webform0) ctx.webform_CONFLICT = Cell("text").mount("webform-CONFLICT.txt") ctx.webform_STATE = Cell("str") ctx.webform_DUMMY = Cell("text") ctx.compute() ctx.merge_webform = ctx.lib.merge(upstream=ctx.initial_webform0, modified=ctx.webform0, conflict=ctx.webform_CONFLICT, merged=ctx.webform_DUMMY,
from seamless.highlevel import Transformer, Cell, Context, Module ctx = Context() ctx.cython_module = Module() ctx.cython_module.language = "ipython" ctx.cython_code = Cell("code").mount("cell-cython.ipy") ctx.cython_code.language = "ipython" ctx.cython_module.code = ctx.cython_code ctx.tf = Transformer() ctx.tf.code = "cython_module.func(100)" ctx.tf.cython_module = ctx.cython_module ctx.compute() print(ctx.tf.result.value) ctx.vis = Transformer() ctx.vis.code = "cython_module.func_html" ctx.vis.cython_module = ctx.cython_module ctx.html = ctx.vis ctx.html.share("cython.html") ctx.html.mimetype = "html" ctx.compute() print("Cython visualization can be seen at localhost:<REST PORT>/ctx/cython.html")
async def main(): #!/usr/bin/env python # coding: utf-8 # In[1]: from seamless.highlevel import Context, Transformer, Cell import numpy as np ctx = Context() # In[2]: ctx.pdb1 = open("1AKE-flanks.pdb").read() ctx.pdb2 = open("1AKE-B-hit.pdb").read() ctx.load_pdb1 = Transformer() ctx.load_pdb1.pdb = ctx.pdb1 ctx.load_pdb_code = ctx.load_pdb1.code.pull() ctx.load_pdb_code.mount("load_pdb.py") ctx.flanks = ctx.load_pdb1 ctx.load_pdb2 = Transformer() ctx.load_pdb2.pdb = ctx.pdb2 ctx.load_pdb2.code = ctx.load_pdb_code ctx.dbca = ctx.load_pdb2 ctx.get_flank1 = lambda flanks: flanks[:4] ctx.get_flank1.flanks = ctx.flanks ctx.flank1 = ctx.get_flank1 ctx.get_flank2 = lambda flanks: flanks[-4:] ctx.get_flank2.flanks = ctx.flanks ctx.flank2 = ctx.get_flank2 await ctx.computation() print(ctx.flank1.value) print(ctx.flank2.value) # ``` # int BCLoopSearch (const Coord *atoms1, int nr_atoms1, const Coord *atoms2, int nr_atoms2, //flank1 and flank2 # int looplength, //size of the gap/loop we are searching # int minloopmatch, int maxloopgap, //for partial matches: minimum total length, maximum gap # int mirror, //looking for mirrors? # float minBC, float maxR, //minimum BC score, maximum rigidity # const Coord *dbca, //CA database # int seg_index[][3], //(dbca offset, segment resnr, segment length) # int pdb_index[][2], int nr_pdbindex, //(seg_index offset, number of segments), total number of PDBs # int hits[][3], //pdbindex line, seg_index line, segment offset # float hitstats[][2] //score, rigidity # ) # { # ``` # In[3]: ctx.bcloopsearch = Transformer() ctx.bcloopsearch.language = "c" ctx.bcloopsearch.main_module.compiler_verbose = False ctx.bcloopsearch.code.mount("bcloopsearch.c", authority="file") ctx.bcloopsearch.main_module.lib.language = "c" ctx.bclib_code = ctx.bcloopsearch.main_module.lib.code.pull() ctx.bclib_code.mount("BCLoopSearch-lib.c", authority="file") ctx.bc_hits = ctx.bcloopsearch await ctx.translation() await ctx.computation() print(1, ctx.status, "\n") # In[4]: def set_example(bc): bc.atoms1 = np.zeros((4, 3)) bc.atoms2 = np.zeros((4, 3)) bc.looplength = 5 bc.minloopmatch = 5 bc.maxloopgap = 0 bc.mirror = False bc.minBC = 0.9 bc.maxR = 9999 bc.dbca = np.zeros((10, 3)) bc.seg_index = np.zeros((10, 3), dtype=np.uint32) bc.pdb_index = np.zeros((10, 2), dtype=np.uint32) set_example(ctx.bcloopsearch.example) schema = ctx.bcloopsearch.schema schema.properties.atoms1["form"].contiguous = True schema.properties.atoms1["form"].shape = (-1, 3) schema.properties.atoms2["form"].contiguous = True schema.properties.atoms2["form"].shape = (-1, 3) schema.properties.dbca["form"].shape = (-1, 3) schema.properties.dbca["form"].contiguous = True schema.properties.seg_index["form"].shape = (-1, 3) schema.properties.seg_index["form"].contiguous = True schema.properties.pdb_index["form"].shape = (-1, 2) schema.properties.pdb_index["form"].contiguous = True MAXHITS = 100000 bcrx = ctx.bcloopsearch.result.example bcrx.nhits = 0 bcrx.hits = np.zeros((MAXHITS, 3), dtype=np.uint32) bcrx.hitstats = np.zeros((MAXHITS, 2), dtype=np.float32) await ctx.computation() print(2, ctx.status, "\n") #print(ctx.bcloopsearch.exception); print() rschema = ctx.bcloopsearch.result.schema rschema.properties.hits["form"].shape = (MAXHITS, 3) rschema.properties.hitstats["form"].shape = (MAXHITS, 2) await ctx.computation() print(3, ctx.status, "\n") #print(ctx.bcloopsearch.exception); print() # In[5]: set_example(ctx.bcloopsearch) ctx.bcloopsearch.atoms1 = ctx.flank1 ctx.bcloopsearch.atoms2 = ctx.flank2 ctx.bcloopsearch.dbca = ctx.dbca await ctx.computation() ctx.bcloopsearch.seg_index = np.array([[0, 1, len(ctx.dbca.value)]], dtype=np.uint32) ctx.bcloopsearch.pdb_index = np.array([[0, 1]], dtype=np.uint32) ctx.bcloopsearch.looplength = 7 ctx.bcloopsearch.minBC = 0 await ctx.computation() # In[6]: print(ctx.bcloopsearch.schema) print() print(ctx.bcloopsearch.result.schema) print() print(ctx.bcloopsearch.status) print(ctx.bcloopsearch.exception) # In[7]: ctx.header = ctx.bcloopsearch.header ctx.header.mimetype = "h" ctx.header.output # In[8]: ctx.bcloopsearch_schema = Cell() ctx.bcloopsearch_schema.celltype = "plain" ctx.link(ctx.bcloopsearch_schema, ctx.bcloopsearch.inp.schema) ctx.bcloopsearch_schema.mount("bcloopsearch-schema.json") await ctx.computation() # In[9]: ctx.bc_hits.value # In[10]: nhits = ctx.bc_hits.value.nhits print(nhits) # In[ ]: ctx.bc_hits.value.unsilk["hitstats"][:nhits] # In[ ]: ctx.pdb2.set(open("1AKE-B.pdb").read()) await ctx.computation() ctx.bcloopsearch.seg_index = np.array([[0, 1, len(ctx.dbca.value)]], dtype=np.uint32) await ctx.computation() ctx.bcloopsearch.minBC = 0.7 await ctx.computation() # In[ ]: nhits = ctx.bc_hits.value.nhits print(nhits) # In[ ]: ctx.bc_hits.value.unsilk["hitstats"][:nhits] # In[ ]: dbca = np.load("db/scop-g.npy")[:, 1].astype(np.float64) ctx.load_db_index = lambda pdbindex, segindex: None ctx.load_db_index.pdbindex = open("db/scop-g.pdbindex").read() ctx.load_db_index.segindex = open("db/scop-g.segindex").read() ctx.load_db_index.code.mount("load_db_index.py", authority="file") ctx.db_index = ctx.load_db_index del ctx.dbca ctx.dbca = dbca ctx.bcloopsearch.dbca = ctx.dbca ctx.bcloopsearch.seg_index = ctx.db_index.seg ctx.bcloopsearch.pdb_index = ctx.db_index.pdb ctx.bcloopsearch.minBC = 0.99 await ctx.computation() # In[ ]: nhits = ctx.bc_hits.value.nhits print(nhits) # In[ ]: pdbs = ctx.bc_hits.value.unsilk["hits"][:nhits, 0] print(np.take(ctx.db_index.value.unsilk["pdb_names"], pdbs)) print(ctx.bc_hits.value.unsilk["hits"][:nhits, 1]) print(ctx.bc_hits.value.unsilk["hits"][:nhits, 2]) print(ctx.bc_hits.value.unsilk["hitstats"][:nhits])
await ctx.computation() ##### def download_pdb(pdb_code): import urllib pdb_data = urllib.request.urlopen("https://files.rcsb.org/download/{}.pdb".format(pdb_code)).read().decode() return pdb_data ctx.download_pdb = download_pdb ctx.download_pdb.pdb_code = ctx.pdb_code ctx.pdb_data = ctx.download_pdb #### ctx.execute_x3dna = Transformer() ctx.execute_x3dna.language = "docker" ctx.execute_x3dna.docker_image = "x3dna" ctx.execute_x3dna.code = "x3dna-dssr -i=pdb_data --json -o=RESULT" ctx.execute_x3dna.pdb_data = ctx.pdb_data ctx.x3dna_analysis = ctx.execute_x3dna await ctx.computation() ctx.x3dna_analysis.output() #### def get_x3dna_nucleotides(x3dna_analysis, na_chain): return [nt for nt in x3dna_analysis["nts"] if nt["chain_name"] == na_chain] ctx.get_x3dna_nucleotides = get_x3dna_nucleotides ctx.get_x3dna_nucleotides.x3dna_analysis = ctx.x3dna_analysis
from seamless.highlevel import Context, Transformer, Cell ctx = Context() ctx.a = Cell() ctx.a.set(2) ctx.b = Cell() ctx.b.set(3) ctx.add = Transformer() ctx.add.a = ctx.a ctx.add.b = ctx.b ctx.add.code = "a + b" ctx.result = Cell() ctx.result = ctx.add ctx.compute() ctx.save_graph("intro.seamless") ctx.save_zip("intro.zip")