<p>I want to extract some sequences using ID from a multifasta file. </p>

<p>Using perl is not possible because it gave an error when indexing the database. Maybe because of it's size? Is there any way to this differently? thanks for your help!</p>

<p>How about <code>samtools faidx</code>?  It seems to be less well-known, but I think it should work for you.</p>

<p>If you have these reads in <code>test.fa</code>:</p>

<pre><code>&gt;one
AAAAA
&gt;two
CCCCC
&gt;three
GGGGG
</code></pre>

<p>Then just run:</p>

<pre><code>samtools faidx test.fa
</code></pre>

<p>This will create an index file that will allow you to do sublinear queries for each name lookup (faster than the awk/grep solutions above and easier than rolling your own script).</p>

<p>For example:</p>

<pre><code>samtools faidx test.fa two
</code></pre>

<p>Will output:</p>

<pre><code>&gt;two
CCCCC
</code></pre>

<p>It works for multiple regions (<code>samtools faidx test.fa one two three</code>) and that lets you play tricks like:</p>

<pre><code>xargs samtools faidx test.fa &lt; names.txt
</code></pre>
