def _run_db2falcon_jobs(cwd, config, dry_run, db2falcon_json_fn=None): """ cwd --- current workding directory dry_run --- if True, do not actually run the scripts db2falcon_json_fn --- if not None, write dict{0: dict('script_fn':script_fn, 'script_dir':script_dir)} """ # Generate preads4falcon.fasta from preads.db script_fn = os.path.join(cwd, "run_db2falcon.sh") job_done = script_fn + "_done" args = { "config": config, "job_done": job_done, "script_fn": script_fn, "preads4falcon_fn": "preads4falcon.fasta", "preads_db": "preads.db", } support.run_db2falcon(**args) json_fn = "db2falcon.json" if db2falcon_json_fn is None else db2falcon_json_fn # add script_dir to args for scattered tasks to work in the correct dir json_data = {0: {"script_fn": os.path.basename(script_fn), "script_dir": cwd}} with open(json_fn, "w") as writer: writer.write(json.dumps(json_data) + "\n") mkdir(cwd) with cd(cwd): if dry_run is False: run_cmd("bash %s" % os.path.basename(script_fn), sys.stdout, sys.stderr, shell=False) assert_nonzero("preads4falcon.fasta")
def run_merge_consensus_jobs(input_files, output_files, db_prefix='raw_reads'): print('run_merge_consensus_jobs: %s %s %s' % (db_prefix, repr(input_files), repr(output_files))) i_json_config_fn, run_daligner_job_fn, i_fofn_fn = input_files o_fofn_fn, = output_files db_dir = os.path.dirname(run_daligner_job_fn) cmds = ['pwd', 'ls -al'] fns = ['.{pre}.bps', '.{pre}.idx', '{pre}.db'] cmds += ['rm -f %s' % fn for fn in fns] cmds += ['ln -sf {dir}/%s .' % fn for fn in fns] cmd = ';'.join(cmds).format(dir=os.path.relpath(db_dir), pre=db_prefix) run_cmd(cmd, sys.stdout, sys.stderr, shell=True) cwd = os.getcwd() # same as dir of o_fofn_fn config = _get_config_from_json_fileobj(open(i_json_config_fn)) # i_fofn_fn has the .las files, so create_merge_tasks does not need to look for theme. tasks = create_merge_tasks(i_fofn_fn, run_daligner_job_fn, cwd, db_prefix=db_prefix, config=config) las_fns = _run_merge_jobs( dict((p_id, (argstuple[0], argstuple[2])) for (p_id, argstuple) in tasks.items())) if db_prefix == 'raw_reads': fasta_fns = _run_consensus_jobs( dict((p_id, (argstuple[1], argstuple[3])) for (p_id, argstuple) in tasks.items())) # Record '*.fasta' in FOFN. write_fns(o_fofn_fn, sorted(os.path.abspath(f) for f in fasta_fns)) assert_nonzero(o_fofn_fn) return # Record '*.las' from merge_jobs in FOFN. write_fns(o_fofn_fn, sorted(os.path.abspath(f) for f in las_fns)) # Generate preads4falcon.fasta from preads.db script_fn = os.path.join(cwd, "run_db2falcon.sh") job_done = script_fn + '_done' args = { 'config': config, 'job_done': job_done, 'script_fn': script_fn, } support.run_db2falcon(**args) run_cmd('bash %s' % script_fn, sys.stdout, sys.stderr, shell=False) assert_nonzero('preads4falcon.fasta') assert_nonzero(o_fofn_fn) return 0
def run_merge_consensus_jobs(input_files, output_files, db_prefix='raw_reads'): print('run_merge_consensus_jobs: %s %s %s' %(db_prefix, repr(input_files), repr(output_files))) i_json_config_fn, run_daligner_job_fn, i_fofn_fn = input_files o_fofn_fn, = output_files db_dir = os.path.dirname(run_daligner_job_fn) cmds = ['pwd', 'ls -al'] fns = ['.{pre}.bps', '.{pre}.idx', '{pre}.db'] cmds += ['rm -f %s' %fn for fn in fns] cmds += ['ln -sf {dir}/%s .' %fn for fn in fns] cmd = ';'.join(cmds).format( dir=os.path.relpath(db_dir), pre=db_prefix) run_cmd(cmd, sys.stdout, sys.stderr, shell=True) cwd = os.getcwd() # same as dir of o_fofn_fn config = _get_config_from_json_fileobj(open(i_json_config_fn)) # i_fofn_fn has the .las files, so create_merge_tasks does not need to look for theme. tasks = create_merge_tasks(i_fofn_fn, run_daligner_job_fn, cwd, db_prefix=db_prefix, config=config) las_fns = _run_merge_jobs( dict((p_id, (argstuple[0], argstuple[2])) for (p_id, argstuple) in tasks.items())) if db_prefix == 'raw_reads': fasta_fns = _run_consensus_jobs( dict((p_id, (argstuple[1], argstuple[3])) for (p_id, argstuple) in tasks.items())) # Record '*.fasta' in FOFN. write_fns(o_fofn_fn, sorted(os.path.abspath(f) for f in fasta_fns)) assert_nonzero(o_fofn_fn) return # Record '*.las' from merge_jobs in FOFN. write_fns(o_fofn_fn, sorted(os.path.abspath(f) for f in las_fns)) # Generate preads4falcon.fasta from preads.db script_fn = os.path.join(cwd, "run_db2falcon.sh") job_done = script_fn + '_done' args = { 'config': config, 'job_done': job_done, 'script_fn': script_fn, } support.run_db2falcon(**args) run_cmd('bash %s' %script_fn, sys.stdout, sys.stderr, shell=False) assert_nonzero('preads4falcon.fasta') assert_nonzero(o_fofn_fn)
def _run_db2falcon_jobs(cwd, config, dry_run, db2falcon_json_fn=None): """ cwd --- current workding directory dry_run --- if True, do not actually run the scripts db2falcon_json_fn --- if not None, write dict{0: dict('script_fn':script_fn, 'script_dir':script_dir)} """ # Generate preads4falcon.fasta from preads.db script_fn = os.path.join(cwd, "run_db2falcon.sh") job_done = script_fn + '_done' args = { 'config': config, 'job_done': job_done, 'script_fn': script_fn, 'preads4falcon_fn': 'preads4falcon.fasta', 'preads_db': 'preads.db', } support.run_db2falcon(**args) json_fn = "db2falcon.json" if db2falcon_json_fn is None else db2falcon_json_fn # add script_dir to args for scattered tasks to work in the correct dir json_data = { 0: { 'script_fn': os.path.basename(script_fn), 'script_dir': cwd } } with open(json_fn, 'w') as writer: writer.write(json.dumps(json_data) + "\n") mkdir(cwd) with cd(cwd): if dry_run is False: run_cmd('bash %s' % os.path.basename(script_fn), sys.stdout, sys.stderr, shell=False) assert_nonzero('preads4falcon.fasta')