<commit_before>#! /usr/bin/env python

import argparse
import csv
import itertools
import logging
import math
import os

import miseq_logging

BAD_ERROR_RATE = 7.5

def parseArgs():
    parser = argparse.ArgumentParser(
        description='Post-processing of short-read alignments.')
    
    parser.add_argument('quality_csv',
                        type=argparse.FileType('rU'),
                        help='QC error rate data, grouped by tile')
    parser.add_argument('bad_cycles_csv',
                        type=argparse.FileType('w'),
                        help='List of tiles and cycles rejected for poor quality')
    
    return parser.parse_args()

logger = miseq_logging.init_logging_console_only(logging.DEBUG)

def grouper(cycle):
    return (cycle['tile'], math.copysign(1, int(cycle['cycle'])))

def main():
    args = parseArgs()
    with args.quality_csv, args.bad_cycles_csv:
        reader = csv.DictReader(args.quality_csv)
        writer = csv.DictWriter(args.bad_cycles_csv,
                                ['tile', 'cycle', 'errorrate'],
                                lineterminator=os.linesep)
        writer.writeheader()
        for _tile_direction, cycles in itertools.groupby(reader, grouper):
            is_bad = False
            for cycle in cycles:
                errorrate = cycle['errorrate']
                is_bad = (is_bad or
                          errorrate == '' or
                          float(errorrate) >= BAD_ERROR_RATE)
                if is_bad:
                    writer.writerow(cycle)

if __name__ == '__main__':<commit_msg>Fix a bunch of PEP8 warnings.<commit_after>#! /usr/bin/env python

import argparse
import csv
import itertools
import logging
import math
import os

import miseq_logging

BAD_ERROR_RATE = 7.5


def parseArgs():
    parser = argparse.ArgumentParser(
        description='Post-processing of short-read alignments.')

    parser.add_argument('quality_csv',
                        type=argparse.FileType('rU'),
                        help='QC error rate data, grouped by tile')
    parser.add_argument('bad_cycles_csv',
                        type=argparse.FileType('w'),
                        help='List of tiles and cycles rejected for poor quality')

    return parser.parse_args()

logger = miseq_logging.init_logging_console_only(logging.DEBUG)


def grouper(cycle):
    return (cycle['tile'], math.copysign(1, int(cycle['cycle'])))


def main():
    args = parseArgs()
    with args.quality_csv, args.bad_cycles_csv:
        reader = csv.DictReader(args.quality_csv)
        writer = csv.DictWriter(args.bad_cycles_csv,
                                ['tile', 'cycle', 'errorrate'],
                                lineterminator=os.linesep)
        writer.writeheader()
        for _tile_direction, cycles in itertools.groupby(reader, grouper):
            is_bad = False
            for cycle in cycles:
                errorrate = cycle['errorrate']
                is_bad = (is_bad or
                          errorrate == '' or
                          float(errorrate) >= BAD_ERROR_RATE)
                if is_bad:
                    writer.writerow(cycle)

if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.0968348480100282, 'fraction_numerical': 0.0021936696960200563, 'mean_word_length': 2.0170132325141776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '640546', 'n_tokens_mistral': 915, 'n_tokens_neox': 871, 'n_words': 204}