def write_cf_from_gp_stream(gp_stream, cfWr):
    """Write counts file using a given GP stream with reference and CFWriter.

    Write the counts format file using all genes in the GP stream.
    The sequences are automatically reversed and complemented if this
    is needed.

    :param GPStream gp_stream: The GP stream and reference :class:`GPStream
      <cflib.gp.GPStream>`.
    :param CFWriter cfWf: The :class:`CFWriter` object that contains
      the VCF files.

    """
    nr_rc_genes_correct_start_codon = 0
    nr_genes_correct_start_codon = 0
    nr_genes_inc = 0
    nr_genes_total = 0
    while True:
        correct_frame_shift_flag = False
        if gp_stream.gene.is_rc and gp_stream.seqs[0].data[-3:].lower(
            ) == 'cat':
            nr_rc_genes_correct_start_codon += 1
            correct_frame_shift_flag = True
        elif not gp_stream.gene.is_rc and gp_stream.seqs[0].data[:3].lower(
            ) == 'atg':
            nr_genes_correct_start_codon += 1
            correct_frame_shift_flag = True
        if correct_frame_shift_flag is False and gp_stream.gene.name.find('inc'
            ) != -1:
            nr_genes_inc += 1
            correct_frame_shift_flag = True
        nr_genes_total += 1
        for s in gp_stream.seqs:
            if s.get_rc() is True:
                s.rev_comp()
        if correct_frame_shift_flag:
            for i in range(gp_stream.gene.nr_exons):
                rg = gp_stream.seqs[i].get_region()
                cfWr.set_seq(gp_stream.seqs[i])
                cfWr.write_Rn(rg)
        else:
            print('Gene has no start codon and is not flagged incomplete:')
            print(gp_stream.gene.name)
        try:
            gp_stream.read_next_gene()
        except ValueError:
            break
    print('+ genes with correct start codon ATG:',
        nr_rc_genes_correct_start_codon)
    print('- genes with correct start codon ATG:', nr_genes_correct_start_codon
        )
    print('Incomplete genes without start codon:', nr_genes_inc)
    print('Total number of processed genes:', nr_genes_total)
