[Biopython] better way to reverse complement?
Peter
biopython at maubp.freeserve.co.uk
Wed Jun 24 19:20:20 EDT 2009
On Wed, Jun 24, 2009 at 11:36 PM, Cedar McKay<cmckay at u.washington.edu> wrote:
> Is there a more efficient way to write reverse complemented records to file
> than I use?
>
> I'm doing:
>
> record = SeqRecord(record.seq.reverse_complement(), record.name)
> out_handle.write(record.format('fasta'))
>
> Is there a way to write the record directly, while specifying that we want
> the reverse complement version? Would it be useful to allow methods of a
> record or sequence object to be applied during writing? Making a whole new
> record just because we want to write a reverse complement seems cumbersome.
What you are doing is fine - although personally I might wrap up the first
line as a function, as done in the tutorial:
http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec:SeqIO-reverse-complement
While we could add a reverse_complement() method to the SeqRecord
(and other Seq methods, like translate etc), there is one big problem:
What to do with the annotation. If your record used to have a name
based on an accession or a GI number, then this really does not apply
to the reverse complement (or a translation etc). We could do something
arbitrary like adding an "rc_" prefix (or variants) but I think the only safe
answer is to make the user think about this and do what is appropriate
in their context. And as you have demonstrated, this can still be done
in one line :)
I make a habit of using this as a justification, but I feel the zen of
Python "Explicit is better than implicit" applies quite well here.
Peter
More information about the Biopython
mailing list