Skip to content

Commit

Permalink
make Fasta Length available
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Füglistaler authored and SoapZA committed Mar 4, 2022
1 parent aa74468 commit 2bd8699
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/api/BamReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class API_EXPORT BamReader
const int& rightPosition);
int64_t Tell() const;


// ----------------------
// access alignment data
// ----------------------
Expand Down
26 changes: 26 additions & 0 deletions src/utils/bamtools_fasta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct Fasta::FastaPrivate
bool CreateIndex(const std::string& indexFilename);
bool GetBase(const int& refId, const int& position, char& base);
bool GetSequence(const int& refId, const int& start, const int& stop, std::string& sequence);
bool GetLength(const int& refId, int& length);
bool Open(const std::string& filename, const std::string& indexFilename);

// internal methods
Expand Down Expand Up @@ -509,6 +510,26 @@ bool Fasta::FastaPrivate::GetSequence(const int& refId, const int& start, const
return true;
}

bool Fasta::FastaPrivate::GetLength(const int& refId, int& length)
{
// make sure FASTA file is open
if (!IsOpen) {
std::cerr << "FASTA error : file not open for reading\n";
return false;
}

// make sure index if available
if (!HasIndex && Index.empty()) {
std::cerr << "FASTA error : could not read from index file\n";
return false;
}

length = Index.at(refId).Length;

// return success
return true;
}

bool Fasta::FastaPrivate::LoadIndexData()
{

Expand Down Expand Up @@ -670,3 +691,8 @@ bool Fasta::Open(const std::string& filename, const std::string& indexFilename)
{
return d->Open(filename, indexFilename);
}

bool Fasta::GetLength(const int& refId, int& length)
{
return d->GetLength(refId, length);
}
1 change: 1 addition & 0 deletions src/utils/bamtools_fasta.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class UTILS_EXPORT Fasta
public:
bool GetBase(const int& refID, const int& position, char& base);
bool GetSequence(const int& refId, const int& start, const int& stop, std::string& sequence);
bool GetLength(const int& refId, int& length);

// index-handling methods
public:
Expand Down

0 comments on commit 2bd8699

Please sign in to comment.