Skip to content

Commit 20cc1b0

Browse files
committed
Import upstream htslib/samtools/bcftools 1.22
For each package: rm -rf htslib; python3 devtools/import.py htslib .../htslib-1.22 rm -rf samtools; python3 devtools/import.py samtools .../samtools-1.22 rm -rf bcftools; python3 devtools/import.py bcftools .../bcftools-1.22 Take care to preserve the #define additions to bcftools/regidx.h. (Don't bother adding {sam,bcf}tools/htslib-1.22/{LICENSE,**/README}.) Also take care to preserve removing the regeneration of htscodecs.mk from htslib/Makefile.
1 parent a8eb988 commit 20cc1b0

File tree

155 files changed

+13107
-2820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+13107
-2820
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ as it resolves non-python dependencies and uses pre-configured
2525
compilation options. Especially for OS X this will potentially save a
2626
lot of trouble.
2727

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

3030
Pysam is available through `PyPI <https://pypi.org/project/pysam/>`_.
3131
To install, type::

bcftools/bcftools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ void error(const char *format, ...) HTS_NORETURN HTS_FORMAT(HTS_PRINTF_FMT, 1, 2
5050
// newline will be added by the function.
5151
void error_errno(const char *format, ...) HTS_NORETURN HTS_FORMAT(HTS_PRINTF_FMT, 1, 2);
5252

53+
// Set hts_verbose and return 0, or return -1 if str is not a valid integer
54+
int apply_verbosity(const char *str);
55+
5356
// For on the fly index creation with --write-index
5457
int init_index2(htsFile *fh, bcf_hdr_t *hdr, const char *fname, char **idx_fname, int idx_fmt);
5558
int init_index(htsFile *fh, bcf_hdr_t *hdr, const char *fname, char **idx_fname);

bcftools/consensus.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* The MIT License
22
3-
Copyright (c) 2014-2024 Genome Research Ltd.
3+
Copyright (c) 2014-2025 Genome Research Ltd.
44
55
Author: Petr Danecek <[email protected]>
66
@@ -228,24 +228,24 @@ static void init_data(args_t *args)
228228
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));
229229
args->hdr = args->files->readers[0].header;
230230
args->isample = -1;
231-
if ( !args->sample )
231+
if ( args->sample_fname )
232232
{
233-
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
234-
if ( !args->smpl->n )
235-
{
236-
smpl_ilist_destroy(args->smpl);
237-
args->smpl = NULL;
238-
}
233+
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
234+
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
239235
}
240236
else if ( args->sample && strcmp("-",args->sample) )
241237
{
242238
args->smpl = smpl_ilist_init(args->hdr,args->sample,0,SMPL_NONE|SMPL_VERBOSE);
243239
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
244240
}
245-
else if ( args->sample_fname )
241+
else if ( !args->sample )
246242
{
247-
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
248-
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
243+
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
244+
if ( !args->smpl->n )
245+
{
246+
smpl_ilist_destroy(args->smpl);
247+
args->smpl = NULL;
248+
}
249249
}
250250
if ( args->smpl )
251251
{
@@ -768,12 +768,26 @@ static void apply_variant(args_t *args, bcf1_t *rec)
768768
}
769769
if ( ialt==-1 )
770770
{
771-
char alleles[4];
772-
alleles[0] = rec->d.allele[0][0];
773-
alleles[1] = ',';
774-
alleles[2] = args->missing_allele;
775-
alleles[3] = 0;
776-
bcf_update_alleles_str(args->hdr, rec, alleles);
771+
// missing allele, it can be a single position or an entire gvcf block
772+
if ( rec->rlen>1 && bcf_has_variant_types(rec,VCF_REF,bcf_match_exact)>0 )
773+
{
774+
kstring_t str = {0,0,0};
775+
int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off; // position of the variant within the modified fasta sequence
776+
kputsn(args->fa_buf.s+idx,rec->rlen, &str);
777+
kputc(',', &str);
778+
for (i=0; i<rec->rlen; i++) kputc(args->missing_allele, &str);
779+
bcf_update_alleles_str(args->hdr, rec, str.s);
780+
free(str.s);
781+
}
782+
else
783+
{
784+
char alleles[4];
785+
alleles[0] = rec->d.allele[0][0];
786+
alleles[1] = ',';
787+
alleles[2] = args->missing_allele;
788+
alleles[3] = 0;
789+
bcf_update_alleles_str(args->hdr, rec, alleles);
790+
}
777791
ialt = 1;
778792
}
779793

