Пример #1
0
def run_falcon_asm(input_files, output_files):
    i_json_config_fn, i_fofn_fn = input_files[0:2]
    o_fasta_fn = output_files[0]
    cwd = os.getcwd()
    pread_dir = os.path.dirname(i_fofn_fn)
    preads4falcon_fasta_fn = os.path.join(pread_dir, "preads4falcon.fasta")
    db_file = os.path.join(pread_dir, "preads.db")
    job_done = os.path.join(cwd, "job_done")
    config = _get_config_from_json_fileobj(open(i_json_config_fn))
    script_fn = os.path.join(cwd, "run_falcon_asm.sh")
    args = {
        "las_fofn_fn": i_fofn_fn,
        "preads4falcon_fasta_fn": preads4falcon_fasta_fn,
        "db_file_fn": db_file,
        "config": config,
        "job_done": job_done,
        "script_fn": script_fn,
    }
    assert_nonzero(i_fofn_fn)
    assert_nonzero(preads4falcon_fasta_fn)
    support.run_falcon_asm(**args)
    run_cmd("bash %s" % script_fn, sys.stdout, sys.stderr, shell=False)
    p_ctg = "p_ctg.fa"
    assert_nonzero(p_ctg)
    n_records = _linewrap_fasta(p_ctg, o_fasta_fn)
    if n_records == 0:
        # We already checked 0-length, but maybe this is still possible.
        # Really, we want to detect 0 base-length, but I do not know how yet.
        raise Exception("No records found in primary contigs: '%s'" % os.path.abspath(p_ctg))
    say("Finished run_falcon_asm(%s, %s)" % (repr(input_files), repr(output_files)))
    return 0
Пример #2
0
def run_falcon_asm(input_files, output_files):
    i_json_config_fn, i_fofn_fn = input_files
    o_fasta_fn, = output_files
    cwd = os.getcwd()
    pread_dir = os.path.dirname(i_fofn_fn)
    preads4falcon_fasta_fn = os.path.join(pread_dir, 'preads4falcon.fasta')
    db_file = os.path.join(pread_dir, 'preads.db')
    job_done = os.path.join(cwd, 'job_done')
    config = _get_config_from_json_fileobj(open(i_json_config_fn))
    script_fn = os.path.join(cwd, "run_falcon_asm.sh")
    args = {
        'las_fofn_fn': i_fofn_fn,
        'preads4falcon_fasta_fn': preads4falcon_fasta_fn,
        'db_file_fn': db_file,
        'config': config,
        'job_done': job_done,
        'script_fn': script_fn,
    }
    assert_nonzero(i_fofn_fn)
    assert_nonzero(preads4falcon_fasta_fn)
    support.run_falcon_asm(**args)
    run_cmd('bash %s' % script_fn, sys.stdout, sys.stderr, shell=False)
    p_ctg = 'p_ctg.fa'
    assert_nonzero(p_ctg)
    n_records = _linewrap_fasta(p_ctg, o_fasta_fn)
    if n_records == 0:
        # We already checked 0-length, but maybe this is still possible.
        # Really, we want to detect 0 base-length, but I do not know how yet.
        raise Exception("No records found in primary contigs: '%s'" %
                        os.path.abspath(p_ctg))
    say('Finished run_falcon_asm(%s, %s)' %
        (repr(input_files), repr(output_files)))
    return 0
Пример #3
0
def run_rm_las(input_files, output_files, prefix):
    """ Delete all intermediate las files. """
    cmd = "pwd && find .. -type f -name '%s*.las' -delete -print" % prefix
    say(cmd)
    run_cmd(cmd, sys.stdout, sys.stderr)
    with open(output_files[0], 'w') as writer:
        writer.write("#%s" % cmd)
    return 0
Пример #4
0
def run_rm_las(input_files, output_files, prefix):
    """ Delete all intermediate las files. """
    cmd = "pwd && find .. -type f -name '%s*.las' -delete -print" % prefix
    say(cmd)
    run_cmd(cmd, sys.stdout, sys.stderr)
    with open(output_files[0], "w") as writer:
        writer.write("#%s" % cmd)
    return 0
