@@ -43,7 +43,7 @@ int JunctionsExtractor::parse_options(int argc, char *argv[]) {
43
43
optind = 1 ; // Reset before parsing again.
44
44
int c;
45
45
stringstream help_ss;
46
- while ((c = getopt (argc, argv, " ha:m:M:o:r:t:s:b:" )) != -1 ) {
46
+ while ((c = getopt (argc, argv, " ha:m:M:f:F:q: o:r:t:s:b:" )) != -1 ) {
47
47
switch (c) {
48
48
case ' h' :
49
49
usage (help_ss);
@@ -57,6 +57,15 @@ int JunctionsExtractor::parse_options(int argc, char *argv[]) {
57
57
case ' M' :
58
58
max_intron_length_ = atoi (optarg );
59
59
break ;
60
+ case ' f' :
61
+ require_flags_ = atoi (optarg );
62
+ break ;
63
+ case ' F' :
64
+ filter_flags_ = atoi (optarg );
65
+ break ;
66
+ case ' q' :
67
+ min_map_qual_ = atoi (optarg );
68
+ break ;
60
69
case ' o' :
61
70
output_file_ = string (optarg );
62
71
break ;
@@ -108,10 +117,17 @@ int JunctionsExtractor::parse_options(int argc, char *argv[]) {
108
117
throw runtime_error (" Strandness mode 'intron-motif' requires a fasta file!\n\n " );
109
118
}
110
119
}
120
+ if ( (require_flags_ & filter_flags_) != 0 ) {
121
+ usage ();
122
+ throw runtime_error (" No overlap allowed between '-f' and '-F' options (same flag filtered and required)!\n\n " );
123
+ }
111
124
112
125
cerr << " Minimum junction anchor length: " << min_anchor_length_ << endl;
113
126
cerr << " Minimum intron length: " << min_intron_length_ << endl;
114
127
cerr << " Maximum intron length: " << max_intron_length_ << endl;
128
+ cerr << " Require alignment flags: " << require_flags_ << endl;
129
+ cerr << " Filter alignment flags: " << filter_flags_ << endl;
130
+ cerr << " Minimum alignment mapping quality: " << int (min_map_qual_) << endl;
115
131
cerr << " Alignment: " << bam_ << endl;
116
132
cerr << " Output file: " << output_file_ << endl;
117
133
if (output_barcodes_file_ != " NA" ){
@@ -130,6 +146,9 @@ int JunctionsExtractor::usage(ostream& out) {
130
146
<< " \t\t\t " << " anchor length on both sides are reported. [8]" << endl;
131
147
out << " \t\t " << " -m INT\t Minimum intron length. [70]" << endl;
132
148
out << " \t\t " << " -M INT\t Maximum intron length. [500000]" << endl;
149
+ out << " \t\t " << " -f INT\t Only use alignments where all flag bits set here are set. [0]" << endl;
150
+ out << " \t\t " << " -F INT\t Only use alignments where no flag bits set here are set. [0]" << endl;
151
+ out << " \t\t " << " -q INT\t Only use alignments with this mapping quality or above. [0]" << endl;
133
152
out << " \t\t " << " -o FILE\t The file to write output to. [STDOUT]" << endl;
134
153
out << " \t\t " << " -r STR\t The region to identify junctions \n "
135
154
<< " \t\t\t " << " in \" chr:start-end\" format. Entire BAM by default." << endl;
@@ -358,7 +377,7 @@ void JunctionsExtractor::set_junction_strand(bam1_t *aln, Junction& j1, string i
358
377
return ;
359
378
}
360
379
361
- // Get the the barcode
380
+ // Get the barcode
362
381
void JunctionsExtractor::set_junction_barcode (bam1_t *aln, Junction& j1) {
363
382
uint8_t *p = bam_aux_get (aln, barcode_tag_.c_str ());
364
383
if (p != NULL ) {
@@ -373,6 +392,14 @@ void JunctionsExtractor::set_junction_barcode(bam1_t *aln, Junction& j1) {
373
392
}
374
393
}
375
394
395
+ // Filters alignments based on filtering flags and mapping quality
396
+ bool JunctionsExtractor::filter_alignment (bam_hdr_t *header, bam1_t *aln) {
397
+ if ((aln->core .flag & filter_flags_) != 0 ) return true ;
398
+ if ((aln->core .flag | require_flags_) != aln->core .flag ) return true ;
399
+ if (aln->core .qual < min_map_qual_) return true ;
400
+ return false ;
401
+ }
402
+
376
403
// Parse junctions from the read and store in junction map
377
404
int JunctionsExtractor::parse_alignment_into_junctions (bam_hdr_t *header, bam1_t *aln) {
378
405
int n_cigar = aln->core .n_cigar ;
@@ -523,6 +550,7 @@ int JunctionsExtractor::identify_junctions_from_BAM() {
523
550
// Initiate the alignment record
524
551
bam1_t *aln = bam_init1 ();
525
552
while (sam_itr_next (in, iter, aln) >= 0 ) {
553
+ if (filter_alignment (header, aln)) continue ;
526
554
parse_alignment_into_junctions (header, aln);
527
555
}
528
556
hts_itr_destroy (iter);
0 commit comments