<?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 fasta sequence by matching name/ids !!]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/27956/perl-script-to-extract-fasta-sequence-by-matching-nameids?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/27956/perl-script-to-extract-fasta-sequence-by-matching-nameids?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27956/perl-script-to-extract-fasta-sequence-by-matching-nameids</guid>
	<pubDate>Tue, 21 Jun 2016 09:28:19 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27956/perl-script-to-extract-fasta-sequence-by-matching-nameids</link>
	<title><![CDATA[Perl script to extract fasta sequence by matching name/ids !!]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use strict;
use warnings;
use Text::Trim qw(trim);

#Usage perl extractSeqbyID.pl ids.txt seq.fasta Result.fasta

$ARGV[2] or die &quot;use extractSeqbyID.pl LIST FASTA OUT\n&quot;;

my $list = shift @ARGV;
my $fasta = shift @ARGV;
my $out = shift @ARGV;
my %select;

open LINE, &quot;$list&quot; or die;
while (&lt;LINE&gt;) {
    chomp;
    next if /^\s*$/;
    s/&gt;//g; 
    my @ids=split (/\t/, $_);
    $select{$ids[0]} = 1;
}
my $size = keys %select;
print &quot;Total Ids $size\n&quot;;
close LINE;

$/ = &quot;\n&gt;&quot;;
open OUT, &quot;&gt;$out&quot; or die;
open FILE, &quot;$fasta&quot; or die;
while (&lt;FILE&gt;) {
    trim($_);
    s/&gt;//g;
    my ($id) = split (/\n/, $_);
    #my @i=split (/\s/, $id); # To avoid &gt;flattened_line_10751 circular cases
    print OUT &quot;&gt;$_&quot; if (defined $select{$id});
}
close FILE;
close OUT;</code>]]></description>
	<dc:creator>Surabhi Chaudhary</dc:creator>
</item>

</channel>
</rss>