-
Notifications
You must be signed in to change notification settings - Fork 0
/
SequenceReader.h
executable file
·85 lines (65 loc) · 1.48 KB
/
SequenceReader.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
#pragma once
#include <fstream>
using namespace std;
/*
This function is called for reading DNA sequences in the file,
taking parameters:
filePath: path to two DNA sequences file.
buffer: pointer to dynamic memory buffering the whole file text.
seq_a: pointer to dynamic memory to store the first DNA sequence.
seq_b: pointer to dynamic memory to store the second DNA sequence.
fileEnd: character signalling the end of file.
*/
void SequenceReader(const char * filePath, char * seq_a, char * seq_b, char fileEnd);
void SequenceReader(const char * filePath, char * seq_a, char * seq_b,char fileEnd)
{
fstream file;
try
{
file.open(filePath);
}
catch (exception)
{
throw("resource error: failed to open the DNA sequence file");
}
char * buffer;
buffer = new char[1000000];
//set the max of file stream to 1000000
file.getline(buffer, 1000000, fileEnd);
int i = 0;
int j = 0;
//skip all the instruction
while (buffer[i] != '<')
i++;
i++;
while (buffer[i] != '>')
{
if (buffer[i] == '\n'|| buffer[i] == ' ')
{
i++;
continue;
}
seq_a[j] = buffer[i];
j++;
i++;
}
seq_a[j] = '\0';
//skip until next "<"
while (buffer[i] != '<')
i++;
i++;
j = 0;
while (buffer[i] != '>')
{
if (buffer[i] == '\n'|| buffer[i] == ' ')
{
i++;
continue;
}
seq_b[j] = buffer[i];
j++;
i++;
}
seq_b[j] = '\0';
delete[] buffer;
}