File Coverage

blib/lib/DNA.pm
Criterion Covered Total %
statement 48 48 100.0
branch 8 10 80.0
condition n/a
subroutine 8 8 100.0
pod 0 6 0.0
total 64 72 88.8


line stmt bran cond sub pod time code
1             package DNA;
2              
3 1     1   879 use strict;
  1         2  
  1         40  
4 1     1   7 use vars qw($VERSION);
  1         2  
  1         3003  
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 = )) {
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             sub mutate {
38 847     847 0 3052 my $na = shift;
39 847 100       4422 $na = join '', map $Acids[rand @Acids], 1..4 unless int rand 1000;
40 847         3313 return $na;
41             }
42              
43             sub ascii_to_na {
44 389     389 0 748 my $ascii = ord shift;
45 389         520 my $na = '';
46              
47 389         499 for (1..4) {
48 1556         2628 $na .= $Acids[$ascii % 4];
49 1556         2499 $ascii = $ascii >> 2;
50             }
51              
52 389         1272 $na = mutate($na);
53              
54 389         3568 return $na;
55             }
56              
57             sub na_to_ascii {
58 69     69 0 111 my $na = mutate(shift);
59 69         83 my $ascii = 0;
60 69         914 for my $chr (0..3) {
61 276         509 $ascii += $Acids{ substr($na, $chr, 1) } * (4 ** $chr);
62             }
63              
64 69         413 return chr $ascii;
65             }
66              
67             my $Acids = join '', @Acids;
68             $Acids = "[$Acids]";
69             sub devolve {
70 1     1 0 10 my $code = shift;
71 1         3 my $idx = 0;
72 1         2 my $perl = '';
73 1         29 while( $code =~ /($Acids{4})/g ) {
74 389         500 my $segment = $idx++ % 96;
75 389 100       4911 next if $segment >= 16;
76 69         110 $perl .= na_to_ascii($1);
77             }
78              
79 1         5 return $perl;
80             }
81              
82             sub evolutionary_junk {
83 20     20 0 38 my $junk = join ' ', map { ascii_to_na(int rand 256) } 0..(75/5);
  320         707  
84             }
85              
86             sub evolve {
87 1     1 0 3 my $code = shift;
88 1         2 my $idx = 0;
89 1         4 my $chromosome = '';
90 1         5 for my $idx (0..length($code) - 1) {
91 69         95 my $chr = substr($code, $idx, 1);
92 69         92 $chromosome .= ascii_to_na($chr). " ";
93 69 100       234 unless( ($idx + 1) % (80 / 5) ) {
94 4         6 chop $chromosome;
95 4         5 $chromosome .= "\n";
96 4         8 for(1..5) {
97 20         34 $chromosome .= evolutionary_junk()."\n";
98             }
99             }
100             }
101            
102 1 50       154 open HOST, ">$0" or
103             die "Cannot complete genetic encoding! ".
104             "Alert the Human Genome Project!\n";
105              
106 1 50       7 print HOST "$shebang\n" if length $shebang;
107 1         20 print HOST "use DNA;\n\n";
108 1         3 print HOST $chromosome, "\n\n";
109 1         4 print HOST $pod;
110 1         66 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, L, L, L, a good psychiatrist.
205              
206              
207             =head1 AUTHOR
208              
209             Michael G Schwern
210              
211             =cut
212              
213             1;