<commit_before>#!/usr/bin/env python
"""A script to split a fasta file into multiple smaller files.

Output files will be <original>.xx.fasta
"""

import argparse
import sys
import os
import re

def header(row):
    regex = re.compile("^>")
    return regex.findall(row)

def next_output_file(input_file, prefix, i):
    if input_file is not None:
        prefix = ".".join(os.path.basename(input_file).split('.')[0:])
    
    new_filename = "{0}.{1}.fasta".format(prefix, i)
    print new_filename
    return open(new_filename, 'w')


def main(args):
    if args.input_fasta is not None:
        input_handle = open(args.input_fasta, 'r')
    else:
        input_handle = sys.stdin

    n = 0
    i = 0
    outputfh = next_output_file(args.input_fasta, args.prefix, i) 
    for row in input_handle:
        if header(row):
            n+=1

        if n > args.n_seqs:
            i += 1
            n = 1<commit_msg>Split fasta more python3 ready<commit_after>#!/usr/bin/env python
"""A script to split a fasta file into multiple smaller files.

Output files will be <original>.xx.fasta
"""
from __future__ import print_function
import argparse
import sys
import os
import re

def header(row):
    regex = re.compile("^>")
    return regex.findall(row)

def next_output_file(input_file, prefix, i):
    if input_file is not None:
        prefix = ".".join(os.path.basename(input_file).split('.')[0:])
    
    new_filename = "{0}.{1}.fasta".format(prefix, i)
    print(new_filename)
    return open(new_filename, 'w')


def main(args):
    if args.input_fasta is not None:
        input_handle = open(args.input_fasta, 'r')
    else:
        input_handle = sys.stdin

    n = 0
    i = 0
    outputfh = next_output_file(args.input_fasta, args.prefix, i) 
    for row in input_handle:
        if header(row):
            n+=1

        if n > args.n_seqs:
            i += 1
            n = 1
{'fraction_non_alphanumeric': 0.12044374009508717, 'fraction_numerical': 0.008980454305335447, 'mean_word_length': 2.621414913957935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7021319', 'n_tokens_mistral': 659, 'n_tokens_neox': 638, 'n_words': 178}