<?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 extract sequence by Ids from multifasta file !]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/37516/perl-script-to-extract-sequence-by-ids-from-multifasta-file?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/37516/perl-script-to-extract-sequence-by-ids-from-multifasta-file?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/37516/perl-script-to-extract-sequence-by-ids-from-multifasta-file</guid>
	<pubDate>Thu, 09 Aug 2018 10:39:27 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/37516/perl-script-to-extract-sequence-by-ids-from-multifasta-file</link>
	<title><![CDATA[Perl script to extract sequence by Ids from multifasta file !]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl -w

use strict;

my $idsfile = &quot;$ARGV[0]&quot;;
my $seqfile = &quot;$ARGV[1]&quot;;
my %ids  = ();

open FILE, $idsfile;
while(&lt;FILE&gt;) {
  chomp;
  $ids{$_} += 1;
}
close FILE;

local $/ = &quot;\n&gt;&quot;;  # read by FASTA record

open FASTA, $seqfile;
while (&lt;FASTA&gt;) {
    chomp;
    my $seq = $_;
    my ($id) = $seq =~ /^&gt;*(\S+)/;  # parse ID as first word in FASTA header
    if (exists($ids{$id})) {
        $seq =~ s/^&gt;*.+\n//;  # remove FASTA header
        $seq =~ s/\n//g;  # remove endlines
        print &quot;&gt;$id\n$seq\n&quot;;
    }
}
close FASTA;</code>]]></description>
	<dc:creator>Abhimanyu Singh</dc:creator>
</item>

</channel>
</rss>