Last active
June 25, 2018 17:02
-
-
Save MattOates/b2ccabc6201daf9ddbd2cba8a29c5b80 to your computer and use it in GitHub Desktop.
Tools to encode and decode files as DNA sequence text assuming 2bit style byte encodings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
sub MAIN ($file) { | |
my %bases = (T => '00', C => '01', A => '10', G => '11'); | |
my %bytes = (0..255).map({ sprintf('%08d', $_.base(2)) }) Z=> (0..255); | |
my $io = $file.IO.open; | |
while (my $hunk = $io.readchars(4)) { | |
last unless $hunk.chars == 4; | |
print %bytes{$hunk.comb.map({%bases{$_}}).join}.chr; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
sub MAIN ($file) { | |
my %bases = (T => '00', C => '01', A => '10', G => '11').invert; | |
my %bytes = (0..255) Z=> (0..255).map({ sprintf('%08d', $_.base(2)) }); | |
my $io = $file.IO.open; | |
while (my $byte = $io.getc) { | |
print %bytes{$byte.ord}.comb.rotor(2).map({ %bases{$_.join} }).join; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example run of the tools
Then to decode the DNA looking string back to the original plain text