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=(&#39;A&#39;,&#39;C&#39;,&#39;D&#39;,&#39;E&#39;,&#39;F&#39;,&#39;G&#39;,&#39;H&#39;,&#39;I&#39;,&#39;K&#39;,&#39;L&#39;,&#39;M&#39;,&#39;N&#39;,&#39;P&#39;,&#39;Q&#39;,&#39;R&#39;,&#39;S&#39;,&#39;T&#39;,&#39;V&#39;,&#39;W&#39;,&#39;Y&#39;);<br />
 
<p>my @aminoacid=(&#39;A&#39;,&#39;C&#39;,&#39;D&#39;,&#39;E&#39;,&#39;F&#39;,&#39;G&#39;,&#39;H&#39;,&#39;I&#39;,&#39;K&#39;,&#39;L&#39;,&#39;M&#39;,&#39;N&#39;,&#39;P&#39;,&#39;Q&#39;,&#39;R&#39;,&#39;S&#39;,&#39;T&#39;,&#39;V&#39;,&#39;W&#39;,&#39;Y&#39;);<br />
my $random_sequence;</p>
+
my @random_sequence;<br />
 +
my $amino;</p>
  
 
<p>for(my$i = 1; $i &lt;=5 ; $i++)<br />
 
<p>for(my$i = 1; $i &lt;=5 ; $i++)<br />
 
{<br />
 
{<br />
 
&nbsp; &nbsp; print $i,&quot;.&quot;;<br />
 
&nbsp; &nbsp; print $i,&quot;.&quot;;<br />
&nbsp; &nbsp; for(1..100)<br />
+
&nbsp; &nbsp; for(my$n = 1; $n &lt;= 100; $n++)<br />
 
&nbsp; &nbsp; {<br />
 
&nbsp; &nbsp; {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</p>
+
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$amino = $aminoacid[rand @aminoacid];<br />
 
+
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;@random_sequence[$n] = $amino;<br />
<p>&nbsp; &nbsp; &nbsp; &nbsp; $random_sequence = $aminoacid[rand @aminoacid];<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print $random_sequence;<br />
 
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; print FILE &quot;$random_sequence&quot;;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; close(FILE);<br />
 
 
&nbsp;&nbsp; &nbsp;};<br />
 
&nbsp;&nbsp; &nbsp;};<br />
&nbsp;&nbsp; &nbsp;print &quot;\n\n&quot;;<br />
+
&nbsp;&nbsp; &nbsp;print @random_sequence[1..100], &quot;\n\n&quot;;<br />
 +
&nbsp;&nbsp; &nbsp;open(FILE, &quot;&gt;&gt;Randomsequences.txt&quot;);<br />
 +
&nbsp;&nbsp; &nbsp;print FILE @random_sequence[1..100], &quot;\n&quot;;<br />
 +
&nbsp;&nbsp; &nbsp;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]]