// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movl %r9d, 0x8(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, %r13
movq %rdx, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %r15
movl 0x90(%rsp), %ebp
movl $0x191, %edi            # imm = 0x191
callq 0x2030
movq %rax, %r12
leaq 0x4c4a(%rip), %rbx      # 0x7ac7
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
callq 0x2cfc
cmpl $0x2, %ebp
movq %r12, 0x18(%rsp)
je 0x30f4
movq %r15, 0x40(%rsp)
xorl %r15d, %r15d
cmpl $0x1, %ebp
je 0x2fe0
testl %ebp, %ebp
jne 0x32fe
movq %r14, %rdi
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c55
xorl %r15d, %r15d
cmpl $-0x1, %eax
je 0x32fe
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x4998(%rip), %rsi      # 0x7887
leaq 0x5c(%rsp), %rdx
leaq 0xf(%rsp), %rcx
leaq 0x1f(%rsp), %r8
leaq 0xd(%rsp), %r9
xorl %eax, %eax
leaq 0x3c(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x54(%rsp), %r10
pushq %r10
callq 0x2150
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x3325
movl 0x3c(%rsp), %r12d
movl 0x38(%rsp), %ebx
movl 0x34(%rsp), %ebp
movl 0x8221(%rip), %ecx      # 0xb160
movl %r12d, %edi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2dc2
movb 0x7(%rsp), %cl
movq 0x28(%rsp), %rdx
movb %cl, (%rdx,%r15)
movb 0x5(%rsp), %cl
movq 0x20(%rsp), %rdx
movb %cl, (%rdx,%r15)
movl %eax, %eax
leaq 0x81f6(%rip), %rcx      # 0xb164
movb (%rax,%rcx), %al
movb %al, (%r13,%r15)
cmpl $0x0, 0x8(%rsp)
je 0x2f8f
movl %r12d, %edi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2d43
cvtss2sd %xmm0, %xmm0
jmp 0x2fb8
leal (%rbx,%r12), %eax
addl %ebp, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
cmpl %ebx, %r12d
cmovgl %r12d, %ebx
cmpl %ebp, %ebx
cmovlel %ebp, %ebx
addsd 0x4058(%rip), %xmm1     # 0x7008
cvtsi2sd %ebx, %xmm0
divsd %xmm1, %xmm0
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movq %r14, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c55
jmp 0x2ed8
movq %r14, %rdi
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c55
movq %r14, %rdi
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c55
cmpl $-0x1, %eax
je 0x32fe
leaq 0x5(%rsp), %rbx
leaq 0x6(%rsp), %rbp
xorl %r15d, %r15d
movq %r12, %rdi
leaq 0x4901(%rip), %rsi      # 0x7921
leaq 0x7(%rsp), %rdx
movq %rbx, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x2150
cmpl $0x3, %eax
jne 0x3334
movzbl 0x5(%rsp), %eax
cmpl $0x43, %eax
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
je 0x3062
cmpl $0x4c, %eax
je 0x3062
cmpl $0x45, %eax
jne 0x3069
movb $0x53, 0x5(%rsp)
movb $0x53, %al
jmp 0x3069
movb $0x52, 0x5(%rsp)
movb $0x52, %al
movzbl 0x6(%rsp), %ecx
cmpl $0x43, %ecx
je 0x3086
cmpl $0x4c, %ecx
je 0x3086
cmpl $0x45, %ecx
jne 0x308d
movb $0x53, 0x6(%rsp)
movb $0x53, %cl
jmp 0x308d
movb $0x52, 0x6(%rsp)
movb $0x52, %cl
movb 0x7(%rsp), %dl
movb %dl, (%rsi,%r15)
movb %al, (%rdi,%r15)
movb %cl, (%r13,%r15)
movl 0x80d4(%rip), %edx      # 0xb178
incq %r15
cmpl %r15d, %edx
jg 0x30d1
movq 0x7f0d(%rip), %rax      # 0xafc0
movq (%rax), %rdi
leaq 0x4881(%rip), %rsi      # 0x793e
xorl %eax, %eax
callq 0x2240
cmpl %r15d, 0x80ad(%rip)     # 0xb178
jle 0x3343
movq %r14, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c55
cmpl $-0x1, %eax
jne 0x3016
jmp 0x32fe
movl $0x65, %edi
callq 0x2030
movq %rax, %rbp
movl 0x8071(%rip), %edi      # 0xb178
incl %edi
callq 0x2030
movq %rax, 0x8(%rsp)
movl $0x4, %r12d
movl 0x8059(%rip), %ecx      # 0xb178
movq %r14, %rdi
movq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %rbp, %r8
movl $0x64, %r9d
callq 0x2ab7
cmpl $-0x1, %eax
je 0x3263
movq %rbp, %rdi
leaq 0x4871(%rip), %rsi      # 0x79bb
callq 0x20a0
testq %rax, %rax
je 0x3184
movq %r13, %rbx
movq %r14, %r13
movslq 0x8017(%rip), %rax      # 0xb178
leaq -0x1(%rax), %r15
cmpq $0xc8, %rax
jg 0x31c2
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x20f0
jmp 0x31da
movq %rbp, %rdi
leaq 0x4830(%rip), %rsi      # 0x79be
callq 0x20a0
testq %rax, %rax
je 0x31e5
movslq 0x7fd9(%rip), %rax      # 0xb178
leaq -0x1(%rax), %r15
cmpq $0xc8, %rax
jg 0x321e
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x20f0
jmp 0x3236
movl %r15d, %r15d
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2130
addq %r14, %r15
movq %r13, %r14
movq %rbx, %r13
jmp 0x3251
movq %rbp, %rdi
leaq 0x47d4(%rip), %rsi      # 0x79c3
callq 0x20a0
testq %rax, %rax
je 0x3255
movslq 0x7f78(%rip), %rax      # 0xb178
leaq -0x1(%rax), %r15
cmpq $0xc8, %rax
jg 0x323b
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x20f0
jmp 0x324e
movl %r15d, %r15d
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2130
addq %rbx, %r15
jmp 0x3251
movl %r15d, %r15d
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2130
addq %r13, %r15
movb $0x0, (%r15)
decl %r12d
jne 0x3119
callq 0x22f7
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x20e0
testl %eax, %eax
movq 0x18(%rsp), %r12
jle 0x32a4
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movzbl (%rbx,%rcx), %edx
cmpl $0x4c, %edx
je 0x3293
cmpl $0x45, %edx
je 0x3297
cmpl $0x43, %edx
jne 0x329c
movb $0x52, %dl
jmp 0x3299
movb $0x53, %dl
movb %dl, (%rbx,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x3280
movq %r13, %rdi
callq 0x20e0
testl %eax, %eax
jle 0x32df
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movzbl (%r13,%rcx), %edx
cmpl $0x4c, %edx
je 0x32cc
cmpl $0x45, %edx
je 0x32d0
cmpl $0x43, %edx
jne 0x32d7
movb $0x52, %dl
jmp 0x32d2
movb $0x53, %dl
movb %dl, (%r13,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x32b7
movq 0x28(%rsp), %rdi
callq 0x20e0
movq %rax, %r15
movq 0x8(%rsp), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2220
testq %r14, %r14
je 0x330b
movq %r14, %rdi
callq 0x2160
movq %r12, %rdi
callq 0x2220
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x23a1
movq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x2333
leaq 0x465d(%rip), %rdi      # 0x79a7
leaq 0x44ed(%rip), %rsi      # 0x783e
leaq 0x4579(%rip), %rcx      # 0x78d1
movl $0x22b, %edx            # imm = 0x22B
callq 0x2110
movq %rax, %r14
jmp 0x3379
movq %rax, %r14
jmp 0x3381
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2220
movq 0x18(%rsp), %rdi
callq 0x2220
movq %r14, %rdi
callq 0x2270