-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.h
executable file
·94 lines (76 loc) · 2.06 KB
/
output.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <fstream>
#include "solver.h"
using namespace std;
/*
This function write the aligned sequences to a specific file,
with option to also write a report to the file.
*/
void outputSeq(const char * path, char * seq_a, char * seq_b, bool reportOn = true, const solver * aliSol=nullptr)
{
fstream file;
try
{
file.open(path,ios::app);
}
catch (exception)
{
throw("output error: cannot open result file.");
}
//Set the pointer to the end of file
file.seekp(ios::end);
try
{
file << "<" << endl;
int length = strlen(aliSol->result_a);
//These variables are for iteratively outputing, the default is 50 characters per line
char matchLine[51];
matchLine[50] = '\0';
char tempA[51];
tempA[50] = '\0';
char tempB[51];
tempB[50] = '\0';
int i;
for (i = 0; i < length; i++)
{
if((i+1) % 50 == 0)
{
strncpy(tempA, (aliSol->result_a)+ i - 49, 50);
strncpy(tempB, (aliSol->result_b)+ i - 49, 50);
file << tempA << endl
<< matchLine << endl
<< tempB << endl
<<endl;
}
matchLine[i % 50] = aliSol->result_a[i]== aliSol->result_b[i] ? '|' : ' ';
}
if ( i % 50 != 0)
{
strncpy(tempA, (aliSol->result_a) + i - (i%50) , i%50 );
strncpy(tempB, (aliSol->result_b) + i - (i%50) , i%50 );
tempA[i%50] = '\0';
tempB[i%50] = '\0';
matchLine[i % 50] = '\0';
file << tempA << endl
<< matchLine << endl
<< tempB << endl
<<endl;
}
file << ">" << endl;
}
catch (exception)
{
throw("output error: failed to output the result.");
}
if (reportOn)
{
file << "----------------------------------------" << endl
<< "report:"<<endl
<< "sequence A length : " << aliSol->length_a << endl
<< "sequence B length : " << aliSol->length_b << endl
<< "aligned sequence length : " << aliSol->aliLen << endl
<< "matched pairs in aligned sequences : " << aliSol->matchCount << endl
<< "----------------------------------------\n" << endl;
}
file.close();
}