Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Created May 11, 2015 17:24
Show Gist options
  • Save mdshw5/15e415f1cadbcdd9e034 to your computer and use it in GitHub Desktop.
Save mdshw5/15e415f1cadbcdd9e034 to your computer and use it in GitHub Desktop.
biostars 141739
from pyfaidx import FastaVariant
consensus = FastaVariant('reference.fasta', 'sample1.vcf.gz', het=True, hom=True)
chrom = 'chr1'
seq = consensus[chrom][0:8]
print(seq) # AGTGCG
# if you don't want to invariant sites masked, you're good to go. otherwise:
masked = []
for base in seq:
if base.start in consensus.variant_sites:
masked.append(base.seq)
else:
masked.append('N')
print(''.join(masked)) # ANTGCN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment