// File: /workspace/github_c_makefile_star2_O2/fukunagatsu[P]RIblast/rna_interaction_search.cpp
// Function: RnaInteractionSearch::Output(RnaInteractionSearchParameters, std::vector<Hit, std::allocator<Hit>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int*, int)
void RnaInteractionSearch::Output(const RnaInteractionSearchParameters parameters, vector<Hit> &hit_result, string q_name, int flag,int *count,int q_length){
  ofstream ofs;
  if(flag==0){
    ofs.open(parameters.GetOutputFilename().c_str(),ios::out);
    ofs << "RIblast ris result"<< endl;
    ofs << "input:" <<parameters.GetInputFilename() <<",database:" <<parameters.GetDbFilename()<<",RepeatFlag:" <<parameters.GetRepeatFlag()<<",MaximalSpan:" << parameters.GetMaximalSpan() <<",MinAccessibleLength:" << parameters.GetMinAccessibleLength() << ",MaxSeedLength:"<< parameters.GetMaxSeedLength() << ",InteractionEnergyThreshold:" << parameters.GetInteractionEnergyThreshold() << ",HybridEnergyThreshold:" << parameters.GetHybridEnergyThreshold() << ",FinalThreshold:" << parameters.GetFinalThreshold() << ",DropOutLengthWoGap:" << parameters.GetDropOutLengthWoGap() << ",DropOutLengthWGap:" << parameters.GetDropOutLengthWGap() << endl;
  }else{
    ofs.open(parameters.GetOutputFilename().c_str(),ios::app);
  }
  if (!ofs){
    cout << "Error: can't open output_file:"+parameters.GetOutputFilename()+"." <<endl;
    exit(1);
  }
  if(flag==0){
    ofs << "Id,Query name, Query Length, Target name, Target Length, Accessibility Energy, Hybridization Energy, Interaction Energy, BasePair"<< endl;
  }
  int output_style = parameters.GetOutputStyle();
  
  for(int i = 0; i< hit_result.size(); i++){
    ofs << *count << ",";
    *count += 1;
    int id = hit_result[i].GetDbSeqId();
    int db_length = _db_seq_length_without_repeat[id];
    int seq_start_position = _db_seq_start_position[id];
    ofs << q_name << ",";
    ofs << q_length << ",";
    ofs << _db_seq_name[id] << ",";
    ofs << db_length << ",";
    ofs << hit_result[i].GetAccessibilityEnergy() << ",";
    ofs << hit_result[i].GetHybridizationEnergy() << ",";
    ofs << hit_result[i].GetEnergy() << ",";
    db_length = _db_seq_length[id];
    int basepair_length = hit_result[i].GetBasePairLength();
    if(output_style==1){
      for(int j = 0; j<basepair_length;j++){
	int dbpos = (db_length-1) - ( hit_result[i].GetBasePairSecond(j)- seq_start_position);
	ofs << "(" << hit_result[i].GetBasePairFirst(j) << ":" << dbpos << ") " ;
      }
    }else{
      ofs << "(" << hit_result[i].GetBasePairFirst(0) << "-" << hit_result[i].GetBasePairFirst(basepair_length-1) << ":" ;
      int dbpos1 = (db_length-1) - ( hit_result[i].GetBasePairSecond(0)- seq_start_position);
      int dbpos2 = (db_length-1) - ( hit_result[i].GetBasePairSecond(basepair_length-1)- seq_start_position);
      ofs << dbpos1 << "-" << dbpos2 << ") " ;
    }
    ofs << endl;
  }
  ofs.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %r9, %rbp
movl %r8d, %ebx
movq %rcx, 0x40(%rsp)
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, 0x28(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x3380
leaq 0x40(%r13), %r14
testl %ebx, %ebx
je 0xce80
movq %rsp, %rdi
movq %r14, %rsi
callq 0x32d0
movq (%rsp), %rsi
leaq 0x88(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x3030
jmp 0xd034
movq %rsp, %rdi
movq %r14, %rsi
callq 0x32d0
movq (%rsp), %rsi
leaq 0x88(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x3030
movq %rsp, %rdi
callq 0x3100
leaq 0x3ac6a(%rip), %rsi     # 0x47b18
leaq 0x88(%rsp), %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
leaq 0x3ac61(%rip), %rsi     # 0x47b2b
leaq 0x88(%rsp), %rdi
callq 0x31e0
movq %rax, %r12
leaq 0x20(%r13), %rsi
movq %rsp, %rdi
callq 0x32d0
movq %rsp, %rsi
movq %r12, %rdi
callq 0x31c0
leaq 0x3ac3a(%rip), %rsi     # 0x47b32
movq %rax, %rdi
callq 0x31e0
movq %rax, %r12
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x32d0
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
callq 0x31c0
leaq 0x3ac19(%rip), %rsi     # 0x47b3d
movq %rax, %rdi
callq 0x31e0
movl 0x68(%r13), %esi
movq %rax, %rdi
callq 0x3390
leaq 0x3ac0b(%rip), %rsi     # 0x47b4a
movq %rax, %rdi
callq 0x31e0
movl 0x6c(%r13), %esi
movq %rax, %rdi
callq 0x3390
leaq 0x3abfe(%rip), %rsi     # 0x47b58
movq %rax, %rdi
callq 0x31e0
movl 0x70(%r13), %esi
movq %rax, %rdi
callq 0x3390
leaq 0x3abf9(%rip), %rsi     # 0x47b6e
movq %rax, %rdi
callq 0x31e0
movl 0x74(%r13), %esi
movq %rax, %rdi
callq 0x3390
leaq 0x3abee(%rip), %rsi     # 0x47b7e
movq %rax, %rdi
callq 0x31e0
movsd 0x78(%r13), %xmm0
movq %rax, %rdi
callq 0x3350
leaq 0x3abee(%rip), %rsi     # 0x47b9b
movq %rax, %rdi
callq 0x31e0
movsd 0x80(%r13), %xmm0
movq %rax, %rdi
callq 0x3350
leaq 0x3abe6(%rip), %rsi     # 0x47bb3
movq %rax, %rdi
callq 0x31e0
movsd 0x88(%r13), %xmm0
movq %rax, %rdi
callq 0x3350
leaq 0x3abd7(%rip), %rsi     # 0x47bc4
movq %rax, %rdi
callq 0x31e0
movl 0x90(%r13), %esi
movq %rax, %rdi
callq 0x3390
leaq 0x3abce(%rip), %rsi     # 0x47bd9
movq %rax, %rdi
callq 0x31e0
movl 0x94(%r13), %esi
movq %rax, %rdi
callq 0x3390
movq %rax, %rdi
callq 0x3110
leaq 0x48(%rsp), %rdi
callq 0x3100
movq %rsp, %rdi
callq 0x3100
movq 0x88(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xa8(%rsp,%rax)
jne 0xd399
testl %ebx, %ebx
jne 0xd076
leaq 0x3abab(%rip), %rsi     # 0x47c0c
leaq 0x88(%rsp), %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
movl 0x60(%r13), %eax
movl %eax, 0x24(%rsp)
xorl %esi, %esi
movq 0x28(%rsp), %r13
movq %rbp, 0x38(%rsp)
movq 0x8(%r15), %rax
subq (%r15), %rax
cqto
pushq $0x50
popq %rcx
idivq %rcx
movq %rsi, 0x30(%rsp)
cmpq %rsi, %rax
jbe 0xd36d
movl (%rbp), %esi
leaq 0x88(%rsp), %rdi
callq 0x3390
movq %rax, %rdi
leaq 0x3abcd(%rip), %rsi     # 0x47c8e
callq 0x31e0
incl (%rbp)
movq (%r15), %rax
imulq $0x50, 0x30(%rsp), %r14
movslq (%rax,%r14), %r12
movq 0xa8(%r13), %rax
movq 0xd8(%r13), %rcx
movl (%rcx,%r12,4), %ebp
movl (%rax,%r12,4), %ebx
leaq 0x88(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x31c0
movq %rax, %rdi
leaq 0x3ab86(%rip), %rsi     # 0x47c8e
callq 0x31e0
leaq 0x88(%rsp), %rdi
movl 0x2c0(%rsp), %esi
callq 0x3390
movq %rax, %rdi
leaq 0x3ab63(%rip), %rsi     # 0x47c8e
callq 0x31e0
movq %r12, %rsi
shlq $0x5, %rsi
addq 0x30(%r13), %rsi
leaq 0x88(%rsp), %rdi
callq 0x31c0
movq %rax, %rdi
leaq 0x3ab3c(%rip), %rsi     # 0x47c8e
callq 0x31e0
leaq 0x88(%rsp), %rdi
movl %ebp, %esi
callq 0x3390
movq %rax, %rdi
leaq 0x3ab1e(%rip), %rsi     # 0x47c8e
callq 0x31e0
movq (%r15), %rax
movsd 0x18(%rax,%r14), %xmm0
leaq 0x88(%rsp), %rdi
callq 0x3350
movq %rax, %rdi
leaq 0x3aaf8(%rip), %rsi     # 0x47c8e
callq 0x31e0
movq (%r15), %rax
movsd 0x20(%rax,%r14), %xmm0
leaq 0x88(%rsp), %rdi
callq 0x3350
movq %rax, %rdi
leaq 0x3aad2(%rip), %rsi     # 0x47c8e
callq 0x31e0
movq (%r15), %rax
movsd 0x28(%rax,%r14), %xmm0
leaq 0x88(%rsp), %rdi
callq 0x3350
movq %rax, %rdi
leaq 0x3aaac(%rip), %rsi     # 0x47c8e
callq 0x31e0
movq %rbx, %rbp
movq (%r15), %rax
movq 0x40(%rax,%r14), %rbx
subq 0x38(%rax,%r14), %rbx
movq 0xc0(%r13), %rax
movl (%rax,%r12,4), %r12d
cmpl $0x1, 0x24(%rsp)
jne 0xd292
shrq $0x3, %rbx
addl %ebp, %r12d
decl %r12d
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
xorl %r13d, %r13d
cmpq %r13, %rbx
je 0xd349
movq (%r15), %rax
movq 0x38(%rax,%r14), %rax
movl %r12d, %ebp
subl 0x4(%rax,%r13,8), %ebp
leaq 0x88(%rsp), %rdi
leaq 0x3aa44(%rip), %rsi     # 0x47c90
callq 0x31e0
movq (%r15), %rcx
movq 0x38(%rcx,%r14), %rcx
movl (%rcx,%r13,8), %esi
movq %rax, %rdi
callq 0x3390
movq %rax, %rdi
leaq 0x3a953(%rip), %rsi     # 0x47bc2
callq 0x31e0
movq %rax, %rdi
movl %ebp, %esi
callq 0x3390
movq %rax, %rdi
leaq 0x3aa0a(%rip), %rsi     # 0x47c92
callq 0x31e0
incq %r13
jmp 0xd224
leaq 0x88(%rsp), %rdi
leaq 0x3a9ef(%rip), %rsi     # 0x47c90
callq 0x31e0
movq (%r15), %rcx
movq 0x38(%rcx,%r14), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x3390
movq %rax, %rdi
leaq 0x3a9d3(%rip), %rsi     # 0x47c95
callq 0x31e0
movq (%r15), %rcx
shlq $0x1d, %rbx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %rbx
sarq $0x20, %rbx
movq 0x38(%rcx,%r14), %rcx
movl (%rcx,%rbx,8), %esi
movq %rax, %rdi
callq 0x3390
movq %rax, %rdi
leaq 0x3a8c9(%rip), %rsi     # 0x47bc2
callq 0x31e0
movq (%r15), %rax
movq 0x38(%rax,%r14), %rax
addl %r12d, %ebp
decl %ebp
movl %ebp, %esi
subl 0x4(%rax), %esi
subl 0x4(%rax,%rbx,8), %ebp
leaq 0x88(%rsp), %rdi
callq 0x3390
movq %rax, %rdi
leaq 0x3a96a(%rip), %rsi     # 0x47c95
callq 0x31e0
movq %rax, %rdi
movl %ebp, %esi
callq 0x3390
movq %rax, %rdi
leaq 0x3a94e(%rip), %rsi     # 0x47c92
callq 0x31e0
leaq 0x88(%rsp), %rdi
callq 0x3110
movq 0x30(%rsp), %rsi
incq %rsi
movq 0x38(%rsp), %rbp
movq 0x28(%rsp), %r13
jmp 0xd08a
leaq 0x88(%rsp), %rdi
callq 0x32f0
leaq 0x88(%rsp), %rdi
callq 0x3310
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x32d0
leaq 0x3a840(%rip), %rsi     # 0x47bed
leaq 0x48(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0xdb99
leaq 0x93b8(%rip), %rdx      # 0x1677b
movq %rsp, %rdi
leaq 0x48(%rsp), %rsi
callq 0x4e73
movq 0xd5bf9(%rip), %rdi     # 0xe2fd0
movq %rsp, %rsi
callq 0x31c0
movq %rax, %rdi
callq 0x3110
movq %rsp, %rdi
callq 0x3100
leaq 0x48(%rsp), %rdi
callq 0x3100
leaq 0x68(%rsp), %rdi
callq 0x3100
pushq $0x1
popq %rdi
callq 0x3250
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3100
jmp 0xd41b
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3100
jmp 0xd42a
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0xd458
jmp 0xd43f
jmp 0xd467
jmp 0xd43f
jmp 0xd467
jmp 0xd467
jmp 0xd43f
jmp 0xd467
movq %rax, %rbx
jmp 0xd455
jmp 0xd467
jmp 0xd467
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3100
movq %rsp, %rdi
callq 0x3100
jmp 0xd46a
jmp 0xd467
jmp 0xd467
jmp 0xd467
jmp 0xd467
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x33a0
nop