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

Dear Monks, 1) I have a fasta raw sequence file which contains A,C,G,T charaters i +n a single string like this:- AAAAAAAAAAAAACTGCTGACTAGCATAGTTAAAAAAAAAAAAAAAAGTTTTTTTA.... 2) I want to create multiple fasta files using this file giving a user + defined range like :- Range of minimum length 10 and maximum length +of 40 suppose and then create short sequence in this range of 10 - 40 + without losing the original positional information randomly. 3) I mean my result should be like this from above >seq1 length 10 AAAAAAAAAA >seq2 length 18 AAACTGCTGACTAGCATA >seq3 length 28 GTTAAAAAAAAAAAAAAAAGTTTTTTTA ..... 4) How can I do this in perl. I need help fast. I would be obliged to get help from Monks.. Thanks..

Replies are listed 'Best First'.
Re: Random sequence creator with range
by ikegami (Patriarch) on Sep 17, 2008 at 03:20 UTC
    my $seq = ...; my $len = ...; die if $len > length($seq); my $start = rand( length($seq) - $len + 1 ); my $subseq = substr( $seq, $start, $len );

    I presume you know how to create and write to a file.

Re: Random sequence creator with range
by repellent (Priest) on Sep 17, 2008 at 03:38 UTC
    This creates files seq001, seq002, seq003, etc.
    perl -e '$file = "seq001"; for (@ARGV) { if (10 <= $_ && $_ <= 40) { r +ead STDIN, my $seq, $_; open my $FH, ">", $file++; print $FH $seq } } +' 10 18 28 < fasta.txt