---

title: Utils module

keywords: fastai
sidebar: home_sidebar

summary: "the util functions"
description: "the util functions"
nb_path: "nbs/03_Utils.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: nbs/03_Utils.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="mkpath" class="doc_header"><code>mkpath</code><a href="__main__.py#L18" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>mkpath</code>(<strong><code>directory</code></strong>)</p>
</blockquote>
<p>Have to use system mkdir here because python2.7's mkpath is currently faulty!</p>

</div>

</div>

</div>
</div>

</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="Environment" class="doc_header"><code>class</code> <code>Environment</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>Environment</code>()</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="StdoutCapturer" class="doc_header"><code>class</code> <code>StdoutCapturer</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>StdoutCapturer</code>(<strong><code>iterable</code></strong>=<em><code>()</code></em>) :: <code>list</code></p>
</blockquote>
<p>Built-in mutable sequence.</p>
<p>If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.</p>

</div>

</div>

</div>
</div>

</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="stdoutRedirect" class="doc_header"><code>stdoutRedirect</code><a href="__main__.py#L177" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>stdoutRedirect</code>(<strong><code>to</code></strong>=<em><code>'/dev/null'</code></em>)</p>
</blockquote>
<p>import os</p>
<p>with stdoutRedirect(to=filename):
    print("from Python")
    os.system("echo non-Python applications are also supported")</p>

</div>

</div>

</div>
</div>

</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="cd" class="doc_header"><code>class</code> <code>cd</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>cd</code>(<strong><code>newPath</code></strong>)</p>
</blockquote>
<p>Context manager for changing the current working directory</p>

</div>

</div>

</div>
</div>

