reverse-complement PHP program
source code
<?php
#
# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# reverse complement in PHP
# contributed by Danny Sauer
#
# We'll need some definitions
define( 'LINE_LENGTH', 60 );
define( 'SRC', 'CGATMKRYVBHD');
define( 'DST', 'GCTAKMYRBVDH');
$str = '';
$seq = '';
# read in the file, a line at a time
while( !feof(STDIN) ) {
$str = trim(fgets(STDIN));
if( $str[0] == '>' ){
# if we're on a comment line, print the previous seq and move on
print_seq();
echo $str, "\n";
}else{
# otherwise, just append to the sequence
$seq .= $str;
}
}
print_seq();
exit;
# print the sequence out, if it exists
function print_seq(){
global $seq; # no time-consuming argument passing for us! :)
if($seq != ''){
echo wordwrap( strrev( strtr(strtoupper($seq), SRC, DST) ),
LINE_LENGTH, "\n", true ), "\n";
}
$seq = '';
}
?>
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
PHP 7.4.5 (cli) (built: May 11 2020 13:25:48) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Mon, 11 May 2020 22:31:03 GMT
COMMAND LINE:
/opt/src/php-7.4.5/bin/php -n -d memory_limit=3072M revcomp.php 0 < revcomp-input100000000.txt
(TRUNCATED) PROGRAM OUTPUT:
>ONE Homo sapiens alu
GGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCGC
CCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCAA
GCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCCC
GGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTCG
AACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGCG
TGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTG
CAGTGGCGC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