From 9fc914ad4f637d1a4368a7f0fd7c591cc2843869 Mon Sep 17 00:00:00 2001 From: Aaron <aaronquinlan@gmail.com> Date: Fri, 24 Jun 2011 11:57:11 -0400 Subject: [PATCH] User can define their own tag type for tagBam. --- src/tagBam/tagBam.cpp | 6 ++++-- src/tagBam/tagBam.h | 4 +++- src/tagBam/tagBamMain.cpp | 24 ++++++++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/tagBam/tagBam.cpp b/src/tagBam/tagBam.cpp index 8ad1ded4..56174357 100644 --- a/src/tagBam/tagBam.cpp +++ b/src/tagBam/tagBam.cpp @@ -14,11 +14,13 @@ // build TagBam::TagBam(const string &bamFile, const vector<string> &annoFileNames, - const vector<string> &annoLables, bool forceStrand, float overlapFraction) : + const vector<string> &annoLables, const string &tag, + bool forceStrand, float overlapFraction) : _bamFile(bamFile), _annoFileNames(annoFileNames), _annoLabels(annoLables), + _tag(tag), _forceStrand(forceStrand), _overlapFraction(overlapFraction) {} @@ -97,7 +99,7 @@ void TagBam::Tag() { } // were there any overlaps with which to make a tag? if (annotations.str().size() > 0) { - al.AddTag("YB", "Z", annotations.str().substr(0, annotations.str().size() - 1)); // get rid of the last ";" + al.AddTag(_tag, "Z", annotations.str().substr(0, annotations.str().size() - 1)); // get rid of the last ";" } writer.SaveAlignment(al); } diff --git a/src/tagBam/tagBam.h b/src/tagBam/tagBam.h index 10295ea0..821d0044 100644 --- a/src/tagBam/tagBam.h +++ b/src/tagBam/tagBam.h @@ -40,7 +40,8 @@ public: // constructor TagBam(const string &bamFile, const vector<string> &annoFileNames, - const vector<string> &annoLabels, bool forceStrand, float overlapFraction); + const vector<string> &annoLabels, const string &tag, + bool forceStrand, float overlapFraction); // destructor ~TagBam(void); @@ -54,6 +55,7 @@ private: string _bamFile; vector<string> _annoFileNames; vector<string> _annoLabels; + string _tag; // instance of a bed file class. BedFile *_bed; diff --git a/src/tagBam/tagBamMain.cpp b/src/tagBam/tagBamMain.cpp index 5eaddfea..9bd0cebb 100644 --- a/src/tagBam/tagBamMain.cpp +++ b/src/tagBam/tagBamMain.cpp @@ -31,9 +31,11 @@ int main(int argc, char* argv[]) { // input file string bamFile; float overlapFraction = 1E-9; + string tag = "YB"; // parm flags - bool haveFraction = false; + bool haveTag = false; + bool haveFraction = false; bool forceStrand = false; bool haveBam = false; bool haveFiles = false; @@ -83,7 +85,7 @@ int main(int argc, char* argv[]) { i--; } } - else if(PARAMETER_CHECK("-tags", 5, parameterLength)) { + else if(PARAMETER_CHECK("-labels", 7, parameterLength)) { if ((i+1) < argc) { haveLabels = true; i = i+1; @@ -107,6 +109,13 @@ int main(int argc, char* argv[]) { i++; } } + else if(PARAMETER_CHECK("-tag", 4, parameterLength)) { + if ((i+1) < argc) { + haveTag = true; + tag = argv[i + 1]; + i++; + } + } else { cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; showHelp = true; @@ -118,9 +127,13 @@ int main(int argc, char* argv[]) { cerr << endl << "*****" << endl << "*****ERROR: Need -i, -files, and -labels. " << endl << "*****" << endl; showHelp = true; } + if (haveTag && tag.size() > 2) { + cerr << endl << "*****" << endl << "*****ERROR: Custom tags should be at most two characters per the SAM specification. " << endl << "*****" << endl; + showHelp = true; + } if (!showHelp) { - TagBam *ba = new TagBam(bamFile, inputFiles, inputLabels, forceStrand, overlapFraction); + TagBam *ba = new TagBam(bamFile, inputFiles, inputLabels, tag, forceStrand, overlapFraction); ba->Tag(); delete ba; return 0; @@ -139,7 +152,7 @@ void ShowHelp(void) { cerr << "Summary: Annotates a BAM file based on overlaps with multiple BED/GFF/VCF files" << endl; cerr << "\t on the intervals in -i." << endl << endl; - cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -i <BAM> -files FILE1 FILE2 .. FILEn -tags LAB1 LAB2 ,,, LABn" << endl << endl; + cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -i <BAM> -files FILE1 FILE2 .. FILEn -labels LAB1 LAB2 ,,, LABn" << endl << endl; cerr << "Options: " << endl; @@ -149,6 +162,9 @@ void ShowHelp(void) { cerr << "\t-f\t" << "Minimum overlap required as a fraction of the alignment." << endl; cerr << "\t\t- Default is 1E-9 (i.e., 1bp)." << endl; cerr << "\t\t- FLOAT (e.g. 0.50)" << endl << endl; + + cerr << "\t-tag\t" << "Dictate what the tag should be. Default is YB." << endl; + cerr << "\t\t- STRING (two characters, e.g., YK)" << endl << endl; exit(1); } -- GitLab