<commit_before>"""
Find runs that match crAssphage with a minimum number of runs, a minimum alignment length, and a minimum percent
identity
"""

import os
import sys
import argparse

import pysam

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Count hits in a bam file")
    parser.add_argument('-d', help='Directory of bam files', required=True)
    parser.add_argument('-l', help='Minimum alignment length (default = 30nt)', default=30, type=int)
    parser.add_argument('-c', help='Minimum coverage as a fraction of read length (default = 0.9)', default=0.9, type=float)
    parser.add_argument('-v', help='Verbose output', action='store_true')
    args = parser.parse_args()

    for f in os.listdir(args.d):
        count = {}
        found = False
        if not f.endswith('.bam'):
            if args.v:
                sys.stderr.write("SKipped {}\n".format(f))
            continue
        bam = pysam.AlignmentFile(os.path.join(args.d, f), 'rb')

        for p in bam.pileup(truncate=True):
            for pilups in p.pileups:
                if pilups.alignment.query_length < args.l:
                    continue
                alignment_frac = 1.0 * pilups.alignment.query_alignment_length / pilups.alignment.query_length
                if alignment_frac <= args.c:
                    continue
                count[pilups.alignment.query_name] = count.get(pilups.alignment.query_name, 0) + 1
                found = True

        if found:
            for q in count:
                print("{}\t{}\t{}".format(f, q, count[q]))<commit_msg>Ignoring empty files<commit_after>"""
Find runs that match crAssphage with a minimum number of runs, a minimum alignment length, and a minimum percent
identity
"""

import os
import sys
import argparse

import pysam

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Count hits in a bam file")
    parser.add_argument('-d', help='Directory of bam files', required=True)
    parser.add_argument('-l', help='Minimum alignment length (default = 30nt)', default=30, type=int)
    parser.add_argument('-c', help='Minimum coverage as a fraction of read length (default = 0.9)', default=0.9, type=float)
    parser.add_argument('-v', help='Verbose output', action='store_true')
    args = parser.parse_args()

    for f in os.listdir(args.d):
        count = {}
        found = False
        if not f.endswith('.bam'):
            if args.v:
                sys.stderr.write("SKipped {}\n".format(f))
            continue
        bam = pysam.AlignmentFile(os.path.join(args.d, f), 'rb')

        try:
            for p in bam.pileup(truncate=True):
                for pilups in p.pileups:
                    if pilups.alignment.query_length < args.l:
                        continue
                    alignment_frac = 1.0 * pilups.alignment.query_alignment_length / pilups.alignment.query_length
                    if alignment_frac <= args.c:
                        continue
                    count[pilups.alignment.query_name] = count.get(pilups.alignment.query_name, 0) + 1
                    found = True
        except ValueError:
            continue

        if found:
            for q in count:
                print("{}\t{}\t{}".format(f, q, count[q]))
{'fraction_non_alphanumeric': 0.11646341463414635, 'fraction_numerical': 0.007317073170731708, 'mean_word_length': 2.245301681503462, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5356146', 'n_tokens_mistral': 1007, 'n_tokens_neox': 940, 'n_words': 257}