-
Notifications
You must be signed in to change notification settings - Fork 446
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
Add support for matching VCF lines by ID #1844
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright (C) 2017-2021 Genome Research Ltd. | ||
Copyright (C) 2017-2024 Genome Research Ltd. | ||
|
||
Author: Petr Danecek <[email protected]> | ||
|
||
|
@@ -32,6 +32,7 @@ | |
#include "htslib/khash_str2int.h" | ||
#include "htslib/kbitset.h" | ||
|
||
// Variant types and pair-wise compatibility of their combinations, see bcf_sr_init_scores() | ||
#define SR_REF 1 | ||
#define SR_SNP 2 | ||
#define SR_INDEL 4 | ||
|
@@ -366,7 +367,7 @@ static int bcf_sr_sort_set(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, | |
// group VCFs into groups, each with a unique combination of variants in the duplicate lines | ||
int ireader,ivar,irec,igrp,ivset,iact; | ||
for (ireader=0; ireader<readers->nreaders; ireader++) srt->vcf_buf[ireader].nrec = 0; | ||
for (iact=0; iact<srt->nactive; iact++) | ||
for (iact=0; iact<srt->nactive; iact++) // process each of the active readers, ie which still have a record to process | ||
{ | ||
ireader = srt->active[iact]; | ||
bcf_sr_t *reader = &readers->readers[ireader]; | ||
|
@@ -384,6 +385,11 @@ static int bcf_sr_sort_set(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, | |
srt->off[srt->noff++] = srt->str.l; | ||
size_t beg = srt->str.l; | ||
int end_pos = -1; | ||
if ( srt->pair & BCF_SR_PAIR_ID ) | ||
{ | ||
kputs(line->d.id,&srt->str); | ||
kputc(':',&srt->str); | ||
} | ||
for (ivar=1; ivar<line->n_allele; ivar++) | ||
{ | ||
if ( ivar>1 ) kputc(',',&srt->str); | ||
|
@@ -417,7 +423,10 @@ static int bcf_sr_sort_set(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, | |
} | ||
|
||
// Create new variant or attach to existing one. But careful, there can be duplicate | ||
// records with the same POS,REF,ALT (e.g. in dbSNP-b142) | ||
// records with the same POS,REF,ALT (e.g. in dbSNP-b142). In such case, use a | ||
// hash table (srt->var_str2int) and a counter (var_idx) to ensure they are | ||
// treated as separate variants, while still allowing them to be matched | ||
// between readers. | ||
char *var_str = beg + srt->str.s; | ||
int ret, var_idx = 0, var_end = srt->str.l; | ||
while ( 1 ) | ||
|
@@ -435,6 +444,7 @@ static int bcf_sr_sort_set(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, | |
} | ||
if ( ret==-1 ) | ||
{ | ||
// the variant is not present, insert | ||
ivar = srt->nvar++; | ||
hts_expand0(var_t,srt->nvar,srt->mvar,srt->var); | ||
srt->var[ivar].nvcf = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-2023 Genome Research Ltd. | ||
Copyright (C) 2012-2017, 2019-2024 Genome Research Ltd. | ||
Author: Petr Danecek <[email protected]> | ||
|
@@ -89,6 +89,7 @@ extern "C" { | |
#define BCF_SR_PAIR_SNP_REF (1<<4) // allow REF-only records with SNPs | ||
#define BCF_SR_PAIR_INDEL_REF (1<<5) // allow REF-only records with indels | ||
#define BCF_SR_PAIR_EXACT (1<<6) // require the exact same set of alleles in all files | ||
#define BCF_SR_PAIR_ID (1<<7) // require matching IDs (overlap) | ||
#define BCF_SR_PAIR_BOTH (BCF_SR_PAIR_SNPS|BCF_SR_PAIR_INDELS) | ||
#define BCF_SR_PAIR_BOTH_REF (BCF_SR_PAIR_SNPS|BCF_SR_PAIR_INDELS|BCF_SR_PAIR_SNP_REF|BCF_SR_PAIR_INDEL_REF) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks OK, and seems to work as advertised.