{"body": "<h1>Source code for iCallSV.Run_targetSeqView</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">Run_targetSeqView</span>\n<span class=\"sd\">~~~~~~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: This module will run targetSeqView</span>\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: This module will run targetSeqView</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n<span class=\"sd\">::Input::</span>\n<span class=\"sd\">RLocation : Location of the R executable (&gt;3.1.2).</span>\n<span class=\"sd\">targetSeqView: Location of R script that will run tragetSeqView</span>\n<span class=\"sd\">nodes : Number of parallel nodes for running targetSeqView</span>\n<span class=\"sd\">bamFile : Location of the bamFile which has the  structural variant events.</span>\n<span class=\"sd\">svFile : targetSeqView compatible input structural variant file.</span>\n<span class=\"sd\">build : Which human reference file to be used, hg18,hg19 or hg38</span>\n<span class=\"sd\">readLength : Sequencing Read Length (101)</span>\n<span class=\"sd\">outputDir : Directory for output files</span>\n<span class=\"sd\">outsvFile : Name of the output structural variant file that has added confidence score to it.</span>\n<span class=\"sd\">::Output::</span>\n<span class=\"sd\">Tab-delimited File with added confidence score and Image of each SV</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\">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\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_targetSeqView&#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_targetSeqView.run\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">run</span><span class=\"p\">(</span>\n        <span class=\"n\">RLocation</span><span class=\"p\">,</span>\n        <span class=\"n\">targetSeqView</span><span class=\"p\">,</span>\n        <span class=\"n\">nodes</span><span class=\"p\">,</span>\n        <span class=\"n\">bamFilePath</span><span class=\"p\">,</span>\n        <span class=\"n\">svFile</span><span class=\"p\">,</span>\n        <span class=\"n\">build</span><span class=\"p\">,</span>\n        <span class=\"n\">readLength</span><span class=\"p\">,</span>\n        <span class=\"n\">outputDir</span><span class=\"p\">,</span>\n        <span class=\"n\">outsvFileName</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    This module will run targetSeqView.</span>\n\n<span class=\"sd\">    :param str RLocation: Location of the R executable (&gt;3.1.2).</span>\n<span class=\"sd\">    :param str targetSeqView: Location of R script that will run tragetSeqView</span>\n<span class=\"sd\">    :param int nodes: Number of parallel nodes for running targetSeqView</span>\n<span class=\"sd\">    :param str bamFile: Location of the bamFile which has the  structural variant events.</span>\n<span class=\"sd\">    :param str svFile: targetSeqView compatible input structural variant file.</span>\n<span class=\"sd\">    :param str build: Which human reference file to be used, hg18,hg19 or hg38</span>\n<span class=\"sd\">    :param int readLength: Sequencing Read Length (101)</span>\n<span class=\"sd\">    :param str outputDir: Directory for output files</span>\n<span class=\"sd\">    :param str outsvFile: Name of the output structural variant file that has added confidence score to it.</span>\n<span class=\"sd\">    :return: str of the output file</span>\n<span class=\"sd\">    :rtype: str</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</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=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n        <span class=\"s2\">&quot;We will now be running targetSeqView. Hope fully the R package targetSeqView is installed.&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\">targetSeqView</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\">nodes</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Number of nodes to run targetSeqView&quot;</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\">bamFilePath</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\">svFile</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\">build</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Genome build to be used for targetSeqView&quot;</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\">readLength</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Sequencing Read Length&quot;</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><span class=\"s2\">&quot;All Input Parameters look good. Lets Run targetSeqView&quot;</span><span class=\"p\">)</span>\n    <span class=\"n\">RLocation</span> <span class=\"o\">=</span> <span class=\"n\">RLocation</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;/bin/R&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\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;Run_targetSeqView: 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=\"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\">outsvFileName</span>\n    <span class=\"n\">stdoutFile</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\">outsvFileName</span><span class=\"p\">[:</span><span class=\"o\">-</span><span class=\"mi\">4</span><span class=\"p\">]</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;_&quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">myPid</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;.stdout&quot;</span>\n    <span class=\"n\">stderrFile</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\">outsvFileName</span><span class=\"p\">[:</span><span class=\"o\">-</span><span class=\"mi\">4</span><span class=\"p\">]</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;_&quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">myPid</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;.stderr&quot;</span>\n    <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">RLocation</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; --slave --vanilla --args &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">nodes</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">bamFilePath</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">svFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">build</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span>\n        <span class=\"n\">readLength</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</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\">outsvFileName</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &lt; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">targetSeqView</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &gt; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">stdoutFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; 2&gt; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">stderrFile</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_targetSeqView: 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=\"c1\"># Remove if the file exists</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\">outputFile</span><span class=\"p\">)):</span>\n        <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">remove</span><span class=\"p\">(</span><span class=\"n\">outputFile</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\">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=\"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=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n            <span class=\"s2\">&quot;Run_targetSeqView: We have finished running targetSeqView for </span><span class=\"si\">%s</span><span class=\"s2\"> using local machine.&quot;</span><span class=\"p\">,</span>\n            <span class=\"n\">svFile</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_targetSeqView 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=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n            <span class=\"s2\">&quot;Run_targetSeqView: targetSeqView 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\">svFile</span><span class=\"p\">)</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\">outputFile</span><span class=\"p\">)</span></div>\n</pre></div>", "title": "iCallSV.Run_targetSeqView", "customsidebar": null, "current_page_name": "_modules/iCallSV/Run_targetSeqView", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}