コード例 #1
0
ファイル: blast.py プロジェクト: JoseBlanca/seq_crumbs
def _makeblastdb_plus(seq_fpath, dbtype, outputdb=None):
    'It creates the blast db database'
    cmd = [get_binary_path('makeblastdb'), '-in', seq_fpath, '-dbtype', dbtype]
    if outputdb is not None:
        cmd.extend(['-out', outputdb])
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #2
0
ファイル: blast.py プロジェクト: bharatpatel/seq_crumbs
def _makeblastdb_plus(seq_fpath, dbtype, outputdb=None):
    "It creates the blast db database"
    cmd = [get_binary_path("makeblastdb"), "-in", seq_fpath, "-dbtype", dbtype]
    if outputdb is not None:
        cmd.extend(["-out", outputdb])
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #3
0
def _makeblastdb_plus(seq_fpath, dbtype, outputdb=None):
    'It creates the blast db database'
    cmd = [get_binary_path('makeblastdb'), '-in', seq_fpath, '-dbtype', dbtype]
    if outputdb is not None:
        cmd.extend(['-out', outputdb])
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #4
0
def _create_bwa_index(index_fpath):
    binary = get_binary_path('bwa')
    # how many sequences do we have?
    n_seqs = [l for l in open(index_fpath) if l[0] == '>']
    algorithm = 'bwtsw' if n_seqs > 10000 else 'is'
    cmd = [binary, 'index', '-a', algorithm, index_fpath]
    process = popen(cmd, stdout=PIPE, stderr=PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #5
0
ファイル: test_utils.py プロジェクト: bharatpatel/seq_crumbs
    def test_check_process(self):
        'It checks that a process finishes OK'

        binary = 'ls'
        process = Popen([binary, '/directorio_que_no_existe'], stderr=PIPE)
        try:
            check_process_finishes(process, binary)
            self.fail('ExternalBinaryErrorExpected')
        except ExternalBinaryError, error:
            assert binary in str(error)
コード例 #6
0
ファイル: test_utils.py プロジェクト: radaniba/seq_crumbs
    def test_check_process(self):
        "It checks that a process finishes OK"

        binary = "ls"
        process = Popen([binary, "/directorio_que_no_existe"], stderr=PIPE)
        try:
            check_process_finishes(process, binary)
            self.fail("ExternalBinaryErrorExpected")
        except ExternalBinaryError, error:
            assert binary in str(error)
コード例 #7
0
    def test_check_process(self):
        'It checks that a process finishes OK'

        binary = 'ls'
        process = Popen([binary, '/directorio_que_no_existe'], stderr=PIPE)
        try:
            check_process_finishes(process, binary)
            self.fail('ExternalBinaryErrorExpected')
        except ExternalBinaryError, error:
            assert binary in str(error)
コード例 #8
0
ファイル: annotation.py プロジェクト: JoseBlanca/seq_crumbs
def _run_estscan(seqs, pep_out_fpath, dna_out_fpath, matrix_fpath):
    'It runs estscan in the input seqs'
    seq_fhand = write_seqs(seqs, file_format='fasta')
    seq_fhand.flush()
    binary = get_binary_path('estscan')

    cmd = [binary, '-t', pep_out_fpath, '-o', dna_out_fpath, '-M',
           matrix_fpath, seq_fhand.name]
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
    seq_fhand.close()
コード例 #9
0
ファイル: annotation.py プロジェクト: terrycojones/seq_crumbs
def _run_estscan(seqs, pep_out_fpath, dna_out_fpath, matrix_fpath):
    'It runs estscan in the input seqs'
    seq_fhand = write_seqs(seqs, file_format='fasta')
    seq_fhand.flush()
    binary = get_binary_path('estscan')

    cmd = [binary, '-t', pep_out_fpath, '-o', dna_out_fpath, '-M',
           matrix_fpath, seq_fhand.name]
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
    seq_fhand.close()
コード例 #10
0
def get_or_create_bowtie2_index(fpath, directory=None):
    "it creates the bowtie2 index"
    binary = get_binary_path('bowtie2-build')
    if directory is not None:
        index_fpath = os.path.join(directory, os.path.basename(fpath))
    else:
        index_fpath = fpath
    if not _bowtie2_index_exists(index_fpath):
        cmd = [binary, '-f', fpath, index_fpath]
        process = popen(cmd, stdout=PIPE, stderr=PIPE)
        check_process_finishes(process, binary=cmd[0])
    return index_fpath
コード例 #11
0
ファイル: blast.py プロジェクト: charles-plessy/seq_crumbs
def do_blast(query_fpath, db_fpath, program, out_fpath, params=None):
    "It does a blast"
    if not params:
        params = {}
    evalue = params.get("evalue", 0.001)
    task = params.get("task", "megablast")
    outfmt = str(params.get("outfmt", 5))
    assert task in ("blastn", "blastn-short", "dc-megablast", "megablast", "rmblastn")

    if program not in ("blastn", "blastp", "blastx", "tblastx", "tblastn"):
        raise ValueError("The given program is invalid: " + str(program))
    binary = get_binary_path(program)
    cmd = [binary, "-query", query_fpath, "-db", db_fpath, "-out", out_fpath]
    cmd.extend(["-evalue", str(evalue), "-task", task])
    cmd.extend(["-outfmt", outfmt])
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #12
0
ファイル: blast.py プロジェクト: bharatpatel/seq_crumbs
def _do_blast_local(query_fpath, db_fpath, program, out_fpath, params=None):
    "It does a blast"
    if not params:
        params = {}
    evalue, task = _parse_blast_params(params, program)

    if "outfmt" in params:
        outfmt = params["outfmt"]
        del params["outfmt"]
    else:
        outfmt = 5

    if program not in ("blastn", "blastp", "blastx", "tblastx", "tblastn"):
        raise ValueError("The given program is invalid: " + str(program))
    binary = get_binary_path(program)
    cmd = [binary, "-query", query_fpath, "-db", db_fpath, "-out", out_fpath]
    cmd.extend(["-evalue", str(evalue), "-outfmt", str(outfmt)])
    if task:
        cmd.extend(["-task", task])
    if params:
        for key, value in params.viewitems():
            cmd.extend(("-" + key, str(value)))
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #13
0
def _do_blast_local(query_fpath, db_fpath, program, out_fpath, params=None):
    'It does a blast'
    if not params:
        params = {}
    evalue, task = _parse_blast_params(params, program)

    if 'outfmt' in params:
        outfmt = params['outfmt']
        del params['outfmt']
    else:
        outfmt = 5

    if program not in ('blastn', 'blastp', 'blastx', 'tblastx', 'tblastn'):
        raise ValueError('The given program is invalid: ' + str(program))
    binary = get_binary_path(program)
    cmd = [binary, '-query', query_fpath, '-db', db_fpath, '-out', out_fpath]
    cmd.extend(['-evalue', str(evalue), '-outfmt', str(outfmt)])
    if task:
        cmd.extend(['-task', task])
    if params:
        for key, value in params.viewitems():
            cmd.extend(('-' + key, str(value)))
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #14
0
ファイル: blast.py プロジェクト: JoseBlanca/seq_crumbs
def _do_blast_local(query_fpath, db_fpath, program, out_fpath, params=None):
    'It does a blast'
    if not params:
        params = {}
    evalue, task = _parse_blast_params(params, program)

    if 'outfmt' in params:
        outfmt = params['outfmt']
        del params['outfmt']
    else:
        outfmt = 5

    if program not in ('blastn', 'blastp', 'blastx', 'tblastx', 'tblastn'):
        raise ValueError('The given program is invalid: ' + str(program))
    binary = get_binary_path(program)
    cmd = [binary, '-query', query_fpath, '-db', db_fpath, '-out', out_fpath]
    cmd.extend(['-evalue', str(evalue), '-outfmt', str(outfmt)])
    if task:
        cmd.extend(['-task', task])
    if params:
        for key, value in params.viewitems():
            cmd.extend(('-' + key, str(value)))
    process = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    check_process_finishes(process, binary=cmd[0])
コード例 #15
0
class UtilsTest(unittest.TestCase):
    'It tests the miscelaneous utilities.'

    def test_rel_symlink(self):
        'It tests various cases of rel symlinks'
        tempdir = TemporaryDir()
        try:
            hola = os.path.join(tempdir.name, 'hola')
            os.mkdir(hola)
            caracola = os.path.join(tempdir.name, 'caracola')
            rel_symlink(hola, caracola)
            assert os.path.exists(caracola)

            fname = os.path.join(hola, 'fname')
            open(fname, 'w')
            caracola2 = os.path.join(tempdir.name, 'caracola2')
            rel_symlink(fname, caracola2)
            assert os.path.exists(caracola2)

            path2 = os.path.join(tempdir.name, 'dir1', 'dir2')
            os.makedirs(path2)
            caracola3 = os.path.join(path2, 'caracola3')
            rel_symlink(hola, caracola3)
            assert os.path.exists(caracola3)
        finally:
            tempdir.close()

    def test_check_process(self):
        'It checks that a process finishes OK'

        binary = 'ls'
        process = Popen([binary, '/directorio_que_no_existe'], stderr=PIPE)
        try:
            check_process_finishes(process, binary)
            self.fail('ExternalBinaryErrorExpected')
        except ExternalBinaryError, error:
            assert binary in str(error)

        stderr = NamedTemporaryFile()
        process = Popen([binary, '/directorio_que_no_existe'], stderr=stderr)
        try:
            check_process_finishes(process, binary, stderr=stderr)
        except ExternalBinaryError, error:
            assert binary in str(error)
コード例 #16
0
ファイル: test_utils.py プロジェクト: bharatpatel/seq_crumbs
        try:
            check_process_finishes(process, binary)
            self.fail('ExternalBinaryErrorExpected')
        except ExternalBinaryError, error:
            assert binary in str(error)

        stderr = NamedTemporaryFile()
        process = Popen([binary, '/directorio_que_no_existe'], stderr=stderr)
        try:
            check_process_finishes(process, binary, stderr=stderr)
        except ExternalBinaryError, error:
            assert binary in str(error)

        cmd = [binary]
        process = Popen(cmd, stdout=PIPE)
        check_process_finishes(process, binary)

    def test_popen(self):
        'It checks that we can create a process'

        try:
            popen(['bad_binary'])
            self.fail()
        except MissingBinaryError:
            pass

        popen(['ls'], stdout=PIPE)

    def test_io_open(self):
        'It checks the file wrapping in ReaderBuffers'
コード例 #17
0
        try:
            check_process_finishes(process, binary)
            self.fail('ExternalBinaryErrorExpected')
        except ExternalBinaryError, error:
            assert binary in str(error)

        stderr = NamedTemporaryFile()
        process = Popen([binary, '/directorio_que_no_existe'], stderr=stderr)
        try:
            check_process_finishes(process, binary, stderr=stderr)
        except ExternalBinaryError, error:
            assert binary in str(error)

        cmd = [binary]
        process = Popen(cmd, stdout=PIPE)
        check_process_finishes(process, binary)

    def test_popen(self):
        'It checks that we can create a process'

        try:
            popen(['bad_binary'])
            self.fail()
        except MissingBinaryError:
            pass

        popen(['ls'], stdout=PIPE)

    def test_io_open(self):
        'It checks the file wrapping in ReaderBuffers'