Skip to content

Commit

Permalink
version 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
amcpherson committed Mar 24, 2014
1 parent ea69e6d commit 2bd318e
Show file tree
Hide file tree
Showing 111 changed files with 4,992 additions and 1,226 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BamAlignment.cpp (c) 2009 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 17 October 2011 (DB)
// Last modified: 4 April 2012 (DB)
// ---------------------------------------------------------------------------
// Provides the BamAlignment data structure
// ***************************************************************************
Expand All @@ -25,12 +25,22 @@ using namespace std;
*/
/*! \var BamAlignment::QueryBases
\brief 'original' sequence (as reported from sequencing machine)
\note Setting this field to "*" indicates that the sequence is not to be stored on output.
In this case, the contents of the Qualities field should be invalidated as well (cleared or marked as "*").
*/
/*! \var BamAlignment::AlignedBases
\brief 'aligned' sequence (includes any indels, padding, clipping)
This field will be completely empty after reading from BamReader/BamMultiReader when
QueryBases is empty.
*/
/*! \var BamAlignment::Qualities
\brief FASTQ qualities (ASCII characters, not numeric values)
\note Setting this field to "*" indicates to BamWriter that the quality scores are not to be stored,
but instead will be output as a sequence of '0xFF'. Otherwise, QueryBases must not be a "*" and
the length of this field should equal the length of QueryBases.
*/
/*! \var BamAlignment::TagData
\brief tag data (use the provided methods to query/modify)
Expand Down Expand Up @@ -70,8 +80,12 @@ using namespace std;
\brief constructor
*/
BamAlignment::BamAlignment(void)
: RefID(-1)
: Length(0)
, RefID(-1)
, Position(-1)
, Bin(0)
, MapQuality(0)
, AlignmentFlag(0)
, MateRefID(-1)
, MatePosition(-1)
, InsertSize(0)
Expand Down Expand Up @@ -134,36 +148,39 @@ bool BamAlignment::BuildCharData(void) {
const unsigned int tagDataLength = dataLength - tagDataOffset;

// check offsets to see what char data exists
const bool hasSeqData = ( seqDataOffset < dataLength );
const bool hasQualData = ( qualDataOffset < dataLength );
const bool hasSeqData = ( seqDataOffset < qualDataOffset );
const bool hasQualData = ( qualDataOffset < tagDataOffset );
const bool hasTagData = ( tagDataOffset < dataLength );

// set up char buffers
const char* allCharData = SupportData.AllCharData.data();
const char* seqData = ( hasSeqData ? (((const char*)allCharData) + seqDataOffset) : (const char*)0 );
const char* qualData = ( hasQualData ? (((const char*)allCharData) + qualDataOffset) : (const char*)0 );
char* tagData = ( hasTagData ? (((char*)allCharData) + tagDataOffset) : (char*)0 );

// store alignment name (relies on null char in name as terminator)
Name.assign((const char*)(allCharData));
Name.assign(SupportData.AllCharData.data());

// save query sequence
QueryBases.clear();
if ( hasSeqData ) {
const char* seqData = SupportData.AllCharData.data() + seqDataOffset;
QueryBases.reserve(SupportData.QuerySequenceLength);
for ( size_t i = 0; i < SupportData.QuerySequenceLength; ++i ) {
const char singleBase = Constants::BAM_DNA_LOOKUP[ ( (seqData[(i/2)] >> (4*(1-(i%2)))) & 0xf ) ];
QueryBases.append(1, singleBase);
}
}

// save qualities, converting from numeric QV to 'FASTQ-style' ASCII character
// save qualities

Qualities.clear();
if ( hasQualData ) {
Qualities.reserve(SupportData.QuerySequenceLength);
for ( size_t i = 0; i < SupportData.QuerySequenceLength; ++i ) {
const char singleQuality = static_cast<const char>(qualData[i]+33);
Qualities.append(1, singleQuality);
const char* qualData = SupportData.AllCharData.data() + qualDataOffset;

// if marked as unstored (sequence of 0xFF) - don't do conversion, just fill with 0xFFs
if ( qualData[0] == (char)0xFF )
Qualities.resize(SupportData.QuerySequenceLength, (char)0xFF);

// otherwise convert from numeric QV to 'FASTQ-style' ASCII character
else {
Qualities.reserve(SupportData.QuerySequenceLength);
for ( size_t i = 0; i < SupportData.QuerySequenceLength; ++i )
Qualities.append(1, qualData[i]+33);
}
}

Expand All @@ -172,7 +189,7 @@ bool BamAlignment::BuildCharData(void) {

// if QueryBases has data, build AlignedBases using CIGAR data
// otherwise, AlignedBases will remain empty (this case IS allowed)
if ( !QueryBases.empty() ) {
if ( !QueryBases.empty() && QueryBases != "*" ) {

// resize AlignedBases
AlignedBases.reserve(SupportData.QuerySequenceLength);
Expand Down Expand Up @@ -231,6 +248,9 @@ bool BamAlignment::BuildCharData(void) {
// save tag data
TagData.clear();
if ( hasTagData ) {

char* tagData = (((char*)SupportData.AllCharData.data()) + tagDataOffset);

if ( IsBigEndian ) {
size_t i = 0;
while ( i < tagDataLength ) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BamAux.h (c) 2009 Derek Barnett, Michael Str�mberg
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 25 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides data structures & utility methods that are used throughout the API.
// ***************************************************************************
Expand All @@ -11,6 +11,7 @@
#define BAMAUX_H

#include "api/api_global.h"
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -441,13 +442,25 @@ API_EXPORT inline unsigned short UnpackUnsignedShort(char* buffer) {
\internal
*/
struct RaiiBuffer {

// data members
char* Buffer;
const size_t NumBytes;

// ctor & dtor
RaiiBuffer(const size_t n)
: Buffer( new char[n]() )
, NumBytes(n)
{ }

~RaiiBuffer(void) {
delete[] Buffer;
}
char* Buffer;

// add'l methods
void Clear(void) {
memset(Buffer, 0, NumBytes);
}
};

} // namespace BamTools
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class API_EXPORT BamIndex {
// loads existing data from file into memory
virtual bool Load(const std::string& filename) =0;

// returns the 'type' enum for derived index format
virtual BamIndex::IndexType Type(void) const =0;

//! \cond

// internal methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BamMultiReader.cpp (c) 2010 Erik Garrison, Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 25 October 2011 (DB)
// ---------------------------------------------------------------------------
// Convenience class for reading multiple BAM files.
//
Expand All @@ -13,7 +13,7 @@
// ***************************************************************************

#include "api/BamMultiReader.h"
#include "api/internal/BamMultiReader_p.h"
#include "api/internal/bam/BamMultiReader_p.h"
using namespace BamTools;

#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 25 October 2011 (DB)
// ---------------------------------------------------------------------------
// Convenience class for reading multiple BAM files.
// ***************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// BamReader.cpp (c) 2009 Derek Barnett, Michael Str�mberg
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 25 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides read access to BAM files.
// ***************************************************************************

#include "api/BamReader.h"
#include "api/internal/BamReader_p.h"
#include "api/internal/bam/BamReader_p.h"
using namespace BamTools;
using namespace BamTools::Internal;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// BamWriter.cpp (c) 2009 Michael Str�mberg, Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 25 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides the basic functionality for producing BAM files
// ***************************************************************************

#include "api/BamAlignment.h"
#include "api/BamWriter.h"
#include "api/SamHeader.h"
#include "api/internal/BamWriter_p.h"
#include "api/internal/bam/BamWriter_p.h"
using namespace BamTools;
using namespace BamTools::Internal;
using namespace std;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ include_directories( ${BamTools_SOURCE_DIR}/src )
add_definitions( -DBAMTOOLS_API_LIBRARY ) # (for proper exporting of library symbols)
add_definitions( -fPIC ) # (attempt to force PIC compiling on CentOS, not being set on shared libs by CMake)

# list of all BamTools API source (.cpp) files
# fetch all internal source files
add_subdirectory ( internal )

# make list of all API source files
set( BamToolsAPISources
BamAlignment.cpp
BamMultiReader.cpp
Expand All @@ -25,41 +28,30 @@ set( BamToolsAPISources
SamReadGroupDictionary.cpp
SamSequence.cpp
SamSequenceDictionary.cpp
internal/BamDeviceFactory_p.cpp
internal/BamException_p.cpp
internal/BamFile_p.cpp
internal/BamFtp_p.cpp
internal/BamHeader_p.cpp
internal/BamHttp_p.cpp
internal/BamIndexFactory_p.cpp
internal/BamMultiReader_p.cpp
internal/BamPipe_p.cpp
internal/BamRandomAccessController_p.cpp
internal/BamReader_p.cpp
internal/BamStandardIndex_p.cpp
internal/BamToolsIndex_p.cpp
internal/BamWriter_p.cpp
internal/BgzfStream_p.cpp
internal/ILocalIODevice_p.cpp
internal/IRemoteIODevice_p.cpp
internal/SamFormatParser_p.cpp
internal/SamFormatPrinter_p.cpp
internal/SamHeaderValidator_p.cpp
${InternalSources}
)

# create main BamTools API shared library
add_library( BamTools SHARED ${BamToolsAPISources} )
set_target_properties( BamTools PROPERTIES SOVERSION "2.0.5" )
set_target_properties( BamTools PROPERTIES OUTPUT_NAME "bamtools" )
set_target_properties( BamTools PROPERTIES
SOVERSION "2.1.0"
OUTPUT_NAME "bamtools" )

# create main BamTools API static library
add_library( BamTools-static STATIC ${BamToolsAPISources} )
set_target_properties( BamTools-static PROPERTIES OUTPUT_NAME "bamtools" )
set_target_properties( BamTools-static PROPERTIES PREFIX "lib" )
set_target_properties( BamTools-static PROPERTIES
OUTPUT_NAME "bamtools"
PREFIX "lib" )

# link libraries automatically with zlib (and Winsock2, if applicable)
if( _WIN32 )
set( APILibs z ws2_32 )
else( _WIN32 )
set( APILibs z )
endif( _WIN32 )

# link libraries with zlib automatically
target_link_libraries( BamTools z )
target_link_libraries( BamTools-static z )
target_link_libraries( BamTools ${APILibs} )
target_link_libraries( BamTools-static ${APILibs} )

# set library install destinations
install( TARGETS BamTools LIBRARY DESTINATION "lib/bamtools" RUNTIME DESTINATION "bin")
Expand All @@ -69,7 +61,7 @@ install( TARGETS BamTools-static ARCHIVE DESTINATION "lib/bamtools")
include(../ExportHeader.cmake)
set(ApiIncludeDir "api")
ExportHeader(APIHeaders api_global.h ${ApiIncludeDir})
ExportHeader(APIHeaders BamAlgorithms.h ${ApiIncludeDir})
ExportHeader(APIHeaders BamAlgorithms.h ${ApiIncludeDir})
ExportHeader(APIHeaders BamAlignment.h ${ApiIncludeDir})
ExportHeader(APIHeaders BamAux.h ${ApiIncludeDir})
ExportHeader(APIHeaders BamConstants.h ${ApiIncludeDir})
Expand All @@ -87,5 +79,5 @@ ExportHeader(APIHeaders SamReadGroupDictionary.h ${ApiIncludeDir})
ExportHeader(APIHeaders SamSequence.h ${ApiIncludeDir})
ExportHeader(APIHeaders SamSequenceDictionary.h ${ApiIncludeDir})

set(AlgorithmsIncludeDir "api/algorithms")
ExportHeader(AlgorithmsHeaders algorithms/Sort.h ${AlgorithmsIncludeDir})
set( AlgorithmsIncludeDir "api/algorithms" )
ExportHeader( AlgorithmsHeaders algorithms/Sort.h ${AlgorithmsIncludeDir} )
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// IBamIODevice.h (c) 2011 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 10 November 2011 (DB)
// ---------------------------------------------------------------------------
// Base class for all BAM I/O devices (e.g. local file, pipe, HTTP, FTP, etc.)
//
Expand All @@ -19,16 +19,18 @@
#define IBAMIODEVICE_H

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

namespace BamTools {

class API_EXPORT IBamIODevice {

// enums
public: enum OpenMode { NotOpen = 0
, ReadOnly
, WriteOnly
public: enum OpenMode { NotOpen = 0x0000
, ReadOnly = 0x0001
, WriteOnly = 0x0002
, ReadWrite = ReadOnly | WriteOnly
};

// ctor & dtor
Expand All @@ -38,14 +40,16 @@ class API_EXPORT IBamIODevice {
// IBamIODevice interface
public:

// TODO: add seek(pos, *from*)

// pure virtuals
virtual void Close(void) =0;
virtual bool IsRandomAccess(void) const =0;
virtual bool Open(const OpenMode mode) =0;
virtual size_t Read(char* data, const unsigned int numBytes) =0;
virtual bool Seek(const int64_t& position) =0;
virtual int64_t Read(char* data, const unsigned int numBytes) =0;
virtual bool Seek(const int64_t& position, const int origin = SEEK_SET) =0;
virtual int64_t Tell(void) const =0;
virtual size_t Write(const char* data, const unsigned int numBytes) =0;
virtual int64_t Write(const char* data, const unsigned int numBytes) =0;

// default implementation provided
virtual std::string GetErrorString(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SamConstants.h (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 10 October 2011 (DB)
// Last modified: 27 March 2012 (DB)
// ---------------------------------------------------------------------------
// Provides constants for SAM header
// ***************************************************************************
Expand All @@ -24,6 +24,8 @@ const char SAM_STAR = '*';
const char SAM_TAB = '\t';
const std::string SAM_DIGITS = "0123456789";

const std::string SAM_CURRENT_VERSION = "1.4";

// HD entries
const std::string SAM_HD_BEGIN_TOKEN = "@HD";
const std::string SAM_HD_VERSION_TAG = "VN";
Expand Down
Loading

0 comments on commit 2bd318e

Please sign in to comment.