</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="runCommand" class="doc_header"><code>runCommand</code><a href="__main__.py#L219" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>runCommand</code>(<strong><code>cmd</code></strong>, <strong><code>instream</code></strong>=<em><code>None</code></em>, <strong><code>msg</code></strong>=<em><code>''</code></em>, <strong><code>upon_succ</code></strong>=<em><code>None</code></em>, <strong><code>show_stderr</code></strong>=<em><code>False</code></em>, <strong><code>return_zero</code></strong>=<em><code>True</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="CMDWorker" class="doc_header"><code>class</code> <code>CMDWorker</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>CMDWorker</code>(<strong><code>queue</code></strong>) :: <code>Process</code></p>
</blockquote>
<p>Process objects represent activity that is run in a separate process</p>
<p>The class is analogous to <code>threading.Thread</code></p>

</div>

</div>

</div>
</div>

</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="runCommands" class="doc_header"><code>runCommands</code><a href="__main__.py#L268" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>runCommands</code>(<strong><code>cmds</code></strong>, <strong><code>ncpu</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="parmap" class="doc_header"><code>parmap</code><a href="__main__.py#L286" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>parmap</code>(<strong><code>f</code></strong>, <strong><code>X</code></strong>, <strong><code>nprocs</code></strong>=<em><code>32</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="downloadURL" class="doc_header"><code>downloadURL</code><a href="__main__.py#L308" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>downloadURL</code>(<strong><code>URL</code></strong>, <strong><code>dest_dir</code></strong>, <strong><code>quiet</code></strong>=<em><code>True</code></em>, <strong><code>mode</code></strong>=<em><code>None</code></em>, <strong><code>force</code></strong>=<em><code>False</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="calculateFileMD5" class="doc_header"><code>calculateFileMD5</code><a href="__main__.py#L337" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>calculateFileMD5</code>(<strong><code>filename</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="zipdir" class="doc_header"><code>zipdir</code><a href="__main__.py#L367" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>zipdir</code>(<strong><code>path</code></strong>, <strong><code>zipfile</code></strong>, <strong><code>arcroot</code></strong>=<em><code>'/'</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="removeFiles" class="doc_header"><code>removeFiles</code><a href="__main__.py#L374" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>removeFiles</code>(<strong><code>dest</code></strong>, <strong><code>exclude</code></strong>=<em><code>[]</code></em>, <strong><code>hidden</code></strong>=<em><code>False</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="removeEmptyDir" class="doc_header"><code>removeEmptyDir</code><a href="__main__.py#L385" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>removeEmptyDir</code>(<strong><code>directory</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="copyFiles" class="doc_header"><code>copyFiles</code><a href="__main__.py#L392" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>copyFiles</code>(<strong><code>pattern</code></strong>, <strong><code>dist</code></strong>, <strong><code>ignore_hidden</code></strong>=<em><code>True</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="downloadResources" class="doc_header"><code>downloadResources</code><a href="__main__.py#L398" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>downloadResources</code>(<strong><code>fromto</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="getColumn" class="doc_header"><code>getColumn</code><a href="__main__.py#L405" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>getColumn</code>(<strong><code>fn</code></strong>, <strong><code>num</code></strong>, <strong><code>delim</code></strong>=<em><code>None</code></em>, <strong><code>exclude</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 class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="wordCount" class="doc_header"><code>wordCount</code><a href="__main__.py#L416" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>wordCount</code>(<strong><code>filename</code></strong>)</p>
</blockquote>
<p>Returns a word/count dict for this filename.</p>

</div>

</div>

</div>
</div>

</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="fileLinesCount" class="doc_header"><code>fileLinesCount</code><a href="__main__.py#L430" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>fileLinesCount</code>(<strong><code>fname</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="connected_components" class="doc_header"><code>connected_components</code><a href="__main__.py#L436" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>connected_components</code>(<strong><code>lists</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="listit" class="doc_header"><code>listit</code><a href="__main__.py#L454" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>listit</code>(<strong><code>t</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="parseVCFline" class="doc_header"><code>parseVCFline</code><a href="__main__.py#L461" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>parseVCFline</code>(<strong><code>line</code></strong>, <strong><code>exclude</code></strong>=<em><code>[]</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="indexVCF" class="doc_header"><code>indexVCF</code><a href="__main__.py#L483" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>indexVCF</code>(<strong><code>vcf</code></strong>, <strong><code>verbose</code></strong>=<em><code>True</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="extractSamplenames" class="doc_header"><code>extractSamplenames</code><a href="__main__.py#L500" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>extractSamplenames</code>(<strong><code>vcf</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="checkVCFBundle" class="doc_header"><code>checkVCFBundle</code><a href="__main__.py#L506" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>checkVCFBundle</code>(<strong><code>vcf</code></strong>)</p>
</blockquote>
<p>VCF bundle should have a .gz file and a tabix file</p>

</div>

</div>

</div>
</div>

</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="rewriteFamfile" class="doc_header"><code>rewriteFamfile</code><a href="__main__.py#L515" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>rewriteFamfile</code>(<strong><code>tfam</code></strong>, <strong><code>samples</code></strong>, <strong><code>keys</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="checkSamples" class="doc_header"><code>checkSamples</code><a href="__main__.py#L520" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>checkSamples</code>(<strong><code>samp1</code></strong>, <strong><code>samp2</code></strong>)</p>
</blockquote>
<p>check if two sample lists agree</p>
<ol>
<li>samples in FAM but not in VCF --&gt; ERROR</li>
<li>samples in VCF but not in FAM --&gt; give a message</li>
</ol>

</div>

</div>

</div>
</div>

</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="NoCache" class="doc_header"><code>class</code> <code>NoCache</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>NoCache</code>()</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="Cache" class="doc_header"><code>class</code> <code>Cache</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>Cache</code>(<strong><code>cache_dir</code></strong>, <strong><code>cache_name</code></strong>, <strong><code>params</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="PseudoAutoRegion" class="doc_header"><code>class</code> <code>PseudoAutoRegion</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>PseudoAutoRegion</code>(<strong><code>chrom</code></strong>, <strong><code>build</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</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="TFAMParser" class="doc_header"><code>class</code> <code>TFAMParser</code><a href="" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>TFAMParser</code>(<strong><code>tfam</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 %}

    {% 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="isnotebook" class="doc_header"><code>isnotebook</code><a href="https://github.com/changebio/SEQLinkage/tree/master/SEQLinkage/Utils.py#L839" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>isnotebook</code>()</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

</div>
 

