Difference between revisions of "5) Extracting a sequence MKKTGIKG from ASMKATAHQMKKTGIKGMSTYALLRL"

From Biolecture.org
imported>S
(Created page with "<p><span style="font-size:14px"><strong>There is given sequence, and if there is MKKTGIKG in sequence, it will match and print it to the new "output.txt" file.</strong>...")
 
imported>S
 
Line 1: Line 1:
<p><span style="font-size:14px"><strong>There is given sequence, and if there is MKKTGIKG in sequence, it will match and print it to the new &quot;output.txt&quot; file.</strong></span> &nbsp;</p>
+
<p><span style="font-size:14px"><strong>There is a given sequence, and this script can extract &quot;MKKTGIKG&quot; from the&nbsp;sequence and print it&nbsp;to the new &quot;output.txt&quot; file.</strong></span> &nbsp;</p>
  
 
<p><span style="font-size:14px">#!/usr/bin/perl<br />
 
<p><span style="font-size:14px">#!/usr/bin/perl<br />
 
&nbsp;use strict;<br />
 
&nbsp;use strict;<br />
 
&nbsp;use warnings;<br />
 
&nbsp;use warnings;<br />
&nbsp;open(<strong>OUT</strong>, &quot;&gt;output.txt&quot;) or die &quot;Can&#39;t open file $_\n&quot;; &nbsp; &nbsp; &nbsp;##it creates new text file<br />
+
<strong>&nbsp;open(OUT, &quot;&gt;output.txt&quot;)</strong> or die &quot;Can&#39;t open file $_\n&quot;;<br />
&nbsp;my <strong>$seq</strong> =&quot;ASMKATAHQMKKTGIKGMSTYALLRL&quot;;<br />
+
&nbsp;my $seq =&quot;ASMKATAHQMKKTGIKGMSTYALLRL&quot;;<br />
&nbsp;if (<strong> $seq =~ /(MKKTGIKG)</strong>/){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##finding particular&nbsp;matchings in a scalar variable<br />
+
&nbsp;print &nbsp;OUT &quot;Original sequence: $seq\n&quot;;<br />
&nbsp;<strong>print OUT &quot;$1\n&quot;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##$1 means matched item in a parenthesis</strong><br />
+
<strong>$seq =~ s/MKKTGIKG//g;</strong><br />
}<br />
+
&nbsp;print OUT &quot;After extraction: $seq\n&quot;;</span></p>
&nbsp;else { print OUT $seq;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##if there is no match, will print out original sequence</span><br />
+
 
&nbsp;</p>
+
<p>-----------------------------------------------------</p>
 +
 
 +
<p><strong>The output file content:</strong></p>
 +
 
 +
<p>Original sequence: ASMKATAHQMKKTGIKGMSTYALLRL<br />
 +
After extraction: ASMKATAHQMSTYALLRL</p>
 +
 
 +
<p>&nbsp;</p>

Latest revision as of 16:07, 11 June 2017

There is a given sequence, and this script can extract "MKKTGIKG" from the sequence and print it to the new "output.txt" file.  

#!/usr/bin/perl
 use strict;
 use warnings;
 open(OUT, ">output.txt") or die "Can't open file $_\n";
 my $seq ="ASMKATAHQMKKTGIKGMSTYALLRL";
 print  OUT "Original sequence: $seq\n";
$seq =~ s/MKKTGIKG//g;
 print OUT "After extraction: $seq\n";

-----------------------------------------------------

The output file content:

Original sequence: ASMKATAHQMKKTGIKGMSTYALLRL
After extraction: ASMKATAHQMSTYALLRL