Esempio n. 1
0
def test_each():
    upper = lambda x: x.upper()
    eq_(run(Fun(linecmd('echo "a\nb\nc"')) |
            each(upper) |
            strip('\n') |
            join),
        'ABC')
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 5
0
def get_git_hash():
    c = iterpipes.cmd('git rev-parse HEAD')
    out = iterpipes.run(c)
    return list(out)[0].strip()
Esempio n. 6
0
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')
Esempio n. 7
0
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())))
Esempio n. 8
0
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)
Esempio n. 9
0
def test_dont_touch_stdout():
    eq_(''.join(run(cmd('ls -d /', stdout=STDOUT_FILENO))), '')
Esempio n. 10
0
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')
Esempio n. 11
0
def test_basic_many():
    eq_(''.join(run(cmd('echo foo | wc -l'))), '1\n')
Esempio n. 12
0
def test_basic_single():
    eq_(''.join(run(cmd('ls -d /'))), '/\n')
Esempio n. 13
0
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'))