{"body": "<h1>Source code for iCallSV.dellyVcf2targetSeqView</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">dellyVcf2targetSeqView</span>\n<span class=\"sd\">~~~~~~~~~~~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: Convert VCF to targetSeqView</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 Mar 19, 2015</span>\n<span class=\"sd\">Description: Convert VCF to targetSeqView</span>\n<span class=\"sd\">#Example:</span>\n<span class=\"sd\">SampleDesc    Chr1    Start1    End1    LeftSideSegDup    Chr2    Start2    End2    RightSideSeqDup    ValidationStatus    Sample    SplitsSample</span>\n<span class=\"sd\">Ramos    15    22462315    22462465    TRUE    14    106467050    106467150    TRUE    Failed PCR    1320KB0009MultipleAlnsort.bam    1320KB0009.bam</span>\n<span class=\"sd\">::Input::</span>\n<span class=\"sd\">sampleName: Name of the sample that has the structural abberations</span>\n<span class=\"sd\">sampleBamName: Name of the bam file.</span>\n<span class=\"sd\">sampleSplitBaName: Name of the split bam file (Use bam file if you dont have split bam file)</span>\n<span class=\"sd\">vcfFile: Input Delly VCF file for the conversion</span>\n<span class=\"sd\">outputDir: Directory to write the output file</span>\n<span class=\"sd\">outputFileName: Name of the output File</span>\n<span class=\"sd\">::Output::</span>\n<span class=\"sd\">outputFile: TargetSeqView format text file for a given vcf file.</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n\n<span class=\"kn\">import</span> <span class=\"nn\">vcf</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\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.dellyVcf2targetSeqView&#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=\"Convert2targetSeqView\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.dellyVcf2targetSeqView.Convert2targetSeqView\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">Convert2targetSeqView</span><span class=\"p\">(</span>\n        <span class=\"n\">sampleName</span><span class=\"p\">,</span>\n        <span class=\"n\">sampleBamName</span><span class=\"p\">,</span>\n        <span class=\"n\">sampleSplitBamName</span><span class=\"p\">,</span>\n        <span class=\"n\">vcfFile</span><span class=\"p\">,</span>\n        <span class=\"n\">outputDir</span><span class=\"p\">,</span>\n        <span class=\"n\">outputFileName</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;This ``converts`` the Delly Vcf file having tumor normal, to tab-delimited format for input to targetSeqView</span>\n\n\n<span class=\"sd\">    :param str sampleName: str for the name of the sample being analyzed</span>\n<span class=\"sd\">    :param str sampleBamName: str for the pair-end reads bam file</span>\n<span class=\"sd\">    :param str sampleSplitBamName: str for the split reads bam file</span>\n<span class=\"sd\">    :param str vcfFile: str of vcf file to be converted</span>\n<span class=\"sd\">    :param str outputDir: str for the output directory</span>\n<span class=\"sd\">    :param str outputFileName: str for the output File</span>\n<span class=\"sd\">    :return: A str name of tab-delimited file</span>\n<span class=\"sd\">    :rtype: str</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n\n    <span class=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;Convert2targetSeqView: Will convert vcf to targetSeqVie format&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\">vcfFile</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\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n        <span class=\"s2\">&quot;Convert2targetSeqView: All Input Parameters look good. Lets convert to tab-delimited file&quot;</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=\"n\">outputFile</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\">outputFileName</span>\n    <span class=\"n\">outputHandle</span> <span class=\"o\">=</span> <span class=\"nb\">open</span><span class=\"p\">(</span><span class=\"n\">outputFile</span><span class=\"p\">,</span> <span class=\"s2\">&quot;w&quot;</span><span class=\"p\">)</span>\n    <span class=\"n\">outputHandle</span><span class=\"o\">.</span><span class=\"n\">write</span><span class=\"p\">(</span>\n        <span class=\"s2\">&quot;SampleDesc</span><span class=\"se\">\\t</span><span class=\"s2\">Chr1</span><span class=\"se\">\\t</span><span class=\"s2\">Start1</span><span class=\"se\">\\t</span><span class=\"s2\">End1</span><span class=\"se\">\\t</span><span class=\"s2\">LeftSideSegDup</span><span class=\"se\">\\t</span><span class=\"s2\">Chr2</span><span class=\"se\">\\t</span><span class=\"s2\">Start2</span><span class=\"se\">\\t</span><span class=\"s2\">End2</span><span class=\"se\">\\t</span><span class=\"s2\">RightSideSeqDup</span><span class=\"se\">\\t</span><span class=\"s2\">ValidationStatus</span><span class=\"se\">\\t</span><span class=\"s2\">Sample</span><span class=\"se\">\\t</span><span class=\"s2\">SplitsSample</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">for</span> <span class=\"n\">record</span> <span class=\"ow\">in</span> <span class=\"n\">vcf_reader</span><span class=\"p\">:</span>\n        <span class=\"p\">(</span><span class=\"n\">chrom1</span><span class=\"p\">,</span>\n         <span class=\"n\">start1</span><span class=\"p\">,</span>\n         <span class=\"n\">start2</span><span class=\"p\">,</span>\n         <span class=\"n\">ciEndNeg</span><span class=\"p\">,</span>\n         <span class=\"n\">ciEndPos</span><span class=\"p\">,</span>\n         <span class=\"n\">ciPosNeg</span><span class=\"p\">,</span>\n         <span class=\"n\">ciPosPos</span><span class=\"p\">,</span>\n         <span class=\"n\">chrom2</span><span class=\"p\">,</span>\n         <span class=\"n\">contype</span><span class=\"p\">,</span>\n         <span class=\"n\">str1</span><span class=\"p\">,</span>\n         <span class=\"n\">str2</span><span class=\"p\">)</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"kc\">None</span> <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"mi\">11</span><span class=\"p\">))</span>\n        <span class=\"n\">chrom1</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">CHROM</span>\n        <span class=\"n\">start1</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">POS</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"s2\">&quot;END&quot;</span> <span class=\"ow\">in</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">):</span>\n            <span class=\"n\">start2</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">[</span><span class=\"s1\">&#39;END&#39;</span><span class=\"p\">]</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"s2\">&quot;CHR2&quot;</span> <span class=\"ow\">in</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">):</span>\n            <span class=\"n\">chrom2</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">[</span><span class=\"s1\">&#39;CHR2&#39;</span><span class=\"p\">]</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"s2\">&quot;CT&quot;</span> <span class=\"ow\">in</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">):</span>\n            <span class=\"n\">contype</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">[</span><span class=\"s1\">&#39;CT&#39;</span><span class=\"p\">]</span>\n        <span class=\"p\">(</span><span class=\"n\">startCT</span><span class=\"p\">,</span> <span class=\"n\">endCT</span><span class=\"p\">)</span> <span class=\"o\">=</span> <span class=\"n\">contype</span><span class=\"o\">.</span><span class=\"n\">split</span><span class=\"p\">(</span><span class=\"s2\">&quot;to&quot;</span><span class=\"p\">)</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"s2\">&quot;CIEND&quot;</span> <span class=\"ow\">in</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">):</span>\n            <span class=\"n\">ciEndNeg</span><span class=\"p\">,</span> <span class=\"n\">ciEndPos</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">[</span><span class=\"s1\">&#39;CIEND&#39;</span><span class=\"p\">]</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"nb\">abs</span><span class=\"p\">(</span><span class=\"n\">ciEndNeg</span><span class=\"p\">)</span> <span class=\"o\">&lt;</span> <span class=\"mi\">50</span><span class=\"p\">):</span>\n            <span class=\"n\">ciEndNeg</span> <span class=\"o\">=</span> <span class=\"mi\">50</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"nb\">abs</span><span class=\"p\">(</span><span class=\"n\">ciEndPos</span><span class=\"p\">)</span> <span class=\"o\">&lt;</span> <span class=\"mi\">50</span><span class=\"p\">):</span>\n            <span class=\"n\">ciEndNeg</span> <span class=\"o\">=</span> <span class=\"mi\">50</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"s2\">&quot;CIPOS&quot;</span> <span class=\"ow\">in</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">):</span>\n            <span class=\"n\">ciPosNeg</span><span class=\"p\">,</span> <span class=\"n\">ciPosPos</span> <span class=\"o\">=</span> <span class=\"n\">record</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">[</span><span class=\"s1\">&#39;CIPOS&#39;</span><span class=\"p\">]</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"nb\">abs</span><span class=\"p\">(</span><span class=\"n\">ciPosNeg</span><span class=\"p\">)</span> <span class=\"o\">&lt;</span> <span class=\"mi\">50</span><span class=\"p\">):</span>\n            <span class=\"n\">ciPosNeg</span> <span class=\"o\">=</span> <span class=\"mi\">50</span>\n        <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"nb\">abs</span><span class=\"p\">(</span><span class=\"n\">ciPosPos</span><span class=\"p\">)</span> <span class=\"o\">&lt;</span> <span class=\"mi\">50</span><span class=\"p\">):</span>\n            <span class=\"n\">ciPosNeg</span> <span class=\"o\">=</span> <span class=\"mi\">50</span>\n        <span class=\"n\">outputHandle</span><span class=\"o\">.</span><span class=\"n\">write</span><span class=\"p\">(</span>\n            <span class=\"n\">sampleName</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">chrom1</span><span class=\"p\">)</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">start1</span><span class=\"p\">)</span> <span class=\"o\">-</span> <span class=\"nb\">abs</span><span class=\"p\">(</span><span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">ciPosNeg</span><span class=\"p\">)))</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">start1</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">ciPosPos</span><span class=\"p\">))</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">FALSE</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">chrom2</span><span class=\"p\">)</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">start2</span><span class=\"p\">)</span> <span class=\"o\">-</span> <span class=\"nb\">abs</span><span class=\"p\">(</span><span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">ciEndNeg</span><span class=\"p\">)))</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">start2</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">ciEndPos</span><span class=\"p\">))</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">FALSE</span><span class=\"se\">\\t</span><span class=\"s2\">Failed PCR</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">sampleBamName</span><span class=\"p\">)</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span> <span class=\"o\">+</span>\n            <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">sampleSplitBamName</span><span class=\"p\">)</span> <span class=\"o\">+</span>\n            <span class=\"s2\">&quot;</span><span class=\"se\">\\n</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span>\n    <span class=\"n\">outputHandle</span><span class=\"o\">.</span><span class=\"n\">close</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;Convert2targetSeqView: Finished conversion of Vcf file to targetSeqView file format.&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;Convert2targetSeqView: Output can be found: </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> <span class=\"n\">outputFile</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">outputFile</span><span class=\"p\">)</span></div>\n</pre></div>", "title": "iCallSV.dellyVcf2targetSeqView", "customsidebar": null, "current_page_name": "_modules/iCallSV/dellyVcf2targetSeqView", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}