Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find(), ConstFind() dictionary methods, .gitignore #89

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build
bin
lib
include
bamtools_version.h
*.swp
.DS_Store
._.*

23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Fork of **bamtools** from <https://github.com/pezmaster31/bamtools/>. I love
the bamtools API and will put mods here that could potentially be part of the
general bamtools offering. More extensive mods (such as my desire to create a
version that can be dropped into an existing Makefile-driven project) will go
in another fork.

#### Reduced header-associated memory usage

I added the methods
```c++
const SamHeader& BamReader::GetConstSamHeader() const { }
```
to the public interface for `BamReader`,
```c++
const SamHeader& BamReaderPrivate::GetConstSamHeader() const { }
```
to the public interface for `Internal::BamReaderPrivate` and
```c++
const SamHeader& BamHeader::ToConstSamHeader() const { }
```
to the `Internal::BamHeader` class, this is the method that ultimately provides
the reference requested by `BamReader::GetConstSamHeader()`.

File renamed without changes.
138 changes: 69 additions & 69 deletions src/api/BamWriter.h
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
// ***************************************************************************
// BamWriter.h (c) 2009 Michael Str�mberg, Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides the basic functionality for producing BAM files
// ***************************************************************************
#ifndef BAMWRITER_H
#define BAMWRITER_H
#include "api/api_global.h"
#include "api/BamAux.h"
#include <string>
namespace BamTools {
class BamAlignment;
class SamHeader;
//! \cond
namespace Internal {
class BamWriterPrivate;
} // namespace Internal
//! \endcond
class API_EXPORT BamWriter {
// enums
public:
enum CompressionMode { Compressed = 0
, Uncompressed
};
// ctor & dtor
public:
BamWriter(void);
~BamWriter(void);
// public interface
public:
// closes the current BAM file
void Close(void);
// returns a human-readable description of the last error that occurred
std::string GetErrorString(void) const;
// returns true if BAM file is open for writing
bool IsOpen(void) const;
// opens a BAM file for writing
bool Open(const std::string& filename,
const std::string& samHeaderText,
const RefVector& referenceSequences);
// opens a BAM file for writing
bool Open(const std::string& filename,
const SamHeader& samHeader,
const RefVector& referenceSequences);
// saves the alignment to the alignment archive
bool SaveAlignment(const BamAlignment& alignment);
// sets the output compression mode
void SetCompressionMode(const BamWriter::CompressionMode& compressionMode);
// private implementation
private:
Internal::BamWriterPrivate* d;
};
} // namespace BamTools
#endif // BAMWRITER_H
// ***************************************************************************
// BamWriter.h (c) 2009 Michael Str�mberg, Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides the basic functionality for producing BAM files
// ***************************************************************************

#ifndef BAMWRITER_H
#define BAMWRITER_H

#include "api/api_global.h"
#include "api/BamAux.h"
#include <string>

namespace BamTools {

class BamAlignment;
struct SamHeader;

//! \cond
namespace Internal {
class BamWriterPrivate;
} // namespace Internal
//! \endcond

class API_EXPORT BamWriter {

// enums
public:
enum CompressionMode { Compressed = 0
, Uncompressed
};

// ctor & dtor
public:
BamWriter(void);
~BamWriter(void);

// public interface
public:
// closes the current BAM file
void Close(void);
// returns a human-readable description of the last error that occurred
std::string GetErrorString(void) const;
// returns true if BAM file is open for writing
bool IsOpen(void) const;
// opens a BAM file for writing
bool Open(const std::string& filename,
const std::string& samHeaderText,
const RefVector& referenceSequences);
// opens a BAM file for writing
bool Open(const std::string& filename,
const SamHeader& samHeader,
const RefVector& referenceSequences);
// saves the alignment to the alignment archive
bool SaveAlignment(const BamAlignment& alignment);
// sets the output compression mode
void SetCompressionMode(const BamWriter::CompressionMode& compressionMode);

// private implementation
private:
Internal::BamWriterPrivate* d;
};

} // namespace BamTools

#endif // BAMWRITER_H
39 changes: 39 additions & 0 deletions src/api/SamSequenceDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,45 @@ SamSequenceConstIterator SamSequenceDictionary::End(void) const {
return m_data.end();
}

/*! \fn SamSequenceIterator SamSequenceDictionary::Find(const std::string& sequenceName)
\return an STL iterator pointing to the sequence having sequenceName, otherwise End()
\sa ConstFind(), Begin(), End()
*/
SamSequenceIterator SamSequenceDictionary::Find(const std::string& sequenceName) {
if ( m_lookupData.find(sequenceName) == m_lookupData.end() )
return End();
SamSequenceIterator it = m_data.begin();
const size_t index = m_lookupData.find(sequenceName)->second;
return it + index;
}

/*! \fn SamSequenceConstIterator SamSequenceDictionary::Find(void) const
\return an STL const_iterator pointing to the sequence having sequenceName, otherwise End()

This is an overloaded function.

\sa ConstFind(), Begin(), End()
*/
SamSequenceConstIterator SamSequenceDictionary::Find(const std::string& sequenceName) const {
if ( m_lookupData.find(sequenceName) == m_lookupData.end() )
return End();
SamSequenceConstIterator it = m_data.begin();
const size_t index = m_lookupData.find(sequenceName)->second;
return it + index;
}

/*! \fn SamSequenceConstIterator SamSequenceDictionary::ConstFind(void) const
\return an STL const_iterator pointing to the sequence having sequenceName, otherwise End()
\sa Find(), ConstBegin(), ConstEnd()
*/
SamSequenceConstIterator SamSequenceDictionary::ConstFind(const std::string& sequenceName) const {
if ( m_lookupData.find(sequenceName) == m_lookupData.end() )
return ConstEnd();
SamSequenceConstIterator it = m_data.begin();
const size_t index = m_lookupData.find(sequenceName)->second;
return it + index;
}

/*! \fn bool SamSequenceDictionary::IsEmpty(void) const
\brief Returns \c true if dictionary contains no sequences
\sa Size()
Expand Down
4 changes: 4 additions & 0 deletions src/api/SamSequenceDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class API_EXPORT SamSequenceDictionary {
SamSequenceIterator End(void); // returns iterator to end()
SamSequenceConstIterator End(void) const; // returns const_iterator to end()
SamSequenceConstIterator ConstEnd(void) const; // returns const_iterator to end()
SamSequenceIterator Find(const std::string& sequenceName);
SamSequenceConstIterator Find(const std::string& sequenceName) const;
SamSequenceConstIterator ConstFind(const std::string& sequenceName) const;


// data members
private:
Expand Down
2 changes: 1 addition & 1 deletion src/toolkit/bamtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int Version(void) {
int main(int argc, char* argv[]) {

// just 'bamtools'
if ( (argc == 1) ) return Help(argc, argv);
if ( argc == 1 ) return Help(argc, argv);

// 'bamtools help', 'bamtools --help', or 'bamtools -h'
if ( IsHelp(argv[1]) ) return Help(argc, argv);
Expand Down