File Format I/O

| Example Program File Format I/O Accessing sequence data in files. File "file_format.cpp" A tutorial about the use of files and file formats.
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 |
10 | int main()
11 | {
Open a standard library stream for binary write. You can use both C++ iostreams or old style FILE pointer. The file format is Fasta.
12 | ::std::FILE * fl = ::std::fopen("testfile.fa", "wb");
13 | write(fl, "aacagtattagaccactaggaccct", "a test file", Fasta());
14 | close (fl);
Read a fasta file.
15 | ::std::fstream fstrm;
16 | fstrm.open("testfile.fa", ::std::ios_base::in | ::std::ios_base::binary);
17 | String<char> fasta_tag;
18 | String<Dna> fasta_seq;
Read the meta-information.
19 | readMeta(fstrm, fasta_tag, Fasta());
20 | ::std::cout << fasta_tag << "\n"; //prints "a test file"
Read the sequence.
21 | read(fstrm, fasta_seq, Fasta());
22 | ::std::cout << fasta_seq << "\n"; //prints the sequence
23 | fstrm.close();
Open a file using a file reader string.
24 | String<Dna, FileReader<Fasta> > fr("testfile.fa");
25 | ::std::cout << fr << "\n"; //prints the sequence
26 | return 0;
27 | }
28 |
See write, read, readMeta, File Reader String SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2011/02/08 21:37:01