8
$\begingroup$

I have some software which takes fastas as the input. I need to include SNVs and InDels from a VCF into the reference hg38 and then use this.

The problem is, I don't know of an algorithmically sound way to do this.

  1. Are there any existing software packages which could do this efficiently? Is it easier to output a FASTA, or a bam (and then convert to a FASTA)?

  2. What about if I wanted to do the same with a bedpe of germline structural variants?

$\endgroup$
  • $\begingroup$ Could you provide an example of what you're looking for? I'm having a hard time picturing what you want. $\endgroup$ – Greg Aug 6 '17 at 19:48
  • $\begingroup$ @Greg The above might be unclear. I have a reference FASTA. I have variants. I would now like to manipulate the reference FASTA to include these variants. The VCF tells us there's a SNP at XX location; I would like to like a FASTA that includes these SNPs. Does this make sense? $\endgroup$ – ShanZhengYang Aug 6 '17 at 20:11
  • $\begingroup$ Oh I understand now. Here's a link to a similar biostars question that has some answers that look good. biostars.org/p/6553 $\endgroup$ – Greg Aug 6 '17 at 20:36
4
$\begingroup$

You could convert VCF to BED via vcf2bed --snvs, vcf2bed --insertions, and vcf2bed --deletions, and then use samtools faidx by way of a wrapper script to convert BED to FASTA, e.g.:

$ vcf2bed --snvs < variants.vcf | bed2faidxsta.pl > snvs.fa
$ vcf2bed --insertions < variants.vcf | bed2faidxsta.pl > insertions.fa
$ vcf2bed --deletions < variants.vcf | bed2faidxsta.pl > deletions.fa

You need FASTA files for your reference genome, which have been indexed with samtools faidx, e.g., for hg38:

$ cd /foo/bar/baz
$ wget ftp://hgdownload.cse.ucsc.edu/goldenPath/hg38/chromosomes/*.fa.gz
$ for fn in `ls *.fa.gz`; do gunzip $fn; done
$ for fn in `ls *.fa`; do samtools faidx $fn; done

Once you have indexed FASTA files somewhere on your file system, you can pipe BED to the bed2faidxsta.pl script, to get out FASTA sequences.

$\endgroup$
7
$\begingroup$

GATK has a solution that might work for you: FastaAlternateReferenceMaker, which : "Given a variant callset, this tool replaces the reference bases at variation sites with the bases supplied in the corresponding callset records."

Input

The reference, requested intervals, and any number of variant ROD files.

Output

A FASTA file representing the requested intervals.

Usage example

java -jar GenomeAnalysisTK.jar \
   -T FastaAlternateReferenceMaker \
   -R reference.fasta \
   -o output.fasta \
   -L input.intervals \
   -V input.vcf \
$\endgroup$
3
$\begingroup$

There's a vcf2fq sub-program that was written as part of vcfutils to convert a VCF file into a fastq file given a reference sequence. Unfortunately this doesn't work properly with INDELs (it will just mask them, rather than actually converting them), so I wrote a modification to implement INDEL correction as well:

./vcf2fq.pl -f <input.fasta> <all-site.vcf> > <output.fastq>

It adds and removes sequence from the reference, as specified by the INDEL information in the VCF file. The code keeps a record of where in the reference sequence the INDELs should go, then inserts (or deletes) the INDELs, updating the reference position as necessary. It should work with things like deletions right next to insertions, but hasn't been extensively tested.

$\endgroup$
  • $\begingroup$ Could you explain how your perl script with the INDEL implementation works? i.e. what changes did you make for vcfutils.pl to work properly $\endgroup$ – ShanZhengYang Nov 8 '17 at 17:46
  • $\begingroup$ "It should work with things like deletions right next to insertions, but hasn't been extensively tested." If you do benchmark this, let me know---this would be interesting to see $\endgroup$ – ShanZhengYang Nov 8 '17 at 19:18
  • $\begingroup$ Another question: have you seen vcfutils.pl written in Python/R? I suspect these exist somewhere, as I don't want to re-invent the wheel. Is this worth a separate SO question? It would be good if your perl script was more advertised IMHO $\endgroup$ – ShanZhengYang Nov 9 '17 at 16:50
  • $\begingroup$ I think an answer to that fits in with this question. The question is about manipulating FASTA files, not about vcfutils. No, I haven't seen any python/R alternatives. I don't see much of a point in them (certainly not a python version), given that the command-line functionality already exists via vcf2fq. $\endgroup$ – gringer Nov 9 '17 at 20:37
  • $\begingroup$ You're welcome to have a go at advertising this further. I've brought it up a few times on SeqAnswers, github, and I think reddit; basically every time I see a question asking something like this. $\endgroup$ – gringer Nov 9 '17 at 20:40
2
$\begingroup$

Here's an update how this work in 2019. (The answer is quite similar to my update in this thread):

bgzip and index your vcf file.

$ bgzip -c input.vcf > input.vcf.gz
$ tabix input.vcf.gz

Now use bcftools consensus:

$ bcftools consensus -f genome.fa input.vcf.gz > consensus.fa
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.