X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FBamIndexFactory_p.cpp;h=2cf871f9df8ec07650136e4178b7cf3f113b9114;hb=9f1ce8c47aeadb6dc1320b52ee671c3341b97935;hp=69b372bb02a770cbaa3d6c1449c1a73d23ffc1e8;hpb=a15dba1bdfe5a1a61e175cb18b1e2694cfcd1746;p=bamtools.git diff --git a/src/api/internal/BamIndexFactory_p.cpp b/src/api/internal/BamIndexFactory_p.cpp index 69b372b..2cf871f 100644 --- a/src/api/internal/BamIndexFactory_p.cpp +++ b/src/api/internal/BamIndexFactory_p.cpp @@ -1,21 +1,18 @@ // *************************************************************************** // BamIndexFactory_p.cpp (c) 2011 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 5 April 2011 (DB) +// Last modified: 10 October 2011 (DB) // --------------------------------------------------------------------------- // Provides interface for generating BamIndex implementations // *************************************************************************** -#include -#include -#include -#include +#include "api/BamAux.h" +#include "api/internal/BamIndexFactory_p.h" +#include "api/internal/BamStandardIndex_p.h" +#include "api/internal/BamToolsIndex_p.h" using namespace BamTools; using namespace BamTools::Internal; - -#include using namespace std; // generates index filename from BAM filename (depending on requested type) @@ -27,7 +24,6 @@ const string BamIndexFactory::CreateIndexFilename(const string& bamFilename, case ( BamIndex::STANDARD ) : return ( bamFilename + BamStandardIndex::Extension() ); case ( BamIndex::BAMTOOLS ) : return ( bamFilename + BamToolsIndex::Extension() ); default : - cerr << "BamIndexFactory ERROR: unknown index type" << type << endl; return string(); } } @@ -60,7 +56,6 @@ BamIndex* BamIndexFactory::CreateIndexOfType(const BamIndex::IndexType& type, case ( BamIndex::STANDARD ) : return new BamStandardIndex(reader); case ( BamIndex::BAMTOOLS ) : return new BamToolsIndex(reader); default : - cerr << "BamIndexFactory ERROR: unknown index type " << type << endl; return 0; } } @@ -73,7 +68,7 @@ const string BamIndexFactory::FileExtension(const string& filename) { return string(); // look for last dot in filename - size_t lastDotPosition = filename.find_last_of('.'); + const size_t lastDotPosition = filename.find_last_of('.'); // if none found, return empty string if ( lastDotPosition == string::npos ) @@ -89,6 +84,10 @@ const string BamIndexFactory::FileExtension(const string& filename) { const string BamIndexFactory::FindIndexFilename(const string& bamFilename, const BamIndex::IndexType& preferredType) { + // skip if BAM filename provided is empty + if ( bamFilename.empty() ) + return string(); + // try to find index of preferred type first // return index filename if found string indexFilename = CreateIndexFilename(bamFilename, preferredType);