---

title: Genodata module


keywords: fastai
sidebar: home_sidebar

summary: "read and extract genodata"
description: "read and extract genodata"
nb_path: "00_Genodata.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: 00_Genodata.ipynb
# command to build the docs after a change: nbdev_build_docs

-->

<div class="container" id="notebook-container">
        
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="read_bgen" class="doc_header"><code>read_bgen</code><a href="https://github.com/changebio/LDtools/tree/master/LDtools/genodata.py#L13" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>read_bgen</code>(<strong><code>file</code></strong>, <strong><code>sample_file</code></strong>=<em><code>None</code></em>)</p>
</blockquote>
<p>the function to read genotype data</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="bgen2dask" class="doc_header"><code>bgen2dask</code><a href="https://github.com/changebio/LDtools/tree/master/LDtools/genodata.py#L30" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>bgen2dask</code>(<strong><code>bgen</code></strong>, <strong><code>index</code></strong>, <strong><code>step</code></strong>=<em><code>500</code></em>)</p>
</blockquote>
<p>The function to covert bgen to dask array</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="extract_bed" class="doc_header"><code>extract_bed</code><a href="https://github.com/changebio/LDtools/tree/master/LDtools/genodata.py#L41" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>extract_bed</code>(<strong><code>geno</code></strong>, <strong><code>idx</code></strong>, <strong><code>row</code></strong>=<em><code>True</code></em>, <strong><code>step</code></strong>=<em><code>500</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h2 id="Genodata" class="doc_header"><code>class</code> <code>Genodata</code><a href="https://github.com/changebio/LDtools/tree/master/LDtools/genodata.py#L57" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>Genodata</code>(<strong><code>geno_path</code></strong>, <strong><code>sample_path</code></strong>=<em><code>None</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Test">Test<a class="anchor-link" href="#Test"> </a></h1>
</div>
</div>
</div>
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">geno_path</span> <span class="o">=</span><span class="s1">&#39;/home/dmc2245/UKBiobank/data/exome_files/project_VCF/072721_run/plink/ukb23156_c1.merged.filtered.bed&#39;</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">dmc2245</span><span class="o">/</span><span class="n">UKBiobank</span><span class="o">/</span><span class="n">data</span><span class="o">/</span><span class="n">exome_files</span><span class="o">/</span><span class="n">project_VCF</span><span class="o">/</span><span class="mi">072721</span><span class="n">_run</span><span class="o">/</span><span class="n">plink</span><span class="o">/</span><span class="mi">092321</span><span class="n">_UKBB_qc_exome_geno_path</span><span class="o">.</span><span class="n">txt</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">region</span> <span class="o">=</span> <span class="p">[</span><span class="mi">5</span><span class="p">,</span><span class="mi">272741</span><span class="p">,</span><span class="mi">1213528</span><span class="o">-</span><span class="mi">900000</span><span class="p">]</span>
<span class="n">geno_path</span> <span class="o">=</span> <span class="s1">&#39;MWE_region_extraction/ukb23156_c5.merged.filtered.5_272741_1213528.bed&#39;</span>
<span class="n">sumstats_path</span> <span class="o">=</span> <span class="s1">&#39;MWE_region_extraction/090321_UKBB_Hearing_aid_f3393_expandedwhite_6436cases_96601ctrl_PC1_2_f3393.regenie.snp_stats&#39;</span>
<span class="n">pheno_path</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">unr_path</span> <span class="o">=</span> <span class="s1">&#39;MWE_region_extraction/UKB_genotypedatadownloaded083019.090221_sample_variant_qc_final_callrate90.filtered.extracted.white_europeans.filtered.092821_ldprun_unrelated.filtered.prune.txt&#39;</span>
<span class="n">imp_geno_path</span> <span class="o">=</span> <span class="s1">&#39;MWE_region_extraction/ukb_imp_chr5_v3_05_272856_1213643.bgen&#39;</span>
<span class="n">imp_sumstats_path</span> <span class="o">=</span> <span class="s1">&#39;MWE_region_extraction/100521_UKBB_Hearing_aid_f3393_expandedwhite_15601cases_237318ctrl_500k_PC1_PC2_f3393.regenie.snp_stats&#39;</span>
<span class="n">imp_ref</span> <span class="o">=</span> <span class="s1">&#39;hg19&#39;</span>

<span class="n">output_sumstats</span> <span class="o">=</span> <span class="s1">&#39;test.snp_stats&#39;</span>
<span class="n">output_LD</span> <span class="o">=</span> <span class="s1">&#39;test_corr.csv&#39;</span>

<span class="c1">#main(region,geno_path,sumstats_path,pheno_path,unr_path,imp_geno_path,imp_sumstats_path,imp_ref,output_sumstats,output_LD)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">pandas_plink</span> <span class="kn">import</span> <span class="n">Chunk</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Chunk</span><span class="p">(</span><span class="mi">512</span><span class="p">,</span><span class="mi">512</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>Chunk(nsamples=512, nvariants=512)</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">exome_geno</span><span class="o">.</span><span class="n">extractbyvariants</span><span class="p">(</span><span class="n">exome_geno</span><span class="o">.</span><span class="n">bim</span><span class="o">.</span><span class="n">snp</span><span class="p">[:</span><span class="mi">50</span><span class="p">])</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">exome_geno</span><span class="o">.</span><span class="n">extractbysamples</span><span class="p">(</span><span class="n">exome_geno</span><span class="o">.</span><span class="n">fam</span><span class="o">.</span><span class="n">iid</span><span class="p">[:</span><span class="mi">60</span><span class="p">])</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

</div>
 

