{"body": "<h1>Source code for iCallSV.combineVCF</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">combineVCF</span>\n<span class=\"sd\">~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: This module will combine multiple vcf file with same headers</span>\n\n<span class=\"sd\">&quot;&quot;&quot;</span>\n\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">Created on December 18, 2015</span>\n<span class=\"sd\">Description: This module will combine multiple vcf file with same headers</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n<span class=\"sd\">::Input::</span>\n<span class=\"sd\">vcfFiles : List of VCF Files to combine in list data structure</span>\n<span class=\"sd\">mergedVCF: Name of the combined vcf to output</span>\n\n<span class=\"sd\">::Output::</span>\n<span class=\"sd\">It is a merged vcf file</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"kn\">import</span> <span class=\"nn\">vcf</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\">checkparameters</span> <span class=\"k\">as</span> <span class=\"nn\">cp</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.combineVCF&#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.combineVCF.run\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">run</span><span class=\"p\">(</span><span class=\"n\">vcfFiles</span><span class=\"p\">,</span> <span class=\"n\">combinedVCF</span><span class=\"p\">,</span> <span class=\"n\">verbose</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    This will ``combine multiple vcf file with same headers``</span>\n\n<span class=\"sd\">    :param list vcfFiles: a list of .vcf files to be combined</span>\n<span class=\"sd\">    :param str combinedVCF: str for the output of combined vcf files</span>\n<span class=\"sd\">    :param bool verbose: a boolean</span>\n<span class=\"sd\">    :return: A str name of combined vcf file</span>\n<span class=\"sd\">    :rtype: str</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    <span class=\"n\">vcf_header</span> <span class=\"o\">=</span> <span class=\"n\">vcf</span><span class=\"o\">.</span><span class=\"n\">Reader</span><span class=\"p\">(</span><span class=\"n\">filename</span><span class=\"o\">=</span><span class=\"n\">vcfFiles</span><span class=\"p\">[</span><span class=\"mi\">1</span><span class=\"p\">])</span>\n    <span class=\"n\">vcf_output</span> <span class=\"o\">=</span> <span class=\"n\">vcf</span><span class=\"o\">.</span><span class=\"n\">Writer</span><span class=\"p\">(</span><span class=\"nb\">open</span><span class=\"p\">(</span><span class=\"n\">combinedVCF</span><span class=\"p\">,</span> <span class=\"s1\">&#39;w&#39;</span><span class=\"p\">),</span> <span class=\"n\">vcf_header</span><span class=\"p\">)</span>\n    <span class=\"k\">for</span> <span class=\"n\">vcffile</span> <span class=\"ow\">in</span> <span class=\"n\">vcfFiles</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\">vcffile</span><span class=\"p\">)):</span>\n            <span class=\"n\">vcf_reader</span> <span class=\"o\">=</span> <span class=\"n\">vcf</span><span class=\"o\">.</span><span class=\"n\">Reader</span><span class=\"p\">(</span><span class=\"nb\">open</span><span class=\"p\">(</span><span class=\"n\">vcffile</span><span class=\"p\">,</span> <span class=\"s1\">&#39;r&#39;</span><span class=\"p\">))</span>\n            <span class=\"k\">for</span> <span class=\"n\">each</span> <span class=\"ow\">in</span> <span class=\"n\">vcf_reader</span><span class=\"p\">:</span>\n                <span class=\"n\">vcf_output</span><span class=\"o\">.</span><span class=\"n\">write_record</span><span class=\"p\">(</span><span class=\"n\">each</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\">warning</span><span class=\"p\">(</span><span class=\"s2\">&quot;VCF file </span><span class=\"si\">%s</span><span class=\"s2\"> does not exists.&quot;</span><span class=\"p\">,</span> <span class=\"n\">vcffile</span><span class=\"p\">)</span>\n            <span class=\"k\">continue</span>\n        \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;Finished combining vcf files&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">combinedVCF</span><span class=\"p\">)</span></div>\n</pre></div>", "title": "iCallSV.combineVCF", "customsidebar": null, "current_page_name": "_modules/iCallSV/combineVCF", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}