Skip to content

Commit

Permalink
reveiw updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vasudeva8 committed Jan 15, 2025
1 parent 285c371 commit cac51cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
12 changes: 6 additions & 6 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-2024 Genome Research Ltd.
Copyright (C) 2012-2017, 2019-2025 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Expand Down Expand Up @@ -243,19 +243,19 @@ int bcf_sr_add_reader(bcf_srs_t *readers, const char *fname);
* @readers: holder of the open readers
* @file_ptr: htsfile already opened
* @autoclose: close file along with reader or not, 1 - close, 0 - do not close
* @fname: file name of @file_ptr
* @idxname: index file name for file in @file_ptr
*
* Returns 1 if the call succeeded, or 0 on error.
*
* See also the bcf_srs_t data structure for parameters controlling
* the reader's logic.
* If fname is NULL, uses file_ptr->fn for fname
* With fname as NULL, index file must be present in default location with
* default name, as file_ptr->fn doesn't contain index information
* If idxname is NULL, uses file_ptr->fn to find index file.
* With idxname as NULL, index file must be present along with the file with
* default name
*/
HTSLIB_EXPORT
int bcf_sr_add_hreader(bcf_srs_t *readers, htsFile *file_ptr, int autoclose,
const char *fname);
const char *idxname);

HTSLIB_EXPORT
void bcf_sr_remove_reader(bcf_srs_t *files, int i);
Expand Down
16 changes: 10 additions & 6 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-2023 Genome Research Ltd.
Copyright (C) 2012-2023, 2025 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Expand Down Expand Up @@ -253,6 +253,7 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname)
{
char fmode[5];
int ret = 0;
const char *idxname = NULL;

strcpy(fmode, "r");
vcf_open_mode(fmode+1, fname, NULL);
Expand All @@ -261,13 +262,16 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname)
files->errnum = open_failed;
return 0;
}
if (!(ret = bcf_sr_add_hreader(files, file_ptr, 1, fname))) {
//get idx name and pass to add_hreader
idxname = strstr(fname, HTS_IDX_DELIM);
idxname += idxname ? sizeof(HTS_IDX_DELIM) - 1 : 0;
if (!(ret = bcf_sr_add_hreader(files, file_ptr, 1, idxname))) {
hts_close(file_ptr); //failed, close the file
}
return ret;
}

int bcf_sr_add_hreader(bcf_srs_t *files, htsFile *file_ptr, int autoclose, const char *fname)
int bcf_sr_add_hreader(bcf_srs_t *files, htsFile *file_ptr, int autoclose, const char *idxname)
{
aux_t *auxdata = NULL;
if ( ! file_ptr ) {
Expand Down Expand Up @@ -306,7 +310,7 @@ int bcf_sr_add_hreader(bcf_srs_t *files, htsFile *file_ptr, int autoclose, const
return 0;
}

reader->tbx_idx = tbx_index_load(fname ? fname : file_ptr->fn);
reader->tbx_idx = tbx_index_load2(file_ptr->fn, idxname);
if ( !reader->tbx_idx )
{
files->errnum = idx_load_failed;
Expand All @@ -325,7 +329,7 @@ int bcf_sr_add_hreader(bcf_srs_t *files, htsFile *file_ptr, int autoclose, const

reader->header = bcf_hdr_read(reader->file);

reader->bcf_idx = bcf_index_load(fname ? fname : file_ptr->fn);
reader->bcf_idx = bcf_index_load2(file_ptr->fn, idxname);
if ( !reader->bcf_idx )
{
files->errnum = idx_load_failed;
Expand Down Expand Up @@ -378,7 +382,7 @@ int bcf_sr_add_hreader(bcf_srs_t *files, htsFile *file_ptr, int autoclose, const
return 0;
}

reader->fname = strdup(fname ? fname : file_ptr->fn);
reader->fname = strdup(file_ptr->fn);
if ( files->apply_filters )
reader->filter_ids = init_filters(reader->header, files->apply_filters, &reader->nfilter_ids);

Expand Down
8 changes: 6 additions & 2 deletions test/test-bcf-sr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2017, 2020, 2023 Genome Research Ltd.
Copyright (C) 2017, 2020, 2023, 2025 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Expand Down Expand Up @@ -63,6 +63,7 @@ void HTS_NORETURN usage(int exit_code)
fprintf(stderr, " -p, --pair <logic[+ref]> logic: snps,indels,both,snps+ref,indels+ref,both+ref,exact,some,all\n");
fprintf(stderr, " -r, --regions <reg_list> comma-separated list of regions\n");
fprintf(stderr, " -t, --targets <reg_list> comma-separated list of targets\n");
fprintf(stderr, " -u, --usefptr use hfile pointer interface on reader addition\n");
fprintf(stderr, "\n");
exit(exit_code);
}
Expand Down Expand Up @@ -240,7 +241,10 @@ int main(int argc, char *argv[])
}
/*with name, index can be anywhere, named as anything
w/o name it has to be along with file with default naming*/
if ( !bcf_sr_add_hreader(sr, htsfp[i], 1, vcfs[i]) ) {

const char *idxname = strstr(vcfs[i], HTS_IDX_DELIM);
idxname += idxname ? sizeof(HTS_IDX_DELIM) - 1 : 0;
if ( !bcf_sr_add_hreader(sr, htsfp[i], 1, idxname) ) {
error("Failed to add reader %s: %s\n", vcfs[i],
bcf_sr_strerror(sr->errnum));
}
Expand Down

0 comments on commit cac51cc

Please sign in to comment.