Fast reverse complement computation of DNA sequences without string concatenation loops

Arguments on why string concatenation loops (SCL) is a bad programming practice were given in a previous post.

You can also google for additional arguments against SCL.

We now show a simple PHP code that makes unnecessary SCL when computing DNA reverse complement sequences. Consider the sequence


This sequence corresponds to the first 21 nucleotides of the NCBI Reference Sequence NC_045512.2; i.e., to the first 21 nts of the complete genome of the severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1 ( ).

To compute its reverse complement sequence,


we just need to use the following one-liner:

echo strrev(strtr(‘ATTAAAGGTTTATACCTTCCC’, ‘ACGT’, ‘TGCA’));


No string splitting, concatenation, or looping are needed!

As I always say, graduate students and postdocs who can code have and edge in multidisciplinary research work over those that cannot code.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s