get_counts_matrix function

Helper function to extract counts matrix with proper handling