@@ -1203,6 +1217,7 @@ static void usage(args_t *args)
12031217
fprintf(stderr, " --regions-overlap 0|1|2 Include if POS in the region (0), record overlaps (1), variant overlaps (2) [1]\n");
12041218
fprintf(stderr, " -s, --samples LIST Comma-separated list of samples to include, \"-\" to ignore samples and use REF,ALT\n");
12051219
fprintf(stderr, " -S, --samples-file FILE File of samples to include\n");
1220+
fprintf(stderr, " -v, --verbosity INT Verbosity level\n");
12061221
fprintf(stderr, "Examples:\n");
12071222
fprintf(stderr, " # Get the consensus for one region. The fasta header lines are then expected\n");
12081223
fprintf(stderr, " # in the form \">chr:from-to\".\n");
@@ -1240,13 +1255,17 @@ int main_consensus(int argc, char *argv[])
12401255
{"chain",1,0,'c'},
12411256
{"prefix",required_argument,0,'p'},
12421257
{"regions-overlap",required_argument,0,5},
1258+
{"verbosity",required_argument,NULL,'v'},
12431259
{0,0,0,0}
12441260
};
12451261
int c;
1246-
while ((c = getopt_long(argc, argv, "h?s:S:1Ii:e:H:f:o:m:c:M:p:a:",loptions,NULL)) >= 0)
1262+
while ((c = getopt_long(argc, argv, "h?s:S:1Ii:e:H:f:o:m:c:M:p:a:v:",loptions,NULL)) >= 0)
12471263
{
12481264
switch (c)
12491265
{
1266+
case 'v':
1267+
if ( apply_verbosity(optarg) < 0 ) error("Could not parse argument: --verbosity %s\n", optarg);
1268+
break;
12501269
case 1 : args->mark_del = optarg[0]; break;
12511270
case 2 :
12521271
if ( !strcasecmp(optarg,"uc") ) args->mark_ins = TO_UPPER;

bcftools/consensus.c.pysam.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* The MIT License
44
5-
Copyright (c) 2014-2024 Genome Research Ltd.
5+
Copyright (c) 2014-2025 Genome Research Ltd.
66
77
Author: Petr Danecek <[email protected]>
88
@@ -230,24 +230,24 @@ static void init_data(args_t *args)
230230
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));
231231
args->hdr = args->files->readers[0].header;
232232
args->isample = -1;
233-
if ( !args->sample )
233+
if ( args->sample_fname )
234234
{
235-
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
236-
if ( !args->smpl->n )
237-
{
238-
smpl_ilist_destroy(args->smpl);
239-
args->smpl = NULL;
240-
}
235+
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
236+
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
241237
}
242238
else if ( args->sample && strcmp("-",args->sample) )
243239
{
244240
args->smpl = smpl_ilist_init(args->hdr,args->sample,0,SMPL_NONE|SMPL_VERBOSE);
245241
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
246242
}
247-
else if ( args->sample_fname )
243+
else if ( !args->sample )
248244
{
249-
args->smpl = smpl_ilist_init(args->hdr,args->sample_fname,1,SMPL_NONE|SMPL_VERBOSE);
250-
if ( args->smpl && !args->smpl->n ) error("No matching sample found\n");
245+
args->smpl = smpl_ilist_init(args->hdr,NULL,0,SMPL_NONE|SMPL_VERBOSE);
246+
if ( !args->smpl->n )
247+
{
248+
smpl_ilist_destroy(args->smpl);
249+
args->smpl = NULL;
250+
}
251251
}
252252
if ( args->smpl )
253253
{
@@ -770,12 +770,26 @@ static void apply_variant(args_t *args, bcf1_t *rec)
770770
}
771771
if ( ialt==-1 )
772772
{
773-
char alleles[4];
774-
alleles[0] = rec->d.allele[0][0];
775-
alleles[1] = ',';
776-
alleles[2] = args->missing_allele;
777-
alleles[3] = 0;
778-
bcf_update_alleles_str(args->hdr, rec, alleles);
773+
// missing allele, it can be a single position or an entire gvcf block
774+
if ( rec->rlen>1 && bcf_has_variant_types(rec,VCF_REF,bcf_match_exact)>0 )
775+
{
776+
kstring_t str = {0,0,0};
777+
int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off; // position of the variant within the modified fasta sequence
778+
kputsn(args->fa_buf.s+idx,rec->rlen, &str);
779+
kputc(',', &str);
780+
for (i=0; i<rec->rlen; i++) kputc(args->missing_allele, &str);
781+
bcf_update_alleles_str(args->hdr, rec, str.s);
782+
free(str.s);
783+
}
784+
else
785+
{
786+
char alleles[4];
787+
alleles[0] = rec->d.allele[0][0];
788+
alleles[1] = ',';
789+
alleles[2] = args->missing_allele;
790+
alleles[3] = 0;
791+
bcf_update_alleles_str(args->hdr, rec, alleles);
792+
}
779793
ialt = 1;
780794
}
781795

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

0 commit comments

Comments
 (0)