// File: millanek[P]evo/evo_getInformativePairs.cpp
// Function: InfoPairsMain(int, char**)
int InfoPairsMain(int argc, char** argv) {
    parseInfoPairsOptions(argc, argv);
    string line; // for reading the input files
    
    std::istream* hetFile = createReader(opt::hetFile.c_str());
    std::ifstream* pairtoolsFile = new std::ifstream(opt::pairtoolsFile.c_str());
    
    std::unordered_set<int> phasedHetsPos;
    
    
    if (opt::hapcutFormat) {
        // Parse the Hapcut blocks file
        while (getline(*hetFile, line)) {
            if (line == "********") continue;
            if (line[0] == 'B' && line[1] == 'L') { // New block - should in the future separate the hets by blocks
                
            } else {
                std::vector<string> phasedSNPdetails = split(line, '\t');
                int snpPos = atoi(phasedSNPdetails[4].c_str());
                phasedHetsPos.insert(snpPos);
            }
        }
    } else {
        while (getline(*hetFile, line)) {
            std::vector<string> phasedSNPdetails = split(line, '\t');
            int snpPos = atoi(phasedSNPdetails[1].c_str());
            phasedHetsPos.insert(snpPos);
        }
    }
    
    // Now parse the pairtools file to find read pairs that can be informative about the phasing and recombination
    while (getline(*pairtoolsFile,line)) {
        // std::cerr << line << std::endl;
        std::vector<string> pairVec = split(line, '\t'); assert(pairVec.size() == 8);
        
        int pair1pos = atoi(pairVec[2].c_str());
        int pair2pos = atoi(pairVec[4].c_str());
        string pair1strand = pairVec[5];
        string pair2strand = pairVec[6];
        
        std::vector<int> posCovered1; posCovered1.resize(150);
        if (pair1strand == "+") std::iota(posCovered1.begin(), posCovered1.end(), pair1pos);
        else std::iota(posCovered1.begin(), posCovered1.end(), pair1pos-150);
        
        std::vector<int> posCovered2; posCovered2.resize(150);
        if (pair2strand == "+") std::iota(posCovered2.begin(), posCovered2.end(), pair2pos);
        else std::iota(posCovered2.begin(), posCovered2.end(), pair2pos-150);
        
        int phasedHetsOnPair = 0;
        
        std::vector<int> hetPosVec;
        
        for (int i = 0; i < posCovered1.size(); i++) {
            if (phasedHetsPos.count(posCovered1[i]) == 1) {
                phasedHetsOnPair++;
                hetPosVec.push_back(posCovered1[i]);
            }
        }
        
        for (int i = 0; i < posCovered2.size(); i++) {
            if (phasedHetsPos.count(posCovered2[i]) == 1) {
                phasedHetsOnPair++;
                hetPosVec.push_back(posCovered2[i]);
            }
        }
        
        if (phasedHetsOnPair > 1) {
            std::cout << line << std::endl;
            //std::cerr << "pair1pos: " << pair1pos << " ; pair2pos: " << pair2pos << std::endl;
            //std::cerr << "pair1strand: " << pair1strand << " ; pair2strand: " << pair2strand << std::endl;
            //print_vector(hetPosVec, std::cerr);
        }
        
    }
    
    return 0;
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x1185c0
leaq -0x30(%rbp), %rdi
callq 0xa820
leaq 0x83b2a(%rip), %rdi     # 0x19b768
callq 0xa220
movq %rax, -0x218(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0xab60
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x2d6c0
jmp 0x117c73
leaq -0x58(%rbp), %rdi
movl $0x8, %esi
callq 0x80e30
movq %rax, -0x220(%rbp)
jmp 0x117c8a
leaq -0x58(%rbp), %rdi
callq 0xac88
leaq -0x59(%rbp), %rdi
callq 0xa640
movq -0x220(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0x228(%rbp)
jmp 0x117cba
leaq 0x83ac7(%rip), %rdi     # 0x19b788
callq 0xa220
movq -0x228(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0x117cdc
movq -0x228(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x1188a0
testb $0x1, 0x83ace(%rip)     # 0x19b7c8
je 0x117edf
jmp 0x117d02
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x230(%rbp)
jmp 0x117d18
movq -0x230(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x231(%rbp)
jmp 0x117d36
movb -0x231(%rbp), %al
testb $0x1, %al
jne 0x117d45
jmp 0x117eda
leaq 0x3648f(%rip), %rsi     # 0x14e1db
leaq -0x30(%rbp), %rdi
callq 0x2d770
movb %al, -0x232(%rbp)
jmp 0x117d5d
movb -0x232(%rbp), %al
testb $0x1, %al
jne 0x117d69
jmp 0x117de0
jmp 0x117d02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x117d8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xac88
leaq -0x59(%rbp), %rdi
callq 0xa640
jmp 0x1185a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x1185a3
movq -0x228(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0x1185a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x118597
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0xac60
movq %rax, -0x240(%rbp)
jmp 0x117df6
movq -0x240(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x42, %eax
jne 0x117e30
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0xac60
movq %rax, -0x248(%rbp)
jmp 0x117e1c
movq -0x248(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4c, %eax
jne 0x117e30
jmp 0x117ed5
leaq -0xc8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0x117e47
leaq -0xc8(%rbp), %rdi
movl $0x4, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xa220
movq %rax, %rdi
callq 0xa970
movl %eax, -0xcc(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x1188c0
movb %dl, -0x251(%rbp)
movq %rax, -0x250(%rbp)
jmp 0x117e90
movb -0x251(%rbp), %al
movq -0x250(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movb %al, -0xd8(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3dfa0
jmp 0x117ed5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3dfa0
jmp 0x118597
jmp 0x117d02
jmp 0x117fce
jmp 0x117ee1
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x260(%rbp)
jmp 0x117ef7
movq -0x260(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x261(%rbp)
jmp 0x117f15
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0x117f24
jmp 0x117fcc
leaq -0xf8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0x117f3b
leaq -0xf8(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xa220
movq %rax, %rdi
callq 0xa970
movl %eax, -0xfc(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0x1188c0
movb %dl, -0x271(%rbp)
movq %rax, -0x270(%rbp)
jmp 0x117f84
movb -0x271(%rbp), %al
movq -0x270(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movb %al, -0x108(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x3dfa0
jmp 0x117ee1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x3dfa0
jmp 0x118597
jmp 0x117fce
jmp 0x117fd0
movq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x280(%rbp)
jmp 0x117fe6
movq -0x280(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x281(%rbp)
jmp 0x118004
movb -0x281(%rbp), %al
testb $0x1, %al
jne 0x118013
jmp 0x118577
leaq -0x128(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0x11802a
leaq -0x128(%rbp), %rdi
callq 0x3ffd0
cmpq $0x8, %rax
jne 0x11803e
jmp 0x11805d
leaq 0x3619f(%rip), %rdi     # 0x14e1e4
leaq 0x361ac(%rip), %rsi     # 0x14e1f8
movl $0x51, %edx
leaq 0x361bc(%rip), %rcx     # 0x14e214
callq 0xa390
leaq -0x128(%rbp), %rdi
movq %rdi, -0x290(%rbp)
movl $0x2, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xa220
movq %rax, %rdi
callq 0xa970
movq -0x290(%rbp), %rdi
movl %eax, -0x12c(%rbp)
movl $0x4, %esi
callq 0x3d940
movq %rax, %rdi
callq 0xa220
movq %rax, %rdi
callq 0xa970
movq -0x290(%rbp), %rdi
movl %eax, -0x130(%rbp)
movl $0x5, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
callq 0xa250
jmp 0x1180d4
leaq -0x128(%rbp), %rdi
movl $0x6, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
callq 0xa250
jmp 0x1180f6
leaq -0x188(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x46270
movq -0x298(%rbp), %rdi
movl $0x96, %esi
callq 0x83c30
jmp 0x11811c
leaq 0x1c9e0(%rip), %rsi     # 0x134b03
leaq -0x150(%rbp), %rdi
callq 0x2d770
movb %al, -0x299(%rbp)
jmp 0x118137
movb -0x299(%rbp), %al
testb $0x1, %al
jne 0x118146
jmp 0x1181c6
leaq -0x188(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x46a90
movq -0x2a8(%rbp), %rdi
movq %rax, -0x190(%rbp)
callq 0x46ac0
movq %rax, -0x198(%rbp)
movl -0x12c(%rbp), %edx
movq -0x190(%rbp), %rdi
movq -0x198(%rbp), %rsi
callq 0x118900
jmp 0x11818e
jmp 0x118216
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x118569
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x11855d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x118545
leaq -0x188(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x46a90
movq -0x2b0(%rbp), %rdi
movq %rax, -0x1a0(%rbp)
callq 0x46ac0
movq %rax, -0x1a8(%rbp)
movl -0x12c(%rbp), %edx
addl $0xffffff6a, %edx       # imm = 0xFFFFFF6A
movq -0x1a0(%rbp), %rdi
movq -0x1a8(%rbp), %rsi
callq 0x118900
jmp 0x118214
jmp 0x118216
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x46270
movq -0x2b8(%rbp), %rdi
movl $0x96, %esi
callq 0x83c30
jmp 0x11823c
leaq 0x1c8c0(%rip), %rsi     # 0x134b03
leaq -0x170(%rbp), %rdi
callq 0x2d770
movb %al, -0x2b9(%rbp)
jmp 0x118257
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x118263
jmp 0x1182be
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x46a90
movq -0x2c8(%rbp), %rdi
movq %rax, -0x1c8(%rbp)
callq 0x46ac0
movq %rax, -0x1d0(%rbp)
movl -0x130(%rbp), %edx
movq -0x1c8(%rbp), %rdi
movq -0x1d0(%rbp), %rsi
callq 0x118900
jmp 0x1182ab
jmp 0x11830e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x118539
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x46a90
movq -0x2d0(%rbp), %rdi
movq %rax, -0x1d8(%rbp)
callq 0x46ac0
movq %rax, -0x1e0(%rbp)
movl -0x130(%rbp), %edx
addl $0xffffff6a, %edx       # imm = 0xFFFFFF6A
movq -0x1d8(%rbp), %rdi
movq -0x1e0(%rbp), %rsi
callq 0x118900
jmp 0x11830c
jmp 0x11830e
movl $0x0, -0x1e4(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x46270
movl $0x0, -0x204(%rbp)
movslq -0x204(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x467f0
movq %rax, %rcx
movq -0x2d8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1183fa
movslq -0x204(%rbp), %rsi
leaq -0x188(%rbp), %rdi
callq 0x4d100
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x118960
movq %rax, -0x2e0(%rbp)
jmp 0x118386
movq -0x2e0(%rbp), %rax
cmpq $0x1, %rax
jne 0x1183e4
movl -0x1e4(%rbp), %eax
incl %eax
movl %eax, -0x1e4(%rbp)
movslq -0x204(%rbp), %rsi
leaq -0x188(%rbp), %rdi
callq 0x4d100
movq %rax, %rsi
leaq -0x200(%rbp), %rdi
callq 0x6b600
jmp 0x1183c5
jmp 0x1183e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x48290
jmp 0x118539
jmp 0x1183e6
movl -0x204(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x204(%rbp)
jmp 0x11832e
movl $0x0, -0x208(%rbp)
movslq -0x208(%rbp), %rax
movq %rax, -0x2e8(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x467f0
movq %rax, %rcx
movq -0x2e8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1184b3
movslq -0x208(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x4d100
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x118960
movq %rax, -0x2f0(%rbp)
jmp 0x11845c
movq -0x2f0(%rbp), %rax
cmpq $0x1, %rax
jne 0x11849d
movl -0x1e4(%rbp), %eax
incl %eax
movl %eax, -0x1e4(%rbp)
movslq -0x208(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x4d100
movq %rax, %rsi
leaq -0x200(%rbp), %rdi
callq 0x6b600
jmp 0x11849b
jmp 0x11849d
jmp 0x11849f
movl -0x208(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x208(%rbp)
jmp 0x118404
cmpl $0x1, -0x1e4(%rbp)
jle 0x1184ec
movq 0x80af5(%rip), %rdi     # 0x198fb8
leaq -0x30(%rbp), %rsi
callq 0xa520
movq %rax, -0x2f8(%rbp)
jmp 0x1184d5
movq -0x2f8(%rbp), %rdi
movq 0x80aa5(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0x1184ea
jmp 0x1184ec
leaq -0x200(%rbp), %rdi
callq 0x48290
leaq -0x1c0(%rbp), %rdi
callq 0x48290
leaq -0x188(%rbp), %rdi
callq 0x48290
leaq -0x170(%rbp), %rdi
callq 0xac88
leaq -0x150(%rbp), %rdi
callq 0xac88
leaq -0x128(%rbp), %rdi
callq 0x3dfa0
jmp 0x117fd0
leaq -0x1c0(%rbp), %rdi
callq 0x48290
leaq -0x188(%rbp), %rdi
callq 0x48290
leaq -0x170(%rbp), %rdi
callq 0xac88
leaq -0x150(%rbp), %rdi
callq 0xac88
leaq -0x128(%rbp), %rdi
callq 0x3dfa0
jmp 0x118597
leaq -0xb0(%rbp), %rdi
callq 0x118990
leaq -0x30(%rbp), %rdi
callq 0xac88
xorl %eax, %eax
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0x118990
leaq -0x30(%rbp), %rdi
callq 0xac88
movq -0x68(%rbp), %rdi
callq 0xab50
nopw %cs:(%rax,%rax)