{"body": "<h1>Source code for iCallSV.launch_Run_Delly</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">launch_Run_Delly</span>\n<span class=\"sd\">~~~~~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: This module will be launching delly using Run_Delly</span>\n<span class=\"sd\">&quot;&quot;&quot;</span>\n\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">Created on November 19, 2015</span>\n<span class=\"sd\">Description: This module will be launching delly using Run_Delly</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n<span class=\"sd\">::Inputs::</span>\n<span class=\"sd\">args: Arguments passed to iCallSV</span>\n<span class=\"sd\">config: configuration file passed to iCallSV</span>\n<span class=\"sd\">sampleOutdirForDelly: Output directory for delly vcf files.</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"kn\">import</span> <span class=\"nn\">os</span>\n<span class=\"kn\">import</span> <span class=\"nn\">logging</span>\n<span class=\"kn\">import</span> <span class=\"nn\">Run_Delly</span> <span class=\"k\">as</span> <span class=\"nn\">rd</span>\n<span class=\"kn\">import</span> <span class=\"nn\">multiprocessing</span> <span class=\"k\">as</span> <span class=\"nn\">mp</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\">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.launch_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=\"launch_delly_for_different_analysis_type\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.launch_Run_Delly.launch_delly_for_different_analysis_type\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">launch_delly_for_different_analysis_type</span><span class=\"p\">(</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"n\">config</span><span class=\"p\">,</span> <span class=\"n\">sampleOutdirForDelly</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    This will launch delly calls in parallel.</span>\n\n<span class=\"sd\">    :param Namespace args: Namespace of args to get other variables</span>\n<span class=\"sd\">    :param Namespace config: configuration file passed to iCallSV</span>\n<span class=\"sd\">    :param str sampleOutdirForDelly: Output directory for delly vcf files.</span>\n<span class=\"sd\">    :return: Multiple objects</span>\n<span class=\"sd\">    :rtype: list</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    <span class=\"n\">verbose</span> <span class=\"o\">=</span> <span class=\"n\">args</span><span class=\"o\">.</span><span class=\"n\">verbose</span>\n    <span class=\"n\">pool</span> <span class=\"o\">=</span> <span class=\"n\">mp</span><span class=\"o\">.</span><span class=\"n\">Pool</span><span class=\"p\">(</span><span class=\"n\">processes</span><span class=\"o\">=</span><span class=\"mi\">4</span><span class=\"p\">)</span>\n    <span class=\"n\">analyisisType</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;DEL&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;DUP&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;INV&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;TRA&quot;</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;launch_Run_Delly: Launched Delly for Deletion, Duplication, Inversion and Translocation Events&quot;</span><span class=\"p\">)</span>\n    <span class=\"c1\"># check of index file before run</span>\n    <span class=\"n\">controlBai</span> <span class=\"o\">=</span> <span class=\"n\">args</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\">args</span><span class=\"o\">.</span><span class=\"n\">controlBam</span><span class=\"p\">)</span>\n    <span class=\"n\">caseBai</span> <span class=\"o\">=</span> <span class=\"n\">args</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\">args</span><span class=\"o\">.</span><span class=\"n\">caseBam</span><span class=\"p\">)</span>\n    <span class=\"c1\"># launch commands</span>\n    <span class=\"n\">results</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"n\">pool</span><span class=\"o\">.</span><span class=\"n\">apply_async</span><span class=\"p\">(</span><span class=\"n\">rd</span><span class=\"o\">.</span><span class=\"n\">run</span><span class=\"p\">,</span> <span class=\"n\">args</span><span class=\"o\">=</span><span class=\"p\">(</span>\n        <span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"s2\">&quot;SVcaller&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;DELLY&quot;</span><span class=\"p\">),</span>\n        <span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"s2\">&quot;SVcaller&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;DellyVersion&quot;</span><span class=\"p\">),</span>\n        <span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"s2\">&quot;SVcaller&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;BCFTOOLS&quot;</span><span class=\"p\">),</span>\n        <span class=\"n\">x</span><span class=\"p\">,</span>\n        <span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"s2\">&quot;ReferenceFasta&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;REFFASTA&quot;</span><span class=\"p\">),</span>\n        <span class=\"n\">args</span><span class=\"o\">.</span><span class=\"n\">controlBam</span><span class=\"p\">,</span>\n        <span class=\"n\">args</span><span class=\"o\">.</span><span class=\"n\">caseBam</span><span class=\"p\">,</span>\n        <span class=\"n\">args</span><span class=\"o\">.</span><span class=\"n\">caseId</span><span class=\"p\">,</span>\n        <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"s2\">&quot;ParametersToRunDelly&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;MAPQ&quot;</span><span class=\"p\">)),</span>\n        <span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"s2\">&quot;ExcludeRegion&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;EXREGIONS&quot;</span><span class=\"p\">),</span>\n        <span class=\"n\">sampleOutdirForDelly</span><span class=\"p\">,</span>\n        <span class=\"n\">verbose</span><span class=\"p\">,</span>\n        <span class=\"kc\">False</span><span class=\"p\">))</span> <span class=\"k\">for</span> <span class=\"n\">x</span> <span class=\"ow\">in</span> <span class=\"n\">analyisisType</span><span class=\"p\">]</span>\n    <span class=\"n\">output</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"n\">p</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">()</span> <span class=\"k\">for</span> <span class=\"n\">p</span> <span class=\"ow\">in</span> <span class=\"n\">results</span><span class=\"p\">]</span>\n    <span class=\"n\">del_vcf</span><span class=\"p\">,</span> <span class=\"n\">dup_vcf</span><span class=\"p\">,</span> <span class=\"n\">inv_vcf</span><span class=\"p\">,</span> <span class=\"n\">tra_vcf</span> <span class=\"o\">=</span> <span class=\"n\">output</span>\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">del_vcf</span><span class=\"p\">,</span> <span class=\"n\">dup_vcf</span><span class=\"p\">,</span> <span class=\"n\">inv_vcf</span><span class=\"p\">,</span> <span class=\"n\">tra_vcf</span><span class=\"p\">)</span></div>\n\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">    # Run Delly for Deletion</span>\n<span class=\"sd\">    if(verbose):</span>\n<span class=\"sd\">        logger.info(&quot;launch_Run_Delly: Launched Delly for Deletion Events&quot;)</span>\n\n<span class=\"sd\">    del_vcf = rd.run(</span>\n<span class=\"sd\">        delly=config.get(&quot;SVcaller&quot;, &quot;DELLY&quot;),</span>\n<span class=\"sd\">        analysisType=&quot;DEL&quot;,</span>\n<span class=\"sd\">        reference=config.get(&quot;ReferenceFasta&quot;, &quot;REFFASTA&quot;),</span>\n<span class=\"sd\">        controlBam=args.controlBam,</span>\n<span class=\"sd\">        caseBam=args.caseBam,</span>\n<span class=\"sd\">        caseId=args.caseId,</span>\n<span class=\"sd\">        mapq=int(config.get(&quot;ParametersToRunDelly&quot;, &quot;MAPQ&quot;)),</span>\n<span class=\"sd\">        excludeRegions=config.get(&quot;ExcludeRegion&quot;, &quot;EXREGIONS&quot;),</span>\n<span class=\"sd\">        outputdir=sampleOutdirForDelly,</span>\n<span class=\"sd\">        verbose=verbose,</span>\n<span class=\"sd\">        debug=False)</span>\n\n<span class=\"sd\"># Run Delly for duplication</span>\n<span class=\"sd\">    if(verbose):</span>\n<span class=\"sd\">        logger.info(&quot;launch_Run_Delly: Launched Delly for Duplication Events&quot;)</span>\n\n<span class=\"sd\">    dup_vcf = rd.run(</span>\n<span class=\"sd\">        delly=config.get(&quot;SVcaller&quot;, &quot;DELLY&quot;),</span>\n<span class=\"sd\">        analysisType=&quot;DUP&quot;,</span>\n<span class=\"sd\">        reference=config.get(&quot;ReferenceFasta&quot;, &quot;REFFASTA&quot;),</span>\n<span class=\"sd\">        controlBam=args.controlBam,</span>\n<span class=\"sd\">        caseBam=args.caseBam,</span>\n<span class=\"sd\">        caseId=args.caseId,</span>\n<span class=\"sd\">        mapq=int(config.get(&quot;ParametersToRunDelly&quot;, &quot;MAPQ&quot;)),</span>\n<span class=\"sd\">        excludeRegions=config.get(&quot;ExcludeRegion&quot;, &quot;EXREGIONS&quot;),</span>\n<span class=\"sd\">        outputdir=sampleOutdirForDelly,</span>\n<span class=\"sd\">        verbose=verbose,</span>\n<span class=\"sd\">        debug=False)</span>\n\n<span class=\"sd\"># Run Delly for inversion</span>\n<span class=\"sd\">    if(verbose):</span>\n<span class=\"sd\">        logger.info(&quot;launch_Run_Delly: Launched Delly for Inversion Events&quot;)</span>\n\n<span class=\"sd\">    inv_vcf = rd.run(</span>\n<span class=\"sd\">        delly=config.get(&quot;SVcaller&quot;, &quot;DELLY&quot;),</span>\n<span class=\"sd\">        analysisType=&quot;INV&quot;,</span>\n<span class=\"sd\">        reference=config.get(&quot;ReferenceFasta&quot;, &quot;REFFASTA&quot;),</span>\n<span class=\"sd\">        controlBam=args.controlBam,</span>\n<span class=\"sd\">        caseBam=args.caseBam,</span>\n<span class=\"sd\">        caseId=args.caseId,</span>\n<span class=\"sd\">        mapq=int(config.get(&quot;ParametersToRunDelly&quot;, &quot;MAPQ&quot;)),</span>\n<span class=\"sd\">        excludeRegions=config.get(&quot;ExcludeRegion&quot;, &quot;EXREGIONS&quot;),</span>\n<span class=\"sd\">        outputdir=sampleOutdirForDelly,</span>\n<span class=\"sd\">        verbose=verbose,</span>\n<span class=\"sd\">        debug=False)</span>\n\n<span class=\"sd\"># Run Delly for Translocation</span>\n<span class=\"sd\">    if(verbose):</span>\n<span class=\"sd\">        logger.info(&quot;launch_Run_Delly: Launched Delly for Translocation Envents&quot;)</span>\n\n<span class=\"sd\">    tra_vcf = rd.run(</span>\n<span class=\"sd\">        delly=config.get(&quot;SVcaller&quot;, &quot;DELLY&quot;),</span>\n<span class=\"sd\">        analysisType=&quot;TRA&quot;,</span>\n<span class=\"sd\">        reference=config.get(&quot;ReferenceFasta&quot;, &quot;REFFASTA&quot;),</span>\n<span class=\"sd\">        controlBam=args.controlBam,</span>\n<span class=\"sd\">        caseBam=args.caseBam,</span>\n<span class=\"sd\">        caseId=args.caseId,</span>\n<span class=\"sd\">        mapq=int(config.get(&quot;ParametersToRunDelly&quot;, &quot;MAPQ&quot;)),</span>\n<span class=\"sd\">        excludeRegions=config.get(&quot;ExcludeRegion&quot;, &quot;EXREGIONS&quot;),</span>\n<span class=\"sd\">        outputdir=sampleOutdirForDelly,</span>\n<span class=\"sd\">        verbose=verbose,</span>\n<span class=\"sd\">        debug=False)</span>\n\n<span class=\"sd\">    return(del_vcf, dup_vcf, inv_vcf, tra_vcf)</span>\n\n<span class=\"sd\"># Run Delly for Insertion</span>\n<span class=\"sd\">    if(verbose):</span>\n<span class=\"sd\">        logger.info(&quot;launch_Run_Delly: Launched Delly for Insertion Events&quot;)</span>\n\n<span class=\"sd\">    ins_vcf = rd.run(</span>\n<span class=\"sd\">        delly=config.get(&quot;SVcaller&quot;, &quot;DELLY&quot;),</span>\n<span class=\"sd\">        analysisType=&quot;INS&quot;,</span>\n<span class=\"sd\">        reference=config.get(&quot;ReferenceFasta&quot;, &quot;REFFASTA&quot;),</span>\n<span class=\"sd\">        controlBam=args.controlBam,</span>\n<span class=\"sd\">        caseBam=args.caseBam,</span>\n<span class=\"sd\">        caseId=args.caseId,</span>\n<span class=\"sd\">        mapq=int(config.get(&quot;ParametersToRunDelly&quot;, &quot;MAPQ&quot;)),</span>\n<span class=\"sd\">        excludeRegions=config.get(&quot;ExcludeRegion&quot;, &quot;EXREGIONS&quot;),</span>\n<span class=\"sd\">        outputdir=sampleOutdirForDelly,</span>\n<span class=\"sd\">        verbose=verbose,</span>\n<span class=\"sd\">        debug=False)</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n</pre></div>", "title": "iCallSV.launch_Run_Delly", "customsidebar": null, "current_page_name": "_modules/iCallSV/launch_Run_Delly", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}