I would like to parse a BAM file in parallel using pysam and multiple_iterators 

Here is my code

    import pysam
    import sys
    from multiprocessing import Pool
    import time
    def countReads(chrom,Bam):
	    count=0
	    #Itr = Bam.fetch(str(chrom),multiple_iterators=False)
	    Itr = Bam.fetch(str(chrom),multiple_iterators=True)
	    for Aln in Itr: count+=1

    if __name__ == '__main__':
	    start = time.time()
	    chroms=[x+1 for x in range(22)]
	    cpu=6
	    BAM = sys.argv[1]
	    bamfh = pysam.AlignmentFile(BAM)
	    pool = Pool(processes=cpu)
	    for x in range(len(chroms)):
		    pool.apply_async(countReads,(chroms[x],bamfh,))
		    #countReads(chroms[x],bamfh)
	    pool.close()
	    pool.join()
	    end = time.time()
	    print(end - start)

I get this error when I run it. 

    TypeError: _open() takes at least 1 positional argument (0 given)

But it spits out a whole bunch of errors. Can anyone help me to use multiprocessing to read a BAM file in parallel using pysam? 

Thanks
fixed it. I was going off some online blog that was wrong

    import pysam
    import sys
    from multiprocessing import Pool
    import time
    def countReads(chrom,BAM):
        count=0
        # here's the fix
        bam = pysam.AlignmentFile(BAM,'rb')

        Itr = bam.fetch(str(chrom),multiple_iterators=True)
        for Aln in Itr: count+=1

    if __name__ == '__main__':
        start = time.time()
        chroms=[x+1 for x in range(22)]
        cpu=6
        BAM = sys.argv[1]
        pool = Pool(processes=cpu)
        for x in range(len(chroms)):
            pool.apply_async(countReads,(chroms[x],BAM,))
        #countReads(chroms[x],bamfh)
        pool.close()
        pool.join()
        end = time.time()
        print(end - start)
