def flush_reads(read_l, fastq_out_fp, read_serial):
  """Write out reads to a fastq file.
  qname is 'read_serial|chrom|copy|ro|pos|rlen|cigar|ro|pos|rlen|cigar'

  :param read_l:
  :param fastq_out_fp:
  :param read_serial:
  :return: read_serial, updated
  """
  qname = '|'.join([str(read_serial), str(read_l[0].reference_id + 1), '0'])
  for ro, r in enumerate(read_l):
    qname += '|'.join([str(ro), str(r.pos), str(r.query_length), r.cigarstring])

  for n, r in enumerate(read_l):
    fastq_out_fp.write('@' + qname + ('/' + str(n + 1) if len(read_l) > 0 else '') + '\n'
                       + r.query_sequence + '\n+\n'
                       + '~' * len(r.query_sequence) + '\n')

  return read_serial + 1