| Example Program File Format I/O Accessing sequence data in files. File "file_format.cpp"
1 | #include <iostream>
2 | #include <fstream>
3 | #include <cstdio>
4 |
5 | #include <seqan/sequence.h>
6 | #include <seqan/file.h>
7 |
8 | using namespace seqan;
9 | using namespace std;
10 |
11 | int main()
12 | {
Create a fasta file: Open a standard library stream for binary write. You can use both C++ iostreams or old style FILE pointer.
13 | FILE * fl = fopen("testfile.fa", "wb");
14 | write(fl, "aacagtattagaccactaggaccct", "a test file", Fasta());
15 | close (fl);
Read a fasta file into a string: Open a stram for binary read.
16 | fstream fstrm;
17 | fstrm.open("testfile.fa", ios_base::in | ios_base::binary);
18 | String<char> fasta_tag;
19 | String<Dna> fasta_seq;
20 |
21 | readMeta(fstrm, fasta_tag, Fasta());
22 | cout << fasta_tag << "\n"; //prints "a test file"
23 |
24 | read(fstrm, fasta_seq, Fasta());
25 | cout << fasta_seq << "\n"; //prints the sequence
26 | fstrm.close();
Opens a file using a file reader string:
27 | String<Dna, FileReader<Fasta> > fr("testfile.fa");
28 | cout << fr << "\n"; //prints the sequence
29 |
30 | return 0;
31 | }
32 |
See File Reader String, read, readMeta, write SeqAn - Sequence Analysis Library - www.seqan.de