{"body": "<h1>Source code for iCallSV.Run_iAnnotateSV</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">Run_iAnnotate</span>\n<span class=\"sd\">~~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: This module will run iAnnotateSV package</span>\n\n<span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">Created on Mar 18, 2015</span>\n<span class=\"sd\">Description: This module will run iAnnotateSV package</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n\n<span class=\"sd\">::Input::</span>\n<span class=\"sd\">python : Location for the python executable.</span>\n<span class=\"sd\">iAnnotateSV : Location of the wrapper iAnnotateSV package (iAnnotateSV.py)</span>\n<span class=\"sd\">build : Which human reference file to be used, hg18,hg19 or hg38</span>\n<span class=\"sd\">inputTabFile : Tab-Delimited Input FIle compatible with iAnnotateSV package.</span>\n<span class=\"sd\">outputPrefix: Prefix of the output files/DIR with Annotations and images</span>\n<span class=\"sd\">outputDir : Name of the output directory where the outputPrefix will be written</span>\n<span class=\"sd\">uniprotFile: Location for ucsc uniprot file</span>\n<span class=\"sd\">cosmicFile: Location for cosmic census file</span>\n<span class=\"sd\">repeatregionFile: Location for repeat region file</span>\n<span class=\"sd\">dgvFile: Location for database of Genomic Variants file</span>\n<span class=\"sd\">::Output::</span>\n<span class=\"sd\">It is a tab-delimited file with annotation in them</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\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_iAnnotateSV&#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_iAnnotateSV.run\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">run</span><span class=\"p\">(</span>\n        <span class=\"n\">python</span><span class=\"p\">,</span>\n        <span class=\"n\">iAnnotateSV</span><span class=\"p\">,</span>\n        <span class=\"n\">build</span><span class=\"p\">,</span>\n        <span class=\"n\">distance</span><span class=\"p\">,</span>\n        <span class=\"n\">canonicalTranscriptFile</span><span class=\"p\">,</span>\n        <span class=\"n\">uniprotFile</span><span class=\"p\">,</span>\n        <span class=\"n\">cosmicFile</span><span class=\"p\">,</span>\n        <span class=\"n\">cosmicCountsFile</span><span class=\"p\">,</span>\n        <span class=\"n\">repeatregionFile</span><span class=\"p\">,</span>\n        <span class=\"n\">dgvFile</span><span class=\"p\">,</span>\n        <span class=\"n\">inputTabFile</span><span class=\"p\">,</span>\n        <span class=\"n\">outputPrefix</span><span class=\"p\">,</span>\n        <span class=\"n\">outputDir</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    This module will run iAnnotateSV package.</span>\n\n<span class=\"sd\">    :param str python: Location for the python executable.</span>\n<span class=\"sd\">    :param str iAnnotateSV: Location of the wrapper iAnnotateSV package (iAnnotateSV.py)</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 str inputTabFile: Tab-Delimited Input FIle compatible with iAnnotateSV package.</span>\n<span class=\"sd\">    :param str outputPrefix: Prefix of the output files/DIR with Annotations and images</span>\n<span class=\"sd\">    :param str outputDir: Name of the output directory where the outputPrefix will be written</span>\n<span class=\"sd\">    :param str uniprotFile: Location for ucsc uniprot file</span>\n<span class=\"sd\">    :param str cosmicFile: Location for cosmic census file</span>\n<span class=\"sd\">    :param str cosmicCountsFile: Location for cosmic fusion counts file</span>\n<span class=\"sd\">    :param str repeatregionFile: Location for repeat region file</span>\n<span class=\"sd\">    :param str dgvFile: Location for database of Genomic Variants file</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\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\">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\">checkFile</span><span class=\"p\">(</span><span class=\"n\">iAnnotateSV</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\">inputTabFile</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\">python</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\">distance</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Distance for extending the promoter region&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\">build</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Which human reference file to be used, hg18,hg19 or hg38&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\">canonicalTranscriptFile</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\">uniprotFile</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\">cosmicFile</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\">cosmicCountsFile</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\">repeatregionFile</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\">dgvFile</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_iAnnotateSV: All input parameters look good. Lets run the package.&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\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;Run_iAnnotateSV: 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\">outputPrefix</span> <span class=\"o\">+</span> <span class=\"s2\">&quot;_Annotated.txt&quot;</span>\n    <span class=\"n\">cmd</span> <span class=\"o\">=</span> <span class=\"n\">python</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; &quot;</span> <span class=\"o\">+</span> <span class=\"n\">iAnnotateSV</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -r &quot;</span> <span class=\"o\">+</span> <span class=\"n\">build</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -i &quot;</span> <span class=\"o\">+</span> <span class=\"n\">inputTabFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -o &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputDir</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -ofp &quot;</span> <span class=\"o\">+</span> <span class=\"n\">outputPrefix</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -d &quot;</span> <span class=\"o\">+</span> <span class=\"nb\">str</span><span class=\"p\">(</span>\n        <span class=\"n\">distance</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -c &quot;</span> <span class=\"o\">+</span> <span class=\"n\">canonicalTranscriptFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -rr &quot;</span> <span class=\"o\">+</span> <span class=\"n\">repeatregionFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -cc &quot;</span> <span class=\"o\">+</span> <span class=\"n\">cosmicFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -cct &quot;</span> <span class=\"o\">+</span> <span class=\"n\">cosmicCountsFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -dgv &quot;</span> <span class=\"o\">+</span> <span class=\"n\">dgvFile</span> <span class=\"o\">+</span> <span class=\"s2\">&quot; -v -p -u &quot;</span> <span class=\"o\">+</span> <span class=\"n\">uniprotFile</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\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span><span class=\"s2\">&quot;Run_iAnnotateSV: 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\">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=\"n\">logger</span><span class=\"o\">.</span><span class=\"n\">info</span><span class=\"p\">(</span>\n            <span class=\"s2\">&quot;Run_iAnnotateSV: We have finished running iAnnotateSV for </span><span class=\"si\">%s</span><span class=\"s2\"> using local machine&quot;</span><span class=\"p\">,</span>\n            <span class=\"n\">inputTabFile</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_iAnnotateSV 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_iAnnotateSV: iAnnotateSV 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\">inputTabFile</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_iAnnotateSV", "customsidebar": null, "current_page_name": "_modules/iCallSV/Run_iAnnotateSV", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}