Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow repeated calls of bcf_sr_set_regions #1624

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions htslib/synced_bcf_reader.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// @file htslib/synced_bcf_reader.h
/// Stream through multiple VCF files.
/*
Copyright (C) 2012-2017, 2019-2021 Genome Research Ltd.
Copyright (C) 2012-2017, 2019-2023 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Expand Down Expand Up @@ -306,8 +306,10 @@ int bcf_sr_set_samples(bcf_srs_t *readers, const char *samples, int is_file);
* Targets (but not regions) can be prefixed with "^" to request logical complement,
* for example "^X,Y,MT" indicates that sequences X, Y and MT should be skipped.
*
* API note: bcf_sr_set_regions/bcf_sr_set_targets MUST be called before the
* first call to bcf_sr_add_reader().
* API notes:
* - bcf_sr_set_targets MUST be called before the first call to bcf_sr_add_reader()
* - bcf_sr_set_regions AFTER readers where initialized will reposition the readers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - bcf_sr_set_regions AFTER readers where initialized will reposition the readers
* - calling bcf_sr_set_regions AFTER readers have been initialized will reposition the readers

* and discard all previous regions.
*/
HTSLIB_EXPORT
int bcf_sr_set_targets(bcf_srs_t *readers, const char *targets, int is_file, int alleles);
Expand Down
14 changes: 10 additions & 4 deletions synced_bcf_reader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* synced_bcf_reader.c -- stream through multiple VCF files.
Copyright (C) 2012-2021 Genome Research Ltd.
Copyright (C) 2012-2023 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Expand Down Expand Up @@ -76,6 +76,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str);
static int _regions_match_alleles(bcf_sr_regions_t *reg, int als_idx, bcf1_t *rec);
static void _regions_sort_and_merge(bcf_sr_regions_t *reg);
static int _bcf_sr_regions_overlap(bcf_sr_regions_t *reg, const char *seq, hts_pos_t start, hts_pos_t end, int missed_reg_handler);
static void bcf_sr_seek_start(bcf_srs_t *readers);

char *bcf_sr_strerror(int errnum)
{
Expand Down Expand Up @@ -187,8 +188,10 @@ int bcf_sr_set_regions(bcf_srs_t *readers, const char *regions, int is_file)
{
if ( readers->nreaders || readers->regions )
{
hts_log_error("Must call bcf_sr_set_regions() before bcf_sr_add_reader()");
return -1;
if ( readers->regions ) bcf_sr_regions_destroy(readers->regions);
readers->regions = bcf_sr_regions_init(regions,is_file,0,1,-2);
bcf_sr_seek_start(readers);
return 0;
}

readers->regions = bcf_sr_regions_init(regions,is_file,0,1,-2);
Expand Down Expand Up @@ -676,7 +679,6 @@ static int _reader_fill_buffer(bcf_srs_t *files, bcf_sr_t *reader)
hts_log_error("This should never happen, just to keep clang compiler happy: %d",BCF_SR_AUX(files)->targets_overlap);
exit(1);
}

if ( beg <= files->regions->prev_end || end < files->regions->start || beg > files->regions->end ) continue;
}

Expand Down Expand Up @@ -843,7 +845,11 @@ static void bcf_sr_seek_start(bcf_srs_t *readers)
for (i=0; i<reg->nseqs; i++)
reg->regs[i].creg = -1;
reg->iseq = 0;
reg->start = -1;
reg->end = -1;
reg->prev_seq = -1;
reg->prev_start = -1;
reg->prev_end = -1;
}


Expand Down