-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMultiFasta.cpp
More file actions
105 lines (86 loc) · 1.96 KB
/
CMultiFasta.cpp
File metadata and controls
105 lines (86 loc) · 1.96 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
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
95
96
97
98
99
100
101
102
/*
* File: CMultiFasta.cpp
* Author: mwittig
*
* Created on July 20, 2012, 1:00 PM
*/
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <set>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include "CMultiFasta.h"
#include "CMyException.h"
#include "MyTools.h"
#define BOOST_ALL_NO_LIB
CMultiFasta::CMultiFasta()
{
}
CMultiFasta::CMultiFasta(const string& filename)
{
readSequence(filename);
}
CMultiFasta::CMultiFasta(const CMultiFasta& orig)
{
}
CMultiFasta::~CMultiFasta()
{
}
void CMultiFasta::readSequence(const string& filename)
{
try
{
ifstream in(filename.c_str());
if(!in)
throw string("Can't open ")+filename;
string strLine;
string strHeader = "";
ostringstream strSeq("");
while(getline(in,strLine))
{
if(strLine.size() == 0)
continue;
if(strLine[0] == '>')
{
if(strHeader!="")
{
m_mapSequences[strHeader]=strSeq.str();
}
else
CMyException("empty header. discard entries and continue with ")+strLine;
strHeader= CMyTools::trim(strLine.substr(1,strLine.find_first_of(" \t")));
strSeq.str("");
}
else
strSeq << strLine;
}
in.close();
if(strHeader!="")
{
m_mapSequences[strHeader]=strSeq.str();
}
}
catch(const string& err)
{
throw CMyException(err);
}
catch(const CMyException& err)
{
throw err;
}
catch(...)
{
throw CMyException("unknown error in CMultiFasta::readSequence ");
}
}
string CMultiFasta::operator[](const string& val)
{
map<string,string>::iterator iter = m_mapSequences.find(val);
if(m_mapSequences.end() == iter)
return "";
return iter->second;
}