// BamIndexFactory_p.cpp (c) 2011 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 5 April 2011 (DB)
+// Last modified: 10 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides interface for generating BamIndex implementations
// ***************************************************************************
-#include <api/BamAux.h>
-#include <api/internal/BamIndexFactory_p.h>
-#include <api/internal/BamStandardIndex_p.h>
-#include <api/internal/BamToolsIndex_p.h>
+#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 <cstdio>
using namespace std;
// generates index filename from BAM filename (depending on requested type)
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();
}
}
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;
}
}
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 )
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);