@@ -3003,7 +3003,7 @@ static void init_filters(args_t *args)
3003
3003
3004
3004
if ( !args -> n_ext ) return ;
3005
3005
3006
- if ( !args -> tgts )
3006
+ if ( !args -> tgts && ! args -> tgt_idx )
3007
3007
error ("Error: dynamic variables in -i/-e expressions can be currently used only with tab-delimited file, not with VCF (todo)\n" );
3008
3008
3009
3009
// contains external values
@@ -3330,6 +3330,41 @@ static int strstr_match(char *a, char *b)
3330
3330
}
3331
3331
return 0 ;
3332
3332
}
3333
+ static int pass_filter_test_ext (args_t * args , bcf1_t * line , annot_line_t * ann )
3334
+ {
3335
+ char * tmp ;
3336
+ int i ;
3337
+ for (i = 0 ; i < args -> n_ext ; i ++ )
3338
+ {
3339
+ int j = args -> ext [i ].icol ;
3340
+ if ( args -> ext [i ].ht_type == BCF_HT_STR ) args -> ext_ptr [i ] = args -> ext [i ].s = ann -> cols [j ];
3341
+ else if ( args -> ext [i ].ht_type == BCF_HT_INT )
3342
+ {
3343
+ args -> ext [i ].i = strtol (ann -> cols [j ],& tmp ,10 );
3344
+ if ( * tmp )
3345
+ {
3346
+ if ( strcmp ("." ,ann -> cols [j ]) ) error ("Error: could not parse the annotation file, expected an integer, found \"%s\"\n" ,ann -> cols [j ]);
3347
+ args -> ext_ptr [i ] = NULL ;
3348
+ }
3349
+ else
3350
+ args -> ext_ptr [i ] = & args -> ext [i ].i ;
3351
+ }
3352
+ else if ( args -> ext [i ].ht_type == BCF_HT_REAL )
3353
+ {
3354
+ args -> ext [i ].f = strtod (ann -> cols [j ],& tmp );
3355
+ if ( * tmp )
3356
+ {
3357
+ if ( strcmp ("." ,ann -> cols [j ]) ) error ("Error: could not parse the annotation file, expected a float, found \"%s\"\n" ,ann -> cols [j ]);
3358
+ args -> ext_ptr [i ] = NULL ;
3359
+ }
3360
+ else
3361
+ args -> ext_ptr [i ] = & args -> ext [i ].f ;
3362
+ }
3363
+ }
3364
+ int pass = filter_test_ext (args -> filter_ext ,line ,NULL ,(const void * * )args -> ext_ptr );
3365
+ if ( args -> filter_logic == FLT_EXCLUDE ) pass = pass ? 0 : 1 ;
3366
+ return pass ;
3367
+ }
3333
3368
static int annotate_from_regidx (args_t * args , bcf1_t * line )
3334
3369
{
3335
3370
int j ;
@@ -3355,6 +3390,11 @@ static int annotate_from_regidx(args_t *args, bcf1_t *line)
3355
3390
if ( args -> min_overlap_vcf && args -> min_overlap_vcf > (float )isec /len_vcf ) continue ;
3356
3391
3357
3392
parse_annot_line (args , regitr_payload (args -> tgt_itr ,char * ), tmp );
3393
+ if ( args -> filter_ext )
3394
+ {
3395
+ if ( !pass_filter_test_ext (args ,line ,tmp ) ) continue ;
3396
+ has_overlap = 1 ;
3397
+ }
3358
3398
3359
3399
// If a plain BED file is provided and we are asked to just mark overlapping sites, there are
3360
3400
// no additional columns. Not sure if there can be any side effects for ill-formatted BED files
@@ -3364,6 +3404,7 @@ static int annotate_from_regidx(args_t *args, bcf1_t *line)
3364
3404
for (j = 0 ; j < args -> ncols ; j ++ )
3365
3405
{
3366
3406
if ( args -> cols [j ].done == 1 ) continue ;
3407
+ if ( !args -> cols [j ].setter ) continue ;
3367
3408
int ret = args -> cols [j ].setter (args ,line ,& args -> cols [j ],tmp );
3368
3409
if ( ret < 0 )
3369
3410
error ("fixme: Could not set %s at %s:%" PRId64 "\n" , args -> cols [j ].hdr_key_src ,bcf_seqname (args -> hdr ,line ),(int64_t ) line -> pos + 1 );
@@ -3382,41 +3423,6 @@ static int annotate_from_regidx(args_t *args, bcf1_t *line)
3382
3423
}
3383
3424
return has_overlap ;
3384
3425
}
3385
- static int pass_filter_test_ext (args_t * args , bcf1_t * line , annot_line_t * ann )
3386
- {
3387
- char * tmp ;
3388
- int i ;
3389
- for (i = 0 ; i < args -> n_ext ; i ++ )
3390
- {
3391
- int j = args -> ext [i ].icol ;
3392
- if ( args -> ext [i ].ht_type == BCF_HT_STR ) args -> ext_ptr [i ] = args -> ext [i ].s = ann -> cols [j ];
3393
- else if ( args -> ext [i ].ht_type == BCF_HT_INT )
3394
- {
3395
- args -> ext [i ].i = strtol (ann -> cols [j ],& tmp ,10 );
3396
- if ( * tmp )
3397
- {
3398
- if ( strcmp ("." ,ann -> cols [j ]) ) error ("Error: could not parse the annotation file, expected an integer, found \"%s\"\n" ,ann -> cols [j ]);
3399
- args -> ext_ptr [i ] = NULL ;
3400
- }
3401
- else
3402
- args -> ext_ptr [i ] = & args -> ext [i ].i ;
3403
- }
3404
- else if ( args -> ext [i ].ht_type == BCF_HT_REAL )
3405
- {
3406
- args -> ext [i ].f = strtod (ann -> cols [j ],& tmp );
3407
- if ( * tmp )
3408
- {
3409
- if ( strcmp ("." ,ann -> cols [j ]) ) error ("Error: could not parse the annotation file, expected a float, found \"%s\"\n" ,ann -> cols [j ]);
3410
- args -> ext_ptr [i ] = NULL ;
3411
- }
3412
- else
3413
- args -> ext_ptr [i ] = & args -> ext [i ].f ;
3414
- }
3415
- }
3416
- int pass = filter_test_ext (args -> filter_ext ,line ,NULL ,(const void * * )args -> ext_ptr );
3417
- if ( args -> filter_logic == FLT_EXCLUDE ) pass = pass ? 0 : 1 ;
3418
- return pass ;
3419
- }
3420
3426
static int annotate_from_tab (args_t * args , bcf1_t * line )
3421
3427
{
3422
3428
int i ,j ;
0 commit comments