def test_each():
    upper = lambda x: x.upper()
    eq_(run(Fun(linecmd('echo "a\nb\nc"')) |
            each(upper) |
            strip('\n') |
            join),
        'ABC')
Beispiel #2
0
def run_and_log_output(cmd_string, *args, **kwargs):
    """
    Runs a command with iterpipes and logs the output
    """
    c = iterpipes.cmd(cmd_string, bufsize=128, *args, **kwargs)
    logging.info('Running %s', iterpipes.format(cmd_string, args))
    out = iterpipes.run(c)
    for line in out:
        logging.info(line)
Beispiel #3
0
def multiple_alignment_use_files(file_input, alignment_type=SeqTypeData().TYPE_DEFAULT):
    muscle_cmd = SeqTypeData().type2cmd_f[alignment_type]
    result = iterpipes.run(iterpipes.linecmd(str(muscle_cmd) + " -in \"" + file_input + "\""))
    result_list = []
    for i in result:
        result_list.append(i.strip())
    # iores = StringIO()
    # for i in result_list:
    #     print(i[0])
    #     iores.write(i)
    name = file_input[:file_input.rfind('.')] + "-aligned.fa"
    with open(name, "wt") as tmpfd:
        tmpfd.write("\n".join(result_list))
    return fasta_tools.read_fasta(name, False)
Beispiel #4
0
def multiple_alignment_use_files(file_input,
                                 alignment_type=SeqTypeData().TYPE_DEFAULT):
    muscle_cmd = SeqTypeData().type2cmd_f[alignment_type]
    result = iterpipes.run(
        iterpipes.linecmd(str(muscle_cmd) + " -in \"" + file_input + "\""))
    result_list = []
    for i in result:
        result_list.append(i.strip())
    # iores = StringIO()
    # for i in result_list:
    #     print(i[0])
    #     iores.write(i)
    name = file_input[:file_input.rfind('.')] + "-aligned.fa"
    with open(name, "wt") as tmpfd:
        tmpfd.write("\n".join(result_list))
    return fasta_tools.read_fasta(name, False)
Beispiel #5
0
def get_git_hash():
    c = iterpipes.cmd('git rev-parse HEAD')
    out = iterpipes.run(c)
    return list(out)[0].strip()
def test_or_operator():
    eq_(run(Fun(cmd('echo foo')) | (lambda x: x) | join), 'foo\n')
    eq_(run(Fun(lambda _: ['a']) | cmd('tr a-z A-Z') | join), 'A')
def test_stdin_iterable_excpt():
    class E(Exception): pass
    def g():
        raise E('foo')
        yield 'bar'
    assert_raises(E, lambda: ''.join(run(cmd('grep foo'), g())))
def test_run_output():
    eq_(''.join(run(cmd('echo foo'))), 'foo\n')
    eq_(run(compose(join, cmd('echo foo'))), 'foo\n')
    eq_(call(cmd('echo foo')), 0)
def test_dont_touch_stdout():
    eq_(''.join(run(cmd('ls -d /', stdout=STDOUT_FILENO))), '')
def test_make_pipeline():
    lines = ''.join(run(cmd(r'echo a b c b a | tr {} \\n | sort | uniq',
                            ' ')))
    eq_(lines, 'a\nb\nc\n')
def test_basic_many():
    eq_(''.join(run(cmd('echo foo | wc -l'))), '1\n')
def test_basic_single():
    eq_(''.join(run(cmd('ls -d /'))), '/\n')
def test_string_input():
    eq_(''.join(run(cmd('tr t T'), 'input')), six.u('inpuT'))
    eq_(''.join(run(cmd('tr t T'), six.u('input'))), six.u('inpuT'))
    eq_(''.join(run(cmd('tr t T'), [six.u('input')])), six.u('inpuT'))