-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFASTA.cpp
More file actions
52 lines (45 loc) · 1.1 KB
/
FASTA.cpp
File metadata and controls
52 lines (45 loc) · 1.1 KB
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
#include "FASTA.h"
FASTA::FASTA(std::string fileName)
{
std::string line;
std::ifstream fastaStream(fileName);
if (fastaStream.is_open())
{
std::string header;
std::string sequence;
while (std::getline(fastaStream, line))
{
// Is it a header or part of the sequence?
if (line.compare(0, 1, ">") == 0)
{
// If we already have a sequence, then save it
if (sequence.length() > 0)
{
//std::cout << "Inserting" << std::endl;
insert(std::pair<std::string, std::string>(header, sequence));
header = line;
sequence.clear();
}
else
{
//std::cout << "Header: " << line << std::endl;
header = line;
}
}
else
{
// Append it to the sequence
sequence.append(line);
}
}
// Add the final sequence
insert(std::pair<std::string, std::string>(header, sequence));
fastaStream.close();
}
// Debug print
for (const std::pair<std::string, std::string>& pair : *this)
std::cout << pair.first << " (" << pair.second.length() << " base pairs)" << std::endl;
}
FASTA::~FASTA()
{
}