Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Shuffling codons

by hippo (Bishop)
on Jun 07, 2018 at 13:29 UTC ( [id://1216104]=note: print w/replies, xml ) Need Help??


in reply to Shuffling CODONS

It's an FAQ!

I am uncapable of installing the list utils

List::Util is in core and has been since 5.7.3 so you probably don't even need to install it. Either way, I'd tackle this problem (module installation) if I were in your shoes as fixing it will solve many more problems that just the one in your post.

In what way are you incapable of installing it?

Replies are listed 'Best First'.
Re^2: Shuffling codons
by WouterVG (Novice) on Jun 07, 2018 at 13:44 UTC

    Thanks for your reply. I know it is an FAQ, That's where I got the Fisher Yates option from, But unable to correctly implement it in my code..

    If I try the list util it doesnt work... My code looks like this

    print "enter sequence and signal end with enter followed by ctrl d\n"; $sequence = <STDIN>; chomp $sequence; print "sequence inserted : $sequence\n"; @trips = unpack("a3" x (length($sequence)-2), $sequence); @trips = join(" ", @trips); use List::Util 'shuffle'; @shuffled = shuffle(@trips); print "@shuffled\n";

    What is wrong/missing here?

    I am incapable of installing the list::utils, I wouldn't know where to unpack them and how to properly install and run them. Do they need to be situated somewhere. I am on perl v5.18.2, so the list utils should already be there you mention?

    How would I implement the fisher Yates algorithm correctly?

      perl v5.18.2 came after perl v5.7.3, so yes, it should be installed for you. However, the name is List::Util, not list::utils. The following shows that list::utils doesn't exist, but that List::Util exists and has been in core since v5.7.3:

      pryrt@debianvm:~$ perl -Mlist::utils -le 'print "OK"' Can't locate list/utils.pm in @INC (you may need to install the list:: +utils module) (@INC contains: ./blib/lib /home/pryrt/perl5/perlbrew/p +erls/perl-5.20.3/lib/site_perl/5.20.3/i686-linux /home/pryrt/perl5/pe +rlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3 /home/pryrt/perl5/perlb +rew/perls/perl-5.20.3/lib/5.20.3/i686-linux /home/pryrt/perl5/perlbre +w/perls/perl-5.20.3/lib/5.20.3 .). BEGIN failed--compilation aborted. pryrt@debianvm:~$ perl -MList::Util -le 'print "OK"' OK pryrt@debianvm:~$ corelist List::Util Data for 2015-09-12 List::Util was first released with perl v5.7.3

      ... Besides, if your example code, which included use List::Util 'shuffle'; compiled at all, then you already knew you had it installed properly.

      Oh, there, that's what you're doing wrong: @trips = join(" ", @trips);. You just replaced the contents of the @trips array with a single value, which is a string which joins all the old elements of @trips with a space. I think what you want is more akin to:

      #!/usr/bin/env perl use warnings; use strict; print "enter sequence and signal end with enter followed by ctrl d\n"; my $sequence = <STDIN>; chomp $sequence; print "sequence inserted : $sequence\n"; my @trips = unpack("a3" x (length($sequence)-2), $sequence); local $" = ", "; print "unshuffled: (@trips)\n"; use List::Util 'shuffle'; my @shuffled = shuffle(@trips); print "shuffled: (@shuffled)\n"; __END__
      __RESULTS__ enter sequence and signal end with enter followed by ctrl d GATTACCAT sequence inserted : GATTACCAT unshuffled: (GAT, TAC, CAT, , , , ) shuffled: (, , GAT, TAC, CAT, , )
      If I try the list util it doesnt work

      Not enough information there. Error message? Segfault? Compilation error?

      What is wrong/missing here?

      This line:

      @trips = join(" ", @trips);

      ruins it. What do you understand this line to be doing? Without it I get at least some shuffling which may or may not be what you want:

      #!/usr/bin/env perl use strict; use warnings; use List::Util 'shuffle'; print "enter sequence and signal end with enter followed by ctrl d\n"; my $sequence = <STDIN>; chomp $sequence; print "sequence inserted : $sequence\n"; my @trips = unpack("a3" x (length($sequence)-2), $sequence); my @shuffled = shuffle(@trips); print "@shuffled\n";

      which gives:

      $ perl /tmp/shuf.pl enter sequence and signal end with enter followed by ctrl d aaabbbcccddd sequence inserted : aaabbbcccddd ccc aaa ddd bbb
      I am on perl v5.18.2, so the list utils should already be there you mention?

      Yes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216104]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found