{"body": "<h1>Source code for iCallSV.makebamindex</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">makebamindex</span>\n<span class=\"sd\">~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: Use PySAM to make bam index</span>\n\n<span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"c1\"># Use PySAM to make bam index</span>\n<span class=\"kn\">import</span> <span class=\"nn\">pysam</span>\n<span class=\"kn\">import</span> <span class=\"nn\">os</span>\n<span class=\"kn\">import</span> <span class=\"nn\">sys</span>\n<span class=\"kn\">import</span> <span class=\"nn\">logging</span>\n<span class=\"kn\">import</span> <span class=\"nn\">coloredlogs</span>\n\n<span class=\"n\">logger</span> <span class=\"o\">=</span> <span class=\"n\">logging</span><span class=\"o\">.</span><span class=\"n\">getLogger</span><span class=\"p\">(</span><span class=\"s1\">&#39;iCallSV.makebamindex&#39;</span><span class=\"p\">)</span>\n<span class=\"n\">coloredlogs</span><span class=\"o\">.</span><span class=\"n\">install</span><span class=\"p\">(</span><span class=\"n\">level</span><span class=\"o\">=</span><span class=\"s1\">&#39;DEBUG&#39;</span><span class=\"p\">)</span>\n\n<div class=\"viewcode-block\" id=\"MakeIndex\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.makebamindex.MakeIndex\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">MakeIndex</span><span class=\"p\">(</span><span class=\"n\">bamFile</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    This will make bam index if not there for a bam file using pysam.</span>\n\n<span class=\"sd\">    :param str bamFile: Path to bam file</span>\n<span class=\"sd\">    :return: None</span>\n<span class=\"sd\">    :rtype: None</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;makebamindex: Trying to make index for bam file&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">path</span><span class=\"o\">.</span><span class=\"n\">isfile</span><span class=\"p\">(</span><span class=\"n\">bamFile</span><span class=\"p\">)):</span>\n        <span class=\"k\">try</span><span class=\"p\">:</span>\n            <span class=\"n\">pysam</span><span class=\"o\">.</span><span class=\"n\">index</span><span class=\"p\">(</span><span class=\"n\">bamFile</span><span class=\"p\">)</span>\n        <span class=\"k\">except</span> <span class=\"ne\">IndexError</span> <span class=\"k\">as</span> <span class=\"n\">err</span><span class=\"p\">:</span>\n            <span class=\"n\">exception</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;Index error(</span><span class=\"si\">{0}</span><span class=\"s2\">): </span><span class=\"si\">{1}</span><span class=\"s2\">&quot;</span><span class=\"o\">.</span><span class=\"n\">format</span><span class=\"p\">(</span><span class=\"n\">err</span><span class=\"o\">.</span><span class=\"n\">errno</span><span class=\"p\">,</span> <span class=\"n\">err</span><span class=\"o\">.</span><span class=\"n\">strerror</span><span class=\"p\">)</span>\n            <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">exception</span><span class=\"p\">)</span>\n        <span class=\"k\">except</span> <span class=\"ne\">IOError</span> <span class=\"k\">as</span> <span class=\"n\">err</span><span class=\"p\">:</span>\n            <span class=\"n\">exception</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;I/O error(</span><span class=\"si\">{0}</span><span class=\"s2\">): </span><span class=\"si\">{1}</span><span class=\"s2\">&quot;</span><span class=\"o\">.</span><span class=\"n\">format</span><span class=\"p\">(</span><span class=\"n\">err</span><span class=\"o\">.</span><span class=\"n\">errno</span><span class=\"p\">,</span> <span class=\"n\">err</span><span class=\"o\">.</span><span class=\"n\">strerror</span><span class=\"p\">)</span>\n            <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">exception</span><span class=\"p\">)</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;Bam File </span><span class=\"si\">%s</span><span class=\"s2\"> does not exists&quot;</span><span class=\"p\">,</span> <span class=\"n\">bamFile</span><span class=\"p\">)</span>\n        <span class=\"n\">sys</span><span class=\"o\">.</span><span class=\"n\">exit</span><span class=\"p\">()</span></div>\n</pre></div>", "title": "iCallSV.makebamindex", "customsidebar": null, "current_page_name": "_modules/iCallSV/makebamindex", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}