reverse_complement on mutated sequence Biopython
1
0
Entering edit mode
7.3 years ago

Hi Biostars,

When I you use reverse_complement() from Biopython to a mutated sequence made by SeqIO I get None.

For example

rev_comp=record.seq.reverse_complement()
print rev_comp

Above code works well. But

sequence=record.seq.tomutable()
reverse_seq=sequence.reverse_complement()
print reverse_seq

prints "None"

How could I change this behaviour?

Thanks

biopython reverse_complement • 1.7k views
ADD COMMENT
0
Entering edit mode

Unlike normal python strings and our basic sequence object (the Seq class) which are immutable, the MutableSeq lets you edit the sequence in place

You're not actually "mutating" the sequence.

ADD REPLY
2
Entering edit mode
7.3 years ago

The method reverse_complement() executed on mutable sequence, reverse the sequence in place and returns None value, so you shouldn't assign it to a variable.

For example:

from Bio.Seq import Seq

seq = Seq("ACGTTGCAC")
mutseq = seq.tomutable()
mutseq.reverse_complement()
print(mutseq)                                        # GTGCAACGT

If you want your reversed sequence to be assigned to a variable you can use reverse_complement() function, instead of the method.

from Bio.Seq import Seq
from Bio.Seq import reverse_complement

seq = Seq("ACGTTGCAC")
mutseq = seq.tomutable()
reverse_seq = reverse_complement(mutseq)
print(reverse_seq)                               # GTGCAACGT
ADD COMMENT
0
Entering edit mode

Beautiful! Thank you!

ADD REPLY

Login before adding your answer.

Traffic: 1830 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