<commit_before>#!/usr/bin/env python
"""
Calculate a number of summary statistics for a BAM file
"""

import os
import sys
import pysam
from support.eta import ETA
from support.refiso import RefIso
from bam_utils import read_calc_mismatches
from support.ngs_utils import natural_sort


def usage():
    print __doc__
    print """
Usage: bamutils stats in.bam {options} {region}

If a region is given, only reads that map to that region will be counted.
Regions should be be in the format: 'ref:start-end' or 'ref:start' using
1-based start coordinates.

Options:
    -tags    tag_name{:sort_order},tag_name{:sort_order},...

            For each tag that is given, the values for that tag will be
            tallied for all reads. Then a list of the counts will be presented
            along with the mean and maximum values. The optional sort order
            should be either '+' or '-' (defaults to +).

            There are also special case tags that can be used as well:
                MAPQ     - use the mapq score
                LENGTH   - use the length of the read
                MISMATCH - use the mismatch score (# mismatches) + (# indels)
                           where indels count for 1 regardless of length

                           Note: this requires the 'NM' tag (edit distance)
                           to be present

            Common tags:
                AS    Alignment score
                IH    Number of alignments
                NM    Edit distance (each indel counts as many as its length)

            For example, to tally the "IH" tag (number of alignments) and the
            read length:
                -tags IH,LENGTH


    -delim  char

            If delimiter is given, the reference names are split by this<commit_msg>whitespace<commit_after>#!/usr/bin/env python
"""
Calculate a number of summary statistics for a BAM file
"""

import os
import sys
import pysam
from support.eta import ETA
from support.refiso import RefIso
from bam_utils import read_calc_mismatches
from support.ngs_utils import natural_sort


def usage():
    print __doc__
    print """
Usage: bamutils stats in.bam {options} {region}

If a region is given, only reads that map to that region will be counted.
Regions should be be in the format: 'ref:start-end' or 'ref:start' using
1-based start coordinates.

Options:
    -tags   tag_name{:sort_order},tag_name{:sort_order},...

            For each tag that is given, the values for that tag will be
            tallied for all reads. Then a list of the counts will be presented
            along with the mean and maximum values. The optional sort order
            should be either '+' or '-' (defaults to +).

            There are also special case tags that can be used as well:
                MAPQ     - use the mapq score
                LENGTH   - use the length of the read
                MISMATCH - use the mismatch score (# mismatches) + (# indels)
                           where indels count for 1 regardless of length

                           Note: this requires the 'NM' tag (edit distance)
                           to be present

            Common tags:
                AS    Alignment score
                IH    Number of alignments
                NM    Edit distance (each indel counts as many as its length)

            For example, to tally the "IH" tag (number of alignments) and the
            read length:
                -tags IH,LENGTH


    -delim  char

            If delimiter is given, the reference names are split by this
{'fraction_non_alphanumeric': 0.05411499436302142, 'fraction_numerical': 0.0011273957158962795, 'mean_word_length': 1.9427860696517414, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1166326', 'n_tokens_mistral': 951, 'n_tokens_neox': 880, 'n_words': 437}