Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- # usage: script.pl {motif_width} {dnafile}
- my $width = shift(@ARGV);
- my $dna;
- while (<>) {
- next if /^[#>]/;
- $dna .= $_;
- }
- $dna =~ s/[\s\d]//g;
- # Initialize counts for motif positions
- my %mot = map { $_ => [ (0) x $width ] } qw( A C G T );
- # Initialize background counts
- my %bg = map { $_ => 0 } qw( A C G T );
- # Generate random start site in the sequence
- # for motif to start from
- my $ms = int(rand(length($dna)-$width));
- # Within a motif, count the bases at the positions
- for my $pos (0..length($dna)-1) {
- my $base = substr($dna, $pos, 1);
- if ($pos >= $ms && $pos < $ms + $width) {
- ++$mot{$base}[$pos-$ms]
- if exists($mot{$base});
- } else {
- ++$bg{$base}
- if exists($bg{$base});
- }
- }
- for my $base (qw( A C G T )) {
- print "$base @{$mot{$base}}\n";
- }
- print "\n";
- for my $base (qw( A C G T )) {
- print "bg$base = $bg{$base}\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement