<p>I have a PLINK formatted database (bed/bim/fam files) and corresponding
recoded files (hh/ped/map). I am looking for an effective way to extract
samples from this database with specific genotypes. I have looked through the PLINK <a href='http://pngu.mgh.harvard.edu/~purcell/plink/index.shtml'>manual</a>
and found that I can extract set of samples using "<a href='http://pngu.mgh.harvard.edu/~purcell/plink/dataman.shtml#keep'>--keep</a>" parameter and
extract set of genotypes using "<a href='http://pngu.mgh.harvard.edu/~purcell/plink/dataman.shtml#extract'>--extract</a>", am wondering if this can be
done in a single step using another parameter or tool. </p>

<p>My input is a list of rsIDs and genotypes; I need to get sample ids and
genotype as output.
INPUT</p>

<pre><code>rs1800562 AA
</code></pre>

<p>OUTPUT</p>

<pre><code>Sample1 AA
Sample5 AA
Sample22 AA
...
</code></pre>

<p>Is there any option in PLINK to do this or I should use unix 'grep' and/or a custom script to extract data. Suggestions on other computational genomics tools to do similar task is also welcome. </p>

<p>You can combine both --keep and --extract in a single step, but you're wanting to condition your --keep based on the genotypes you get from your --extract, which PLINK can't do to my knowledge. If you want a single ped file for each snp you could do something like</p>

<pre><code>awk '{print $1}' INPUT &gt; mysnps
plink --bfile data --extract mysnps --tfile mysnps
(some code here to loop through each line of mysnps.tped and pulling out column index when your genotype matches, and write out a list of samples for each snp)
(some code here to run plink --keep for each list of samples)
</code></pre>

<p>... but you probably already knew this, and just need an implementation. Sorry this wasn't much help.</p>
