#! /soe/mollyzhang/anaconda/bin/python
"""cat_stats.py
Created by Molly Zhang on 09/09/14 at 11:32
this program will concatenant the stat file for all chromosomes generated by
the program tag_reads.py
"""
import sys
import argparse

def parse_args():
    """Set up and parse command-line arguments."""
    parser = argparse.ArgumentParser("cat_stats.py")
    parser.add_argument("folder", 
                        help = "folder where all the stats files are located")
    return parser.parse_args()

def main(args):
    """Main method"""
    args = parse_args()
    chroms = ['1', '2A', '2B', '3', '4', '5', '6', '7', '8', '9', '10', '11', 
              '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
              '22', 'X']
    stats = [0]*7
    for chrm in chroms:
        f = open(args.folder + "/chr" + chrm + ".labeled.r1.stat", "r")
        i = 0
        line_num = 0
        for line in f:
            items = line.split()
            line_num += 1
            if line_num != 3:
                stats[i] += int(items[-1])
                i += 1
            else:
                stats[i] += int(items[-3][0:-1])
                i += 1
    sys.stdout.write("total number of mapped reads in bam file: " + 
                     str(stats[0]) + "\n")
    sys.stdout.write("total number of difference positions: " 
                     + str(stats[1]) + "\n" )
    sys.stdout.write("total number of labeled reads: " + str(stats[2]) + 
                     ", percentage: " + str(stats[2]*100/float(stats[0])) + 
                     "\n")
    sys.stdout.write("total number of reads labeled as chimpanzee: " +
                     str(stats[3]) + "\n")
    sys.stdout.write("total number of reads labeled as bonobo: " + 
                     str(stats[4]) + "\n")
    sys.stdout.write("number of reads labeled as both chimpanzee and bonobo: "
                     + str(stats[5]) + " (" + 
                     str( 100* stats[5]/float(stats[2])) + " %)\n")
    sys.stdout.write("total number of cigar errors: " + str(stats[6]) + "\n")


if __name__ == "__main__" :
    sys.exit(main(sys.argv))


4a266b4a8cf788764a4d84f834562100df438a48
<mask token>


def main(args):
    """Main method"""
    args = parse_args()
    chroms = ['1', '2A', '2B', '3', '4', '5', '6', '7', '8', '9', '10',
        '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
        '22', 'X']
    stats = [0] * 7
    for chrm in chroms:
        f = open(args.folder + '/chr' + chrm + '.labeled.r1.stat', 'r')
        i = 0
        line_num = 0
        for line in f:
            items = line.split()
            line_num += 1
            if line_num != 3:
                stats[i] += int(items[-1])
                i += 1
            else:
                stats[i] += int(items[-3][0:-1])
                i += 1
    sys.stdout.write('total number of mapped reads in bam file: ' + str(
        stats[0]) + '\n')
    sys.stdout.write('total number of difference positions: ' + str(stats[1
        ]) + '\n')
    sys.stdout.write('total number of labeled reads: ' + str(stats[2]) +
        ', percentage: ' + str(stats[2] * 100 / float(stats[0])) + '\n')
    sys.stdout.write('total number of reads labeled as chimpanzee: ' + str(
        stats[3]) + '\n')
    sys.stdout.write('total number of reads labeled as bonobo: ' + str(
        stats[4]) + '\n')
    sys.stdout.write(
        'number of reads labeled as both chimpanzee and bonobo: ' + str(
        stats[5]) + ' (' + str(100 * stats[5] / float(stats[2])) + ' %)\n')
    sys.stdout.write('total number of cigar errors: ' + str(stats[6]) + '\n')


<mask token>

<mask token>


def parse_args():
    """Set up and parse command-line arguments."""
    parser = argparse.ArgumentParser('cat_stats.py')
    parser.add_argument('folder', help=
        'folder where all the stats files are located')
    return parser.parse_args()


def main(args):
    """Main method"""
    args = parse_args()
    chroms = ['1', '2A', '2B', '3', '4', '5', '6', '7', '8', '9', '10',
        '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
        '22', 'X']
    stats = [0] * 7
    for chrm in chroms:
        f = open(args.folder + '/chr' + chrm + '.labeled.r1.stat', 'r')
        i = 0
        line_num = 0
        for line in f:
            items = line.split()
            line_num += 1
            if line_num != 3:
                stats[i] += int(items[-1])
                i += 1
            else:
                stats[i] += int(items[-3][0:-1])
                i += 1
    sys.stdout.write('total number of mapped reads in bam file: ' + str(
        stats[0]) + '\n')
    sys.stdout.write('total number of difference positions: ' + str(stats[1
        ]) + '\n')
    sys.stdout.write('total number of labeled reads: ' + str(stats[2]) +
        ', percentage: ' + str(stats[2] * 100 / float(stats[0])) + '\n')
    sys.stdout.write('total number of reads labeled as chimpanzee: ' + str(
        stats[3]) + '\n')
    sys.stdout.write('total number of reads labeled as bonobo: ' + str(
        stats[4]) + '\n')
    sys.stdout.write(
        'number of reads labeled as both chimpanzee and bonobo: ' + str(
        stats[5]) + ' (' + str(100 * stats[5] / float(stats[2])) + ' %)\n')
    sys.stdout.write('total number of cigar errors: ' + str(stats[6]) + '\n')


<mask token>

<mask token>


def parse_args():
    """Set up and parse command-line arguments."""
    parser = argparse.ArgumentParser('cat_stats.py')
    parser.add_argument('folder', help=
        'folder where all the stats files are located')
    return parser.parse_args()


