def guess_array_memory_usage( bam_readers, dtype, use_strand=False ):
ARRAY_COUNT = <NUM_LIT:5><EOL>if not isinstance( bam_readers, list ):<EOL><INDENT>bam_readers = [ bam_readers ]<EOL><DEDENT>if isinstance( dtype, basestring ):<EOL><INDENT>dtype = NUMPY_DTYPES.get( dtype, None )<EOL><DEDENT>use_strand = use_strand + <NUM_LIT:1> <EOL>dtypes = guess_numpy_dtypes_from_idxstats( bam_readers, default=None, force_dtype=False )<EOL>if not [ dt for dt in dtypes if dt is not None ]:<EOL><INDENT>dtypes = guess_numpy_dtypes_from_idxstats( bam_readers, default=dtype or numpy.uint64, force_dtype=True )<EOL><DEDENT>elif dtype:<EOL><INDENT>dtypes = [ dtype if dt else None for dt in dtypes ]<EOL><DEDENT>read_groups = []<EOL>no_read_group = False<EOL>for bam in bam_readers:<EOL><INDENT>rgs = bam.get_read_groups()<EOL>if rgs:<EOL><INDENT>for rg in rgs:<EOL><INDENT>if rg not in read_groups:<EOL><INDENT>read_groups.append( rg )<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>no_read_group = True<EOL><DEDENT><DEDENT>read_groups = len( read_groups ) + no_read_group<EOL>max_ref_size = <NUM_LIT:0><EOL>array_byte_overhead = sys.getsizeof( numpy.zeros( ( <NUM_LIT:0> ), dtype=numpy.uint64 ) )<EOL>array_count = ARRAY_COUNT * use_strand * read_groups<EOL>for bam in bam_readers:<EOL><INDENT>for i, ( name, length ) in enumerate( bam.get_references() ):<EOL><INDENT>if dtypes[i] is not None:<EOL><INDENT>max_ref_size = max( max_ref_size, ( length + length * dtypes[i]().nbytes * array_count + ( array_byte_overhead * ( array_count + <NUM_LIT:1> ) ) ) )<EOL><DEDENT><DEDENT><DEDENT>return max_ref_size<EOL>
Returns an estimate for the maximum amount of memory to be consumed by numpy arrays.