This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Consensus fasta file with uncovered bases set to Ns

I am looking forward to generating a consensus fasta file by providing my BED file and the reference fasta as inputs.I want to have the bases in my reference genome, showing 0 coverage to be substituted by Ns. Is there any script/tool available to do this?

reference genome bed fasta consensus

2 answers

bedtools maskfasta

Just provide the bed file with 0 coverage regions

You can do this with pyfaidx as well.

$ pip install pyfaidx
$ faidx -m -b regions.bed file.fa  # mask with "N"
$ faidx -s X -m -b regions.bed file.fa  # mask with "X"
$ faidx -M -b regions.bed file.fa  # soft-mask with lowercase characters

These all modify file.fa in-place, so make sure you're either testing on a copy or ready to change the file.

Log in to answer this question.