Skip to content

Commit

Permalink
Checks for forcing sorting and indexing of bam files.
Browse files Browse the repository at this point in the history
  • Loading branch information
maplesond committed Apr 30, 2014
1 parent 434e2fd commit 1ff8b45
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/portculis.cc
Expand Up @@ -59,6 +59,7 @@ int main(int argc, char *argv[]) {
string genomeFile;
string outputPrefix;
bool collectiveMode;
bool forcePrep;
uint16_t threads;
bool disableThreadedIO;
uint32_t gap_size;
Expand All @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) {
generic_options.add_options()
("output_prefix,o", po::value<string>(&outputPrefix)->default_value(DEFAULT_OUTPUT_PREFIX), "Path prefix for files generated by this program.")
("collective,c", po::value<bool>(&collectiveMode)->default_value(false), "Whether to treat all provided bam files as one large merged bam file or to handle each separately.")

("force_prep,fp", po::value<bool>(&forcePrep)->default_value(false), "Whether to force preparation (sorting and indexing) of the input bam files. By default, portculis only sorts bam files if the header does not contain a sorted (coordinate) flag. Also, it only indexes if it cannot find a bam file with a bamtools bti extension suffix.")
("threads,t", po::value<uint16_t>(&threads)->default_value(DEFAULT_THREADS), "The number of threads to use.")
("disable_threaded_io", po::value<bool>(&disableThreadedIO)->default_value(false), "Whether to acquire data in parallel to processing.")
("gap,g", po::value<uint32_t>(&gap_size)->default_value(DEFAULT_GAP_SIZE), "The minimum gap size between adjacent alignments that determines whether or not we can chunk the data at this point.")
Expand Down Expand Up @@ -173,6 +174,7 @@ int main(int argc, char *argv[]) {

// In collective mode make sure all bam files are merged and then sorted
// and indexed. Create a vector of the index files.
// TODO: Might be possible to replace these with BamReaders instead!
vector<string> indexFiles;
vector<string> modBamFiles;
if (collectiveMode) {
Expand All @@ -194,16 +196,18 @@ int main(int argc, char *argv[]) {
string bamFileToIndex = bamFile;

// Sort the BAM file if necessary
if (!portculis::isSortedBam(bamFile)) {
if (!portculis::isSortedBam(bamFile) || forcePrep) {
string sortedBam = bamFile + ".sorted.bam";
portculis::sortBam(bamFile, sortedBam, false);
bamFileToIndex = sortedBam;
}

string indexedBam = bamFile + ".sorted.bam.bti";

// Index the BAM file.
portculis::indexBam(bamFileToIndex, indexedBam);
// Index the BAM file if necessary.
if (!boost::filesystem::exists(indexedBam) || forcePrep) {
portculis::indexBam(bamFileToIndex, indexedBam);
}
indexFiles.push_back(indexedBam);
modBamFiles.push_back(bamFileToIndex);
}
Expand Down

0 comments on commit 1ff8b45

Please sign in to comment.