예제 #1
0
    def build_diamond_db(self):
        """Build DIAMOND database.
        """
        # create temporary taxon map
        taxonmap = join(self.tmpdir, 'prot.accession2taxid')
        with open(taxonmap, 'w') as f:
            f.write('accession\taccession.version\ttaxid\n')
            for p, tid in sorted(self.taxonmap.items()):
                f.write(f'{p.rsplit(".", 1)[0]}\t{p}\t{tid}\n')

        # build DIAMOND database
        makedirs(join(self.output, 'diamond'), exist_ok=True)
        cmd = ' '.join(
            (self.diamond, 'makedb', '--threads', str(self.threads), '--in',
             join(self.output,
                  'db.faa'), '--taxonmap', taxonmap, '--taxonnodes',
             join(self.output, 'taxdump', 'nodes.dmp'), '--taxonnames',
             join(self.output, 'taxdump',
                  'names.dmp'), '--db', join(self.output, 'diamond',
                                             'db'), '--tmpdir', self.tmpdir))
        print('Build DIAMOND database...', flush=True)
        ec, out = run_command(cmd)
        if ec:
            raise ValueError(f'diamond failed with error code {ec}.')

        # clean up
        remove(taxonmap)
        print('Done.')
예제 #2
0
    def test_run_command(self):
        # simple command
        cmd = 'echo "This is a test!"'
        obs = run_command(cmd)
        self.assertEqual(obs[0], 0)
        self.assertListEqual(obs[1], ['This is a test!'])

        # multiple-line output
        cmd = 'for i in 1 2 3; do echo $i; done'
        obs = run_command(cmd)[1]
        self.assertListEqual(obs, ['1', '2', '3'])

        # capture stderr
        cmd = 'echo "This is an error!" >&2'
        obs = run_command(cmd)[1]
        self.assertListEqual(obs, ['This is an error!'])
예제 #3
0
    def build_diamond_db(self):
        """Build DIAMOND database.
        """
        # create temporary taxon map
        taxonmap = join(self.tmpdir, 'prot.accession2taxid')
        with open(taxonmap, 'w') as f:
            f.write('accession\taccession.version\ttaxid\n')
            for p, tid in sorted(self.taxonmap.items()):
                f.write('{}\t{}\t{}\n'.format(p.rsplit('.', 1)[0], p, tid))

        # build DIAMOND database
        makedirs(join(self.output, 'diamond'), exist_ok=True)
        cmd = ('{} makedb --threads {} --in {} --taxonmap {} --taxonnodes {} '
               '--taxonnames {} --db {} --tmpdir {}'.format(
                   self.diamond, self.threads, join(self.output, 'db.faa'),
                   taxonmap, join(self.output, 'taxdump', 'nodes.dmp'),
                   join(self.output, 'taxdump', 'names.dmp'),
                   join(self.output, 'diamond', 'db'), self.tmpdir))
        print('Build DIAMOND database...', flush=True)
        ec, out = run_command(cmd, capture=False, merge=False)
        if ec:
            raise ValueError('diamond failed with error code {}.'.format(ec))

        # clean up
        remove(taxonmap)
        print('Done.')
예제 #4
0
 def build_blast_db(self):
     """Build BLAST database.
     """
     makedirs(join(self.output, 'blast'), exist_ok=True)
     cmd = ('{} -dbtype prot -in {} -out {} -title db -parse_seqids '
            '-taxid_map {}'.format(self.makeblastdb,
                                   join(self.output, 'db.faa'),
                                   join(self.output, 'blast', 'db'),
                                   join(self.output, 'taxon.map')))
     print('Build BLAST database...', flush=True)
     ec, out = run_command(cmd, capture=False)
     if ec:
         raise ValueError(
             'makeblastdb failed with error code {}.'.format(ec))
     print('Done.')
예제 #5
0
 def build_blast_db(self):
     """Build BLAST database.
     """
     makedirs(join(self.output, 'blast'), exist_ok=True)
     cmd = ' '.join(
         (self.makeblastdb, '-dbtype', 'prot', '-in',
          join(self.output,
               'db.faa'), '-out', join(self.output, 'blast',
                                       'db'), '-title', 'db',
          '-parse_seqids', '-taxid_map', join(self.output, 'taxon.map')))
     print('Build BLAST database...', flush=True)
     ec, out = run_command(cmd)
     if ec:
         raise ValueError(f'makeblastdb failed with error code {ec}.')
     print('Done.')
예제 #6
0
    def build_blast_db(self):
        """Build BLAST database.
        """
        # create temporary taxon map
        taxonmap = join(self.tmpdir, 'taxon.map')
        with open(taxonmap, 'w') as f:
            for p, tid in sorted(self.taxonmap.items()):
                f.write(f'{p}\t{tid}\n')

        # build BLAST database
        makedirs(join(self.output, 'blast'), exist_ok=True)
        cmd = ' '.join((self.makeblastdb, '-dbtype', 'prot', '-in',
                        join(self.output,
                             'db.faa'), '-out', join(self.output, 'blast',
                                                     'db'), '-title', 'db',
                        '-parse_seqids', '-taxid_map', taxonmap))
        print('Build BLAST database...', flush=True)
        ec, out = run_command(cmd)
        if ec:
            raise ValueError(f'makeblastdb failed with error code {ec}.')

        # clean up
        remove(taxonmap)
        print('Done.')