Biopython: .count() method not working when importing DNA sequence
1
0
Entering edit mode
7.6 years ago
bnicholl66 • 0

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 • 2.4k views
ADD COMMENT
1
Entering edit mode

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?

ADD REPLY
0
Entering edit mode
7.6 years ago
Ben Fulton ▴ 150

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'))
ADD COMMENT

Login before adding your answer.

Traffic: 1661 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6