Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Selecting Random Sequence

by Sameet (Beadle)
on Apr 23, 2004 at 12:25 UTC ( [id://347584]=perlquestion: print w/replies, xml ) Need Help??

Sameet has asked for the wisdom of the Perl Monks concerning the following question:

Hi, actually, i am a biologist by training, and only recently have i become a fan of PERL. Now i want to write a program, which is download sequences from a given genome randomly. There was a way published in PNAS recently, where they concatenated all the chromosomes end to end, and considered it as a single chromosome. Used a random number generator to generate a number and then depending on position decided what chromosome it belonged and download the sequence from Human Genome Sequence database. Now I want to do exactly same thing, but i dont have a local copy of human genome database, so i need to go to the net and do it for each random number. Is there a way to do it. It will help me a great deal thanks

Replies are listed 'Best First'.
Re: Selecting Random Sequence
by matija (Priest) on Apr 23, 2004 at 12:35 UTC
    It's a bit hard to help you since you don't give details on what URLs are needed to fetch the parts of human genome, but I think LWP::Simple and LWP::UserAgent should help you with that.
      using LWP::Simple and LWP::UserAgent, is fine, but the URL changes with each chromosme and the region of each chromosome! Is there a way around
        The changes in the URL are most likely somewhat regular. If you can figure out the rule, adjusting the script as needed to transform the random number into the URL.

        But since you didn't post any examples, it's a bit hard for us to help you.

Re: Selecting Random Sequence
by thor (Priest) on Apr 23, 2004 at 12:45 UTC
    Which part are you having problems with: the "random number" part, or the "fetch it from the web" part? With a little more guidance, we should be able to help you.

    thor

        Okay...that's a start. First, let's cover the "random sequence" part. I'll make some assumptions here, as I don't really have a lot to go on. I'll assume that you have your data in a single string (I'll call it $super). So, in order to get a "random sequence", there are two elements of randomness that we have the ability to introduce: length and starting position. I'll try to incorporate both.
        my $start = int(rand(length($super))); my $length = int(rand(length($super) - $start)) + 1; my $substring = substr($super, $start, $length);
        Of course, you could make either $start or $length static by just assigning a value to them.
        Now, on the the fetching part. Once you have all of the appropriate values for the variable in your URL, fetching it is not so bad:
        use LWP::Simple; getstore($url, $localfile);
        If I can elaborate any further, let me know how and I'll do my best.

        thor

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://347584]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found