-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #831 from Genomicsplc/develop
Add VariantKey support
- Loading branch information
Showing
21 changed files
with
2,210 additions
and
1 deletion.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* plugins/add-variantkey.c -- add VariantKey INFO field. | ||
Copyright (C) 2017-2018 GENOMICS plc. | ||
Author: Nicola Asuni <nicola.asuni@genomicsplc.com> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. */ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <htslib/hts.h> | ||
#include <htslib/vcf.h> | ||
#include <htslib/vcfutils.h> | ||
#include <inttypes.h> | ||
#include "../variantkey.h" | ||
|
||
bcf_hdr_t *in_hdr, *out_hdr; | ||
|
||
const char *about(void) | ||
{ | ||
return "Add VariantKey INFO fields VKX and RSX.\n"; | ||
} | ||
|
||
const char *usage(void) | ||
{ | ||
return | ||
"\n" | ||
"About: Add VKX and RSX columns.\n" | ||
"Usage: bcftools +add-variantkey [General Options] \n" | ||
"Options:\n" | ||
" run \"bcftools plugin\" for a list of common options\n" | ||
"\n" | ||
"Example:\n" | ||
" bcftools +add-variantkey in.vcf\n" | ||
"\n"; | ||
} | ||
|
||
int init(int argc, char **argv, bcf_hdr_t *in, bcf_hdr_t *out) | ||
{ | ||
in_hdr = in; | ||
out_hdr = out; | ||
bcf_hdr_append(out_hdr, "##INFO=<ID=VKX,Number=1,Type=String,Description=\"Hexadecimal representation of 64 bit VariantKey\">"); | ||
bcf_hdr_append(out_hdr, "##INFO=<ID=RSX,Number=1,Type=String,Description=\"Hexadecimal representation of ID minus the 'rs' prefix (32bit)\">"); | ||
return 0; | ||
} | ||
|
||
bcf1_t *process(bcf1_t *rec) | ||
{ | ||
uint64_t vk = variantkey( | ||
in_hdr->id[BCF_DT_CTG][rec->rid].key, | ||
strlen(in_hdr->id[BCF_DT_CTG][rec->rid].key), | ||
rec->pos, | ||
rec->d.allele[0], | ||
strlen(rec->d.allele[0]), | ||
rec->d.allele[1], | ||
strlen(rec->d.allele[1])); | ||
char vs[17]; | ||
variantkey_hex(vk, vs); | ||
bcf_update_info_string(out_hdr, rec, "VKX", vs); | ||
char rsid[9]; | ||
char *ptr = rec->d.id; | ||
ptr += 2; // remove 'rs' | ||
sprintf(rsid, "%08" PRIx32, (uint32_t)strtoul(ptr, NULL, 10)); | ||
bcf_update_info_string(out_hdr, rec, "RSX", rsid); | ||
return rec; | ||
} | ||
|
||
void destroy(void) | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* plugins/allele-length.c -- Calculate stats about the length of alleles | ||
Copyright (C) 2017-2018 GENOMICS plc. | ||
Author: Nicola Asuni <nicola.asuni@genomicsplc.com> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. */ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <htslib/vcf.h> | ||
#include <inttypes.h> | ||
|
||
#define MAXLEN 512 | ||
|
||
static uint64_t numvar; | ||
static uint64_t numxvar; | ||
static uint64_t reflen[MAXLEN]; | ||
static uint64_t altlen[MAXLEN]; | ||
static uint64_t refaltlen[MAXLEN]; | ||
static uint64_t xrefaltlen[MAXLEN]; | ||
|
||
const char *about(void) | ||
{ | ||
return "Count the frequency of the length of REF, ALT and REF+ALT\n"; | ||
} | ||
|
||
const char *usage(void) | ||
{ | ||
return | ||
"\n" | ||
"About: Count the frequency of the length of alleles.\n" | ||
"Usage: bcftools +allele-length [General Options] \n" | ||
"Options:\n" | ||
" run \"bcftools plugin\" for a list of common options\n" | ||
"\n" | ||
"Example:\n" | ||
" bcftools +allele-length in.vcf\n" | ||
"\n"; | ||
} | ||
|
||
// return 0 if the string contains characters other than standard ACGT base letters | ||
int contain_non_base(const char *str) | ||
{ | ||
int c; | ||
while ((c = *str++)) | ||
{ | ||
if ((c != 'A') && (c != 'a') && (c != 'C') && (c != 'c') && (c != 'G') && (c != 'g') && (c != 'T') && (c != 't')) | ||
{ | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
// Called once at startup, allows to initialize local variables. | ||
// Return 1 to suppress VCF/BCF header from printing, 0 otherwise. | ||
int init(int argc, char **argv, bcf_hdr_t *in, bcf_hdr_t *out) | ||
{ | ||
numvar = 0; | ||
int i = 0; | ||
for(i = 0; i < MAXLEN; i++) { | ||
reflen[i] = 0; | ||
altlen[i] = 0; | ||
refaltlen[i] = 0; | ||
xrefaltlen[i] = 0; | ||
} | ||
return 1; | ||
} | ||
|
||
// Called for each VCF record. Return rec to output the line or NULL to suppress output. | ||
bcf1_t *process(bcf1_t *rec) | ||
{ | ||
int rl = strlen(rec->d.allele[0]); | ||
int al = strlen(rec->d.allele[1]); | ||
reflen[rl] += 1; | ||
altlen[al] += 1; | ||
refaltlen[(rl + al)] += 1; | ||
if ((contain_non_base(rec->d.allele[0])) || (contain_non_base(rec->d.allele[1]))) | ||
{ | ||
xrefaltlen[(rl + al)] += 1; | ||
numxvar++; | ||
} | ||
numvar++; | ||
return NULL; | ||
} | ||
|
||
// Print final output | ||
void destroy(void) | ||
{ | ||
int i = 0; | ||
printf("LENGTH\tREF\tALT\tREF+ALT\tREF+ALT WITH NON-BASE NUCLEOTIDES\n"); | ||
for(i = 0; i < MAXLEN; i++) { | ||
printf("%d\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n", i, reflen[i], altlen[i], refaltlen[i], xrefaltlen[i]); | ||
} | ||
printf("\t\t\t%"PRIu64"\t%"PRIu64"\n", numvar, numxvar); | ||
} |
Oops, something went wrong.