<commit_before><commit_msg>add function for outputting only certain read groups<commit_after>#! /usr/bin/env python
"""
usage:
  bam readgroups <bam>
  bam readgroups <bam> (--include=<args>...|--exclude=<args>...) 

options:
  -h --help                   Show this screen.
  --version                   Show version.
  --eav                       Print eav representation of data.

"""
from docopt import docopt
import sys
from clint.textui import colored, indent, puts_err
from pysam import AlignmentFile
import os
from subprocess import Popen
import tempfile

from pprint import pprint as pp


if __name__ == '__main__':
    args = docopt(__doc__,
                  version='BAM-Toolbox v0.1',
                  options_first=False)
    if not os.path.exists(args["<bam>"]):
        with indent(4):
            puts_err("\n" + colored.red(args["<bam>"] + " does not exist") + "\n")
    bamfile = AlignmentFile(args["<bam>"])
    readgroups = []
    for x in [x for x in bamfile.header["RG"]]:
        readgroups.append(x["ID"])
    if len(args["--include"] + args["--exclude"]) == 0:
        with indent(4):
            puts_err("Readgroups:")
            with indent(4):
                puts_err(colored.green("\n" + '\n'.join(readgroups)))
    elif args["--include"]:
        include = args["--include"][0].split(",")
        for x in include:
            if x not in readgroups:
                with indent(4):
                    puts_err(colored.red("\n" + x + " not a Readgroup"))

        readgroups = [x for x in readgroups if x not in include]
    else:
        exclude = args["--exclude"][0].split(",")
        for x in exclude:
            if x not in readgroups:
                with indent(4):
                    puts_err(colored.red("\n" + x + " not a Readgroup"))
        
        readgroups = [x for x in readgroups if x in exclude]

    for i in readgroups:
        print i







{'fraction_non_alphanumeric': 0.13519200420831143, 'fraction_numerical': 0.0052603892688058915, 'mean_word_length': 1.971875, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '4366053', 'n_tokens_mistral': 591, 'n_tokens_neox': 572, 'n_words': 171}