{"body": "<h1>Source code for iCallSV.Run_Delly</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">Run_Delly</span>\n<span class=\"sd\">~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: Runs the delly program on case and control bam file to give its results</span>\n\n<span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">Created on March 17, 2015</span>\n<span class=\"sd\">Description: Runs the delly program on case and control bam file to give its results</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n<span class=\"sd\">::Inputs::</span>\n<span class=\"sd\">delly:Path to delly executables (0.7.3 or above)</span>\n<span class=\"sd\">bcftools:Path to bcftools executables (1.3.1 or above)</span>\n<span class=\"sd\">type: What ot run in delly, DEL:Deletion, DUP: Duplication,TRA:Translocation, INV:Inversion</span>\n<span class=\"sd\">reference: Reference Genome that was used to align the reads.</span>\n<span class=\"sd\">controlBam: Path to control/normal bam file</span>\n<span class=\"sd\">caseBam: Path to case/tumor bam file</span>\n<span class=\"sd\">controlID: Id of the control/normal sample</span>\n<span class=\"sd\">caseID: Id of the case/tumor sample</span>\n<span class=\"sd\">mapq: mapping quality cutoff for delly</span>\n<span class=\"sd\">excludeRegions: Regions to be excluded for calling structural variation.</span>\n<span class=\"sd\">outputdir: directory for the output of delly</span>\n<span class=\"sd\">debug: If you just wish to test what we will do</span>\n<span class=\"sd\">::Output::</span>\n<span class=\"sd\">VCF file having all the structural variants called</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<span class=\"kn\">import</span> <span class=\"nn\">coloredlogs</span>\n<span class=\"kn\">import</span> <span class=\"nn\">makebamindex</span> <span class=\"k\">as</span> <span class=\"nn\">mbi</span>\n<span class=\"kn\">from</span> <span class=\"nn\">distutils.version</span> <span class=\"k\">import</span> <span class=\"n\">LooseVersion</span><span class=\"p\">,</span> <span class=\"n\">StrictVersion</span>\n<span class=\"c1\"># This function will run delly based on given inputs</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.Run_Delly&#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=\"run\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.Run_Delly.run\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">run</span><span class=\"p\">(</span>\n        <span class=\"n\">delly</span><span class=\"p\">,</span>\n        <span class=\"n\">version</span><span class=\"p\">,</span>\n        <span class=\"n\">bcftools</span><span class=\"p\">,</span>\n        <span class=\"n\">analysisType</span><span class=\"p\">,</span>\n        <span class=\"n\">reference</span><span class=\"p\">,</span>\n        <span class=\"n\">controlBam</span><span class=\"p\">,</span>\n        <span class=\"n\">caseBam</span><span class=\"p\">,</span>\n        <span class=\"n\">caseId</span><span class=\"p\">,</span>\n        <span class=\"n\">mapq</span><span class=\"p\">,</span>\n        <span class=\"n\">excludeRegions</span><span class=\"p\">,</span>\n        <span class=\"n\">outputdir</span><span class=\"p\">,</span>\n        <span class=\"n\">verbose</span><span class=\"p\">,</span>\n        <span class=\"n\">debug</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    This will Runs the delly program on case and control bam file to give its</span>\n<span class=\"sd\">    results.</span>\n\n<span class=\"sd\">    :param str delly: Path to delly executables (0.7.3 or above)</span>\n<span class=\"sd\">    :param str bcftools: Path to bcftools executables (1.3.1 or above)</span>\n<span class=\"sd\">    :param str type: What ot run in delly, DEL:Deletion, DUP: Duplication,TRA:Translocation, INV:Inversion</span>\n<span class=\"sd\">    :param str reference: Reference Genome that was used to align the reads.</span>\n<span class=\"sd\">    :param str controlBam: Path to control/normal bam file</span>\n<span class=\"sd\">    :param str caseBam: Path to case/tumor bam file</span>\n<span class=\"sd\">    :param str controlID: Id of the control/normal sample</span>\n<span class=\"sd\">    :param str caseID: Id of the case/tumor sample</span>\n<span class=\"sd\">    :param int mapq: mapping quality cutoff for delly</span>\n<span class=\"sd\">    :param str excludeRegions: Regions to be excluded for calling structural variation.</span>\n<span class=\"sd\">    :param str outputdir: directory for the output of delly</span>\n<span class=\"sd\">    :param bool debug: If you just wish to test what we will do</span>\n<span class=\"sd\">    :return: str of the output vcf</span>\n<span class=\"sd\">    :rtype: str</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n\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=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</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;Run_Delly: We are now going to run Delly for you. It going to be exciting time.&quot;</span><span class=\"p\">)</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\">tag</span> <span class=\"o\">=</span> <span class=\"n\">analysisType</span><span class=\"o\">.</span><span class=\"n\">lower</span><span class=\"p\">()</span>\n    <span class=\"n\">outputBcf</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\">caseId</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;_&quot;</span> <span class=\"o\">+</span> <span class=\"n\">tag</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;.bcf&quot;</span>\n    <span class=\"n\">outputVcf</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\">caseId</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;_&quot;</span> <span class=\"o\">+</span> <span class=\"n\">tag</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;.vcf&quot;</span>\n    <span class=\"c1\"># Check all input variables</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkFile</span><span class=\"p\">(</span><span class=\"n\">controlBam</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\">caseBam</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\">delly</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\">version</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Delly Version&quot;</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\">bcftools</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\">reference</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\">excludeRegions</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\">checkInt</span><span class=\"p\">(</span><span class=\"n\">mapq</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Delly MAPQ&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\">caseId</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Delly Case BAM ID&quot;</span><span class=\"p\">)</span>\n    <span class=\"n\">cp</span><span class=\"o\">.</span><span class=\"n\">checkDellyAnalysisType</span><span class=\"p\">(</span><span class=\"n\">analysisType</span><span class=\"p\">)</span>\n    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</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;Run_Delly: All the input parameters look good for running delly&quot;</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;Run_Delly: ProcessID:</span><span class=\"si\">%s</span><span class=\"s2\">,Date:</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">myPid</span><span class=\"p\">,</span> <span class=\"n\">today</span><span class=\"p\">)</span>\n    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">debug</span><span class=\"p\">):</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">version</span> <span class=\"o\">&gt;=</span> <span class=\"n\">StrictVersion</span><span class=\"p\">(</span><span class=\"s1\">&#39;0.7.3&#39;</span><span class=\"p\">)):</span>\n            <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">delly</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -t &quot;</span> <span class=\"o\">+</span> <span class=\"n\">analysisType</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -g &quot;</span> <span class=\"o\">+</span> <span class=\"n\">reference</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -x &quot;</span> <span class=\"o\">+</span> <span class=\"n\">excludeRegions</span> <span class=\"o\">+</span> \\\n                <span class=\"s2\">&quot; -q &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">mapq</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -o &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputBcf</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">caseBam</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">controlBam</span>\n            <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">debug</span><span class=\"p\">(</span><span class=\"s2\">&quot;Run_Delly: Command that will be run </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">cmd</span><span class=\"p\">)</span>\n        <span class=\"k\">else</span><span class=\"p\">:</span>\n            <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">delly</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -t &quot;</span> <span class=\"o\">+</span> <span class=\"n\">analysisType</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -g &quot;</span> <span class=\"o\">+</span> <span class=\"n\">reference</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -x &quot;</span> <span class=\"o\">+</span> <span class=\"n\">excludeRegions</span> <span class=\"o\">+</span> \\\n                <span class=\"s2\">&quot; -q &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">mapq</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -o &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputVcf</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">caseBam</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">controlBam</span>\n            <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">debug</span><span class=\"p\">(</span><span class=\"s2\">&quot;Run_Delly: Command that will be run </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">cmd</span><span class=\"p\">)</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        <span class=\"c1\"># Check if bam index files are there else make them</span>\n        <span class=\"n\">controlBai</span> <span class=\"o\">=</span> <span class=\"n\">controlBam</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;.bai&quot;</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\">controlBai</span><span class=\"p\">)):</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</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;Run_Delly: Bam Index file is present for </span><span class=\"si\">%s</span><span class=\"s2\"> &quot;</span><span class=\"p\">,</span> <span class=\"n\">controlBai</span><span class=\"p\">)</span>\n        <span class=\"k\">else</span><span class=\"p\">:</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">warn</span><span class=\"p\">(</span>\n                    <span class=\"s2\">&quot;Run_Delly: Bam Index file is not present and we will make it for </span><span class=\"si\">%s</span><span class=\"s2\"> &quot;</span><span class=\"p\">,</span>\n                    <span class=\"n\">controlBai</span><span class=\"p\">)</span>\n            <span class=\"n\">mbi</span><span class=\"o\">.</span><span class=\"n\">MakeIndex</span><span class=\"p\">(</span><span class=\"n\">controlBam</span><span class=\"p\">)</span>\n        <span class=\"n\">caseBai</span> <span class=\"o\">=</span> <span class=\"n\">caseBam</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;.bai&quot;</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\">caseBai</span><span class=\"p\">)):</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</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;Run_Delly: Bam Index file is present for </span><span class=\"si\">%s</span><span class=\"s2\"> &quot;</span><span class=\"p\">,</span> <span class=\"n\">caseBai</span><span class=\"p\">)</span>\n        <span class=\"k\">else</span><span class=\"p\">:</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">warn</span><span class=\"p\">(</span>\n                    <span class=\"s2\">&quot;Run_Delly: Bam Index file is not present and we will make it for </span><span class=\"si\">%s</span><span class=\"s2\"> &quot;</span><span class=\"p\">,</span>\n                    <span class=\"n\">caseBai</span><span class=\"p\">)</span>\n            <span class=\"n\">mbi</span><span class=\"o\">.</span><span class=\"n\">MakeIndex</span><span class=\"p\">(</span><span class=\"n\">caseBam</span><span class=\"p\">)</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">version</span> <span class=\"o\">&gt;=</span> <span class=\"n\">StrictVersion</span><span class=\"p\">(</span><span class=\"s1\">&#39;0.7.3&#39;</span><span class=\"p\">)):</span>\n            <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">delly</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; call -t &quot;</span> <span class=\"o\">+</span> <span class=\"n\">analysisType</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -g &quot;</span> <span class=\"o\">+</span> <span class=\"n\">reference</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -x &quot;</span> <span class=\"o\">+</span> <span class=\"n\">excludeRegions</span> <span class=\"o\">+</span> \\\n                <span class=\"s2\">&quot; -q &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">mapq</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -o &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputBcf</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">caseBam</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">controlBam</span>\n        <span class=\"k\">else</span><span class=\"p\">:</span>\n            <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">delly</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -t &quot;</span> <span class=\"o\">+</span> <span class=\"n\">analysisType</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -g &quot;</span> <span class=\"o\">+</span> <span class=\"n\">reference</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -x &quot;</span> <span class=\"o\">+</span> <span class=\"n\">excludeRegions</span> <span class=\"o\">+</span> \\\n                <span class=\"s2\">&quot; -q &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">mapq</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -o &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputVcf</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">caseBam</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">controlBam</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</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;Run_Delly: Command that will be run:</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">cmd</span><span class=\"p\">)</span>\n        <span class=\"n\">args</span> <span class=\"o\">=</span> <span class=\"n\">shlex</span><span class=\"o\">.</span><span class=\"n\">split</span><span class=\"p\">(</span><span class=\"n\">cmd</span><span class=\"p\">)</span>\n        <span class=\"n\">proc</span> <span class=\"o\">=</span> <span class=\"n\">Popen</span><span class=\"p\">(</span><span class=\"n\">args</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=\"n\">totaltime</span> <span class=\"o\">=</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>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n                    <span class=\"s2\">&quot;Run_Delly: We have finished running Delly for </span><span class=\"si\">%s</span><span class=\"s2\"> using local machine&quot;</span><span class=\"p\">,</span> <span class=\"n\">caseId</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;Run_Delly Duration: </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">totaltime</span><span class=\"p\">)</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">version</span> <span class=\"o\">&gt;=</span> <span class=\"n\">StrictVersion</span><span class=\"p\">(</span><span class=\"s1\">&#39;0.7.3&#39;</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\">outputBcf</span><span class=\"p\">)):</span>\n                    <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">bcftools</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; view &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputBcf</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -O v -o &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputVcf</span>\n                    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</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;Run_Delly_bcf2vcf: Command that will be run:</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">cmd</span><span class=\"p\">)</span>\n                    <span class=\"n\">args</span> <span class=\"o\">=</span> <span class=\"n\">shlex</span><span class=\"o\">.</span><span class=\"n\">split</span><span class=\"p\">(</span><span class=\"n\">cmd</span><span class=\"p\">)</span>\n                    <span class=\"n\">proc</span> <span class=\"o\">=</span> <span class=\"n\">Popen</span><span class=\"p\">(</span><span class=\"n\">args</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=\"n\">totaltime</span> <span class=\"o\">=</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>\n                        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                            <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n                                <span class=\"s2\">&quot;Run_Delly_bcf2vcf: We have finished running bcftools for </span><span class=\"si\">%s</span><span class=\"s2\"> using local machine&quot;</span><span class=\"p\">,</span> <span class=\"n\">caseId</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;Run_Delly_bcf2vcf Duration: </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">totaltime</span><span class=\"p\">)</span>\n                    <span class=\"k\">else</span><span class=\"p\">:</span>\n                        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                            <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">fatal</span><span class=\"p\">(</span>\n                                <span class=\"s2\">&quot;Run_Delly_bcf2vcf: bcftools is either still running on local machine or it errored out with return code </span><span class=\"si\">%d</span><span class=\"s2\"> for </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>\n                                <span class=\"n\">retcode</span><span class=\"p\">,</span>\n                                <span class=\"n\">caseId</span><span class=\"p\">)</span>\n                        <span class=\"n\">sys</span><span class=\"o\">.</span><span class=\"n\">exit</span><span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n                <span class=\"k\">else</span><span class=\"p\">:</span>\n                    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                        <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">fatal</span><span class=\"p\">(</span>\n                            <span class=\"s2\">&quot;Run_Delly_bcf2vcf: bcf file was not generated the return code is </span><span class=\"si\">%d</span><span class=\"s2\"> for </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>\n                            <span class=\"n\">retcode</span><span class=\"p\">,</span>\n                            <span class=\"n\">caseId</span><span class=\"p\">)</span>\n                        <span class=\"c1\">#sys.exit(1)</span>\n            <span class=\"k\">else</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\">outputVcf</span><span class=\"p\">)):</span>\n                    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">outputVcf</span><span class=\"p\">)</span>\n                <span class=\"k\">else</span><span class=\"p\">:</span>\n                    <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                        <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">fatal</span><span class=\"p\">(</span>\n                            <span class=\"s2\">&quot;Run_Delly: Delly is either still running on local machine or it errored out with return code </span><span class=\"si\">%d</span><span class=\"s2\"> for </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>\n                            <span class=\"n\">retcode</span><span class=\"p\">,</span>\n                            <span class=\"n\">caseId</span><span class=\"p\">)</span>\n                    <span class=\"n\">sys</span><span class=\"o\">.</span><span class=\"n\">exit</span><span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n        <span class=\"k\">else</span><span class=\"p\">:</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">verbose</span><span class=\"p\">):</span>\n                <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">fatal</span><span class=\"p\">(</span>\n                    <span class=\"s2\">&quot;Run_Delly: Delly is either still running on local machine or it errored out with return code </span><span class=\"si\">%d</span><span class=\"s2\"> for </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>\n                    <span class=\"n\">retcode</span><span class=\"p\">,</span>\n                    <span class=\"n\">caseId</span><span class=\"p\">)</span>\n            <span class=\"n\">sys</span><span class=\"o\">.</span><span class=\"n\">exit</span><span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">outputVcf</span><span class=\"p\">)</span></div>\n</pre></div>", "title": "iCallSV.Run_Delly", "customsidebar": null, "current_page_name": "_modules/iCallSV/Run_Delly", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}