This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Reverse Complement Of A Sequence Raises Assertionerror: Invalid Alphabet Found

I read a fasta-formatted genome sequence and try to get its reverse complement:

genomeSeq = FastaIO.FastaIterator(genomeHandle, IUPACUnambiguousDNA).next()
genomeSeq.seq.reverse_complement()

but it doesn't work and I can't understand why:

File "/Users/charodeika/Dropbox/genesGelfand/scripts/genome/src/matrixCount/sigma.py", line 127, in <module>
    print genomeSeq.seq[:10].reverse_complement()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Seq.py", line 804, in reverse_complement
    return self.complement()[::-1]
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Seq.py", line 752, in complement
    base = Alphabet._get_base_alphabet(self.alphabet)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Alphabet/__init__.py", line 213, in _get_base_alphabet
    "Invalid alphabet found, %s" % repr(a)
AssertionError: Invalid alphabet found, <class 'Bio.Alphabet.IUPAC.IUPACUnambiguousDNA'>

And, of course, I would like to find out how to make it work!

biopython

2 answers

What I think the problem is, that genome sequences contain N's for nucleotides of which they are not sure what nucleotide it is. IUPACUnambiguousDNA only accepts ACTG. So you would want to change your script to ignore the N's (or any other non-dna letter there is in there.

No, certainly not. It doesn't work for slices, that do not contain any other letters as A, T, G,C

Agreed - the alphabet letters are not relevant to this error.

Well, when I added

from Bio.Alphabet import IUPAC

and changed

genomeSeq.seq.reverse_complement()

to

genomeSeq = FastaIO.FastaIterator(genomeHandle, IUPAC.unambiguous_dna).next()

it started working nicely. However, I would still be happy to learn why.

Without seeing the complete code (the imports) I can't be 100% sure, but I believe your error is passing an alphabet class rather than an instance of the class (an alphabet object).

Log in to answer this question.