Skip to content

Update imports to htslib/samtools/bcftools 1.22 #1343

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ as it resolves non-python dependencies and uses pre-configured
compilation options. Especially for OS X this will potentially save a
lot of trouble.

The current version of pysam wraps 3rd-party code from htslib-1.21, samtools-1.21, and bcftools-1.21.
The current version of pysam wraps 3rd-party code from htslib-1.22, samtools-1.22, and bcftools-1.22.

Pysam is available through `PyPI <https://pypi.org/project/pysam/>`_.
To install, type::
Expand Down
3 changes: 3 additions & 0 deletions bcftools/bcftools.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ void error(const char *format, ...) HTS_NORETURN HTS_FORMAT(HTS_PRINTF_FMT, 1, 2
// newline will be added by the function.
void error_errno(const char *format, ...) HTS_NORETURN HTS_FORMAT(HTS_PRINTF_FMT, 1, 2);

// Set hts_verbose and return 0, or return -1 if str is not a valid integer
int apply_verbosity(const char *str);

// For on the fly index creation with --write-index
int init_index2(htsFile *fh, bcf_hdr_t *hdr, const char *fname, char **idx_fname, int idx_fmt);
int init_index(htsFile *fh, bcf_hdr_t *hdr, const char *fname, char **idx_fname);
Expand Down
55 changes: 37 additions & 18 deletions bcftools/consensus.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* The MIT License

Copyright (c) 2014-2024 Genome Research Ltd.
Copyright (c) 2014-2025 Genome Research Ltd.

Author: Petr Danecek <[email protected]>

Expand Down Expand Up @@ -228,24 +228,24 @@ static void init_data(args_t *args)
if ( !bcf_sr_add_reader(args->files,args->fname) ) error("Failed to read from %s: %s\n", !strcmp("-",args->fname)?"standard input":args->fname, bcf_sr_strerror(args->files->errnum));
args->hdr = args->files->readers[0].header;
args->isample = -1;
if ( !args->sample )
if ( args->sample_fname )
{
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
if ( !args->smpl->n )
{
smpl_ilist_destroy(args->smpl);
args->smpl = NULL;
}
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
}
else if ( args->sample && strcmp("-",args->sample) )
{
args->smpl = smpl_ilist_init(args->hdr,args->sample,0,SMPL_NONE|SMPL_VERBOSE);
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
}
else if ( args->sample_fname )
else if ( !args->sample )
{
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
if ( !args->smpl->n )
{
smpl_ilist_destroy(args->smpl);
args->smpl = NULL;
}
}
if ( args->smpl )
{
Expand Down Expand Up @@ -768,12 +768,26 @@ static void apply_variant(args_t *args, bcf1_t *rec)
}
if ( ialt==-1 )
{
char alleles[4];
alleles[0] = rec->d.allele[0][0];
alleles[1] = ',';
alleles[2] = args->missing_allele;
alleles[3] = 0;
bcf_update_alleles_str(args->hdr, rec, alleles);
// missing allele, it can be a single position or an entire gvcf block
if ( rec->rlen>1 && bcf_has_variant_types(rec,VCF_REF,bcf_match_exact)>0 )
{
kstring_t str = {0,0,0};
int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off; // position of the variant within the modified fasta sequence
kputsn(args->fa_buf.s+idx,rec->rlen, &str);
kputc(',', &str);
for (i=0; i<rec->rlen; i++) kputc(args->missing_allele, &str);
bcf_update_alleles_str(args->hdr, rec, str.s);
free(str.s);
}
else
{
char alleles[4];
alleles[0] = rec->d.allele[0][0];
alleles[1] = ',';
alleles[2] = args->missing_allele;
alleles[3] = 0;
bcf_update_alleles_str(args->hdr, rec, alleles);
}
ialt = 1;
}

Expand Down Expand Up @@ -1203,6 +1217,7 @@ static void usage(args_t *args)
fprintf(stderr, " --regions-overlap 0|1|2 Include if POS in the region (0), record overlaps (1), variant overlaps (2) [1]\n");
fprintf(stderr, " -s, --samples LIST Comma-separated list of samples to include, \"-\" to ignore samples and use REF,ALT\n");
fprintf(stderr, " -S, --samples-file FILE File of samples to include\n");
fprintf(stderr, " -v, --verbosity INT Verbosity level\n");
fprintf(stderr, "Examples:\n");
fprintf(stderr, " # Get the consensus for one region. The fasta header lines are then expected\n");
fprintf(stderr, " # in the form \">chr:from-to\".\n");
Expand Down Expand Up @@ -1240,13 +1255,17 @@ int main_consensus(int argc, char *argv[])
{"chain",1,0,'c'},
{"prefix",required_argument,0,'p'},
{"regions-overlap",required_argument,0,5},
{"verbosity",required_argument,NULL,'v'},
{0,0,0,0}
};
int c;
while ((c = getopt_long(argc, argv, "h?s:S:1Ii:e:H:f:o:m:c:M:p:a:",loptions,NULL)) >= 0)
while ((c = getopt_long(argc, argv, "h?s:S:1Ii:e:H:f:o:m:c:M:p:a:v:",loptions,NULL)) >= 0)
{
switch (c)
{
case 'v':
if ( apply_verbosity(optarg) < 0 ) error("Could not parse argument: --verbosity %s\n", optarg);
break;
case 1 : args->mark_del = optarg[0]; break;
case 2 :
if ( !strcasecmp(optarg,"uc") ) args->mark_ins = TO_UPPER;
Expand Down
55 changes: 37 additions & 18 deletions bcftools/consensus.c.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* The MIT License

Copyright (c) 2014-2024 Genome Research Ltd.
Copyright (c) 2014-2025 Genome Research Ltd.

Author: Petr Danecek <[email protected]>

Expand Down Expand Up @@ -230,24 +230,24 @@ static void init_data(args_t *args)
if ( !bcf_sr_add_reader(args->files,args->fname) ) error("Failed to read from %s: %s\n", !strcmp("-",args->fname)?"standard input":args->fname, bcf_sr_strerror(args->files->errnum));
args->hdr = args->files->readers[0].header;
args->isample = -1;
if ( !args->sample )
if ( args->sample_fname )
{
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
if ( !args->smpl->n )
{
smpl_ilist_destroy(args->smpl);
args->smpl = NULL;
}
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
}
else if ( args->sample && strcmp("-",args->sample) )
{
args->smpl = smpl_ilist_init(args->hdr,args->sample,0,SMPL_NONE|SMPL_VERBOSE);
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
}
else if ( args->sample_fname )
else if ( !args->sample )
{
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
if ( !args->smpl->n )
{
smpl_ilist_destroy(args->smpl);
args->smpl = NULL;
}
}
if ( args->smpl )
{
Expand Down Expand Up @@ -770,12 +770,26 @@ static void apply_variant(args_t *args, bcf1_t *rec)
}
if ( ialt==-1 )
{
char alleles[4];
alleles[0] = rec->d.allele[0][0];
alleles[1] = ',';
alleles[2] = args->missing_allele;
alleles[3] = 0;
bcf_update_alleles_str(args->hdr, rec, alleles);
// missing allele, it can be a single position or an entire gvcf block
if ( rec->rlen>1 && bcf_has_variant_types(rec,VCF_REF,bcf_match_exact)>0 )
{
kstring_t str = {0,0,0};
int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off; // position of the variant within the modified fasta sequence
kputsn(args->fa_buf.s+idx,rec->rlen, &str);
kputc(',', &str);
for (i=0; i<rec->rlen; i++) kputc(args->missing_allele, &str);
bcf_update_alleles_str(args->hdr, rec, str.s);
free(str.s);
}
else
{
char alleles[4];
alleles[0] = rec->d.allele[0][0];
alleles[1] = ',';
alleles[2] = args->missing_allele;
alleles[3] = 0;
bcf_update_alleles_str(args->hdr, rec, alleles);
}
ialt = 1;
}

Expand Down Expand Up @@ -1205,6 +1219,7 @@ static void usage(args_t *args)
fprintf(bcftools_stderr, " --regions-overlap 0|1|2 Include if POS in the region (0), record overlaps (1), variant overlaps (2) [1]\n");
fprintf(bcftools_stderr, " -s, --samples LIST Comma-separated list of samples to include, \"-\" to ignore samples and use REF,ALT\n");
fprintf(bcftools_stderr, " -S, --samples-file FILE File of samples to include\n");
fprintf(bcftools_stderr, " -v, --verbosity INT Verbosity level\n");
fprintf(bcftools_stderr, "Examples:\n");
fprintf(bcftools_stderr, " # Get the consensus for one region. The fasta header lines are then expected\n");
fprintf(bcftools_stderr, " # in the form \">chr:from-to\".\n");
Expand Down Expand Up @@ -1242,13 +1257,17 @@ int main_consensus(int argc, char *argv[])
{"chain",1,0,'c'},
{"prefix",required_argument,0,'p'},
{"regions-overlap",required_argument,0,5},
{"verbosity",required_argument,NULL,'v'},
{0,0,0,0}
};
int c;
while ((c = getopt_long(argc, argv, "h?s:S:1Ii:e:H:f:o:m:c:M:p:a:",loptions,NULL)) >= 0)
while ((c = getopt_long(argc, argv, "h?s:S:1Ii:e:H:f:o:m:c:M:p:a:v:",loptions,NULL)) >= 0)
{
switch (c)
{
case 'v':
if ( apply_verbosity(optarg) < 0 ) error("Could not parse argument: --verbosity %s\n", optarg);
break;
case 1 : args->mark_del = optarg[0]; break;
case 2 :
if ( !strcasecmp(optarg,"uc") ) args->mark_ins = TO_UPPER;
Expand Down
Loading
Loading