How to use psmap method in fMBT

Best Python code snippet using fMBT_python

psmap.py

Source:psmap.py Github

copy

Full Screen

...9 return fib(n-1) + fib(n-2)10print "map..."11print map(fib, [32] * 16)12print "psmap..."13print psmap.psmap(fib, [32] * 16)14---152. Example, use all workers registered on two pythonshare-server hubs:16import psmap17psmap.use_workers(hub_1_hostspec)18psmap.use_workers(hub_2_hostspec)19...20psmap.psmap(fib, [32] * 16)21---223. Example, use explicitly listed workers, some may be local, some remote:23import psmap24psmap.use_worker(worker_1_hostspec)25psmap.use_worker(worker_2_hostspec)26...27psmap.use_worker(worker_n_hostspec)28psmap.psmap(fib, [32] * 16)29"""30import atexit31import Queue32import inspect33import os34import pythonshare35import subprocess36import thread37import time38g_hubs = []39g_hubs_kill_at_exit = []40g_workers = []41g_worker_conns = []42g_workers_free = Queue.Queue()43def soe(cmd, stdin="", cwd=None, env=None, bg=False):44 """Run cmd, return (status, stdout, stderr)"""45 run_env = dict(os.environ)46 if not env is None:47 run_env.update(env)48 try:49 p = subprocess.Popen(50 cmd,51 stdin=subprocess.PIPE,52 stdout=subprocess.PIPE,53 stderr=subprocess.PIPE,54 close_fds=True,55 cwd=cwd,56 env=run_env)57 if bg:58 return (p, None, None)59 out, err = p.communicate(input=stdin)60 except Exception, e:61 return (None, None, str(e))62 return (p.returncode, out, err)63def use_workers(hub_hostspec):64 g_hubs.append(hub_hostspec)65 conn = pythonshare.connect(hub_hostspec)66 for ns in conn.ls_remote():67 use_worker(hub_hostspec + "/" + ns)68def launch_workers(count, hub_port=9999):69 hub_addr = launch_hub(hub_port)70 for worker_id in xrange(count):71 launch_worker(worker_id, hub_addr)72def launch_hub(port=9999):73 hub_addr = "localhost:%s" % (port,)74 try:75 pythonshare.connect(hub_addr).kill_server()76 except:77 pass78 soe(["pythonshare-server", "-p", hub_addr.split(":")[-1]])79 g_hubs_kill_at_exit.append(hub_addr)80 g_hubs.append(hub_addr)81 return hub_addr82def launch_worker(worker_id, hub_addr):83 if hub_addr is None:84 hub_addr = g_hub_addr85 namespace = str(worker_id)86 soe(["pythonshare-server", "-p", "stdin", "-n", namespace, "-E", hub_addr],87 bg=True)88 worker_addr = hub_addr + "/" + namespace89 use_worker(worker_addr)90def use_worker(worker_hostspec):91 conn = pythonshare.connect(worker_hostspec)92 g_workers.append(worker_hostspec)93 g_worker_conns.append(conn)94 g_workers_free.put(conn)95 thread.start_new_thread(eval_thread, ())96def _clean_up():97 for _ in xrange(len(g_workers)):98 g_workers_free.put(None)99 eval_jobs.put(None)100 time.sleep(0.01)101 for conn in g_worker_conns:102 try:103 conn.close()104 except:105 pass106 for hub_addr in g_hubs_kill_at_exit:107 try:108 pythonshare.connect(hub_addr).kill_server()109 except:110 pass111atexit.register(_clean_up)112eval_results = Queue.Queue()113eval_jobs = Queue.Queue()114def eval_thread():115 while 1:116 conn = g_workers_free.get()117 if conn is None:118 break119 job = eval_jobs.get()120 if job is None:121 break122 try:123 job['conn'] = conn124 job['result'] = job['conn'].eval_(job['code'])125 eval_results.put(job)126 finally:127 g_workers_free.put(conn)128def psmap(func, params_list):129 func_source = inspect.getsource(func)130 results = [None] * len(params_list)131 for worker_conn in g_worker_conns:132 worker_conn.exec_(func_source)133 for job_index, params in enumerate(params_list):134 if isinstance(params, tuple):135 params_tuple = params136 else:137 params_tuple = (params,)138 eval_jobs.put({139 'conn': None,140 'job_index': job_index,141 'code': func.__name__ + repr(params_tuple)})142 for params in params_list:143 job = eval_results.get()144 results[job['job_index']] = job['result']145 return results146def fib(n):147 if n <= 1:148 return 1149 else:150 return fib(n-1) + fib(n-2)151if __name__ == "__main__":152 import sys153 if len(sys.argv) == 1:154 launch_workers(8)155 else:156 print "using workers from hubs: ", ", ".join(sys.argv[1:])157 for hub in sys.argv[1:]:158 use_workers(hub)159 print "running", len(g_worker_conns), "workers"160 job_count = 30161 print "will run", job_count, "jobs"162 print "running local map..."163 s = time.time()164 print map(fib, [31] * job_count)165 e = time.time()166 print "map:", e-s167 print "running psmap..."168 s = time.time()169 print psmap(fib, [31] * job_count)170 e = time.time()...

Full Screen

Full Screen

pseudo2refConvert.py

Source:pseudo2refConvert.py Github

copy

Full Screen

1import sys2def gapFlanks(ch,pos,psmap,FR):3 for i in range(int(pos)-4,int(pos)+5):4 if psmap[ch][i+1] - psmap[ch][i] > 1:5 if FR == "F":6 return psmap[ch][i]7 else:8 return psmap[ch][i+1]9 print "Error: no gap found", psmap[ch][int(pos)-4], psmap[ch][int(pos)+5]10 sys.exit()11def isGap(ch,pos,psmap):12 """if there is a gap near the position to be transformed13 return the left most position of the gap for a forward read and the rightmost for a reverse read14 else, return the normal transformation of the position"""15 if int(pos)+5 >= len(psmap[ch]) or int(pos)-4 < 0:16 return 017 elif abs(psmap[ch][int(pos)+5] - psmap[ch][int(pos)-4]) > 10:18 return 119 else:20 return 021def pseudo2refConvert_portal(bedFILE,pseudo2refMap,outFILE):22 pseudoMap=pseudo2refMap23 print "Converting coordinates from pseudospace to reference-based coordinates..."24 with open(bedFILE, 'r') as fIN, open(outFILE, 'w') as fOUT:25 line_ct=126 for line in fIN:27 orgls=line.split()28 ls=orgls[:-3]+orgls[-1:]29 chrom=ls[0]30 for ch in pseudoMap:31 if ch == chrom:32 if ls[1].isdigit() and not ls[2].isdigit():33 if isGap(chrom,ls[1],pseudoMap) == 0:34 ls[1]=pseudoMap[chrom][int(ls[1])-1]35 else:36 ls[1]=gapFlanks(chrom,ls[1],pseudoMap,"F")37 elif not ls[1].isdigit() and ls[2].isdigit():38 if isGap(chrom,ls[2],pseudoMap) == 0:39 ls[2]=pseudoMap[chrom][int(ls[2])]40 else:41 ls[2]=gapFlanks(chrom,ls[2],pseudoMap,"R")42 elif ls[1].isdigit() and ls[2].isdigit():43 if isGap(chrom,ls[1],pseudoMap) == 0:44 ls[1]=pseudoMap[chrom][int(ls[1])-1]45 else:46 ls[1]=gapFlanks(chrom,ls[1],pseudoMap,"F")47 if isGap(chrom,ls[2],pseudoMap) == 0:48 ls[2]=pseudoMap[chrom][int(ls[2])]49 else:50 ls[2]=gapFlanks(chrom,ls[2],pseudoMap,"R")51 if line_ct<10:52 line_ct="0"+str(line_ct)53 fOUT.write("\t".join([str(x) for x in ls])+"\tte"+str(line_ct)+"\n")54 line_ct=int(line_ct)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful