{"body": "<h1>Source code for iCallSV.Run_samblaster</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">Run_samblaster</span>\n<span class=\"sd\">~~~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: This module will run samblaster for extracting discordant and spit reads in sam format</span>\n\n<span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">Created on Mar 20, 2015</span>\n<span class=\"sd\">Description: This module will run samblaster for extracting discordant and spit reads in sam format</span>\n<span class=\"sd\">@author: Ronak Shah</span>\n<span class=\"sd\">::Input::</span>\n<span class=\"sd\">samtools: To stream bam to sam into samblaster</span>\n<span class=\"sd\">samblaster: Location of the samblaster executables</span>\n<span class=\"sd\">bamFile: ReadName sorted bamFile</span>\n<span class=\"sd\">discordantFileName : Name of the discordant SAM file</span>\n<span class=\"sd\">splitFileName : Name of the split SAM file</span>\n<span class=\"sd\">outputDir : name the output directory</span>\n<span class=\"sd\">::Output::</span>\n<span class=\"sd\">discordantFile : SAM file containing discordant read entries</span>\n<span class=\"sd\">splitFile : SAM file containing split read entries</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n\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\">from</span> <span class=\"nn\">subprocess</span> <span class=\"k\">import</span> <span class=\"n\">Popen</span>\n<span class=\"kn\">import</span> <span class=\"nn\">shlex</span>\n<span class=\"kn\">import</span> <span class=\"nn\">time</span>\n<span class=\"kn\">from</span> <span class=\"nn\">datetime</span> <span class=\"k\">import</span> <span class=\"n\">date</span><span class=\"p\">,</span> <span class=\"n\">timedelta</span>\n<span class=\"kn\">import</span> <span class=\"nn\">checkparameters</span> <span class=\"k\">as</span> <span class=\"nn\">cp</span>\n<span class=\"kn\">import</span> <span class=\"nn\">logging</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=\"n\">__name__</span><span class=\"p\">)</span>\n\n<div class=\"viewcode-block\" id=\"run\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.Run_samblaster.run\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">run</span><span class=\"p\">(</span><span class=\"n\">samtools</span><span class=\"p\">,</span> <span class=\"n\">samblaster</span><span class=\"p\">,</span> <span class=\"n\">bamFile</span><span class=\"p\">,</span> <span class=\"n\">discordantFileName</span><span class=\"p\">,</span> <span class=\"n\">splitFileName</span><span class=\"p\">,</span> <span class=\"n\">outputDir</span><span class=\"p\">):</span>\n    <span class=\"n\">start_time</span> <span class=\"o\">=</span> <span class=\"n\">time</span><span class=\"o\">.</span><span class=\"n\">time</span><span class=\"p\">()</span>\n    <span class=\"nb\">print</span> <span class=\"s2\">&quot;We will now run samblaster to extract from BAM file discordant and spit reads</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n    <span class=\"n\">myPid</span> <span class=\"o\">=</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">getpid</span><span class=\"p\">()</span>\n    <span class=\"n\">day</span> <span class=\"o\">=</span> <span class=\"n\">date</span><span class=\"o\">.</span><span class=\"n\">today</span><span class=\"p\">()</span>\n    <span class=\"n\">today</span> <span class=\"o\">=</span> <span class=\"n\">day</span><span class=\"o\">.</span><span class=\"n\">isoformat</span><span class=\"p\">()</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkDir</span><span class=\"p\">(</span><span class=\"n\">outputDir</span><span class=\"p\">)</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkFile</span><span class=\"p\">(</span><span class=\"n\">samblaster</span><span class=\"p\">)</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkFile</span><span class=\"p\">(</span><span class=\"n\">bamFile</span><span class=\"p\">)</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkEmpty</span><span class=\"p\">(</span><span class=\"n\">discordantFileName</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Name of the Discordant Read SAM File output by samblaster&quot;</span><span class=\"p\">)</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkEmpty</span><span class=\"p\">(</span><span class=\"n\">splitFileName</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Name of the split Read SAM File output by samblaster&quot;</span><span class=\"p\">)</span>\n    <span class=\"nb\">print</span> <span class=\"s2\">&quot;Run_samblaster: All the input parameters look good for running samblaster</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n    <span class=\"nb\">print</span> <span class=\"s2\">&quot;Run_samblaster: ProcessID:&quot;</span><span class=\"p\">,</span> <span class=\"n\">myPid</span><span class=\"p\">,</span> <span class=\"s2\">&quot; Date:&quot;</span><span class=\"p\">,</span> <span class=\"n\">today</span><span class=\"p\">,</span> <span class=\"s2\">&quot;</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n    <span class=\"n\">discordantFile</span> <span class=\"o\">=</span> <span class=\"n\">outputDir</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;/&quot;</span> <span class=\"o\">+</span> <span class=\"n\">discordantFileName</span>\n    <span class=\"n\">splitFile</span> <span class=\"o\">=</span> <span class=\"n\">outputDir</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;/&quot;</span> <span class=\"o\">+</span> <span class=\"n\">splitFileName</span>\n    <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">samtools</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; view -h &quot;</span> <span class=\"o\">+</span> <span class=\"n\">bamFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; | &quot;</span> <span class=\"o\">+</span> <span class=\"n\">samblaster</span> <span class=\"o\">+</span> \\\n        <span class=\"s2\">&quot; -a -e --maxSplitCount 10 -d &quot;</span> <span class=\"o\">+</span> <span class=\"n\">discordantFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -s &quot;</span> <span class=\"o\">+</span> <span class=\"n\">splitFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -o /dev/null&quot;</span>\n    <span class=\"nb\">print</span> <span class=\"s2\">&quot;Run_samblaster: Command that will be run</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">cmd</span><span class=\"p\">,</span> <span class=\"s2\">&quot;</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n    <span class=\"c1\">#args = shlex.split(cmd)</span>\n    <span class=\"n\">proc</span> <span class=\"o\">=</span> <span class=\"n\">Popen</span><span class=\"p\">(</span><span class=\"n\">cmd</span><span class=\"p\">,</span> <span class=\"n\">shell</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n    <span class=\"n\">proc</span><span class=\"o\">.</span><span class=\"n\">wait</span><span class=\"p\">()</span>\n    <span class=\"n\">retcode</span> <span class=\"o\">=</span> <span class=\"n\">proc</span><span class=\"o\">.</span><span class=\"n\">returncode</span>\n    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">retcode</span> <span class=\"o\">&gt;=</span> <span class=\"mi\">0</span><span class=\"p\">):</span>\n        <span class=\"n\">end_time</span> <span class=\"o\">=</span> <span class=\"n\">time</span><span class=\"o\">.</span><span class=\"n\">time</span><span class=\"p\">()</span>\n        <span class=\"nb\">print</span> <span class=\"s2\">&quot;Run_samblaster: We have finished running samblaster for &quot;</span><span class=\"p\">,</span> <span class=\"n\">bamFile</span><span class=\"p\">,</span> <span class=\"s2\">&quot; using local machine.</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n        <span class=\"nb\">print</span> <span class=\"s2\">&quot;Run_samblaster Duration:&quot;</span><span class=\"p\">,</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">timedelta</span><span class=\"p\">(</span><span class=\"n\">seconds</span><span class=\"o\">=</span><span class=\"n\">end_time</span> <span class=\"o\">-</span> <span class=\"n\">start_time</span><span class=\"p\">)),</span> <span class=\"s2\">&quot;</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        <span class=\"nb\">print</span> <span class=\"s2\">&quot;Run_samblaster: samblaster is either still running on local machine or it errored out with return code&quot;</span><span class=\"p\">,</span> <span class=\"n\">retcode</span><span class=\"p\">,</span> <span class=\"s2\">&quot; for&quot;</span><span class=\"p\">,</span> <span class=\"n\">bamFile</span><span class=\"p\">,</span> <span class=\"s2\">&quot;</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span>\n        <span class=\"n\">sys</span><span class=\"o\">.</span><span class=\"n\">exit</span><span class=\"p\">()</span>\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">discordantFile</span><span class=\"p\">,</span> <span class=\"n\">splitFile</span><span class=\"p\">)</span></div>\n</pre></div>", "title": "iCallSV.Run_samblaster", "customsidebar": null, "current_page_name": "_modules/iCallSV/Run_samblaster", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}