Example #1
0
 def test_build_contig_db_from_fasta(self):
     conn = sqlite3.connect(':memory:')
     ramifier = RotatingRamifier.from_file(4, KMER_ROTATION)
     contig_db = ContigDB(conn, ramifier=ramifier, box_side_len=0.5)
     contig_db.fast_add_kmers_from_fasta(KMER_FASTA)
     contig_db.commit()
     stored = contig_db.get_all_contigs()
     self.assertGreaterEqual(len(stored), 3)
Example #2
0
def build_contig_cover_fasta(radius, dimension, threads, outfile, rotation,
                             fasta_list):
    environ[
        'OPENBLAS_NUM_THREADS'] = f'{threads}'  # numpy uses one of these two libraries
    environ['MKL_NUM_THREADS'] = f'{threads}'
    fasta_list = [line.strip() for line in fasta_list]
    ramifier = RotatingRamifier.from_file(dimension, rotation)
    grid = ContigDB(sqlite3.connect(outfile),
                    ramifier=ramifier,
                    box_side_len=radius)
    click.echo(f'Adding {len(fasta_list)} fastas.', err=True)
    start = time()
    with click.progressbar(fasta_list) as fastas:
        for fasta_filename in fastas:
            n_added = grid.fast_add_kmers_from_fasta(fasta_filename)
    grid.close()
    add_time = time() - start
    click.echo(f'Added {n_added:,} kmers to {outfile} in {add_time:.5}s. ',
               err=True)