diff --git a/src/portculis.cc b/src/portculis.cc index 57c9b96c..8388baa1 100644 --- a/src/portculis.cc +++ b/src/portculis.cc @@ -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; @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) { generic_options.add_options() ("output_prefix,o", po::value(&outputPrefix)->default_value(DEFAULT_OUTPUT_PREFIX), "Path prefix for files generated by this program.") ("collective,c", po::value(&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(&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(&threads)->default_value(DEFAULT_THREADS), "The number of threads to use.") ("disable_threaded_io", po::value(&disableThreadedIO)->default_value(false), "Whether to acquire data in parallel to processing.") ("gap,g", po::value(&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.") @@ -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 indexFiles; vector modBamFiles; if (collectiveMode) { @@ -194,7 +196,7 @@ 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; @@ -202,8 +204,10 @@ int main(int argc, char *argv[]) { 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); }