Skip to content
Snippets Groups Projects
Commit 0cca2731 authored by Aaron's avatar Aaron
Browse files

Added -scores option to tagBam

parent 47771289
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment