fa.cpp
1.13 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
/*
* $Id$
*
* Copyright (C) 2008-2010 Kengo Sato
*
* This file comes from Ipknot.
*/
#include "fa.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cctype>
#include <cstring>
#include <cassert>
typedef unsigned int uint;
//static
unsigned int Fasta::load(std::list<Fasta>& data, const char* file){
std::string line, name, seq, str;
std::ifstream ifs(file);
while (std::getline(ifs, line)) {
if (line[0]=='>') { // header
if (!name.empty()) {
assert(str.size()==0 || seq.size()==str.size());
data.push_back(Fasta(name, seq, str));
}
name=line.substr(1);
seq.clear();
str.clear();
continue;
}
if (std::strchr("()[].?xle ", line[0])==NULL) { // seq
uint i;
for (i=0; i!=line.size(); ++i)
if (!isalpha(line[i])) break;
seq+=line.substr(0, i);
} else {
uint i;
for (i=0; i!=line.size(); ++i)
if (std::strchr("()[].?xle ", line[i])==NULL) break;
str+=line.substr(0, i);
}
}
if (!name.empty())
data.push_back(Fasta(name, seq, str));
return data.size();
}