Skip to content

Commit 06138db

Browse files
committed
Added new argument -G to count gaps towards depth for variants.
1 parent 94a9f24 commit 06138db

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/call_variants.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ double *get_frequency_depth(
3232
int call_variants_from_plup(std::istream &cin, std::string out_file,
3333
uint8_t min_qual, double min_threshold,
3434
uint32_t min_depth, std::string ref_path,
35-
std::string gff_path) {
35+
std::string gff_path, bool gapped_depth) {
3636
std::string line, cell, bases, qualities, region;
3737
ref_antd refantd(ref_path, gff_path);
3838
std::ostringstream out_str;
@@ -108,7 +108,13 @@ int call_variants_from_plup(std::istream &cin, std::string out_file,
108108
// Get ungapped depth
109109
pdepth = 0;
110110
for (std::vector<allele>::iterator it = ad.begin(); it != ad.end(); ++it) {
111-
if (it->nuc[0] == '*' || it->nuc[0] == '+' || it->nuc[0] == '-') continue;
111+
// if ((gapped_depth && (it->nuc[0] == '+' || it->nuc[0] == '-')) || (!gapped_depth && (it->nuc[0] == '+' || it->nuc[0] == '*' || it->nuc[0] == '-'))) continue;
112+
// Split into two if statements for readability.
113+
if (gapped_depth) {
114+
if (it->nuc[0] == '+' || it->nuc[0] == '-') continue; // Count gaps ('*') towards depth
115+
} else {
116+
if (it->nuc[0] == '+' || it->nuc[0] == '*' || it->nuc[0] == '-') continue;
117+
}
112118
pdepth += it->depth;
113119
}
114120
if (pdepth < min_depth) { // Check for minimum depth

src/call_variants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
int call_variants_from_plup(std::istream &cin, std::string out_file,
2020
uint8_t min_qual, double min_threshold,
2121
uint32_t min_depth, std::string ref_path,
22-
std::string gff_path);
22+
std::string gff_path, bool gapped_depth);
2323
std::vector<allele>::iterator get_ref_allele(std::vector<allele> &ad, char ref);
2424

2525
#endif

src/ivar.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct args_t {
4444
bool write_no_primers_flag; // -e
4545
std::string gff; // -g
4646
bool keep_for_reanalysis; // -k
47+
bool gapped_depth; // -G
4748
} g_args;
4849

4950
void print_usage() {
@@ -110,6 +111,7 @@ void print_variants_usage() {
110111
" -t Minimum frequency threshold(0 - 1) to call variants "
111112
"(Default: 0.03)\n"
112113
" -m Minimum read depth to call variants (Default: 0)\n"
114+
" -G Count gaps towards depth. By default, gaps are not counted\n"
113115
" -r Reference file used for alignment. This is used to "
114116
"translate the nucleotide sequences and identify intra host single "
115117
"nucleotide variants\n"
@@ -241,7 +243,7 @@ void print_version_info() {
241243
}
242244

243245
static const char *trim_opt_str = "i:b:f:x:p:m:q:s:ekh?";
244-
static const char *variants_opt_str = "p:t:q:m:r:g:h?";
246+
static const char *variants_opt_str = "p:t:q:m:r:g:Gh?";
245247
static const char *consensus_opt_str = "i:p:q:t:c:m:n:kh?";
246248
static const char *removereads_opt_str = "i:p:t:b:h?";
247249
static const char *filtervariants_opt_str = "p:t:f:h?";
@@ -361,6 +363,7 @@ int main(int argc, char *argv[]) {
361363
g_args.min_depth = 0;
362364
g_args.ref = "";
363365
g_args.gff = "";
366+
g_args.gapped_depth = false;
364367
opt = getopt(argc, argv, variants_opt_str);
365368
while (opt != -1) {
366369
switch (opt) {
@@ -382,6 +385,9 @@ int main(int argc, char *argv[]) {
382385
case 'g':
383386
g_args.gff = optarg;
384387
break;
388+
case 'G':
389+
g_args.gapped_depth = true;
390+
break;
385391
case 'h':
386392
case '?':
387393
print_variants_usage();
@@ -422,7 +428,7 @@ int main(int argc, char *argv[]) {
422428
}
423429
res = call_variants_from_plup(std::cin, g_args.prefix, g_args.min_qual,
424430
g_args.min_threshold, g_args.min_depth,
425-
g_args.ref, g_args.gff);
431+
g_args.ref, g_args.gff, g_args.gapped_depth);
426432
}
427433
// ivar consensus
428434
else if (cmd.compare("consensus") == 0) {

tests/test_variants.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int call_var_check_outfile(std::string prefix, uint8_t min_qual,
1111
std::string path = "../data/test.indel.mpileup";
1212
std::ifstream mplp(path);
1313
call_variants_from_plup(mplp, prefix, min_qual, min_threshold, min_depth,
14-
"../data/db/test_ref.fa", "../data/test.gff");
14+
"../data/db/test_ref.fa", "../data/test.gff", false);
1515
std::ifstream outFile(prefix + ".tsv");
1616
std::string l;
1717
getline(outFile, l); // Ignore first line

tests/test_variants_reverse_strand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int call_var_check_outfile(std::string prefix, uint8_t min_qual,
1111
std::string path = "../data/test.strand.pileup";
1212
std::ifstream mplp(path);
1313
call_variants_from_plup(mplp, prefix, min_qual, min_threshold, min_depth,
14-
"../data/db/test_ref.fa", "../data/test_strand.gff");
14+
"../data/db/test_ref.fa", "../data/test_strand.gff", false);
1515
std::ifstream outFile(prefix + ".tsv");
1616
std::string l;
1717
getline(outFile, l); // Ignore first line

0 commit comments

Comments
 (0)