Difference between revisions of "8. Randomly generate five 100 AA long protein sequences and store them in a FASTA file MJ"
From Biolecture.org
imported>Myeongji Park (Created page with "<h1>Idea</h1> <p>Using 'rand' and 'for' functions, I generate 5 different random sequences and store them in a text file.</p> <h1>Code</h1> <p>#!/usr/bin/perl<...") |
imported>Myeongji Park |
||
Line 10: | Line 10: | ||
<p>my @aminoacid=('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y');<br /> | <p>my @aminoacid=('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y');<br /> | ||
− | my $ | + | my @random_sequence;<br /> |
+ | my $amino;</p> | ||
<p>for(my$i = 1; $i <=5 ; $i++)<br /> | <p>for(my$i = 1; $i <=5 ; $i++)<br /> | ||
{<br /> | {<br /> | ||
print $i,".";<br /> | print $i,".";<br /> | ||
− | for(1 | + | for(my$n = 1; $n <= 100; $n++)<br /> |
{<br /> | {<br /> | ||
− | | + | $amino = $aminoacid[rand @aminoacid];<br /> |
− | + | @random_sequence[$n] = $amino;<br /> | |
− | |||
− | | ||
− | |||
− | |||
− | |||
};<br /> | };<br /> | ||
− | print "\n\n";<br /> | + | print @random_sequence[1..100], "\n\n";<br /> |
+ | open(FILE, ">>Randomsequences.txt");<br /> | ||
+ | print FILE @random_sequence[1..100], "\n";<br /> | ||
+ | close(FILE);<br /> | ||
};<br /> | };<br /> | ||
exit;</p> | exit;</p> |
Latest revision as of 04:35, 25 May 2017
Idea
Using 'rand' and 'for' functions, I generate 5 different random sequences and store them in a text file.
Code
#!/usr/bin/perl
use strict;
use warnings;
my @aminoacid=('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y');
my @random_sequence;
my $amino;
for(my$i = 1; $i <=5 ; $i++)
{
print $i,".";
for(my$n = 1; $n <= 100; $n++)
{
$amino = $aminoacid[rand @aminoacid];
@random_sequence[$n] = $amino;
};
print @random_sequence[1..100], "\n\n";
open(FILE, ">>Randomsequences.txt");
print FILE @random_sequence[1..100], "\n";
close(FILE);
};
exit;
Result
[[1]]