// File: millanek[P]evo/process_vcf_coding_sequences.cpp
// Function: printPerGeneSummaries(std::basic_ofstream<char, std::char_traits<char>>*&, Annotation&)
void printPerGeneSummaries(std::ofstream*& stopsPerGeneSummaryFile, Annotation& wgAnnotation) {
    std::string previousGene = "";
    int numTranscripsWithStopsThisGene = 0;
    double stopAlleleFrequencySum = 0;
    std::vector<double> stopPosPctVec;
    for (std::vector<string>::size_type i = 0; i != stopsTranscriptRecord.size(); i++) {
         std::cerr << "previousGene: " << previousGene << std::endl;
        std::vector<string> oneTransctipt = split(stopsTranscriptRecord[i], '\t');
        if (geneFromTranscript(oneTransctipt[0]) == previousGene) {
            numTranscripsWithStopsThisGene++;
            stopAlleleFrequencySum += convertToDouble(oneTransctipt[3]);
            double stopPosPct = convertToDouble(oneTransctipt[1]) / convertToDouble(oneTransctipt[2]);
            stopPosPctVec.push_back(stopPosPct);
        } else {
            if (previousGene != "")
                *stopsPerGeneSummaryFile << previousGene << "\t" << numTranscripsWithStopsThisGene << "\t" << wgAnnotation.getTranscriptCount(previousGene) << "\t" << stopAlleleFrequencySum/numTranscripsWithStopsThisGene << "\t" << vector_average(stopPosPctVec) << std::endl;
            previousGene = geneFromTranscript(oneTransctipt[0]);
            numTranscripsWithStopsThisGene = 1; stopAlleleFrequencySum = convertToDouble(oneTransctipt[3]); stopPosPctVec.clear();
            double stopPosPct = convertToDouble(oneTransctipt[1]) / convertToDouble(oneTransctipt[2]);
            stopPosPctVec.push_back(stopPosPct);
        }
        
        // print the final gene
        if (i == (stopsTranscriptRecord.size() - 1)) {
            *stopsPerGeneSummaryFile << geneFromTranscript(oneTransctipt[0]) << "\t" << numTranscripsWithStopsThisGene << "\t" << wgAnnotation.getTranscriptCount(previousGene) << "\t" << stopAlleleFrequencySum/numTranscripsWithStopsThisGene << "\t" << vector_average(stopPosPctVec) << std::endl;
        }
        
        //oneTransctipt[0]
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0xab60
movq -0x130(%rbp), %rdx
leaq 0x86c3e(%rip), %rsi     # 0x135edf
leaq -0x30(%rbp), %rdi
callq 0x2d6c0
jmp 0xaf2ac
leaq -0x31(%rbp), %rdi
callq 0xa640
movl $0x0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x48410
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq 0xeb771(%rip), %rdi     # 0x19aa58
callq 0x3ffd0
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
je 0xaf978
movq 0xe9cea(%rip), %rdi     # 0x198ff0
leaq 0x91697(%rip), %rsi     # 0x1409a4
callq 0xa5c0
movq %rax, -0x140(%rbp)
jmp 0xaf31b
movq -0x140(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa520
movq %rax, -0x148(%rbp)
jmp 0xaf334
movq -0x148(%rbp), %rdi
movq 0xe9c46(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xaf349
movq -0x70(%rbp), %rsi
leaq 0xeb704(%rip), %rdi     # 0x19aa58
callq 0x3d940
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
movl $0x9, %edx
callq 0x7bbe0
jmp 0xaf36f
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x598c0
jmp 0xaf390
leaq -0xa8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x39210
movb %al, -0x149(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xac88
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0xaf3c1
jmp 0xaf4b7
movl -0x48(%rbp), %eax
incl %eax
movl %eax, -0x48(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x3, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xb75e0
movsd %xmm0, -0x158(%rbp)
jmp 0xaf3ec
movsd -0x158(%rbp), %xmm1
movsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xb75e0
movsd %xmm0, -0x160(%rbp)
jmp 0xaf425
leaq -0x88(%rbp), %rdi
movl $0x2, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xb75e0
movsd %xmm0, -0x168(%rbp)
jmp 0xaf448
movsd -0x168(%rbp), %xmm1
movsd -0x160(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xb77b0
jmp 0xaf476
jmp 0xaf751
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0xa640
jmp 0xaf9a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xaf993
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xaf96a
leaq 0x86a21(%rip), %rsi     # 0x135edf
leaq -0x30(%rbp), %rdi
callq 0x50eb0
movb %al, -0x169(%rbp)
jmp 0xaf4cf
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0xaf4de
jmp 0xaf657
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa520
movq %rax, -0x178(%rbp)
jmp 0xaf4f7
movq -0x178(%rbp), %rdi
leaq 0x869d9(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x180(%rbp)
jmp 0xaf513
movq -0x180(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0xab20
movq %rax, -0x188(%rbp)
jmp 0xaf52b
movq -0x188(%rbp), %rdi
leaq 0x869a5(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x190(%rbp)
jmp 0xaf547
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb7820
movl %eax, -0x194(%rbp)
jmp 0xaf55c
movl -0x194(%rbp), %esi
movq -0x190(%rbp), %rdi
callq 0xab20
movq %rax, -0x1a0(%rbp)
jmp 0xaf577
movq -0x1a0(%rbp), %rdi
leaq 0x86959(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x1a8(%rbp)
jmp 0xaf593
movq -0x1a8(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
cvtsi2sdl -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0xabd0
movq %rax, -0x1b0(%rbp)
jmp 0xaf5b6
movq -0x1b0(%rbp), %rdi
leaq 0x8691a(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x1b8(%rbp)
jmp 0xaf5d2
leaq -0xc8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x53120
jmp 0xaf5e4
leaq -0xc8(%rbp), %rdi
callq 0x53060
movsd %xmm0, -0x1c0(%rbp)
jmp 0xaf5fa
movsd -0x1c0(%rbp), %xmm0
movq -0x1b8(%rbp), %rdi
callq 0xabd0
movq %rax, -0x1c8(%rbp)
jmp 0xaf617
movq -0x1c8(%rbp), %rdi
movq 0xe9963(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xaf62c
leaq -0xc8(%rbp), %rdi
callq 0x3ecb0
jmp 0xaf657
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3ecb0
jmp 0xaf96a
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x598c0
jmp 0xaf678
leaq -0x30(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movq %rsi, -0x1d8(%rbp)
callq 0xa710
movq -0x1d8(%rbp), %rdi
callq 0xac88
movl $0x1, -0x48(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x3, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xb75e0
movsd %xmm0, -0x1d0(%rbp)
jmp 0xaf6c5
movsd -0x1d0(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x53210
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xb75e0
movsd %xmm0, -0x1e0(%rbp)
jmp 0xaf6fe
leaq -0x88(%rbp), %rdi
movl $0x2, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xb75e0
movsd %xmm0, -0x1e8(%rbp)
jmp 0xaf721
movsd -0x1e8(%rbp), %xmm1
movsd -0x1e0(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xb77b0
jmp 0xaf74f
jmp 0xaf751
movq -0x70(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq 0xeb2f5(%rip), %rdi     # 0x19aa58
callq 0x3ffd0
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0xaf94d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1f8(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0x110(%rbp), %rdi
callq 0x598c0
jmp 0xaf7ae
movq -0x1f8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xa520
movq %rax, -0x200(%rbp)
jmp 0xaf7ca
movq -0x200(%rbp), %rdi
leaq 0x86706(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x208(%rbp)
jmp 0xaf7e6
movq -0x208(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0xab20
movq %rax, -0x210(%rbp)
jmp 0xaf7fe
movq -0x210(%rbp), %rdi
leaq 0x866d2(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x218(%rbp)
jmp 0xaf81a
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb7820
movl %eax, -0x21c(%rbp)
jmp 0xaf82f
movl -0x21c(%rbp), %esi
movq -0x218(%rbp), %rdi
callq 0xab20
movq %rax, -0x228(%rbp)
jmp 0xaf84a
movq -0x228(%rbp), %rdi
leaq 0x86686(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x230(%rbp)
jmp 0xaf866
movq -0x230(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
cvtsi2sdl -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0xabd0
movq %rax, -0x238(%rbp)
jmp 0xaf889
movq -0x238(%rbp), %rdi
leaq 0x86647(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x240(%rbp)
jmp 0xaf8a5
leaq -0x128(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x53120
jmp 0xaf8b7
leaq -0x128(%rbp), %rdi
callq 0x53060
movsd %xmm0, -0x248(%rbp)
jmp 0xaf8cd
movsd -0x248(%rbp), %xmm0
movq -0x240(%rbp), %rdi
callq 0xabd0
movq %rax, -0x250(%rbp)
jmp 0xaf8ea
movq -0x250(%rbp), %rdi
movq 0xe9690(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xaf8ff
leaq -0x128(%rbp), %rdi
callq 0x3ecb0
leaq -0x110(%rbp), %rdi
callq 0xac88
jmp 0xaf94d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xaf93f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3ecb0
leaq -0x110(%rbp), %rdi
callq 0xac88
jmp 0xaf96a
leaq -0x88(%rbp), %rdi
callq 0x3dfa0
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xaf2d5
leaq -0x88(%rbp), %rdi
callq 0x3dfa0
jmp 0xaf993
leaq -0x68(%rbp), %rdi
callq 0x3ecb0
leaq -0x30(%rbp), %rdi
callq 0xac88
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x3ecb0
leaq -0x30(%rbp), %rdi
callq 0xac88
movq -0x40(%rbp), %rdi
callq 0xab50
nop