Hi All,
I want to extract ampliconIDs for all the variants called in multiple samples.
I have VCFs for each sample (~200) and I have a bed file with chrno,amplicon start and end coordinates and ampliconIDs. So for each variant, I want to extract the corresponding ampliconID in which it falls based on the coordinates and then add the ampliconID next to the variant. This will help in knowing which variant is found in which particular amplicon.
Any suggestions on the same would be helpful.
Thanks!!
3 answers
Assuming you have a sorted BED file called amplicons.bed, you could use BEDOPS vcf2bed to convert sample.snps.vcf to BED, and BEDOPS bedmap to map SNP IDs to amplicons:
$ bedmap --echo --echo-map-id-uniq --delim '\t' amplicons.bed <(vcf2bed < sample.snps.vcf) > answer.bed
The file answer.bed will have each amplicon region and ID, and the rsIDs of all SNPs that overlap that amplicon's region, specific to that SNP's sample. The amplicon ID and rsIDs will be in adjacent columns, if I understand your file format correctly.
To repeat for all samples, use a for loop or the like:
$ for sampleFn in `ls *.vcf`; do bedmap --echo --echo-map-id-uniq --delim '\t' amplicons.bed <(vcf2bed < ${sampleFn}) > ${sampleFn}.answer.bed; done
After converting .vcf to bed, similar thing as mentioned by Alex can also been done using 'bedtools intersect'
Another way is to use bcftools.
To get it work, you must first bgzip and index your bed file:
$ bgzip -c amplicons.bed > amplicons.bed.gz
$ tabix -p bed amplicons.bed.gz
For annotating all the vcf files I prefer gnu parallel:
$ parallel 'bcftools annotate -c CHROM,FROM,TO,ID -a amplicons.bed.gz -o {.}.ann.vcf {}' ::: *.vcf
fin swimmer
Log in to answer this question.