Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlKCarlK authored Nov 4, 2023
1 parent 9307565 commit ec94b48
Show file tree
Hide file tree
Showing 6 changed files with 2,440 additions and 0 deletions.
1,600 changes: 1,600 additions & 0 deletions docs/beta/_modules/bed_reader/_open_bed.html

Large diffs are not rendered by default.

208 changes: 208 additions & 0 deletions docs/beta/_modules/bed_reader/_sample_data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>bed_reader._sample_data &mdash; Bed Reader 1.0.0 documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>

<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >



<a href="../../index.html" class="icon icon-home">
Bed Reader
</a>
<div class="version">
1.0.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<!-- Local TOC -->
<div class="local-toc"></div>
</div>
</div>
</nav>

<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Bed Reader</a>
</nav>

<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
<li class="breadcrumb-item active">bed_reader._sample_data</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">

<h1>Source code for bed_reader._sample_data</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Union</span>

<span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">pooch</span>

<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Load sample data.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">POOCH</span> <span class="o">=</span> <span class="n">pooch</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
<span class="c1"># Use the default cache folder for the OS</span>
<span class="n">path</span><span class="o">=</span><span class="n">pooch</span><span class="o">.</span><span class="n">os_cache</span><span class="p">(</span><span class="s2">&quot;bed_reader&quot;</span><span class="p">),</span>
<span class="c1"># The remote data is on Github</span>
<span class="n">base_url</span><span class="o">=</span><span class="s2">&quot;https://raw.githubusercontent.com/&quot;</span>
<span class="o">+</span> <span class="s2">&quot;fastlmm/bed-reader/Oct2023/bed_reader/tests/data/&quot;</span><span class="p">,</span>
<span class="c1"># If this is a development version, get the data from the master branch</span>
<span class="n">version_dev</span><span class="o">=</span><span class="s2">&quot;master&quot;</span><span class="p">,</span>
<span class="c1"># The registry specifies the files that can be fetched</span>
<span class="n">env</span><span class="o">=</span><span class="s2">&quot;BED_READER_DATA_DIR&quot;</span><span class="p">,</span>
<span class="p">)</span>

<span class="c1"># Get registry file from package_data</span>
<span class="n">registry_file</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span> <span class="o">/</span> <span class="s2">&quot;tests/registry.txt&quot;</span>
<span class="c1"># Load this registry file</span>
<span class="n">POOCH</span><span class="o">.</span><span class="n">load_registry</span><span class="p">(</span><span class="n">registry_file</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="n">pooch</span> <span class="o">=</span> <span class="kc">None</span>


<div class="viewcode-block" id="sample_file"><a class="viewcode-back" href="../../index.html#bed_reader.sample_file">[docs]</a><span class="k">def</span> <span class="nf">sample_file</span><span class="p">(</span><span class="n">filepath</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Path</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieve a sample .bed file. (Also retrieves associated .fam and .bim files).</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> filepath</span>
<span class="sd"> Name of the sample .bed file.</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> str</span>
<span class="sd"> Local name of sample .bed file.</span>


<span class="sd"> By default this function puts files under the user&#39;s cache directory.</span>
<span class="sd"> Override this by setting</span>
<span class="sd"> the `BED_READER_DATA_DIR` environment variable.</span>

<span class="sd"> Example</span>
<span class="sd"> --------</span>

<span class="sd"> .. doctest::</span>

<span class="sd"> &gt;&gt;&gt; # pip install bed-reader[samples] # if needed</span>
<span class="sd"> &gt;&gt;&gt; from bed_reader import sample_file</span>
<span class="sd"> &gt;&gt;&gt;</span>
<span class="sd"> &gt;&gt;&gt; file_name = sample_file(&quot;small.bed&quot;)</span>
<span class="sd"> &gt;&gt;&gt; print(f&quot;The local file name is &#39;{file_name}&#39;&quot;)</span>
<span class="sd"> The local file name is &#39;...small.bed&#39;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">pooch</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span>
<span class="s2">&quot;The function sample_file() requires pooch. &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Install it with &#39;pip install --upgrade bed-reader[sample]&#39;.&quot;</span>
<span class="p">)</span>

<span class="n">filepath</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">filepath</span><span class="p">)</span>
<span class="n">file_string</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">filepath</span><span class="p">)</span>
<span class="k">if</span> <span class="n">file_string</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;.bed&quot;</span><span class="p">):</span>
<span class="n">POOCH</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="n">file_string</span><span class="p">[:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;.fam&quot;</span><span class="p">)</span>
<span class="n">POOCH</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="n">file_string</span><span class="p">[:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;.bim&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">POOCH</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="n">file_string</span><span class="p">)</span></div>


<div class="viewcode-block" id="tmp_path"><a class="viewcode-back" href="../../index.html#bed_reader.tmp_path">[docs]</a><span class="k">def</span> <span class="nf">tmp_path</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="n">Path</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a :class:`pathlib.Path` to a temporary directory.</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> pathlib.Path</span>
<span class="sd"> a temporary directory</span>

<span class="sd"> Example</span>
<span class="sd"> --------</span>

<span class="sd"> .. doctest::</span>

<span class="sd"> &gt;&gt;&gt; from bed_reader import to_bed, tmp_path</span>
<span class="sd"> &gt;&gt;&gt;</span>
<span class="sd"> &gt;&gt;&gt; output_file = tmp_path() / &quot;small3.bed&quot;</span>
<span class="sd"> &gt;&gt;&gt; val = [[1, 0, -127, 0], [2, 0, -127, 2], [0, 1, 2, 0]]</span>
<span class="sd"> &gt;&gt;&gt; to_bed(output_file, val)</span>

<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">temp_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">gettempdir</span><span class="p">()</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">temp_dir</span><span class="p">)</span> <span class="o">/</span> <span class="s2">&quot;bed_reader_tmp_path&quot;</span>
<span class="n">path</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">path</span></div>


<span class="c1"># if __name__ == &quot;__main__&quot;:</span>
<span class="c1"># logging.basicConfig(level=logging.INFO)</span>

<span class="c1"># import pytest</span>

<span class="c1"># pytest.main([&quot;--doctest-modules&quot;, __file__])</span>
</pre></div>

</div>
</div>
<footer>

<hr/>

<div role="contentinfo">
<p>&#169; Copyright 2023, Carl Kadie.</p>
</div>

Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.


</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>

</body>
</html>
Loading

0 comments on commit ec94b48

Please sign in to comment.