-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9307565
commit ec94b48
Showing
6 changed files
with
2,440 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 — 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">"""</span> | ||
<span class="sd"> Load sample data.</span> | ||
<span class="sd"> """</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">"bed_reader"</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">"https://raw.githubusercontent.com/"</span> | ||
<span class="o">+</span> <span class="s2">"fastlmm/bed-reader/Oct2023/bed_reader/tests/data/"</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">"master"</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">"BED_READER_DATA_DIR"</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">"tests/registry.txt"</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">-></span> <span class="nb">str</span><span class="p">:</span> | ||
<span class="w"> </span><span class="sd">"""</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'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"> >>> # pip install bed-reader[samples] # if needed</span> | ||
<span class="sd"> >>> from bed_reader import sample_file</span> | ||
<span class="sd"> >>></span> | ||
<span class="sd"> >>> file_name = sample_file("small.bed")</span> | ||
<span class="sd"> >>> print(f"The local file name is '{file_name}'")</span> | ||
<span class="sd"> The local file name is '...small.bed'</span> | ||
<span class="sd"> """</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">"The function sample_file() requires pooch. "</span> | ||
<span class="o">+</span> <span class="s2">"Install it with 'pip install --upgrade bed-reader[sample]'."</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">".bed"</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">".fam"</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">".bim"</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">-></span> <span class="n">Path</span><span class="p">:</span> | ||
<span class="w"> </span><span class="sd">"""</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"> >>> from bed_reader import to_bed, tmp_path</span> | ||
<span class="sd"> >>></span> | ||
<span class="sd"> >>> output_file = tmp_path() / "small3.bed"</span> | ||
<span class="sd"> >>> val = [[1, 0, -127, 0], [2, 0, -127, 2], [0, 1, 2, 0]]</span> | ||
<span class="sd"> >>> to_bed(output_file, val)</span> | ||
|
||
<span class="sd"> """</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">"bed_reader_tmp_path"</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__ == "__main__":</span> | ||
<span class="c1"># logging.basicConfig(level=logging.INFO)</span> | ||
|
||
<span class="c1"># import pytest</span> | ||
|
||
<span class="c1"># pytest.main(["--doctest-modules", __file__])</span> | ||
</pre></div> | ||
|
||
</div> | ||
</div> | ||
<footer> | ||
|
||
<hr/> | ||
|
||
<div role="contentinfo"> | ||
<p>© 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> |
Oops, something went wrong.