+// ***************************************************************************
+// bamtools_fasta.cpp (c) 2010 Derek Barnett, Erik Garrison
+// Marth Lab, Department of Biology, Boston College
+// All rights reserved.
+// ---------------------------------------------------------------------------
+// Last modified: 13 July 2010
+// ---------------------------------------------------------------------------
+// Provides FASTA reading/indexing functionality.
+// ***************************************************************************
+
#include <cstdio>
#include <cstdlib>
#include <cstring>
string sequence = "";
while ( GetNextHeader(header) ) {
+ // ---------------------------
// build index entry data
FastaIndexData data;
- GetNameFromHeader(header, data.Name);
+
+ // store file offset of beginning of DNA sequence (after header)
data.Offset = ftello(Stream);
- GetNextSequence(sequence);
+ // parse header, store sequence name in data.Name
+ if ( !GetNameFromHeader(header, data.Name) ) {
+ cerr << "FASTA error : could not parse read name from FASTA header" << endl;
+ return false;
+ }
+
+ // retrieve FASTA sequence
+ if ( !GetNextSequence(sequence) ) {
+ cerr << "FASTA error : could not read in next sequence from FASTA file" << endl;
+ return false;
+ }
+
+ // store sequence length & line/byte lengths
data.Length = sequence.length();
data.LineLength = lineLength;
data.ByteLength = byteLength;
// open index file
if ( !indexFilename.empty() ) {
- IndexStream = fopen64(indexFilename.c_str(), "wb");
+ IndexStream = fopen(indexFilename.c_str(), "wb");
if ( !IndexStream ) {
cerr << "FASTA error : Could not open " << indexFilename << " for writing." << endl;
return false;
}
if ( start == stop ) {
- cout << "FASTA error : could not parse read name from FASTA header." << endl;
+ cerr << "FASTA error : could not parse read name from FASTA header" << endl;
return false;
}
bool success = true;
// open FASTA filename
- Stream = fopen64(filename.c_str(), "rb");
+ Stream = fopen(filename.c_str(), "rb");
if ( !Stream ) {
cerr << "FASTA error: Could not open " << filename << " for reading" << endl;
return false;
// open index file if it exists
if ( !indexFilename.empty() ) {
- IndexStream = fopen64(indexFilename.c_str(), "rb");
+ IndexStream = fopen(indexFilename.c_str(), "rb");
if ( !IndexStream ) {
cerr << "FASTA error : Could not open " << indexFilename << " for reading." << endl;
return false;
d = 0;
}
-bool Fasta::Close(void) {
+bool Fasta::Close(void) {
return d->Close();
}
bool Fasta::Open(const string& filename, const string& indexFilename) {
return d->Open(filename, indexFilename);
-}
\ No newline at end of file
+}