def main(args):
    """Main method"""
    args = parse_args()
    chroms = ['1', '2A', '2B', '3', '4', '5', '6', '7', '8', '9', '10',
        '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
        '22', 'X']
    stats = [0] * 7
    for chrm in chroms:
        f = open(args.folder + '/chr' + chrm + '.labeled.r1.stat', 'r')
        i = 0
        line_num = 0
        for line in f:
            items = line.split()
            line_num += 1
            if line_num != 3:
                stats[i] += int(items[-1])
                i += 1
            else:
                stats[i] += int(items[-3][0:-1])
                i += 1
    sys.stdout.write('total number of mapped reads in bam file: ' + str(
        stats[0]) + '\n')
    sys.stdout.write('total number of difference positions: ' + str(stats[1
        ]) + '\n')
    sys.stdout.write('total number of labeled reads: ' + str(stats[2]) +
        ', percentage: ' + str(stats[2] * 100 / float(stats[0])) + '\n')
    sys.stdout.write('total number of reads labeled as chimpanzee: ' + str(
        stats[3]) + '\n')
    sys.stdout.write('total number of reads labeled as bonobo: ' + str(
        stats[4]) + '\n')
    sys.stdout.write(
        'number of reads labeled as both chimpanzee and bonobo: ' + str(
        stats[5]) + ' (' + str(100 * stats[5] / float(stats[2])) + ' %)\n')
    sys.stdout.write('total number of cigar errors: ' + str(stats[6]) + '\n')


if __name__ == '__main__':
    sys.exit(main(sys.argv))

<mask token>
import sys
import argparse


def parse_args():
    """Set up and parse command-line arguments."""
    parser = argparse.ArgumentParser('cat_stats.py')
    parser.add_argument('folder', help=
        'folder where all the stats files are located')
    return parser.parse_args()


def main(args):
    """Main method"""
    args = parse_args()
    chroms = ['1', '2A', '2B', '3', '4', '5', '6', '7', '8', '9', '10',
        '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
        '22', 'X']
    stats = [0] * 7
    for chrm in chroms:
        f = open(args.folder + '/chr' + chrm + '.labeled.r1.stat', 'r')
        i = 0
        line_num = 0
        for line in f:
            items = line.split()
            line_num += 1
            if line_num != 3:
                stats[i] += int(items[-1])
                i += 1
            else:
                stats[i] += int(items[-3][0:-1])
                i += 1
    sys.stdout.write('total number of mapped reads in bam file: ' + str(
        stats[0]) + '\n')
    sys.stdout.write('total number of difference positions: ' + str(stats[1
        ]) + '\n')
    sys.stdout.write('total number of labeled reads: ' + str(stats[2]) +
        ', percentage: ' + str(stats[2] * 100 / float(stats[0])) + '\n')
    sys.stdout.write('total number of reads labeled as chimpanzee: ' + str(
        stats[3]) + '\n')
    sys.stdout.write('total number of reads labeled as bonobo: ' + str(
        stats[4]) + '\n')
    sys.stdout.write(
        'number of reads labeled as both chimpanzee and bonobo: ' + str(
        stats[5]) + ' (' + str(100 * stats[5] / float(stats[2])) + ' %)\n')
    sys.stdout.write('total number of cigar errors: ' + str(stats[6]) + '\n')


if __name__ == '__main__':
    sys.exit(main(sys.argv))

#! /soe/mollyzhang/anaconda/bin/python
"""cat_stats.py
Created by Molly Zhang on 09/09/14 at 11:32
this program will concatenant the stat file for all chromosomes generated by
the program tag_reads.py
"""
import sys
import argparse

def parse_args():
    """Set up and parse command-line arguments."""
    parser = argparse.ArgumentParser("cat_stats.py")
    parser.add_argument("folder", 
                        help = "folder where all the stats files are located")
    return parser.parse_args()

def main(args):
    """Main method"""
    args = parse_args()
    chroms = ['1', '2A', '2B', '3', '4', '5', '6', '7', '8', '9', '10', '11', 
              '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
              '22', 'X']
    stats = [0]*7
    for chrm in chroms:
        f = open(args.folder + "/chr" + chrm + ".labeled.r1.stat", "r")
        i = 0
        line_num = 0
        for line in f:
            items = line.split()
            line_num += 1
            if line_num != 3:
                stats[i] += int(items[-1])
                i += 1
            else:
                stats[i] += int(items[-3][0:-1])
                i += 1
    sys.stdout.write("total number of mapped reads in bam file: " + 
                     str(stats[0]) + "\n")
    sys.stdout.write("total number of difference positions: " 
                     + str(stats[1]) + "\n" )
    sys.stdout.write("total number of labeled reads: " + str(stats[2]) + 
                     ", percentage: " + str(stats[2]*100/float(stats[0])) + 
                     "\n")
    sys.stdout.write("total number of reads labeled as chimpanzee: " +
                     str(stats[3]) + "\n")
    sys.stdout.write("total number of reads labeled as bonobo: " + 
                     str(stats[4]) + "\n")
    sys.stdout.write("number of reads labeled as both chimpanzee and bonobo: "
                     + str(stats[5]) + " (" + 
                     str( 100* stats[5]/float(stats[2])) + " %)\n")
    sys.stdout.write("total number of cigar errors: " + str(stats[6]) + "\n")


if __name__ == "__main__" :
    sys.exit(main(sys.argv))

