def cib(args):
    """
    %prog cib bamfile samplekey

    Convert BAM to CIB (a binary storage of int8 per base).
    """
    p = OptionParser(cib.__doc__)
    p.add_option("--prefix", help="Report seqids with this prefix only")
    p.set_cpus()
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    bamfile, samplekey = args
    mkdir(samplekey)
    bam = pysam.AlignmentFile(bamfile, "rb")
    refs = [x for x in bam.header["SQ"]]
    prefix = opts.prefix
    if prefix:
        refs = [x for x in refs if x["SN"].startswith(prefix)]

    task_args = []
    for r in refs:
        task_args.append((bamfile, r, samplekey))
    cpus = min(opts.cpus, len(task_args))
    logging.debug("Use {} cpus".format(cpus))

    p = Pool(processes=cpus)
    for res in p.imap(bam_to_cib, task_args):
        continue
def cib ( args ) : p = OptionParser ( cib . __doc__ ) p . add_option ( "--prefix" , help = "Report seqids with this prefix only" ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) bamfile , samplekey = args mkdir ( samplekey ) bam = pysam . AlignmentFile ( bamfile , "rb" ) refs = [ x for x in bam . header [ "SQ" ] ] prefix = opts . prefix if prefix : refs = [ x for x in refs if x [ "SN" ] . startswith ( prefix ) ] task_args = [ ] for r in refs : task_args . append ( ( bamfile , r , samplekey ) ) cpus = min ( opts . cpus , len ( task_args ) ) logging . debug ( "Use {} cpus" . format ( cpus ) ) p = Pool ( processes = cpus ) for res in p . imap ( bam_to_cib , task_args ) : continue
%prog cib bamfile samplekey

    Convert BAM to CIB (a binary storage of int8 per base).