This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Biopython: .count() method not working when importing DNA sequence

My goal here is to receive the amount of time 'g' appears in a DNA sequence.

I imported a DNA sequence via Biopython using list comprehension

seq = [record for record in SeqIO.parse('sequences/hiv.gbk.rtf', 'fasta')]

I then tried using the .count() method on the newly created list comp variable

print(seq.count('g'))

I get an error that reads

NotImplementedError: SeqRecord comparison is deliberately not implemented. Explicitly compare the attributes of interest.

Anyone know what the dealio is? Biopython's manual says all standard python methods should work. Can you not manipulate data when you import a DNA sequence with Biopython?

python biopython

i don't remember list has count method. the str does has. please check the biopython api, you may call count on something like seqrecord.seq .

is the .gbk.rtf in fasta format?

1 answer

Your list comprehension has created a list of SeqRecords, and you are going through all of the records and asking if each sequence is equal to "G". I think what you might be looking for is something like

print(seq[0].seq.count('g'))

Log in to answer this question.