<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Perl script to read multi fasta sequence one by one]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/36107/perl-script-to-read-multi-fasta-sequence-one-by-one?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/36107/perl-script-to-read-multi-fasta-sequence-one-by-one?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/36107/perl-script-to-read-multi-fasta-sequence-one-by-one</guid>
	<pubDate>Fri, 06 Apr 2018 09:01:17 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/36107/perl-script-to-read-multi-fasta-sequence-one-by-one</link>
	<title><![CDATA[Perl script to read multi fasta sequence one by one]]></title>
	<description><![CDATA[<code>#!/usr/bin/env perl

use strict;
use warnings;

#USAGE
#perl rohanRun.pl seq.fa
my $outfile=&#039;tmp.fa&#039;;
my $fastaSeq_ref = readfasta (&quot;$ARGV[0]&quot;);
my %fastaSeq = %$fastaSeq_ref;
foreach my $key ( keys %fastaSeq) {
open (OUT, &quot;&gt;$outfile&quot;) or die &quot;couldn&#039;t open the file $outfile $!&quot;;
print OUT &quot;$key\n$fastaSeq{$key}\n&quot;;

}


sub readfasta 
{
  (my $file)=@_;
	my %sequence;
	my $header;
	my $temp_seq;
	
	#suppose fasta files contains multiple sequences;
	 
	open (IN, &quot;&lt;$file&quot;) or die &quot;couldn&#039;t open the file $file $!&quot;;
	
	while (&lt;IN&gt;)
	{	
		chop;
		next if /^\s*$/; #skip empty line 
		if ($_ =~ /^&gt;/)  #when see head line
		{	
			$header= $_;
			if ($sequence{$header}){print colored(&quot;#CAUTION: SAME FASTA HAS BEEN READ MULTIPLE TIMES.\n#CAUTION: PLEASE CHECK FASTA SEQUENCE:$header\n&quot;,&quot;red&quot;)};
			if ($temp_seq) {$temp_seq=&quot;&quot;} # If there is alreay sequence in temp_seq, empty the sequence file
			
		}
		else # when see the sequence line 
		{
		   s/\s+//g;
		   $temp_seq .= $_;
		   $sequence{$header}=$temp_seq; #update the contents
		}
	
	}
	
	return \%sequence;
}</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>