{"body": "<h1>Source code for iCallSV.checkBlackList</h1><div class=\"highlight\"><pre>\n<span></span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">checkBlackList</span>\n<span class=\"sd\">~~~~~~~~~~~~~~</span>\n\n<span class=\"sd\">:Description: This module will read the Black List file and tell if and event is blacklisted or not</span>\n\n<span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"sd\">Created on Nov 20, 2015</span>\n<span class=\"sd\">@author: Ronak H Shah</span>\n<span class=\"sd\">::Inputs::</span>\n<span class=\"sd\">BlackListFile: List of Position that have Black List Structural Variants (Tab-delimited Format without header:chr1    start1    end1\tchr2    start2    end2).</span>\n<span class=\"sd\">chr1: Chromosome location for 1st breakpoint</span>\n<span class=\"sd\">start1: Start location of the 1st breakpoint</span>\n<span class=\"sd\">chr2: Chromosome location for 2nd breakpoint</span>\n<span class=\"sd\">start2: Start Location of the second breakpoint</span>\n<span class=\"sd\">extention: How much should the intervals be extended in positive and negative directions</span>\n<span class=\"sd\">&#39;&#39;&#39;</span>\n<span class=\"kn\">import</span> <span class=\"nn\">os</span>\n\n\n<span class=\"c1\"># Read the hotspot file and make a dictionary of it</span>\n<div class=\"viewcode-block\" id=\"ReadBlackListFile\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.checkBlackList.ReadBlackListFile\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">ReadBlackListFile</span><span class=\"p\">(</span><span class=\"n\">BlackListFile</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    Read the ``blacklist region file``</span>\n\n<span class=\"sd\">    :param str BlackListFile: str of file to be read.</span>\n<span class=\"sd\">    :return: A list containing black listed regions.</span>\n<span class=\"sd\">    :rtype: list.</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    <span class=\"n\">blacklist</span> <span class=\"o\">=</span> <span class=\"p\">[]</span>\n    <span class=\"k\">if</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\">BlackListFile</span><span class=\"p\">):</span>\n        <span class=\"k\">with</span> <span class=\"nb\">open</span><span class=\"p\">(</span><span class=\"n\">BlackListFile</span><span class=\"p\">,</span> <span class=\"s1\">&#39;r&#39;</span><span class=\"p\">)</span> <span class=\"k\">as</span> <span class=\"n\">filecontent</span><span class=\"p\">:</span>\n            <span class=\"k\">for</span> <span class=\"n\">line</span> <span class=\"ow\">in</span> <span class=\"n\">filecontent</span><span class=\"p\">:</span>\n                <span class=\"c1\">#(chrom1, start1, chrom2, start2) = line.rstrip().split(&quot;\\t&quot;)</span>\n                <span class=\"n\">blacklist</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">(</span><span class=\"n\">line</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">blacklist</span><span class=\"p\">)</span></div>\n\n\n<span class=\"c1\"># Read the hotspot dictionary and tell if the event occurs in blacklist or not</span>\n<div class=\"viewcode-block\" id=\"CheckIfItIsBlacklisted\"><a class=\"viewcode-back\" href=\"../../../iCallSV/#iCallSV.checkBlackList.CheckIfItIsBlacklisted\">[docs]</a><span class=\"k\">def</span> <span class=\"nf\">CheckIfItIsBlacklisted</span><span class=\"p\">(</span><span class=\"n\">chr1</span><span class=\"p\">,</span> <span class=\"n\">start1</span><span class=\"p\">,</span> <span class=\"n\">chr2</span><span class=\"p\">,</span> <span class=\"n\">start2</span><span class=\"p\">,</span> <span class=\"n\">blacklist</span><span class=\"p\">,</span> <span class=\"n\">extention</span><span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    Check if coordinate are present in the ``blacklist region file``</span>\n\n<span class=\"sd\">    :param str chr1: str of the breakpoint in first chromosome</span>\n<span class=\"sd\">    :param int start1: int of the start location of the breakpoint in first chromosome</span>\n<span class=\"sd\">    :param str chr2: str of the breakpoint in second chromosome</span>\n<span class=\"sd\">    :param int start2: int of the start location of the breakpoint in second chromosome</span>\n<span class=\"sd\">    :param list blacklist: A list containing black listed regions</span>\n<span class=\"sd\">    :param int extension: an value for search in positive and negative direction of the start1 and start2 location</span>\n<span class=\"sd\">    :return: A boolean tag indicating True or False</span>\n<span class=\"sd\">    :rtype: bool</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">None</span>\n    <span class=\"n\">chr1</span> <span class=\"o\">=</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">chr1</span><span class=\"p\">)</span>\n    <span class=\"n\">chr2</span> <span class=\"o\">=</span> <span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">chr2</span><span class=\"p\">)</span>\n    <span class=\"n\">start1</span> <span class=\"o\">=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">start1</span><span class=\"p\">)</span>\n    <span class=\"n\">start2</span> <span class=\"o\">=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">start2</span><span class=\"p\">)</span>\n    <span class=\"k\">if</span> <span class=\"n\">chr1</span> <span class=\"o\">==</span> <span class=\"n\">chr2</span><span class=\"p\">:</span>\n        <span class=\"n\">start</span> <span class=\"o\">=</span> <span class=\"n\">start1</span>\n        <span class=\"n\">end</span> <span class=\"o\">=</span> <span class=\"n\">start2</span>\n        <span class=\"k\">for</span> <span class=\"n\">entries</span> <span class=\"ow\">in</span> <span class=\"n\">blacklist</span><span class=\"p\">:</span>\n            <span class=\"p\">(</span><span class=\"n\">bchr1</span><span class=\"p\">,</span> <span class=\"n\">bstart1</span><span class=\"p\">,</span> <span class=\"n\">bchr2</span><span class=\"p\">,</span> <span class=\"n\">bstart2</span><span class=\"p\">)</span> <span class=\"o\">=</span> <span class=\"n\">entries</span><span class=\"o\">.</span><span class=\"n\">rstrip</span><span class=\"p\">()</span><span class=\"o\">.</span><span class=\"n\">split</span><span class=\"p\">(</span><span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span>\n            <span class=\"n\">bstart1</span> <span class=\"o\">=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span><span class=\"p\">)</span>\n            <span class=\"n\">bstart2</span> <span class=\"o\">=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span><span class=\"p\">)</span>\n            <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">bchr1</span> <span class=\"o\">==</span> <span class=\"n\">bchr2</span><span class=\"p\">):</span>\n                <span class=\"k\">if</span><span class=\"p\">(</span><span class=\"n\">chr1</span> <span class=\"o\">==</span> <span class=\"n\">bchr1</span><span class=\"p\">):</span>\n                    <span class=\"k\">if</span><span class=\"p\">(((</span><span class=\"n\">start</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">start</span> <span class=\"o\">&gt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))</span>\n                       <span class=\"ow\">and</span> <span class=\"p\">((</span><span class=\"n\">end</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">end</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))):</span>\n                        <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">True</span>\n                    <span class=\"k\">else</span><span class=\"p\">:</span>\n                        <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">False</span>\n                    <span class=\"k\">if</span><span class=\"p\">(((</span><span class=\"n\">end</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">end</span> <span class=\"o\">&gt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))</span>\n                            <span class=\"ow\">and</span> <span class=\"p\">((</span><span class=\"n\">start</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">start</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))):</span>\n                        <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">True</span>\n                    <span class=\"k\">else</span><span class=\"p\">:</span>\n                        <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">False</span>\n                <span class=\"k\">else</span><span class=\"p\">:</span>\n                    <span class=\"k\">continue</span>\n            <span class=\"k\">else</span><span class=\"p\">:</span>\n                <span class=\"k\">continue</span>\n\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        <span class=\"k\">for</span> <span class=\"n\">entries</span> <span class=\"ow\">in</span> <span class=\"n\">blacklist</span><span class=\"p\">:</span>\n            <span class=\"p\">(</span><span class=\"n\">bchr1</span><span class=\"p\">,</span> <span class=\"n\">bstart1</span><span class=\"p\">,</span> <span class=\"n\">bchr2</span><span class=\"p\">,</span> <span class=\"n\">bstart2</span><span class=\"p\">)</span> <span class=\"o\">=</span> <span class=\"n\">entries</span><span class=\"o\">.</span><span class=\"n\">rstrip</span><span class=\"p\">()</span><span class=\"o\">.</span><span class=\"n\">split</span><span class=\"p\">(</span><span class=\"s2\">&quot;</span><span class=\"se\">\\t</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span>\n            <span class=\"n\">bstart1</span> <span class=\"o\">=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span><span class=\"p\">)</span>\n            <span class=\"n\">bstart2</span> <span class=\"o\">=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span><span class=\"p\">)</span>\n            <span class=\"k\">if</span><span class=\"p\">(((</span><span class=\"n\">chr1</span> <span class=\"o\">==</span> <span class=\"n\">bchr1</span><span class=\"p\">)</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">chr2</span> <span class=\"o\">==</span> <span class=\"n\">bchr2</span><span class=\"p\">))</span> <span class=\"ow\">or</span> <span class=\"p\">((</span><span class=\"n\">chr1</span> <span class=\"o\">==</span> <span class=\"n\">bchr2</span><span class=\"p\">)</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">chr2</span> <span class=\"o\">==</span> <span class=\"n\">bchr1</span><span class=\"p\">))):</span>\n                <span class=\"k\">if</span><span class=\"p\">(((</span><span class=\"n\">start1</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">start1</span> <span class=\"o\">&gt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))</span>\n                   <span class=\"ow\">and</span> <span class=\"p\">((</span><span class=\"n\">start2</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">start2</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))):</span>\n                    <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">True</span>\n                <span class=\"k\">else</span><span class=\"p\">:</span>\n                    <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">False</span>\n                <span class=\"k\">if</span><span class=\"p\">(((</span><span class=\"n\">start2</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">start2</span> <span class=\"o\">&gt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart1</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))</span>\n                   <span class=\"ow\">and</span> <span class=\"p\">((</span><span class=\"n\">start1</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">-</span> <span class=\"n\">extention</span><span class=\"p\">))</span> <span class=\"ow\">and</span> <span class=\"p\">(</span><span class=\"n\">start1</span> <span class=\"o\">&lt;=</span> <span class=\"nb\">int</span><span class=\"p\">(</span><span class=\"n\">bstart2</span> <span class=\"o\">+</span> <span class=\"n\">extention</span><span class=\"p\">)))):</span>\n                    <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">True</span>\n                <span class=\"k\">else</span><span class=\"p\">:</span>\n                    <span class=\"n\">blacklistTag</span> <span class=\"o\">=</span> <span class=\"kc\">False</span>\n            <span class=\"k\">else</span><span class=\"p\">:</span>\n                <span class=\"k\">continue</span>\n\n    <span class=\"k\">return</span><span class=\"p\">(</span><span class=\"n\">blacklistTag</span><span class=\"p\">)</span></div>\n</pre></div>", "title": "iCallSV.checkBlackList", "customsidebar": null, "current_page_name": "_modules/iCallSV/checkBlackList", "sidebars": null, "parents": [{"link": "../../", "title": "Module code"}], "alabaster_version": "0.7.9"}