Пример #5
0
def run_falcon_config_get_fasta(input_files, output_files):
    i_config_fn, = input_files
    o_fofn_fn, = output_files
    config = _get_config(i_config_fn)
    i_fofn_fn = config['input_fofn']
    if not os.path.isabs(i_fofn_fn):
        i_fofn_fn = os.path.join(os.path.dirname(i_config_fn), i_fofn_fn)
    msg = '%r -> %r' % (i_fofn_fn, o_fofn_fn)
    say(msg)
    with cd(os.path.dirname(i_fofn_fn)):
        return support.make_fofn_abs(i_fofn_fn, o_fofn_fn)
    return 0
Пример #6
0
def run_falcon_config_get_fasta(input_files, output_files):
    i_config_fn, = input_files
    o_fofn_fn, = output_files
    config = _get_config(i_config_fn)
    i_fofn_fn = config["input_fofn"]
    if not os.path.isabs(i_fofn_fn):
        i_fofn_fn = os.path.join(os.path.dirname(i_config_fn), i_fofn_fn)
    msg = "%r -> %r" % (i_fofn_fn, o_fofn_fn)
    say(msg)
    with cd(os.path.dirname(i_fofn_fn)):
        return support.make_fofn_abs(i_fofn_fn, o_fofn_fn)
    return 0
Пример #7
0
def run_falcon_make_fofn_abs(input_files, output_files):
    i_json_fn, = input_files
    o_fofn_fn, = output_files
    config = _get_config_from_json_fileobj(open(i_json_fn))
    i_fofn_fn = config["input_fofn"]
    if not i_fofn_fn.startswith("/"):
        # i_fofn_fn can be relative to the location of the config file.
        original_config_fn = config["original_self"]
        i_fofn_fn = os.path.join(os.path.dirname(original_config_fn), i_fofn_fn)
    msg = "run_falcon_make_fofn_abs(%r -> %r)" % (i_fofn_fn, o_fofn_fn)
    say(msg)
    with cd(os.path.dirname(i_fofn_fn)):
        return support.make_fofn_abs(i_fofn_fn, o_fofn_fn)
    return 0
Пример #8
0
def run_falcon_make_fofn_abs(input_files, output_files):
    i_json_fn, = input_files
    o_fofn_fn, = output_files
    config = _get_config_from_json_fileobj(open(i_json_fn))
    i_fofn_fn = config['input_fofn']
    if not i_fofn_fn.startswith('/'):
        # i_fofn_fn can be relative to the location of the config file.
        original_config_fn = config['original_self']
        i_fofn_fn = os.path.join(os.path.dirname(original_config_fn),
                                 i_fofn_fn)
    msg = 'run_falcon_make_fofn_abs(%r -> %r)' % (i_fofn_fn, o_fofn_fn)
    say(msg)
    with cd(os.path.dirname(i_fofn_fn)):
        return support.make_fofn_abs(i_fofn_fn, o_fofn_fn)
    return 0
Пример #9
0
def _get_config_from_json_fileobj(ifs_json):
    i_json = ifs_json.read()
    say('JSON=\n%s' % i_json[:1024])  # truncated
    return json.loads(i_json)
Пример #10
0
def run_cmd(cmd, *args, **kwds):
    say('RUN: %s' % repr(cmd))
    rc = pb_run_cmd(cmd, *args, **kwds)
    say(' RC: %s' % repr(rc))
    if rc.exit_code:
        raise Exception(repr(rc))
Пример #11
0
def _get_config_from_json_fileobj(ifs_json):
    i_json = ifs_json.read()
    say("JSON=\n%s" % i_json[:1024])  # truncated
    return json.loads(i_json)
Пример #12
0
def run_cmd(cmd, *args, **kwds):
    say("RUN: %s" % repr(cmd))
    rc = pb_run_cmd(cmd, *args, **kwds)
    say(" RC: %s" % repr(rc))
    if rc.exit_code:
        raise Exception(repr(rc))