Skip to content

Language Shootout

A user-supported site Fastest, Shortest, Simplest

Benchmarks

Reverse Complement

Background

By knowing the sequence of bases of one strand of DNA we immediately know the sequence of the DNA strand which will bind to it, this strand is called the reverse complement.

How to implement

We ask that contributed programs not only give the correct result, but also use the same algorithm to calculate that result.

Each program should:

  • Read line-by-line a redirected FASTA format file from stdin
  • For each sequence:
    • Write the id, description, and the reverse-complement sequence in FASTA format to stdout

Use these code complements:

code    meaning           complement
A       A                 T
C       C                 G
G       G                 C
T/U     T                 A
M       A or C            K
R       A or G            Y
W       A or T            W
S       C or G            S
Y       C or T            R
K       G or T            M
V       A or C or G       B
H       A or C or T       D
D       A or G or T       H
B       C or G or T       V
N       G or A or T or C  N

Verification: Use diff to compare program output with the reference output file.

Use a larger input file (generated with the fasta program with command line arguments: 25000000) to check program performance.

Times are wall-clock milliseconds, with this implementation’s hello-world startup time subtracted. gz is the source in bytes with comments removed and gzipped. style is the idiomatic-code score. Click a heading to sort.

# source ms cpu ms mem KB gz style by
1 Python CPython #1 1,525.5 1,512.6 1,008,684 335 ★★★★☆ sysop-
2 PHP #1 1,094.0 993.6 394,136 310 ★★★★☆ sysop-
3 Object Pascal FPC #1 486.7 464.1 131,952 805 ★★★☆☆ sysop-
4 Java Temurin #1 387.5 872.4 383,052 1,622 ★★★☆☆ sysop-