<?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: Extract fasta sequence from a multifasta file with fasta header Ids]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/33511/extract-fasta-sequence-from-a-multifasta-file-with-fasta-header-ids?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/33511/extract-fasta-sequence-from-a-multifasta-file-with-fasta-header-ids?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/33511/extract-fasta-sequence-from-a-multifasta-file-with-fasta-header-ids</guid>
	<pubDate>Tue, 13 Jun 2017 07:49:37 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/33511/extract-fasta-sequence-from-a-multifasta-file-with-fasta-header-ids</link>
	<title><![CDATA[Extract fasta sequence from a multifasta file with fasta header Ids]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use strict;
use warnings;

#Usage: perl &lt;list_of_ids_one_per_line&gt; &lt;fasta&gt; &lt;outfile&gt;

my $list = shift @ARGV;
my $fasta = shift @ARGV;
my $out = shift @ARGV;
my %select;

open LIST, &quot;$list&quot; or die;
while (&lt;LIST&gt;) {
    chomp;
    s/&gt;//g;
    $select{$_} = 1;
}
close LIST;

$/ = &quot;\n&gt;&quot;;
open OUT, &quot;&gt;$out&quot; or die;
open FASTA, &quot;$fasta&quot; or die;
while (&lt;FASTA&gt;) {
    s/&gt;//g;
    my ($id) = split (/\n/, $_);
    print OUT &quot;&gt;$_&quot; if (defined $select{$id});
}
close FASTA;
close OUT;</code>]]></description>
	<dc:creator>Abhimanyu Singh</dc:creator>
</item>
<item>
	<guid isPermaLink='true'>https://bioinformaticsonline.com/snippets/view/33511/extract-fasta-sequence-from-a-multifasta-file-with-fasta-header-ids#item-annotation-3583</guid>
	<pubDate>Mon, 11 Feb 2019 06:07:39 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/33511/extract-fasta-sequence-from-a-multifasta-file-with-fasta-header-ids#item-annotation-3583</link>
	<title><![CDATA[Comment by Rahul Nayak]]></title>
	<description><![CDATA[<pre>perl -ne 'if(/^&gt;(\S+)/){$c=grep{/^$1$/}qw(id1 id2)}print if $c' fasta.file</pre>
<p>If you have a large number of sequences that you want to extract, then you most likely have the sequence identifiers in a separate file. Assuming that you have one sequence identifier per line in the file ids.file, then you can use this one line:</p>
<pre>perl -ne 'if(/^&gt;(\S+)/){$c=$i{$1}}$c?print:chomp;$i{$_}=1 if @ARGV' ids.file fasta.file</pre>]]></description>
	<dc:creator>Rahul Nayak</dc:creator>
</item>

</channel>
</rss>