Skip to content

Instantly share code, notes, and snippets.

@idolawoye
Created June 11, 2022 13:37
Show Gist options
  • Select an option

  • Save idolawoye/b8846f4f1e12f9e82a924e9a7bf2ae8e to your computer and use it in GitHub Desktop.

Select an option

Save idolawoye/b8846f4f1e12f9e82a924e9a7bf2ae8e to your computer and use it in GitHub Desktop.
Python script to count number of Ns in a multifasta file
#!/usr/bin/env python
from Bio import SeqIO
fasta = "the_fasta_file.fasta"
for record in SeqIO.parse(fasta, "fasta"):
print("ID: %s" % record.id)
print("Sequence length: %s" % len(record))
print("Number of Ns: %s" % record.seq.count('N'))
print((record.seq.count('N')/len(record))*100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment