| 1 | package DNA; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | $VERSION = '0.03'; | ||||||||||
| 6 | |||||||||||
| 7 | my $i = 0; | ||||||||||
| 8 | my @Acids = qw(A T C G); | ||||||||||
| 9 | my %Acids = map { $_ => $i++ } @Acids; | ||||||||||
| 10 | open HOST, "$0" or die "Genetic resequencing failed: $!"; | ||||||||||
| 11 | |||||||||||
| 12 | my($code, $pod, $shebang) = ('', '', ''); | ||||||||||
| 13 | my($inpod) = 0; | ||||||||||
| 14 | my $line; | ||||||||||
| 15 | while(defined($line = <HOST>)) { | ||||||||||
| 16 | if( $. == 1 and $line =~ /^\#!/ ) { | ||||||||||
| 17 | $shebang = $line; | ||||||||||
| 18 | } | ||||||||||
| 19 | elsif( $line =~ /^=cut/ ) { | ||||||||||
| 20 | $inpod = 0; | ||||||||||
| 21 | } | ||||||||||
| 22 | elsif( $line =~ /^=\w+/ ) { | ||||||||||
| 23 | $pod .= $line; | ||||||||||
| 24 | $inpod = 1; | ||||||||||
| 25 | } | ||||||||||
| 26 | else { | ||||||||||
| 27 | if( $inpod ) { | ||||||||||
| 28 | $pod .= $line; | ||||||||||
| 29 | } else { | ||||||||||
| 30 | $code .= $line; | ||||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | close HOST; | ||||||||||
| 36 | |||||||||||
| 37 | 847 | ▶ | sub mutate { | ||||||||
|
Subroutine
mutate: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 38 | 847 | my $na = shift; | |||||||||
| 39 | 847 | ▶ | $na = join '', map $Acids[rand @Acids], 1..4 unless int rand 1000; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 847 | return $na; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 389 | ▶ | sub ascii_to_na { | ||||||||
|
Subroutine
ascii_to_na: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 389 | my $ascii = ord shift; | |||||||||
| 45 | 389 | my $na = ''; | |||||||||
| 46 | |||||||||||
| 47 | 389 | for (1..4) { | |||||||||
| 48 | 1556 | $na .= $Acids[$ascii % 4]; | |||||||||
| 49 | 1556 | $ascii = $ascii >> 2; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 389 | $na = mutate($na); | |||||||||
| 53 | |||||||||||
| 54 | 389 | return $na; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 69 | ▶ | sub na_to_ascii { | ||||||||
|
Subroutine
na_to_ascii: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 69 | my $na = mutate(shift); | |||||||||
| 59 | 69 | my $ascii = 0; | |||||||||
| 60 | 69 | for my $chr (0..3) { | |||||||||
| 61 | 276 | $ascii += $Acids{ substr($na, $chr, 1) } * (4 ** $chr); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 69 | return chr $ascii; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | my $Acids = join '', @Acids; | ||||||||||
| 68 | $Acids = "[$Acids]"; | ||||||||||
| 69 | 1 | ▶ | sub devolve { | ||||||||
|
Subroutine
devolve: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 70 | 1 | my $code = shift; | |||||||||
| 71 | 1 | my $idx = 0; | |||||||||
| 72 | 1 | my $perl = ''; | |||||||||
| 73 | 1 | ▶ | while( $code =~ /($Acids{4})/g ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 389 | my $segment = $idx++ % 96; | |||||||||
| 75 | 389 | ▶ | next if $segment >= 16; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 69 | $perl .= na_to_ascii($1); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 1 | return $perl; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 20 | ▶ | sub evolutionary_junk { | ||||||||
|
Subroutine
evolutionary_junk: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 83 | 20 | my $junk = join ' ', map { ascii_to_na(int rand 256) } 0..(75/5); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 1 | ▶ | sub evolve { | ||||||||
|
Subroutine
evolve: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||
| 87 | 1 | my $code = shift; | |||||||||
| 88 | 1 | my $idx = 0; | |||||||||
| 89 | 1 | my $chromosome = ''; | |||||||||
| 90 | 1 | for my $idx (0..length($code) - 1) { | |||||||||
| 91 | 69 | my $chr = substr($code, $idx, 1); | |||||||||
| 92 | 69 | $chromosome .= ascii_to_na($chr). " "; | |||||||||
| 93 | 69 | ▶ | unless( ($idx + 1) % (80 / 5) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 4 | chop $chromosome; | |||||||||
| 95 | 4 | $chromosome .= "\n"; | |||||||||
| 96 | 4 | for(1..5) { | |||||||||
| 97 | 20 | $chromosome .= evolutionary_junk()."\n"; | |||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 1 | ▶ | open HOST, ">$0" or | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | die "Cannot complete genetic encoding! ". | ||||||||||
| 104 | "Alert the Human Genome Project!\n"; | ||||||||||
| 105 | |||||||||||
| 106 | 1 | ▶ | print HOST "$shebang\n" if length $shebang; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 1 | print HOST "use DNA;\n\n"; | |||||||||
| 108 | 1 | print HOST $chromosome, "\n\n"; | |||||||||
| 109 | 1 | print HOST $pod; | |||||||||
| 110 | 1 | close HOST; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | if( $code =~ s/^use DNA;\n\n(?=[ATCG]{4})//sm ) { | ||||||||||
| 114 | $code =~ s/($Acids{4})/mutate($1)/ge; | ||||||||||
| 115 | my $perl = devolve($code); | ||||||||||
| 116 | evolve($perl); | ||||||||||
| 117 | eval $perl; | ||||||||||
| 118 | } | ||||||||||
| 119 | elsif( $code =~ s/(use|require)\s+DNA\s*;\n//sm ) { | ||||||||||
| 120 | evolve($code); | ||||||||||
| 121 | eval $code; | ||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | exit; | ||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | =head1 NAME | ||||||||||
| 128 | |||||||||||
| 129 | DNA - Encodes your Perl program into an Nucleic Acid sequence | ||||||||||
| 130 | |||||||||||
| 131 | =head1 SYNOPSIS | ||||||||||
| 132 | |||||||||||
| 133 | use DNA; | ||||||||||
| 134 | |||||||||||
| 135 | CCAA CCAA AAGT CAGT TCCT CGCT ATGT AACA CACA TCTT GGCT TTGT AACA GTGT TCCT AGCT | ||||||||||
| 136 | CAGA TAGA ACGA TAGA TAGA CAGA TAGA CAGA CAGA CAGA TAGA CAGA CAGA CAGA TAGA ATGA | ||||||||||
| 137 | TAGA TAGA GTGA CAGA TAGA CTGA CAGA TAGA CAGA CAGA CAGA TAGA TTGA CAGA TAGA CTGA | ||||||||||
| 138 | TAGA CAGA CTGA TAGA TCGA CTGA ATGA TAGA TAGA TAGA CAGA TAGA ACGA TAGA ACGA TAGA | ||||||||||
| 139 | TAGA TAGA TAGA TAGA TAGA TAGA CTGA CAGA CAGA TTGA TAGA CAGA ATGA CAGA TAGA TAGA | ||||||||||
| 140 | GAGA TAGA GTGA CAGA CAGA GTGA TAGA TAGA TTGA TAGA CAGA TAGA CAGA TCGA TTGA CAGA | ||||||||||
| 141 | AGCT AACA TACT AGCT AGCT AACA TTGT GAGT TTCT AACA GTTT TCCT CGCT ATCT GGCT GTGT | ||||||||||
| 142 | CAGA CAGA TAGA TAGA GAGA TAGA TAGA GAGA TAGA CAGA TAGA GTGA GTGA TAGA GTGA GAGA | ||||||||||
| 143 | ATGA TAGA TAGA CAGA TAGA TAGA CAGA TAGA TAGA CAGA TAGA CAGA TAGA CAGA TAGA TAGA | ||||||||||
| 144 | TAGA CAGA CTGA GAGA CAGA TCGA GTGA TAGA ATGA TAGA TAGA CAGA ATGA TAGA TTGA TAGA | ||||||||||
| 145 | CAGA TAGA TAGA TAGA CAGA CAGA TAGA TAGA ATGA CTGA TAGA ATGA TAGA ATGA ATGA TAGA | ||||||||||
| 146 | TAGA TAGA TAGA TAGA CAGA TAGA CAGA TAGA TAGA CAGA TAGA ACGA ACGA TAGA CAGA TAGA | ||||||||||
| 147 | GAGT TACA AGTT CGCT CACA GCGA CCAA CCAA | ||||||||||
| 148 | |||||||||||
| 149 | |||||||||||
| 150 | =head1 DESCRIPTION | ||||||||||
| 151 | |||||||||||
| 152 | So you say you're a rabid Perl programmer? You've got a Camel | ||||||||||
| 153 | tattooed on your arm. You took your wife to TPC for your second | ||||||||||
| 154 | honeymoon. But you're worried about your children, they might not be | ||||||||||
| 155 | such devoted Perl addicts. How do you guarantee the continuation of | ||||||||||
| 156 | the line? Until now, there was no solution (what, do you think they | ||||||||||
| 157 | teach Perl in school?!) | ||||||||||
| 158 | |||||||||||
| 159 | Through the magic of Gene Splicing, now you can encode your very genes | ||||||||||
| 160 | with the essense of Perl! Simply take your best one-liner, encode it | ||||||||||
| 161 | with this nifty DNA module and head on down to your local sperm bank | ||||||||||
| 162 | and have them inject that sucker in. | ||||||||||
| 163 | |||||||||||
| 164 | |||||||||||
| 165 | As the encoding of programs on bacterial DNA will soon revolutionize | ||||||||||
| 166 | the data storage industry, I'm downloading the necessary forms from | ||||||||||
| 167 | the US patent office as I write. Imagine, all of CPAN on an airborne | ||||||||||
| 168 | bacteria. You can breathe Perl code! | ||||||||||
| 169 | |||||||||||
| 170 | |||||||||||
| 171 | When you use the DNA module on your code, the first time through it | ||||||||||
| 172 | will convert your code into a series of DNA sequences. Of course, | ||||||||||
| 173 | most of the DNA is simply junk. We're not sure why... someone spilled | ||||||||||
| 174 | coffee on the documentation. | ||||||||||
| 175 | |||||||||||
| 176 | There's also a slight chance on each use that a mutation will | ||||||||||
| 177 | occur... or maybe its a bug in perl, we're not sure. Of course, this | ||||||||||
| 178 | means your code may suddenly fall over dead... but you made a few | ||||||||||
| 179 | million copies, right? | ||||||||||
| 180 | |||||||||||
| 181 | POD will, of course, be preserved. God made the mistake of not | ||||||||||
| 182 | writing docs, and look at all the trouble we've had to go through to | ||||||||||
| 183 | figure out his code! | ||||||||||
| 184 | |||||||||||
| 185 | |||||||||||
| 186 | =head1 NOTES | ||||||||||
| 187 | |||||||||||
| 188 | The tests are encoded in DNA! But it sometimes introduces bugs... oh | ||||||||||
| 189 | dear. | ||||||||||
| 190 | |||||||||||
| 191 | As Steve Lane pointed out, it would be better to group them into | ||||||||||
| 192 | groups of three rather than four, as this makes a codon. However, | ||||||||||
| 193 | that means I can only get 6 bits on one group, and God didn't have to | ||||||||||
| 194 | work with high ASCII. | ||||||||||
| 195 | |||||||||||
| 196 | |||||||||||
| 197 | =head1 BUGS | ||||||||||
| 198 | |||||||||||
| 199 | There were only a few flipper babies. | ||||||||||
| 200 | |||||||||||
| 201 | |||||||||||
| 202 | =head1 SEE ALSO | ||||||||||
| 203 | |||||||||||
| 204 | L<Sex>, L<Morse>, L<Bleach>, L<Buffy>, a good psychiatrist. | ||||||||||
| 205 | |||||||||||
| 206 | |||||||||||
| 207 | =head1 AUTHOR | ||||||||||
| 208 | |||||||||||
| 209 | Michael G Schwern <schwern@pobox.com> | ||||||||||
| 210 | |||||||||||
| 211 | =cut | ||||||||||
| 212 | |||||||||||
| 213 | 1; | ||||||||||