From 213bfb8279d7c403b9bd3dfcf12b7f010c83acd9 Mon Sep 17 00:00:00 2001 From: Rone Charles Date: Wed, 24 Apr 2024 10:58:41 -0400 Subject: [PATCH] Add support for toggling SAM Opt flags from the command line --- bt2_search.cpp | 18 ++++++++++ opts.h | 1 + sam.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/bt2_search.cpp b/bt2_search.cpp index 97f9d42d..d453d259 100644 --- a/bt2_search.cpp +++ b/bt2_search.cpp @@ -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 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; @@ -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 }; @@ -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': { @@ -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 diff --git a/opts.h b/opts.h index 6a7edeae..6f06ec74 100644 --- a/opts.h +++ b/opts.h @@ -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 diff --git a/sam.h b/sam.h index 7745909e..06d46582 100644 --- a/sam.h +++ b/sam.h @@ -22,6 +22,8 @@ #include #include +#include + #include "ds.h" #include "read.h" #include "util.h" @@ -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. \*|[!-()+-<>-~][!-~]*