Skip to content

Commit

Permalink
Add support for toggling SAM Opt flags from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4rr0 committed Apr 24, 2024
1 parent f2ad9c8 commit 213bfb8
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bt2_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static bool sam_print_zi;
static bool sam_print_zp;
static bool sam_print_zu;
static bool sam_print_zt;
static EList<string> sam_opt_flags;
static bool preserve_tags; // Only applies when aligning BAM files
static bool align_paired_reads; // Process only the paired reads in BAM file
static bool bwaSwLike;
Expand Down Expand Up @@ -670,6 +671,7 @@ static struct option long_options[] = {
{(char*)"sra-acc", required_argument, 0, ARG_SRA_ACC},
#endif
{(char*)"sam-append-comment", no_argument, 0, ARG_SAM_APPEND_COMMENT},
{(char*)"sam-opt-config", required_argument, 0, ARG_SAM_OPT_CONFIG},
{(char*)0, 0, 0, 0} // terminator
};

Expand Down Expand Up @@ -1555,6 +1557,16 @@ static void parseOption(int next_option, const char *arg) {
}
break;
}
case ARG_SAM_OPT_CONFIG: {
// string no_defaults("-as,-xs,-xn,-x0,-x1,-xm,-xo,-xg,-nm,-md,-yf,-yt,-ys");
// string defaults("as,xs,xn,x0,x1,xm,xo,xg,nm,md,yf,yt,ys");

// if (strncmp(arg, "-default", 8) == 0) {
// no_defaults += arg;
// }
tokenize(arg, ",", sam_opt_flags);
break;
}
case ARG_DESC: printArgDesc(cout); throw 0;
case 'S': outfile = arg; break;
case 'U': {
Expand Down Expand Up @@ -4990,6 +5002,12 @@ static void driver(
sam_print_zp,
sam_print_zu,
sam_print_zt);

if (sam_opt_flags.size() > 0) {
for (size_t i = 0; i < sam_opt_flags.size(); i++) {
samc.toggleOptFlagByName(sam_opt_flags[i]);
}
}
// Set up hit sink; if sanityCheck && !os.empty() is true,
// then instruct the sink to "retain" hits in a vector in
// memory so that we can easily sanity check them later on
Expand Down
1 change: 1 addition & 0 deletions opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ enum {
ARG_ALIGN_PAIRED_READS, // --align-paired-reads
ARG_SRA_ACC, // --sra-acc
ARG_SAM_APPEND_COMMENT, // --sam-append-comment
ARG_SAM_OPT_CONFIG, // --sam-opt-config
};

#endif
93 changes: 93 additions & 0 deletions sam.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <string>
#include <vector>
#include <string.h>

#include "ds.h"
#include "read.h"
#include "util.h"
Expand Down Expand Up @@ -157,6 +159,97 @@ class SamConfig {
assert_eq(refnames_.size(), reflens_.size());
}

void toggleOptFlagByName(string& str) {
bool value = false;
const char *name = str.c_str();

if (str.size() < 2) {
cerr << "Error: " << name << " is not a valid SAM Optional flag." << endl;
return;
}

if (name[0] == '-') {
name += 1;
} else {
value = true;
}

if (strcasecmp(name, "as") == 0) {
print_yn_ = value;
} else if(strcasecmp(name, "xs") == 0) {
print_xs_ = value;
} else if(strcasecmp(name, "xss") == 0) {
print_xss_ = value;
} else if(strcasecmp(name, "yn") == 0) {
print_yn_ = value;
} else if(strcasecmp(name, "xn") == 0) {
print_xn_ = value;
} else if(strcasecmp(name, "x0") == 0) {
print_x0_ = value;
} else if(strcasecmp(name, "x1") == 0) {
print_x1_ = value;
} else if(strcasecmp(name, "xm") == 0) {
print_xm_ = value;
} else if(strcasecmp(name, "xo") == 0) {
print_xo_ = value;
} else if(strcasecmp(name, "xg") == 0) {
print_xg_ = value;
} else if(strcasecmp(name, "nm") == 0) {
print_nm_ = value;
} else if(strcasecmp(name, "md") == 0) {
print_md_ = value;
} else if(strcasecmp(name, "yf") == 0) {
print_yf_ = value;
} else if(strcasecmp(name, "yi") == 0) {
print_yi_ = value;
} else if(strcasecmp(name, "ym") == 0) {
print_ym_ = value;
} else if(strcasecmp(name, "yp") == 0) {
print_yp_ = value;
} else if(strcasecmp(name, "yt") == 0) {
print_yt_ = value;
} else if(strcasecmp(name, "ys") == 0) {
print_ys_ = value;
} else if(strcasecmp(name, "zs") == 0) {
print_zs_ = value;
} else if(strcasecmp(name, "xr") == 0) {
print_xr_ = value;
} else if(strcasecmp(name, "xt") == 0) {
print_xt_ = value;
} else if(strcasecmp(name, "xd") == 0) {
print_xd_ = value;
} else if(strcasecmp(name, "xu") == 0) {
print_xu_ = value;
} else if(strcasecmp(name, "ye") == 0) {
print_ye_ = value;
} else if(strcasecmp(name, "yl") == 0) {
print_yl_ = value;
} else if(strcasecmp(name, "yu") == 0) {
print_yu_ = value;
} else if(strcasecmp(name, "xp") == 0) {
print_xp_ = value;
} else if(strcasecmp(name, "yr") == 0) {
print_yr_ = value;
} else if(strcasecmp(name, "zb") == 0) {
print_zb_ = value;
} else if(strcasecmp(name, "zr") == 0) {
print_zr_ = value;
} else if(strcasecmp(name, "zf") == 0) {
print_zf_ = value;
} else if(strcasecmp(name, "zm") == 0) {
print_zm_ = value;
} else if(strcasecmp(name, "zi") == 0) {
print_zi_ = value;
} else if(strcasecmp(name, "zp") == 0) {
print_zp_ = value;
} else if(strcasecmp(name, "zu") == 0) {
print_zu_ = value;
} else if(strcasecmp(name, "zt") == 0) {
print_zt_ = value;
} else {
cerr << "Error: " << name << " is not a valid SAM Optional flag." << endl;
}
}
/**
* Print a reference name in a way that doesn't violate SAM's character
* constraints. \*|[!-()+-<>-~][!-~]*
Expand Down

0 comments on commit 213bfb8

Please sign in to comment.