// File: /workspace/github_cpp_makefile_star2_O2/nanjiangshu[P]calSOV/calSOV.cpp
// Function: ReadInSecPredFile(char const*, char*, char*, char*, double*, int, int)
int ReadInSecPredFile(const char *infile, char *aaSeq, char *obsSec, char *predSec, double *predConf, int typeConfidence, int fileFormat)/*{{{*/
{
    int linesize;
    int maxline = 400;
    Array1D <char> line_1darray(maxline+1);
    char *line = line_1darray.array1D;
    char aa;
    char obs_sec;
    char pred_sec;
    int status_sscanf = 0;

    int seqLength = 0;
    FILE *fp = fopen(infile, "r");
    checkfilestream(fp, infile, "r", true);

    if (fileFormat == 0) /*Res file format*//*{{{*/
    {
        int num ; 
        char shape;
        int probH;
        int probS;
        int probR;
        int predHSRstate = 0; /*predicted HSR state, 0 -- H, 1 -- S, 2 -- R*/
        int cntRes = 0;
        while((linesize=fgetline(fp, line, maxline)) != EOF)
        { 
            status_sscanf = sscanf(line,"%d %c %c %c %d %d %d" , &num,&aa,&shape, &obs_sec,&probH,&probS,&probR);
            if (status_sscanf != 7)
            {
                fprintf(stderr,"sscanf error!");
                fprintf(stderr,"File: %s\n", infile);
                fprintf(stderr,"line: %s\n", line);
                assert (status_sscanf == 7);
            }
            predHSRstate = GetHSRState(probH, probS, probR, method_HSR);

            aaSeq[cntRes] = aa;
            obsSec[cntRes] = obs_sec;
            predSec[cntRes] = HSRalphabet[predHSRstate];
            if (typeConfidence == 0) /*Raw confidence*/
            {
                predConf[cntRes] = GetRawHSRConfidence(probH, probS, probR);
            }
            else 
            {
                predConf[cntRes] = GetNormHSRConfidence(probH, probS, probR);
            }

            cntRes ++;
        } 
        seqLength = cntRes;
    }/*}}}*/
    else if (fileFormat == 1) /*AA OSEC PSEC NUM*//*{{{*/
    {
        /*AA OSEC PSEC NUM*/
        linesize=fgetline(fp,line,maxline); /*neglect the header line*/
        int cntRes = 0;
        while((linesize=fgetline(fp, line, maxline)) != EOF)
        { 
            status_sscanf = sscanf(line," %c %c %c" , &aa,&obs_sec,&pred_sec);
            if (status_sscanf != 3)
            {
                fprintf(stderr,"sscanf error!");
                fprintf(stderr,"File: %s\n", infile);
                fprintf(stderr,"line: %s\n", line);
                assert (status_sscanf == 3);
            }
            if (obs_sec == 'E' ) { obs_sec = 'S'; }
            else if (obs_sec == 'C' || obs_sec == 'L') { obs_sec = 'R'; }

            if (pred_sec == 'E' ) { pred_sec = 'S'; }
            else if (pred_sec == 'C' || pred_sec == 'L') { pred_sec = 'R'; }

            aaSeq[cntRes] = aa;
            obsSec[cntRes] = obs_sec;
            predSec[cntRes] = pred_sec;
#ifdef DEBUG
            fprintf(stdout, "line=%s\n", line);
            fprintf(stdout, "cntRes=%d\n", cntRes);
#endif
            cntRes ++;
            if (cntRes >= maxSeqLength){
                fprintf(stdout,"Number of residues in the input file exceeds the maxSeqLength (%d). Please check your input file. Exit.\n", maxSeqLength);
                assert(cntRes<maxSeqLength);
            }
        } 
        seqLength = cntRes;
    }/*}}}*/
    else if (fileFormat == 2) /*Fasta format >AA, >OSEC, >PSEC*//*{{{*/
    {
        int maxSizeAnno = 100;
        Array1D <char> anno_1darray(maxSizeAnno+1);
        Array1D <char> tmpSeq_1darray(maxSeqLength+1);
        char *tmpSeq = tmpSeq_1darray.array1D;
        char *anno = anno_1darray.array1D;
        int seqlength = 0;
        /*>AA >OSEC >PSEC*/
        int cntSeq = 0;
        while((seqlength = ReadNextSeq_FASTA(fp, tmpSeq, NULL, maxSeqLength, anno, maxSizeAnno))!= EOF)
        {
            if(strstr(anno, "AA") != NULL){
                my_strcpy(aaSeq,tmpSeq, maxSeqLength-1);
            }else if(strstr(anno, "OSEC") != NULL){
                my_strcpy(obsSec,tmpSeq, maxSeqLength-1);
            }else if(strstr(anno, "PSEC") != NULL){
                my_strcpy(predSec,tmpSeq, maxSeqLength-1);
            }
            cntSeq ++;
            if (cntSeq>3){
                fprintf(stderr, "You input file contains more than 3 sequences. Please check the format of your input file\n");
                assert(cntSeq<=3);
            }
        }
        int i = 0;
        seqlength = strlen(obsSec);
        for (i = 0; i<seqlength; i++){
            if (obsSec[i] == 'E' ) { obsSec[i] = 'S'; }
            else if (obsSec[i] == 'C' || obsSec[i] == 'L') { obsSec[i] = 'R'; }
        }

        seqlength = strlen(predSec);
        for (i = 0; i<seqlength; i++){
            if (predSec[i]  == 'E' ) { predSec[i] = 'S'; }
            else if (predSec[i]  == 'C' || predSec[i]  == 'L') { predSec[i]  = 'R'; }
        }
        seqLength = strlen(aaSeq);
    }/*}}}*/
    if (fp != NULL) { fclose(fp); }
    return seqLength;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, 0x24(%rsp)
movq %r8, 0x60(%rsp)
movq %rcx, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbp
movl 0xb0(%rsp), %r14d
movl $0x191, %edi            # imm = 0x191
callq 0x2030
movq %rax, %r13
movq %rax, 0x70(%rsp)
movl $0x191, 0x68(%rsp)      # imm = 0x191
leaq 0x4e29(%rip), %rbx      # 0x7a6f
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2220
movq %rax, %r15
pushq $0x1
popq %rcx
movq %rax, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2a98
cmpl $0x2, %r14d
je 0x2ea8
movq %rbp, 0x30(%rsp)
cmpl $0x1, %r14d
je 0x2d9d
xorl %ebp, %ebp
testl %r14d, %r14d
jne 0x3035
xorl %ebp, %ebp
movq %r13, 0x38(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x29fd
cmpl $-0x1, %eax
je 0x3035
movq %r13, %rdi
movq %r15, %r13
subq $0x8, %rsp
leaq 0x4b75(%rip), %rsi      # 0x782f
leaq 0x58(%rsp), %rdx
leaq 0x16(%rsp), %rcx
leaq 0x17(%rsp), %r8
leaq 0x14(%rsp), %r9
xorl %eax, %eax
leaq 0x30(%rsp), %r10
pushq %r10
leaq 0x3c(%rsp), %r10
pushq %r10
leaq 0x58(%rsp), %r10
pushq %r10
callq 0x2190
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x305d
movl 0x40(%rsp), %r15d
movl 0x2c(%rsp), %r14d
movl 0x28(%rsp), %ebx
movl 0x847d(%rip), %ecx      # 0xb188
movl %r15d, %edi
movl %r14d, %esi
movl %ebx, %edx
callq 0x2b8a
movb 0xe(%rsp), %cl
movq 0x18(%rsp), %rdx
movb %cl, (%rdx,%rbp)
movb 0xc(%rsp), %cl
movq 0x10(%rsp), %rdx
movb %cl, (%rdx,%rbp)
movl %eax, %eax
leaq 0x8453(%rip), %rcx      # 0xb18c
movb (%rax,%rcx), %al
movb %al, (%r12,%rbp)
cmpl $0x0, 0x24(%rsp)
je 0x2d5a
movl %r15d, %edi
movl %r14d, %esi
movl %ebx, %edx
callq 0x2b0e
cvtss2sd %xmm0, %xmm0
jmp 0x2d83
leal (%r14,%r15), %eax
addl %ebx, %eax
cvtsi2sd %eax, %xmm1
cmpl %r14d, %r15d
cmovgl %r15d, %r14d
cmpl %ebx, %r14d
cmovlel %ebx, %r14d
addsd 0x428e(%rip), %xmm1     # 0x7008
cvtsi2sd %r14d, %xmm0
divsd %xmm1, %xmm0
movq 0x60(%rsp), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
movq %r13, %r15
movq 0x38(%rsp), %r13
jmp 0x2c90
movq %r15, %rdi
movq %r13, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x29fd
leaq 0xd(%rsp), %r14
movq 0x8207(%rip), %rbx      # 0xafc0
xorl %ebp, %ebp
movq %r15, %rdi
movq %r13, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x29fd
cmpl $-0x1, %eax
je 0x3035
movq %r13, %rdi
leaq 0x4aeb(%rip), %rsi      # 0x78c9
leaq 0xe(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x2190
cmpl $0x3, %eax
jne 0x30c4
movzbl 0xc(%rsp), %eax
cmpl $0x43, %eax
je 0x2e18
cmpl $0x4c, %eax
je 0x2e18
cmpl $0x45, %eax
jne 0x2e1f
movb $0x53, 0xc(%rsp)
movb $0x53, %al
jmp 0x2e1f
movb $0x52, 0xc(%rsp)
movb $0x52, %al
movzbl 0xd(%rsp), %ecx
cmpl $0x43, %ecx
je 0x2e3c
cmpl $0x4c, %ecx
je 0x2e3c
cmpl $0x45, %ecx
jne 0x2e43
movb $0x53, 0xd(%rsp)
movb $0x53, %cl
jmp 0x2e43
movb $0x52, 0xd(%rsp)
movb $0x52, %cl
movb 0xe(%rsp), %dl
movq 0x18(%rsp), %rsi
movb %dl, (%rsi,%rbp)
movq 0x10(%rsp), %rdx
movb %al, (%rdx,%rbp)
movb %cl, (%r12,%rbp)
movl 0x833f(%rip), %edx      # 0xb1a0
incq %rbp
cmpl %ebp, %edx
jg 0x2dbb
movq (%rbx), %rdi
leaq 0x4a70(%rip), %rsi      # 0x78e6
xorl %eax, %eax
callq 0x2290
cmpl %ebp, 0x831d(%rip)      # 0xb1a0
jg 0x2dbb
leaq 0x4abf(%rip), %rdi      # 0x794f
leaq 0x494f(%rip), %rsi      # 0x77e6
leaq 0x49db(%rip), %rcx      # 0x7879
movl $0x22b, %edx            # imm = 0x22B
callq 0x2140
pushq $0x65
popq %rdi
callq 0x2030
movq %rax, %r14
movq %rax, 0x58(%rsp)
movl $0x65, 0x50(%rsp)
movl 0x82da(%rip), %ebx      # 0xb1a0
incl %ebx
movq %rbx, %rdi
callq 0x2030
movq %rax, %r13
movq %rax, 0x48(%rsp)
movl %ebx, 0x40(%rsp)
pushq $0x4
popq %rbx
pushq $0x64
popq %rbp
movl 0x82b8(%rip), %ecx      # 0xb1a0
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %r8
movl %ebp, %r9d
callq 0x287e
cmpl $-0x1, %eax
je 0x2f9c
movq %r14, %rdi
leaq 0x4a55(%rip), %rsi      # 0x7963
callq 0x20a0
movq 0x18(%rsp), %rdi
testq %rax, %rax
jne 0x2f4d
movq %r14, %rdi
leaq 0x4a3f(%rip), %rsi      # 0x7966
callq 0x20a0
movq 0x10(%rsp), %rdi
testq %rax, %rax
jne 0x2f4d
movq %r14, %rdi
leaq 0x4a2b(%rip), %rsi      # 0x796b
callq 0x20a0
movq %r12, %rdi
testq %rax, %rax
je 0x2f5d
movl 0x824d(%rip), %edx      # 0xb1a0
decl %edx
movq %r13, %rsi
callq 0x26b8
decl %ebx
jne 0x2ee2
movq 0x8070(%rip), %rax      # 0xafd8
movq (%rax), %rcx
leaq 0x49fe(%rip), %rdi      # 0x7970
pushq $0x5a
popq %rsi
pushq $0x1
popq %rdx
callq 0x22e0
leaq 0x4a47(%rip), %rdi      # 0x79cb
leaq 0x485b(%rip), %rsi      # 0x77e6
leaq 0x48e7(%rip), %rcx      # 0x7879
movl $0x246, %edx            # imm = 0x246
callq 0x2140
movq 0x10(%rsp), %rdi
callq 0x20f0
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq 0x10(%rsp), %rsi
cmpq %rcx, %rax
je 0x2fdd
movq 0x10(%rsp), %rdx
movzbl (%rdx,%rcx), %edx
cmpl $0x4c, %edx
je 0x2fcf
cmpl $0x45, %edx
je 0x2fd3
cmpl $0x43, %edx
jne 0x2fd8
movb $0x52, %dl
jmp 0x2fd5
movb $0x53, %dl
movb %dl, (%rsi,%rcx)
incq %rcx
jmp 0x2fb2
movq %r12, %rdi
callq 0x20f0
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x3014
movzbl (%r12,%rcx), %edx
cmpl $0x4c, %edx
je 0x3005
cmpl $0x45, %edx
je 0x3009
cmpl $0x43, %edx
jne 0x300f
movb $0x52, %dl
jmp 0x300b
movb $0x53, %dl
movb %dl, (%r12,%rcx)
incq %rcx
jmp 0x2fec
movq 0x18(%rsp), %rdi
callq 0x20f0
movq %rax, %rbp
leaq 0x40(%rsp), %rdi
callq 0x5bf8
leaq 0x50(%rsp), %rdi
callq 0x5bf8
testq %r15, %r15
je 0x3042
movq %r15, %rdi
callq 0x21a0
leaq 0x68(%rsp), %rdi
callq 0x5bf8
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7f74(%rip), %rbx      # 0xafd8
movq (%rbx), %rcx
leaq 0x47d6(%rip), %rdi      # 0x7844
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
callq 0x22e0
movq (%rbx), %rdi
leaq 0x47cf(%rip), %rsi      # 0x7852
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2290
movq (%rbx), %rdi
leaq 0x47c3(%rip), %rsi      # 0x785c
movq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0x2290
leaq 0x47ba(%rip), %rdi      # 0x7866
leaq 0x4733(%rip), %rsi      # 0x77e6
leaq 0x47bf(%rip), %rcx      # 0x7879
movl $0x1f8, %edx            # imm = 0x1F8
callq 0x2140
movq 0x7f0d(%rip), %rbx      # 0xafd8
movq (%rbx), %rcx
leaq 0x476f(%rip), %rdi      # 0x7844
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
callq 0x22e0
movq (%rbx), %rdi
leaq 0x4768(%rip), %rsi      # 0x7852
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2290
movq (%rbx), %rdi
leaq 0x475c(%rip), %rsi      # 0x785c
movq %r13, %rdx
xorl %eax, %eax
callq 0x2290
leaq 0x47c2(%rip), %rdi      # 0x78d3
leaq 0x46ce(%rip), %rsi      # 0x77e6
leaq 0x475a(%rip), %rcx      # 0x7879
movl $0x219, %edx            # imm = 0x219
callq 0x2140
movq %rax, %rbx
jmp 0x3140
movq %rax, %rbx
jmp 0x314a
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5bf8
leaq 0x50(%rsp), %rdi
callq 0x5bf8
leaq 0x68(%rsp), %rdi
callq 0x5bf8
movq %rbx, %rdi
callq 0x22c0