Skip to content

Commit c71d3d6

Browse files
author
nicolaasuni
committed
Merge upstream VariantKey changes
1 parent e152429 commit c71d3d6

File tree

5 files changed

+15
-28
lines changed

5 files changed

+15
-28
lines changed

plugins/variantkey-hex.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DEALINGS IN THE SOFTWARE. */
3333

3434
const char *FILE_VKRS = "vkrs.unsorted.hex";
3535
const char *FILE_RSVK = "rsvk.unsorted.hex";
36-
const char *FILE_VKNR = "vknr.unsorted.hex";
36+
const char *FILE_VKNR = "vknr.unsorted.tsv";
3737

3838
FILE *fp_vkrs; // VariantKey -> rsID
3939
FILE *fp_rsvk; // rsID -> VariantKey
@@ -99,15 +99,6 @@ int init(int argc, char **argv, bcf_hdr_t *in, bcf_hdr_t *out)
9999
return 1;
100100
}
101101

102-
void str2hex(const char *str, char *hex)
103-
{
104-
int i = 0;
105-
while (*str)
106-
{
107-
sprintf(hex+(i++)*2, "%02x", (uint8_t) *str++);
108-
}
109-
}
110-
111102
// Called for each VCF record. Return rec to output the line or NULL to suppress output.
112103
bcf1_t *process(bcf1_t *rec)
113104
{
@@ -129,11 +120,7 @@ bcf1_t *process(bcf1_t *rec)
129120
if (vk & 1)
130121
{
131122
// map VariantKey to REF and ALT
132-
char hex_ref[2*len_ref+1];
133-
char hex_alt[2*len_alt+1];
134-
str2hex(rec->d.allele[0], hex_ref);
135-
str2hex(rec->d.allele[1], hex_alt);
136-
fprintf(fp_vknr, "%016" PRIx64 "\t%016" PRIx64 "\t%02" PRIx8 "\t%02" PRIx8 "\t%s\t%s\n", vk, (uint64_t)(len_ref + len_alt + 2), len_ref, len_alt, hex_ref, hex_alt);
123+
fprintf(fp_vknr, "%016" PRIx64 "\t%s\t%s\n", vk, rec->d.allele[0], rec->d.allele[1]);
137124
nrv++;
138125
}
139126
numvar++;

test/vknr.unsorted.hex

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/vknr.unsorted.tsv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
080013f9a00e1d03 TAACCCCTAACCCTAACCCTAAACCCTA T
2+
0800142b90367897 AACCCCTAACCCTAACCCTAACCCT A
3+
080014bb8ad3d64f CCGCCGTTGCAAAGGCGCGCCG C

variantkey.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ inline int compare_variantkey_chrom_pos(uint64_t vka, uint64_t vkb)
329329
return compare_uint64_t((vka >> VKSHIFT_POS), (vkb >> VKSHIFT_POS));
330330
}
331331

332-
inline size_t variantkey_hex(uint64_t code, char *str)
332+
inline size_t variantkey_hex(uint64_t vk, char *str)
333333
{
334-
return sprintf(str, "%016" PRIx64, code);
334+
return sprintf(str, "%016" PRIx64, vk);
335335
}
336336

337337
inline uint64_t parse_variantkey_hex(const char *vs)

variantkey.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern "C" {
6565
typedef struct variantkey_t
6666
{
6767
uint8_t chrom; //!< Chromosome encoded number (only the LSB 5 bit are used)
68-
uint32_t pos; //!< Reference position, with the 1st base having position 0 (only the LSB 28 bit are used)
68+
uint32_t pos; //!< Reference position, with the first base having position 0 (only the LSB 28 bit are used)
6969
uint32_t refalt; //!< Code for Reference and Alternate allele (only the LSB 31 bits are used)
7070
} variantkey_t;
7171

@@ -130,7 +130,7 @@ size_t decode_refalt(uint32_t code, char *ref, size_t *sizeref, char *alt, size_
130130
/** @brief Returns a 64 bit variant key based on the pre-encoded CHROM, POS (0-based) and REF+ALT.
131131
*
132132
* @param chrom Encoded Chromosome (see encode_chrom).
133-
* @param pos Position. The reference position, with the 1st base having position 0.
133+
* @param pos Position. The reference position, with the first base having position 0.
134134
* @param refalt Encoded Reference + Alternate (see encode_refalt).
135135
*
136136
* @return VariantKey 64 bit code.
@@ -174,7 +174,7 @@ void decode_variantkey(uint64_t code, variantkey_t *vk);
174174
*
175175
* @param chrom Chromosome. An identifier from the reference genome, no white-space or leading zeros permitted.
176176
* @param sizechrom Length of the chrom string, excluding the terminating null byte.
177-
* @param pos Position. The reference position, with the 1st base having position 0.
177+
* @param pos Position. The reference position, with the first base having position 0.
178178
* @param ref Reference allele. String containing a sequence of nucleotide letters.
179179
* The value in the pos field refers to the position of the first nucleotide in the String.
180180
* Characters must be A-Z, a-z or *
@@ -190,8 +190,8 @@ uint64_t variantkey(const char *chrom, size_t sizechrom, uint32_t pos, const cha
190190
/** @brief Returns minimum and maximum VariantKeys for range searches.
191191
*
192192
* @param chrom Chromosome encoded number.
193-
* @param pos_min Start reference position, with the 1st base having position 0.
194-
* @param pos_max End reference position, with the 1st base having position 0.
193+
* @param pos_min Start reference position, with the first base having position 0.
194+
* @param pos_max End reference position, with the first base having position 0.
195195
* @param range VariantKey range values.
196196
*
197197
* @return Min and Max variant keys for any given REF+ALT encoding.
@@ -223,15 +223,15 @@ int compare_variantkey_chrom_pos(uint64_t vka, uint64_t vkb);
223223
* - 28 bit for POS
224224
* - 31 bit for REF+ALT
225225
*
226-
* @param code VariantKey code.
227-
* @param str String buffer to be returned (it must be sized 17 bytes at leasr).
226+
* @param vk VariantKey code.
227+
* @param str String buffer to be returned (it must be sized 17 bytes at least).
228228
*
229229
* @return Upon successful return, these function returns the number of characters processed
230230
* (excluding the null byte used to end output to strings).
231231
* If the buffer size is not sufficient, then the return value is the number of characters required for
232232
* buffer string, including the terminating null byte.
233233
*/
234-
size_t variantkey_hex(uint64_t code, char *str);
234+
size_t variantkey_hex(uint64_t vk, char *str);
235235

236236
/** @brief Parses a VariantKey hexadecimal string and returns the code.
237237
*

0 commit comments

Comments
 (0)