-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathseqio.hh
More file actions
59 lines (49 loc) · 1.66 KB
/
seqio.hh
File metadata and controls
59 lines (49 loc) · 1.66 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
#pragma once
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;
// SeqRecord class --- a fasta record, accno + sequence
class SeqRecord
{
private:
string header, description, sequence;
public:
SeqRecord(const SeqRecord&);
SeqRecord(string, string, string);
~SeqRecord();
string seq() const {return sequence;}
string id() const {return header;}
string desc() const {return description;}
int length() const {return sequence.length();}
SeqRecord toupper() const; // capitalize the sequence
SeqRecord rc() const; // reverse complement
};
// Sequentially read records from a FASTA file, avoiding the need to read
// huge files into memory at once; before reading a sequence using the
// next() method one needs to make sure the stream is in a good state using
// the good() method
class RecordGenerator
{
private:
ifstream ifs;
// we make the following variables instance attributes in order
// to allow for persistence between the call of the constructor
// and the subsequent call to the next() method
string id, desc;
bool is_good;
public:
RecordGenerator(string);
~RecordGenerator();
bool good() {return is_good;} // indicates whether the fasta file
// is good for reading another sequence
SeqRecord next(); // read the next sequence
};
// Function for reading the vector of sequences into memory.
// Vector to read the sequence records into is passed by reference,
// and it gets appended with the newly read records --- it allows to
// cumulatively read sequences from several files.
void FastaRead(string fname, vector<SeqRecord>& recs);
// Function for counting reads in a fasta file
int CountReads(string fname);