<commit_before>#!/usr/bin/env python
import click
import os

from ninja_utils.parsers import FASTA
from ninja_utils.utils import find_between
from ninja_utils.utils import verify_make_dir

from ninja_dojo.taxonomy import NCBITree


@click.command()
@click.option('-i', '--input', type=click.File(), default='-')
@click.option('-o', '--output', type=click.Path(), default=os.path.join(os.getcwd(), 'annotated'))
@click.option('-x', '--extract_ncbi_tid', default='ncbi_tid|,|')
def shogun_capitalist_db(input, output, extract_ncbi_tid):

    verify_make_dir(output)
    verify_make_dir(os.path.join(output, 'capitalist'))

    begin, end = extract_ncbi_tid.split(',')
    tree = NCBITree()

    inf_fasta = FASTA(input)
    for title, seq in inf_fasta.read():
        title = '>' + title
        title.replace('\t', '|')
        ncbi_tid = find_between(title, begin, end)
        if ncbi_tid:
            gg = tree.gg_lineage(ncbi_tid[0])
            with open(os.path.join(output, 'capitalist', gg + '.fna'), 'a+') as output_fna:
                header = 'ncbi_tid|%d|%s' % (ncbi_tid[0], title[1:])
                output_fna.write('>%s\n%s\n' % (header, seq))


if __name__ == '__main__':
    shogun_capitalist_db()
<commit_msg>NCBI TID MUST BE AN INT.<commit_after>#!/usr/bin/env python
import click
import os

from ninja_utils.parsers import FASTA
from ninja_utils.utils import find_between
from ninja_utils.utils import verify_make_dir

from ninja_dojo.taxonomy import NCBITree


@click.command()
@click.option('-i', '--input', type=click.File(), default='-')
@click.option('-o', '--output', type=click.Path(), default=os.path.join(os.getcwd(), 'annotated'))
@click.option('-x', '--extract_ncbi_tid', default='ncbi_tid|,|')
def shogun_capitalist_db(input, output, extract_ncbi_tid):

    verify_make_dir(output)
    verify_make_dir(os.path.join(output, 'capitalist'))

    begin, end = extract_ncbi_tid.split(',')
    tree = NCBITree()

    inf_fasta = FASTA(input)
    for title, seq in inf_fasta.read():
        title = '>' + title
        title.replace('\t', '|')
        ncbi_tid = int(find_between(title, begin, end))
        if ncbi_tid:
            gg = tree.gg_lineage(ncbi_tid[0])
            with open(os.path.join(output, 'capitalist', gg + '.fna'), 'a+') as output_fna:
                header = 'ncbi_tid|%d|%s' % (ncbi_tid, title[1:])
                output_fna.write('>%s\n%s\n' % (header, seq))


if __name__ == '__main__':
    shogun_capitalist_db()

{'fraction_non_alphanumeric': 0.1656541109761037, 'fraction_numerical': 0.002025111381125962, 'mean_word_length': 3.6516007532956687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4143048', 'n_tokens_mistral': 953, 'n_tokens_neox': 893, 'n_words': 173}