diff --git a/src/tagBam/tagBam.cpp b/src/tagBam/tagBam.cpp index d06cf9ede54d65c92918a9f9d1f9e0a9eb5389a9..36a2c4d11e582efff9fa067d8aaae872fbd2503d 100644 --- a/src/tagBam/tagBam.cpp +++ b/src/tagBam/tagBam.cpp @@ -15,13 +15,14 @@ // build TagBam::TagBam(const string &bamFile, const vector<string> &annoFileNames, const vector<string> &annoLables, const string &tag, - bool useNames, bool sameStrand, bool diffStrand, float overlapFraction): + bool useNames, bool useScores, bool sameStrand, bool diffStrand, float overlapFraction): _bamFile(bamFile), _annoFileNames(annoFileNames), _annoLabels(annoLables), _tag(tag), _useNames(useNames), + _useScores(useScores), _sameStrand(sameStrand), _diffStrand(diffStrand), _overlapFraction(overlapFraction) @@ -92,15 +93,25 @@ void TagBam::Tag() { // grab the current annotation file. BedFile *anno = _annoFiles[i]; - if (!_useNames) { + if (!_useNames && !_useScores) { // add the label for this annotation file to tag if there is overlap if (anno->FindOneOrMoreOverlapsPerBin(a.chrom, a.start, a.end, a.strand, _sameStrand, _diffStrand, _overlapFraction)) { annotations << _annoLabels[i] << ";"; } } + // use the score field + else if (!_useNames && _useScores) { + anno->FindOverlapsPerBin(a.chrom, a.start, a.end, a.strand, hits, _sameStrand, _diffStrand); + for (size_t i = 0; i < hits.size(); ++i) { + annotations << hits[i].score; + if (i < hits.size() - 1) annotations << ","; + } + if (hits.size() > 0) annotations << ";"; + hits.clear(); + } // use the name field from the annotation files to populate tag - else { + else if (_useNames && !_useScores) { anno->FindOverlapsPerBin(a.chrom, a.start, a.end, a.strand, hits, _sameStrand, _diffStrand); for (size_t i = 0; i < hits.size(); ++i) { annotations << hits[i].name; diff --git a/src/tagBam/tagBam.h b/src/tagBam/tagBam.h index 10ade9ad574d03f0f2ac2d9d239766897226af29..689dd0ac31a5acd44fff8e206f78e13bdeabff19 100644 --- a/src/tagBam/tagBam.h +++ b/src/tagBam/tagBam.h @@ -40,8 +40,9 @@ public: // constructor TagBam(const string &bamFile, const vector<string> &annoFileNames, - const vector<string> &annoLabels, const string &tag, - bool useNames, bool sameStrand, bool diffStrand, float overlapFraction); + const vector<string> &annoLabels, const string &tag, + bool useNames, bool useScores, bool sameStrand, + bool diffStrand, float overlapFraction); // destructor ~TagBam(void); @@ -55,6 +56,7 @@ private: string _bamFile; vector<string> _annoFileNames; vector<string> _annoLabels; + string _tag; // instance of a bed file class. @@ -63,6 +65,7 @@ private: // should we use the name field from the annotation files? bool _useNames; + bool _useScores; // do we care about strandedness when tagging? bool _sameStrand; diff --git a/src/tagBam/tagBamMain.cpp b/src/tagBam/tagBamMain.cpp index acd9c70ee8e77b76de1e870cc75603c235184b67..6bef5734e67486469b558cd6849e4f2a993be7ec 100644 --- a/src/tagBam/tagBamMain.cpp +++ b/src/tagBam/tagBamMain.cpp @@ -34,14 +34,16 @@ int main(int argc, char* argv[]) { string tag = "YB"; // parm flags - bool haveTag = false; - bool haveFraction = false; - bool useNames = false; - bool sameStrand = false; - bool diffStrand = false; - bool haveBam = false; - bool haveFiles = false; - bool haveLabels = false; + bool haveTag = false; + bool haveFraction = false; + bool useNames = false; + bool useScores = false; + bool sameStrand = false; + bool diffStrand = false; + bool haveBam = false; + bool haveFiles = false; + bool haveLabels = false; + // list of annotation files / names vector<string> inputFiles; @@ -104,6 +106,9 @@ int main(int argc, char* argv[]) { else if (PARAMETER_CHECK("-names", 6, parameterLength)) { useNames = true; } + else if (PARAMETER_CHECK("-scores", 7, parameterLength)) { + useScores = true; + } else if (PARAMETER_CHECK("-s", 2, parameterLength)) { sameStrand = true; } @@ -135,8 +140,8 @@ int main(int argc, char* argv[]) { cerr << endl << "*****" << endl << "*****ERROR: Need -i, -files" << endl << "*****" << endl; showHelp = true; } - if (!useNames && !haveLabels) { - cerr << endl << "*****" << endl << "*****ERROR: Need -labels or -names" << endl << "*****" << endl; + if (!useNames && !haveLabels && !useScores) { + cerr << endl << "*****" << endl << "*****ERROR: Need -labels or -names or -scores" << endl << "*****" << endl; showHelp = true; } if (sameStrand && diffStrand) { @@ -147,13 +152,17 @@ int main(int argc, char* argv[]) { cerr << endl << "*****" << endl << "*****ERROR: Use -labels or -names, not both. " << endl << "*****" << endl; showHelp = true; } + if (useScores && useNames) { + cerr << endl << "*****" << endl << "*****ERROR: Use -scores or -names, not both. " << 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, tag, useNames, sameStrand, diffStrand, overlapFraction); + TagBam *ba = new TagBam(bamFile, inputFiles, inputLabels, tag, useNames, useScores, sameStrand, diffStrand, overlapFraction); ba->Tag(); delete ba; return 0; @@ -191,6 +200,9 @@ void ShowHelp(void) { cerr << "\t-names\t" << "Use the name field from the annotation files to populate tags." << endl; cerr << "\t\tBy default, the -labels values are used." << endl << endl; + + cerr << "\t-scores\t" << "A list of 1-based columns for each annotation file" << endl; + cerr << "\t\tin which a color can be found." << endl << endl; exit(1);