<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Into the genomics - Medium]]></title>
        <description><![CDATA[Articles on genomic concepts, workflows and scripts - Medium]]></description>
        <link>https://medium.com/intothegenomics?source=rss----b37a6ec849b5---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Into the genomics - Medium</title>
            <link>https://medium.com/intothegenomics?source=rss----b37a6ec849b5---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:43:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/intothegenomics" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Docker in genomics workflows]]></title>
            <link>https://medium.com/intothegenomics/using-docker-in-genomics-workflows-cd366850b185?source=rss----b37a6ec849b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/cd366850b185</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[sequence-analysis]]></category>
            <category><![CDATA[genomic-concepts]]></category>
            <category><![CDATA[mutation]]></category>
            <dc:creator><![CDATA[Pubudu samarakoon]]></dc:creator>
            <pubDate>Tue, 29 Oct 2019 09:53:32 GMT</pubDate>
            <atom:updated>2019-10-29T09:53:32.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpvPqVCOZ86xjDLQv6t9Vw.jpeg" /></figure><h3>Why use docker in genomics workflows?</h3><p>Genomics workflows implement a broad range of programs that have many dependencies. Typically, many different research groups develop these programs, and they are updated independently of one another. Therefore using such applications in a workflow can lead to various challenges. Importantly, significant issues in genomics workflows are related to their portability, reproducibility and conflicts in required dependencies. Docker provides an effective solution to address these issues.</p><p>In this article, I’ll first provide an overview of the docker technology that includes a brief introduction to docker, docker concepts and a set of frequently used docker commands. Next, I’ll demonstrate the utility of docker technology in DNA sequence analysis using BWA, samtools, Picard and GATK3 docker images.</p><h3>What is docker?</h3><p>Docker is a widely-used container technology that allows users to bundle software into standardised packages. In other words, docker allows users to create an isolated copy (instance) of one or more applications, including their dependencies and deploy them on a host system.</p><blockquote><a href="https://www.docker.com/resources/what-container">Docker is a type of container.</a> “A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.”</blockquote><p>Docker is not a virtual machine (VM). A VM can isolate an entire operating system (OS) and deploy as guest systems. Therefore multiple VMs can deploy multiple guest systems on a host. However, since a single VM contains a complete copy of the guest OS, implementing multiple VMs on a host is a resource-intensive task. In contrast to VMs, docker only packages the code (of an app) along with dependencies and enables them to run them on a host. When deploying multiple containers on a single host, they can share the host OS kernel. Therefore Docker containers require less computational resources than VMs.</p><h3>Why we need docker?</h3><p>Docker provides a single solution to multiple key issues</p><ul><li>Lack of isolation of processes within a system</li><li>Higher demand for resources when implementing multiple isolated environments</li><li>Issues related to reusability of application in different operating systems</li></ul><p>In essence, docker enables users to develop and test applications locally, and ship them to any other computer, cluster or cloud in a way that guarantees the same behaviour.</p><h3>Docker concepts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*e5whLfl6cxAqmhQpmUUx-g.png" /><figcaption><a href="https://www.docker.com/resources/what-container">source image</a></figcaption></figure><p><strong>Docker has three main components — Docker engine, containers and images.</strong></p><p><strong>Docker engine</strong></p><ul><li>Docker engine lives on the host computer and can carry many containers</li><li>Docker engine manage resources accordingly</li></ul><p><strong>Docker containers</strong></p><ul><li>Containers enable to run processes by exposing them to the host OS</li><li>A single container can have a single isolated process (or multiple processes on rare occasions)</li></ul><p><strong>Docker images</strong></p><ul><li>A Docker image is a file with all the instructions needed to execute an application in a Docker container. Therefore docker images are used to initiate docker containers.</li><li>You can use any Docker image in docker-engines independent to the underline OS</li><li>By creating a docker image, you can improve the portability of your application. i.e., You can transfer a docker image into a docker engine that runs on a different OS and expects the same behaviour.</li></ul><h4>How to build a docker container</h4><p>The process of building a docker container in three main steps.</p><ul><li>Step 1: Create the Dockerfile that provide instructions to build the container</li><li>Step 2: Use docker build command to pass the Dockerfile to docker engine. Docker engine then build a docker image that helps run the specified process</li><li>Step 3: Use docker run command to start a container using a docker image. Docker container initiated in this step runs alongside with other containers in the Docker engine.</li></ul><blockquote>The blog-post — <a href="https://medium.com/free-code-camp/docker-quick-start-video-tutorials-1dfc575522a0">A fast and easy Docker tutorial for beginners (video series)</a> provides a well described overview of the docker technology</blockquote><h3>Useful Docker commands</h3><pre><strong><em>Check the docker version<br></em></strong>&gt; docker — version</pre><pre><strong><em>Download (pull) docker images<br></em></strong>&gt; docker pull &lt;IMAGE NAME&gt;:&lt;TAG&gt;</pre><pre><strong><em>List docker images<br></em></strong>&gt; docker images</pre><pre><strong><em>Build a docker image - docker build looks for the d</em></strong><strong><em>ockerfile and the &quot;context&quot; in the given path </em><br></strong>&gt; docker build .</pre><pre><strong><em>Create a Docker container - create the container and print the containerID to STDOUT (do not start the container)<br>&gt; </em></strong>docker create</pre><pre><strong><em>List Docker containers<br></em></strong><em>&gt; </em>docker ps -a <em># list all <br></em>&gt; docker ps <em># list running containers</em> <br>&gt; docker ps — filter “status=exited” <em># stopped containers</em></pre><pre><strong><em>Start and run a Docker container (docker create + docker start)<br></em></strong>&gt; docker run [ OPTIONS ] IMAGE[:TAG] [COMMAND] [ARG…]</pre><pre><strong><em>docker run options<br>-i</em></strong><em>: Starts the container in interactive mode. <br></em><strong><em>-ti</em></strong><em>: Run shell commands inside a particular container <br></em><strong><em>–name</em></strong><em>: User friendly name for the container. If the name is not specified, random string will be assigned as the container name. <br></em><strong><em>-v &lt;path to host directory&gt;:&lt;path to container directory&gt;:</em></strong><em> map host directory to specified directory in the container <br></em><strong><em>-rm:</em></strong><em> remove the container after executing the command <br></em><strong><em>-p:</em></strong><em> map ports in the host computer to the Docker container</em></pre><pre><strong><em>Executing an initiated container<br></em></strong>&gt; docker container exec</pre><pre><strong><em>Stop a running a Docker Container<br></em></strong>&gt; docker stop [-t| — time[=10]] CONTAINERID [CONTAINER…] <br>&gt; docker stop $(docker ps -q) ## stop all containers</pre><pre><strong><em>Kill all running containers and clean the memory<br></em></strong>&gt; docker kill $(docker ps -q)</pre><pre><strong><em>Deleting a Docker container (Stop the container before deleting)<br></em></strong>&gt; docker rm [ OPTIONS ] CONTAINER [ CONTAINER ]</pre><h3>Implementing genomics workflows using docker</h3><p>Here, I’ll use a test dataset and implement a basic genomics workflow to highlight the use of docker technology in DNA sequence analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*vogOfaV4zcmAIkfM7bljTQ.jpeg" /><figcaption><strong>Sequence analysis and variant calling workflow using BWA, Samtools, Picard and GATK3 docker images</strong></figcaption></figure><h4>Datasets:</h4><ul><li>Input</li></ul><pre>7859_GPI.read1.fq and 7859_GPI.read2.fq FASTQ files <br>- <a href="https://drive.google.com/drive/folders/1aBcbV_Hlyg0wOOmZDDSBeIc0uw1r3f_w">from GATK google drive folder — tutorial_7859.tar.gz</a></pre><ul><li>Reference sequence</li></ul><pre>chr19_KI270866v1_alt <br>- <a href="https://software.broadinstitute.org/gatk/documentation/article?id=7859">two contigs from human GRCh38/hg38: chr19</a></pre><h4>Download docker images and initiate relevant containers</h4><ul><li><a href="http://bio-bwa.sourceforge.net/bwa.shtml">BWA</a></li></ul><pre>&gt; docker pull biocontainers/bwa:v0.7.17–3-deb_cv1</pre><ul><li><a href="https://github.com/samtools/samtools">Samtools</a></li></ul><pre>&gt; docker pull biocontainers/samtools:v1.7.0_cv3</pre><ul><li><a href="http://broadinstitute.github.io/picard/">Picard</a></li></ul><pre>&gt; docker pull biocontainers/picard:v2.3.0_cv3</pre><ul><li><a href="https://software.broadinstitute.org/gatk/">GATK</a></li></ul><pre><strong><em>Download latest GATK release</em></strong><em><br></em>&gt; docker pull broadinstitute/gatk</pre><pre><strong><em>Download a specific GATK release<br></em></strong>&gt; docker pull quay.io/biocontainers/gatk:3.6–7 ## specific GATK release</pre><pre><strong><em>Run and initiate the gatk_3.6 image and follow GATK3 setup (download a licensed copy of GATK from the Broad Institute and copy GATK into your conda environment)</em></strong><br>docker run — name gatk_3.6 -it -v &lt;host directory&gt;:/data &lt;IMAGE ID&gt;<br>docker container exec -it gatk_3.6 bash ## Follow GATK3 setup</pre><h4>Run basic steps in a sequence analysis workflow using docker</h4><ul><li>Indexing the reference genome</li></ul><pre><strong><em>Initiate bwa container... and</em></strong></pre><pre>&gt; docker run — name bwa_v0.7.17 -it -v &lt;host directory&gt;:/data &lt;IMAGE ID&gt; bash</pre><pre><strong><em>Index the reference</em></strong></pre><pre>&gt; bwa index chr19_KI270866v1_alt.fasta<br>           <em># Create </em>BWA index with<br>                    <em> *fasta.amb,<br>                     *fasta.ann,<br>                     *fasta.bwt, <br>                     *fasta.pac, <br>                     *fasta.sa files</em></pre><pre><strong><em>Create *fasta.fai and *dict indexes for GATK analysis</em></strong></pre><pre>&gt; docker run — name samtools_v1.7 -it -v &lt;host directory&gt;:/data samtools faidx chr19_KI270866v1_alt.fasta</pre><pre><em>&gt; docker run -v </em>&lt;host directory&gt;:/data --<em>rm &lt;IMAGE ID&gt; picard CreateSequenceDictionary R=chr19_KI270866v1_alt.fasta O=chr19_KI270866v1_alt.dict</em></pre><ul><li>Read-mapping using BWA mem</li></ul><pre><strong><em>Execute BWA container... and</em></strong></pre><pre>&gt; docker container exec -it bwa_v0.7.17 bash</pre><pre><strong><em>Align *fq files to the reference</em></strong></pre><pre>&gt; bwa mem -R &#39;@RG\tID:t1\tSM:t1&#39; chr19_KI270866v1_alt.fasta 7859_GPI.read1.fq 7859_GPI.read2.fq &gt; 7859_GPI.aln_pe.sam<br>  # Created 7859_GPI.aln_pe.sam file</pre><ul><li>Sorting SAM file, marking duplicated reads and indexing BAM files</li></ul><pre><strong><em>Sort sam file and create a bam file, then index the bam file</em></strong></pre><pre>&gt; docker run -v &lt;host directory&gt;:/data --rm <em>&lt;IMAGE ID&gt;</em> picard SortSam INPUT=7859_GPI.aln_pe.sam OUTPUT=7859_GPI.aln_pe.bam SORT_ORDER=coordinate<br>&gt; docker run -v &lt;host directory&gt;:/data --rm <em>&lt;IMAGE ID&gt; </em>picard BuildBamIndex VALIDATION_STRINGENCY=LENIENT I=7859_GPI.aln_pe.bam</pre><pre><strong><em>Mark duplicated reads in the indexed bam file and create a new marked-bam file</em></strong></pre><pre>&gt; docker run -v &lt;host directory&gt;:/data --rm <em>&lt;IMAGE ID&gt;</em> picard MarkDuplicates VALIDATION_STRINGENCY=LENIENT AS=true REMOVE_DUPLICATES=true I=7859_GPI.aln_pe.bam O=7859_GPI.aln_pe.md.bam M=7859_GPI.aln_pe.md.metrics</pre><pre><strong><em>Index the marked-bam file</em></strong></pre><pre>&gt; docker run -v &lt;host directory&gt;:/data --rm <em>&lt;IMAGE ID&gt; </em>picard BuildBamIndex VALIDATION_STRINGENCY=LENIENT I=7859_GPI.aln_pe.md.bam</pre><ul><li>GATK3 analysis and calling variants</li></ul><pre><strong><em>Execute GATK3 container... and</em></strong></pre><pre>&gt; docker container exec -it gatk_3.6 bash</pre><pre><strong><em>Define intervals to target for local realignment</em></strong></pre><pre>&gt; java -jar GenomeAnalysisTK.jar -T RealignerTargetCreator \<br>-nt 4 -R chr19_KI270866v1_alt.fasta -I 7859_GPI.aln_pe.md.bam \<br>-o 7859_GPI.aln_pe.intervals</pre><pre><strong><em>Perform local realignment of reads around indels</em></strong></pre><pre>&gt; java -jar GenomeAnalysisTK.jar -T IndelRealigner \<br>-R chr19_KI270866v1_alt.fasta -I 7859_GPI.aln_pe.md.bam \<br>-targetIntervals 7859_GPI.aln_pe.intervals -o 7859_GPI.aln_pe.md.bam.realigned.bam</pre><pre><strong><em>Call variants using HaplotypeCaller</em></strong></pre><pre>&gt; java -jar GenomeAnalysisTK.jar -T HaplotypeCaller \<br>-R chr19_KI270866v1_alt.fasta -ERC GVCF \<br>-I 7859_GPI.aln_pe.md.bam.realigned.bam -o 7859_GPI.aln_pe.md.bam.realigned.g.vcf</pre><blockquote>In summary, this workflow uses multiple docker images that take *.fastq files and a reference genome file, and create a *.vcf file with a list of variants.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd366850b185" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intothegenomics/using-docker-in-genomics-workflows-cd366850b185">Using Docker in genomics workflows</a> was originally published in <a href="https://medium.com/intothegenomics">Into the genomics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CNVs (Copy Number Variants)-Detection methods and exploratory data analysis with Python]]></title>
            <link>https://medium.com/intothegenomics/cnvs-copy-number-variants-context-detection-methods-and-exploratory-data-analysis-with-python-986de6a58072?source=rss----b37a6ec849b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/986de6a58072</guid>
            <category><![CDATA[cnv-prediction]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[copy-number-variants]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[genomic-concepts]]></category>
            <dc:creator><![CDATA[Pubudu samarakoon]]></dc:creator>
            <pubDate>Thu, 24 Jan 2019 19:01:01 GMT</pubDate>
            <atom:updated>2019-10-29T09:46:10.546Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-C_wxy0AtyzIhxTnPcJ3w.jpeg" /></figure><h3>CNVs (Copy Number Variants)— Context, detection methods and exploratory data analysis with Python</h3><p>In this article, I’ll be providing a detailed view on Copy Number Variants (CNVs) in three main sections.</p><ol><li><strong>Introduction:</strong> In the first section, I’ll discuss what a CNV is and why it is essential to study these variants.</li><li><strong>CNV detection methods:</strong> Here, I’ll provide an overview of how to identify CNVs using experimental and computational techniques.</li><li><strong>Visualisation of CNVs using python: </strong>Today, computational CNV prediction is becoming a popular variant detection method. Therefore in this third section, I’ll demonstrate how to analyse and visualise computationally predicted CNVs to help identify systematic biases in results.</li></ol><h3>1. What are genetic variants?… What are CNVs?… Why study CNVs?…</h3><h4>1.1 Variants in the human genome</h4><p>These are the genetic differences between individuals, within and among populations. There are three broad categories of genetic variants: sequence variants-changes in DNA sequence, structural alterations, and modifications in chromosome number.</p><h4>1.2 Copy Number Variant (CNV)</h4><p>CNVs are a type of structural alterations that affect genomic regions ranging from <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2669898/">one kilobase (Kb) to several megabases (Mb)</a>. These large-scale genetic variants can occur throughout the genome and alter the structure. For example, in the human genome, there are 23 pairs of chromosomes. Two chromosomes in these 23 pairs are from each parent. Therefore historically, regions in a genome of a healthy individual were thought to occur in two copies — one copy from the mother and the other from the father. However, with the identification of copy number variants, scientists found out that the number of copies of genomic regions can vary between individuals in a population. Therefore due to CNVs, some individuals may have more (or fewer) copies of genomic regions compared to others in a population.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*foqUV3LQrQkhtA-E_xYAlg.jpeg" /></figure><blockquote><strong>CNVs can change the number of copies of a specific region either by deleting or duplicating these regions. These CNVs are known as deletions (losses) or duplications (gains).</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*qE2mqwsV1l0s2DamChp-Vg.jpeg" /><figcaption>Deletion (loss) or duplication (gain) of the chromosomal region — C</figcaption></figure><p>Although CNVs are primarily known as the variants that change the number of copies, inversions — another type of CNVs, only change the orientation of genomic regions (not the number of copies). However, the vast majority of methods used in current CNV detection protocols were developed to detect deletions and duplications. Therefore this article is mainly focussed on deletions and duplications.</p><h4>1.3 Why study CNVs?</h4><p>CNVs can cause a broad range of diseases including Mendelian diseases (single-gene diseases), complex diseases (diseases due to many genes) and cancer. These diseases can occur in different ways. For example, deletion of an entire gene or part of a gene can disrupt the function of a gene and cause diseases. CNVs that affect multiple genes can also cause diseases by changing the structure of these genes (e.g. fusion genes). Moreover, CNVs cause diseases by affecting genomic interactions that are critical to a gene function (e.g. deleting or duplicating enhancers or promoters that could affect their interactions). Additionally, by altering the number of copies of genes, CNVs can change the level of their products and cause diseases.</p><h3>2. CNV detection methods</h3><h4>2.1 Classical methods used to detect CNVs</h4><p>Since the advent of genetic testing in clinical laboratories, various techniques have been introduced to detect CNVs. <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC395705/">Comparative Genomic Hybridization</a> (CGH) was one of the earliest techniques used to detect genome-wide CNVs (CNVs spread throughout the genome). CGH uses two different fluorescent stains to label test and reference (normal) DNA samples. Then these differentially labelled samples are co-hybridised to normal human metaphase chromosomes. Next, changes in the fluorescence intensity ratios between test-reference samples are used to identify the regions of chromosomal losses and gains. Chromosomal losses are the regions with decreased intensities (test-specific fluorescence), while chromosomal gains are the regions with increased intensities. CGH enabled the detection of genome-wide CNVs, yet the resolution is limited to <a href="https://www.agilent.com/cs/library/slidepresentation/public/New%20Agilent%20CGH%20microarrays%20focused%20on%20exons%20for%20clinical%20applications.pdf">CNVs &gt; 5Mb</a>. Therefore, the CGH method was further improved using microarrays to detect genome-wide CNVs in high-resolution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*XlwoMJ19-PZdyTH3G1p_Jw.gif" /><figcaption><a href="http://www.els.net/WileyCDA/ElsArticle/refId-a0002651.html">Ref: DOI: 10.1002/9780470015902.a0002651.pub2</a></figcaption></figure><p>Microarray-based methods implement the same principle used in CGH techniques. For example, they use differently labelled test and reference DNA samples as starting materials and detect CNV regions by examining changes in fluorescence intensity ratios (between test-reference samples). However, in contrast to normal metaphase chromosomes used in CGH, microarrays contain probes printed on glass slides. These probes are spread throughout the genome and can hybridise to specific DNA segments. First generation microarray platforms used few thousand probes (<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1356528/">large-insert clones</a> — <a href="https://en.wikipedia.org/wiki/Bacterial_artificial_chromosome">bacterial artificial chromosomes</a>) and had a resolution of <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1356528/">1Mb-3Mb</a>. Next wave of arrays contained millions of short probes to improve the CNV detection resolution. There are two main types of microarrays — SNP-arrays and CGH-arrays (aCGH). SNP-arrays use probes that target single nucleotide changes (polymorphisms) — SNPs to tag CNVs. aCGH uses ~60bp long oligonucleotide probes as array elements. Both these arrays can contain <a href="https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0027859">1-4 million</a> probes to detect CNVs in high-resolution (e.g. <a href="https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0027859">1Kb</a>-<a href="https://www.nature.com/articles/ng1697">5Kb</a> resolution).</p><p>Microarrays offer a reliable, efficient and scalable method to detect CNVs in both clinical and research setting. Today, commercial services like Agilent, Nimblegen, Affymetrix and Illumina provide a broad range of array platforms for various purposes. Additionally, it is possible to custom design arrays for scientists with specific requirements. However, the sensitivity and precision of these platforms vary greatly depending on their design (the spread of probes across the genome). Therefore differences in CNV detection sensitivities in different platforms is considered as the main drawback of these arrays. For example, a<a href="https://www.ncbi.nlm.nih.gov/pubmed/19995423"> study has shown </a>that large CNVs (&gt;1Mb) were detected with high accuracy even in arrays with different probe distributions, but these arrays have shown variable efficiencies in detecting short CNVs. Scientists have developed next-generation sequencing-based methods to predict CNVs to address this issue.</p><h4>2.2 CNV prediction using next-generation- sequencing (NGS) based methods</h4><h4>Next Generation Sequencing (NGS)</h4><p>NGS allows to sequence DNA and RNA rapidly and cost-effectively than the previously used <a href="https://www.youtube.com/watch?v=UTDwfgIM-ss">Sanger sequencing method</a>. NGS has revolutionised the field of genomics and molecular biology. NGS is also known as high-throughput- sequencing and <a href="https://www.ebi.ac.uk/training/online/course/ebi-next-generation-sequencing-practical-course/what-you-will-learn/what-next-generation-dna-">represents many different technologies. </a><a href="https://emea.illumina.com/science/technology/next-generation-sequencing.html">Illumina sequencing by synthesis</a> is the most commonly used technology today.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfCd6B5HRaZ8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfCd6B5HRaZ8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfCd6B5HRaZ8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd0eb1c35ca1f6564ef4d8c63adc4dd5/href">https://medium.com/media/fd0eb1c35ca1f6564ef4d8c63adc4dd5/href</a></iframe><blockquote><strong><em>NGS Terminology</em></strong></blockquote><blockquote><a href="https://en.wikipedia.org/wiki/DNA_fragmentation"><strong>Fragmentation</strong></a><strong>:</strong><br>Typical sequencing experiment involves fragmentation of the genome into millions of molecules. These DNA molecules are known as DNA fragments. Then these fragments are sequenced to produce a set of reads.</blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Read_(biology)"><strong>Read:</strong></a><br>A read is a sequence of <a href="https://en.wikipedia.org/wiki/Base_pair">base pairs</a> corresponding to all or part of a single DNA fragment.</blockquote><blockquote><a href="https://www.ebi.ac.uk/training/online/course/functional-genomics-ii-common-technologies-and-data-analysis-methods/read-mapping-or"><strong>Read mapping or alignment:</strong></a><strong> </strong><br>After generating a set of reads, these are aligned to the reference genome of a target organism. For example, if the sequencing process generates a set of reads from a patient genome, these are aligned (or mapped) to the human reference genome.</blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Coverage_(genetics)"><strong>Depth/Coverage (Depth-of-coverage):</strong></a><br>Fragmentation and sequencing process generates sets of overlapping reads covering the entire genome or exome. Then the mapping process aligns these reads to the reference genome so that each set of reads maps to its’ relevant genomic region. Coverage (or depth) is the number of reads that overlap with a specific region in the reference genome. In other words, it the number of time a region in the reference genome is covered during the sequencing process.</blockquote><blockquote>Read mapping or alignment process provides various measures that could help detect sequencing artefacts. Coverage calculation step uses these measures to filter-out sequencing artefacts. For example, mapping process considers reads with the same chromosomal start and end positions (100% overlap) as sequencing artefacts (duplicated reads) and reads that map to more than one genomic regions as low-quality reads. Coverage calculation step removes all the duplicated and low-quality reads and counts the number of unique reads that map to a given region in the reference genome. <strong>Deep sequencing</strong> refers to the general concept of aiming for a high number of unique reads of each region of a sequence.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*QnbOH-GrL8o4kf0UaNPUDQ.jpeg" /><figcaption><a href="https://www.illumina.com/documents/products/illumina_sequencing_introduction.pdf">https://www.illumina.com/documents/products/illumina_sequencing_introduction.pdf</a></figcaption></figure><p>With the introduction of NGS, whole genomes could be rapidly characterised at single base pair resolution. The continuous development of these technologies lead to the rapid decrease in sequencing cost, and therefore massive amounts of sequence data were generated with ever-decreasing effort. In 2010–2011, when whole-genome sequencing was not available at an affordable price, exome sequencing was introduced as a cost-effective approach that sequence coding regions of the human genome.</p><blockquote><a href="https://en.wikipedia.org/wiki/Whole_genome_sequencing">Whole-genome sequencing is the process of determining the entire DNA sequence of an organism’s genome.</a></blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Exome_sequencing">Exome sequencing is the process of determining the complete sequence of all the protein-coding regions in a genome.</a></blockquote><p>When exome sequencing was first introduced, it was estimated that <a href="https://www.ncbi.nlm.nih.gov/pubmed/19861545">~85% of clinically relevant (disease-relevant) variants were in exonic regions</a>. While this figure is likely an overestimate due to the scarcity of data on disease causality, scientists still expect that the majority of causal variants to be in the exome. Since the introduction, exome sequencing has been a useful genetic diagnostic test that revolutionised the detection of a broad range of disease-relevant variants (novel, de novo — <a href="https://www.cancer.gov/publications/dictionaries/genetics-dictionary/def/de-novo-mutation">present for the first time in one family member</a> and rare — <a href="https://www.nature.com/subjects/rare-variants">less than 1% of the population</a> variants).</p><h4>Predicting CNVs in exome sequence data</h4><p>Since the introduction of exome sequencing technologies, various CNV prediction programs have been developed to detect CNVs in exomes. These programs use different strategies to predict CNVs. Today, depth-of-coverage based method is the most commonly used strategy in predicting CNVs in exomes.</p><p>In NGS, copy number (CN) variable genomic regions (CN≠2) generate higher or lower read counts compared to copy number neutral regions (CNV=2). Here, duplicated regions generate higher read counts (higher coverage) compared to CN neutral regions while deleted regions generate lower read counts (lower coverage). Therefore when calling CNVs, prediction programs expect that the coverage is proportional to the copy number of the region.</p><p>In depth-of-coverage based CNV prediction, first, a control dataset is created from a set of target exomes. This control dataset represents the depth-of-coverage distribution in a copy number neutral sample. Then the prediction program compares each exome to the control and looks for regions with increased or decreased coverage. Duplications (amplification) are the regions with increased coverage and deletions are the regions with decreased coverage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ZUR7IuOP4x5ZHz25-rW-w.png" /><figcaption>Schematic representation of CNV prediction in exomes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*UHqim39CXfBhF1BUJnjWZA.jpeg" /><figcaption>Commonly used CNV prediction programs</figcaption></figure><p>With the increasing popularity of exome sequencing as a diagnostic tool, a large number of detection programs have been developed to call CNVs in exomes. Word-cloud in this figure lists commonly used prediction programs (font size represents the google citation count). These programs have different strengths and weaknesses, and therefore selecting a program has become a challenging task. I have published scientific articles <a href="https://bmcgenomics.biomedcentral.com/articles/10.1186/1471-2164-15-661">discussing these matters</a> and <a href="https://bmcgenomics.biomedcentral.com/articles/10.1186/s12864-016-2374-2">presenting a way to improve the disease-relevant CNV detection</a>. Following is a list of critical points discussed in these articles.</p><ul><li>CNV prediction programs are better at predicting long CNVs (containing 4 or more CNVs)</li><li>These programs show a high false positive rate when predicting short CNVs</li><li>ExCopyDepth is optimised to predict short CNVs with high accuracy (we have used this to predict disease-causing single exon heterozygous deletions)</li><li>When detecting rare CNVs, ExomeDepth showed the highest sensitivity and CONIFER showed the lowest false positive rate</li><li><a href="https://github.com/PubuduSaneth/cnvScan">cnvScan</a> can be used effectively to reduce false positive counts based on CNV quality scores</li><li><a href="https://github.com/PubuduSaneth/cnvScan">cnvScan</a> provides a broad range of information that can improve the functional and clinical interpretation of predicted CNVs</li><li>Computationally predicted CNVs need to be validated using a relevant microarray when detecting a disease-causing variant</li></ul><h3>3. Exploratory CNV analysis with python</h3><p>After predicting, annotating and filtering CNVs from a group of patients, we manually examine variants containing genes that are relevant to a particular disease. These disease-relevant genes are commonly known as candidate genes. However, before the manual examination, we need to analyse CNVs further and identify various biases in the results. This step is also useful to prioritise the most relevant gene set in the dataset especially when a long list of candidate genes is not available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wknAp7Nl5KHqWVn0uNd7GQ.jpeg" /><figcaption>Access <a href="https://genome.ucsc.edu/cgi-bin/hgCustom">UCSC add custom track</a> and upload the bed file as shown here</figcaption></figure><p>Here we’ll discuss how to visualise CNVs using <a href="http://exac.broadinstitute.org/downloads">publically available ExAC dataset</a>. You can access the FTP site and download the “exac-final.autosome-1pct-sq60-qc-prot-coding.cnv.bed” file. This file lists all the high-quality deletions and duplications identified in the ExAC project. Since this file is not a tab-delimited file, we can either write a script or use UCSC table browser to extract ExAC deletions and duplications.</p><h4>CNV analysis with python</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65f49a9bd0e3710d56f8c18336607cea/href">https://medium.com/media/65f49a9bd0e3710d56f8c18336607cea/href</a></iframe><p>This GitHubGist provides a detailed description of how to explore quality-scores, length and genes in ExAC deletions and duplications. The main steps in this script are as follows.</p><ul><li><strong>Read ExAC deletions and duplications into a pandas dataframe. Then, delete columns that are not relevant to the analysis.</strong></li></ul><pre>exac = pd.concat([pd.read_table(&quot;ExAC_deletions.bed&quot;, names=[&#39;chr&#39;, &#39;start&#39;, &#39;end&#39;, &#39;population&#39;, &#39;score&#39;, &#39;strand&#39;, &#39;x1&#39;, &#39;x2&#39;, &#39;x3&#39;], skiprows=1).assign(cns=&quot;del&quot;),<br> pd.read_table(&quot;ExAC_duplications.bed&quot;, names=[&#39;chr&#39;, &#39;start&#39;, &#39;end&#39;, &#39;population&#39;, &#39;score&#39;, &#39;strand&#39;, &#39;x1&#39;, &#39;x2&#39;, &#39;x3&#39;], skiprows=1).assign(cns=&quot;dup&quot;)]) ## In [2]</pre><pre>exac = exac.drop(columns=[&#39;x1&#39;, &#39;x2&#39;, &#39;x3&#39;]) ## In [4]</pre><p><em>Here we read ExAC_deletions.bed and ExAC_duplications.bed files into two pandas dataframes and merge them using pandas </em><a href="https://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.concat.html"><em>concat</em></a><em> function.</em></p><ul><li><strong>Visualise deletion and duplication counts in the dataset</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*0JKFdVV8UAR3RbX5b_vyOQ.jpeg" /></figure><p><em>We can use the merged dataframe from the previous stage to count and visualise the number of the deletion and duplication in each population (with </em><a href="https://seaborn.pydata.org/generated/seaborn.countplot.html"><em>seaborn countplot</em></a><em>). As you can see, the majority of the CNVs are from Non-Finnish Europeans (ExAC-NFE) and duplications are overrepresented in each population.</em></p><ul><li><strong>Analysis of CNV quality-score</strong></li></ul><p>CNV quality score provides statistical support for the prediction. In other words, this provides a measure of how likely a CNV called incorrectly. Different prediction programs use different strategies to calculate CNV scores. For example, ExomeDepth and ExCopyDepth use log-likelihood ratio, ExomeCopy uses log odds ratio, XHMM use Phread scaled likelihood and CoNIFER do not report the score (normalised SVD score). After calling CNVs using the preferred program, we need to analyse the quality of the predictions to study systematic biases in the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TYaIbmjlu3TSg9ILzc1CXQ.jpeg" /></figure><p><em>Above figure shows the distribution of ExAC deletions and duplications using density plot, cumulative distribution plots and box plot. We can use these plots to study various aspects of quality scores of the CNVs in ExAC dataset.</em></p><ul><li><strong>Study the distribution of CNV length</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OYpF0yJ-ZmOFod06lUpbQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UkT-Lxnlw1VcbsLJO26fgw.jpeg" /></figure><p><em>Similar to CNV quality scores, we can study the distribution of CNV length using </em><a href="https://seaborn.pydata.org/"><em>seaborn</em></a><em> plotting functions. CNV length varies from ~100bp — ~35mb. Therefore CNV length density plots are highly skewed (In[21]). We can avoid that by plotting the length in log10 scale (e.g. In [26] and In [30]).</em></p><ul><li><strong>Visualise the distribution of CNVs after binning them based on their quality scores and length</strong></li></ul><p><em>Binning CNVs based on quality scores:</em></p><pre>$ score_bins = list(range(min(exac[&#39;score&#39;]), max(exac[&#39;score&#39;]+10), 10 ))<br>$ score_bins<br>&gt; [60, 70, 80, 90, 100]</pre><pre>$ exac[&#39;s_bin&#39;] = pd.cut(exac[&#39;score&#39;], bins=score_bins, labels=score_bins[:-1])</pre><p><em>Binning CNVs based on length:</em></p><pre>$ len_bins = list(range(int(min(exac[&#39;Len_inKb&#39;])), 10000, 1000 ))<br>$ len_bins[:5]<br>&gt; [0, 1000, 2000, 3000, 4000]</pre><pre>$ exac[&#39;l_bin&#39;] = pd.cut(exac[&#39;Len_inKb&#39;], bins=len_bins, labels=len_bins[:-1])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*FGAMTrMSnR-60UZelrvs4A.jpeg" /></figure><p><em>Figures show CNV quality score and length distribution in different bins. Here, CNV length (log 10 scale) do not vary in different quality score categories, but quality score distribution varies greatly when CNVs are in different length categories. For example, CNV score varies from 60–100 when deletions and duplications are in 0–10kb bin. However, duplications are overrepresented in bins over 7000kb (7mb) and have high CNV scores.</em></p><ul><li><strong>Identification of top 25 most affected genes in the dataset</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGB4BRT7UmOLev7Qj_SH8Q.jpeg" /></figure><p><em>Finally, we can identify the most affected genes in the CNV dataset. Here we identify the genes internal to each CNV and count the number of times each gene appear in CNV calls. These gene counts are then used to select the top 25 most affected genes in the CNV dataset.</em></p><p><em>We can follow the steps discussed in my post on</em><a href="https://medium.com/intothegenomics/annotate-genes-and-genomic-coordinates-using-python-9259efa6ffc2"><em> “Annotating gene coordinates and gene lists — python way”</em></a><em> to identify the genes in the dataset. Then we can use </em><a href="https://seaborn.pydata.org/generated/seaborn.barplot.html"><em>seaborn barplot</em></a><em> to visualize most affected genes.</em></p><blockquote>After exploratory analysis of CNV predictions, we can study the functional and clinical effects of these variants using annotations provided by programs like cnvScan. In my scientific article on <a href="https://bmcgenomics.biomedcentral.com/articles/10.1186/s12864-016-2374-2">cnvScan</a>, I have provided a detailed account of techniques used to interpret CNVs.</blockquote><h4>PyScripts</h4><ul><li><a href="https://github.com/PubuduSaneth/intoTheGenomics/blob/master/02.ExAC_CNV_analysis.ipynb">Jupyter notebook</a> with the python script</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=986de6a58072" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intothegenomics/cnvs-copy-number-variants-context-detection-methods-and-exploratory-data-analysis-with-python-986de6a58072">CNVs (Copy Number Variants)-Detection methods and exploratory data analysis with Python</a> was originally published in <a href="https://medium.com/intothegenomics">Into the genomics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Annotating gene coordinates and gene lists — The python way]]></title>
            <link>https://medium.com/intothegenomics/annotate-genes-and-genomic-coordinates-using-python-9259efa6ffc2?source=rss----b37a6ec849b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/9259efa6ffc2</guid>
            <category><![CDATA[genomic-coordinates]]></category>
            <category><![CDATA[gene-lists]]></category>
            <category><![CDATA[gencode]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[genome-annotation]]></category>
            <dc:creator><![CDATA[Pubudu samarakoon]]></dc:creator>
            <pubDate>Tue, 25 Dec 2018 21:18:46 GMT</pubDate>
            <atom:updated>2018-12-27T13:01:13.731Z</atom:updated>
            <content:encoded><![CDATA[<h3>Annotating gene coordinates and gene lists — The python way</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*x06EVEnruJ8l8JrrJobVDA.jpeg" /></figure><p>As described in my post “<a href="https://medium.com/intothegenomics/annotate-genes-and-genomic-coordinates-ecdad47d0c8e">Genomic coordinates to gene lists and vice versa</a>”, python programmers need to rely on a generic package — <a href="https://pythonhosted.org/gffutils/contents.html">gffutil</a> when annotating lists of genes and gene coordinates. Gffutil package may not be the optimum solution for bioinformaticians with specific requirements. For example, the gffutil package may not be the best option when your pipeline only needs to map a set of genomic intervals to GENCODE protein-coding genes which were prioritised based on their GENCODE level information. Therefore, when we have specific requirements, we’ll have to write custom programs that solve those needs. Here, I’ll describe how to</p><ol><li>Create a source dataset from <a href="https://www.gencodegenes.org/human/releases.html">GENCODE Gene Set release</a> (section A)</li><li>Find genes in a list of input genomic coordinates using the source dataset (section B)</li><li>Find genomic coordinates of a gene list using the source dataset (section C)</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2b2d9dab2c86eedaa774eaff5af5df4/href">https://medium.com/media/a2b2d9dab2c86eedaa774eaff5af5df4/href</a></iframe><h4>Section A: Creating a source dataset from <a href="https://www.gencodegenes.org/human/releases.html">GENCODE Gene Set release</a></h4><ul><li><strong>STEP 01: Read the gff3 file into a pandas dataframe</strong></li></ul><pre>gencode = pd.read_table(&lt;path to .gff3&gt;, comment=&quot;#&quot;, sep = &quot;<strong>\t</strong>&quot;, names = [&#39;seqname&#39;, &#39;source&#39;, &#39;feature&#39;, &#39;start&#39; , &#39;end&#39;, &#39;score&#39;, &#39;strand&#39;, &#39;frame&#39;, &#39;attribute&#39;])</pre><pre>gencode.head() <br>gencode.info()</pre><p><em>There are </em><a href="https://www.ensembl.org/info/website/upload/gff3.html"><em>nine columns in a gff3 file</em></a><em>. They are seqname, source, feature, start, end, score, strand, frame, attribute. Comments in gff3 files start with “#”.</em></p><ul><li><strong>STEP 02: Extract Genes in the gff3 file “feature = gene”</strong></li></ul><pre>gencode_genes = gencode[(gencode.feature == &quot;gene&quot;)][[&#39;seqname&#39;, &#39;start&#39;, &#39;end&#39;, &#39;attribute&#39;]].copy().reset_index().drop(&#39;index&#39;, axis=1)</pre><p><em>This code shows how to extract GENCODE genes. However, if you need to extract other GENCODE feature types like transcripts, exons, CDSs and UTRs, this can be changed accordingly. For example, if you need to access transcripts, you can replace “gene” with “ transcript” (</em>gencode.feature == “<em>transcript</em>”<em>).</em></p><ul><li><strong>STEP 03: Extract gene_name, gene_type, gene_status, level of each gene</strong></li></ul><pre><strong>def</strong> gene_info(x):<br><em># Extract gene names, </em>gene_type, gene_status and level<br>    g_name = list(filter(<strong>lambda</strong> x: &#39;gene_name&#39; <strong>in</strong> x,  x.split(&quot;;&quot;)))[0].split(&quot;=&quot;)[1]<br>    g_type = list(filter(<strong>lambda</strong> x: &#39;gene_type&#39; <strong>in</strong> x,  x.split(&quot;;&quot;)))[0].split(&quot;=&quot;)[1]<br>    g_status = list(filter(<strong>lambda</strong> x: &#39;gene_status&#39; <strong>in</strong> x,  x.split(&quot;;&quot;)))[0].split(&quot;=&quot;)[1]<br>    g_leve = int(list(filter(<strong>lambda</strong> x: &#39;level&#39; <strong>in</strong> x,  x.split(&quot;;&quot;)))[0].split(&quot;=&quot;)[1])<br>    <strong>return</strong> (g_name, g_type, g_status, g_leve)</pre><pre>gencode_genes[&quot;gene_name&quot;], gencode_genes[&quot;gene_type&quot;], gencode_genes[&quot;gene_status&quot;], gencode_genes[&quot;gene_level&quot;] = zip(*gencode_genes.attribute.apply(<strong>lambda</strong> x: gene_info(x)))</pre><p><em>This function reads GENCODE “attribute” column and access all key-value pairs. Then the filter command extracts relevant values using the gene_name, gene_type, gene_status and level keywords. Depending on the previous step (step 02), you can change the code. For example, you might need to access transcript_type, transcript_status and tag if you extracted all the transcripts in step 02. Similarly, you can change step 04 and 05 accordingly.</em></p><ul><li><strong>STEP 04: Extract all known protein_coding genes</strong></li></ul><pre>gencode_genes = gencode_genes[gencode_genes[&#39;gene_status&#39;] == &#39;KNOWN&#39;].reset_index().drop(&#39;index&#39;, axis=1)<br>gencode_genes = gencode_genes[gencode_genes[&#39;gene_type&#39;] == &#39;protein_coding&#39;].reset_index().drop(&#39;index&#39;, axis=1)</pre><ul><li><strong>STEP 05: Remove duplicates — Prioritize verified and manually annotated loci over automatically annotated loci</strong></li></ul><pre>gencode_genes = gencode_genes.sort_values([&#39;gene_level&#39;, &#39;seqname&#39;], ascending=<strong>True</strong>).drop_duplicates(&#39;gene_name&#39;, keep=&#39;first&#39;).reset_index().drop(&#39;index&#39;, axis=1)</pre><p><em>Level attribute in the GENCODE gff3 file provides </em>an assessment<em> of the reliability of a given feature. Here, level 01 indicates that the element is manually annotated and experimentally verified (Eg. genes and transcripts by RT-PCR-seq and pseudogenes by three different methods). Level 02 means that the feature is annotated manually by HAVANA and merged with features predicted by ENSEMBL automated pipeline. Lastly, level 03 indicates that the element is predicted only by the ENSEMBL automated pipeline.</em></p><p><em>As described above, step 04 identified all the known protein-coding genes. GENCODE contains multiple records for the same gene when they belong to more than one level. Above code remove all the duplicates while prioritising level-01 over -02 and level-02 over -03. As shown in the GitHub .gist, step 05 removed 46 such duplicated genes.</em></p><ul><li><strong>STEP 06: Generating the indexed GENCODE gene source dataset</strong></li></ul><pre>%%bash -s gencode.v19.annotation.gff3_all_known_genes.txt<br>cut -f 1,2,3,5 $1 | sortBed -i &gt; gencode.v19.annotation.gff3_all_known_genes.txt.sorted.formatted.bed<br>bgzip gencode.v19.annotation.gff3_all_known_genes.txt.sorted.formatted.bed<br>tabix -p bed gencode.v19.annotation.gff3_all_known_genes.txt.sorted.formatted.bed.gz</pre><p><em>Samtools “tabix” is a generic indexer for TAB-delimited genome position files. gencode_genes dataframe created in step 05 can be saved as a tab-delimited text file (</em>gencode.v19.annotation.gff3_all_known_genes.txt<em>) and then index it using tabix as shown in the above bash command.</em></p><h4>Section B: Using the indexed GENCODE gene source dataset to annotate genomic coordinates</h4><ul><li><strong>Step 01 and 02: Defining relevant functions</strong></li></ul><pre><strong>def</strong> overlap(q_st, q_end, res_st, res_end):<br>    o  = min(q_end, res_end)-max(q_st, res_st)<br>    <strong>return</strong> o</pre><pre><strong>def</strong> gencode_all_known_genes(a, tb):<br>    genes = []</pre><pre><strong>    try</strong>:<br>        <strong>for</strong> region <strong>in</strong> tb.fetch(a[&#39;chr&#39;], int(a[&#39;start&#39;]), int(a[&#39;end&#39;])):<br>            <strong>if</strong> region:<br>                r = region.split(&#39;<strong>\t</strong>&#39;)<br>                overlap_len = overlap(int(a[&#39;start&#39;]), int(a[&#39;end&#39;]), int(r[1]), int(r[2]))<br>                ret_val = &#39;<strong>{}</strong>(<strong>{}</strong>)&#39;.format(r[3], np.round(overlap_len/float(int(a[&#39;end&#39;])-int(a[&#39;start&#39;]))*100, 2)) <em>### Percentage of the input interval that overlap with the gene</em><br>                genes.append(ret_val)</pre><pre>        if len(genes)&gt;0:<br>            return &quot;;&quot;.join(genes)<br>        else:<br>            return &quot;NA(0)&quot;<br>    except ValueError:<br>        return &quot;NA(0)&quot;</pre><p><em>Above code defines two functions to find genes that overlap with genomic intervals (gencode_all_known_genes) and then to calculate overlapping base-pairs (overlap). Here, the </em>gencode_all_known_genes <em>function takes genomic coordinates (a row in a dataframe indicating the chromosome, start and end positions) and a tabix indexed GENCODE gene file. Then “</em>tb.fetch” command reads the tabix file and finds all the genes that overlap with the given genomic interval. Next, overlap function calculates the overlap between the input and tb.fetch results. Finally, the gencode_all_known_genes function returns the gene and the overlap percentage.</p><p><em>Here, the</em> overlap p<em>ercentage is the fraction of the input interval that overlaps with the GENCODE gene. You can change the code accordingly if you want to find the fraction of the GENCODE gene that overlaps with the input interval (e.g. </em>overlap_len/float(int(r[2])-int(r[1]))*100<em>).</em></p><p>Following code calls the gencode_all_known_genes function and accepts return values into a new genes column in the dataframe df.</p><pre><strong>import</strong> <strong>pysam</strong><br>gencode_v19 = pysam.TabixFile(&#39;gencode.v19.annotation.gff3_all_known_genes.txt.sorted.formatted.bed.gz&#39;)</pre><pre>df[&#39;genes&#39;] = df.apply(<strong>lambda</strong> x: gencode_all_known_genes(x[[&#39;chr&#39;, &#39;start&#39;, &#39;end&#39;]], gencode_v19), axis=1)</pre><p><em>When a genomic interval overlaps with more than one gene, the gencode_all_known_genes function returns a single string with all the overlapping genes that are separated by semicolons (e.g. SLC2A7(23.04);SLC2A5(53.37)). If you need to apply various filters to these genes, this may not be the optimum format for your pipeline. In such instances, you can transform the dataframe using the following code.</em></p><pre>new_rows = []<br><strong>for</strong> i,r <strong>in</strong> df.iterrows():<br>    g_list = r[&#39;genes&#39;].split(&quot;;&quot;)<br>    <strong>for</strong> g <strong>in</strong> g_list:<br>        g = g.replace(&quot; &quot;,&quot;&quot;)<br>        new_rows.append(np.append(r[[&#39;chr&#39;, &#39;start&#39;, &#39;end&#39;, &#39;name&#39;, &#39;score&#39;, &#39;strand&#39;, &#39;genes&#39;]].values, g))<br>        <br>df_perGene = pd.DataFrame()<br>df_perGene = df_perGene.append(pd.DataFrame(new_rows, columns=[&#39;chr&#39;, &#39;start&#39;, &#39;end&#39;, &#39;name&#39;, &#39;score&#39;, &#39;strand&#39;, &#39;genes&#39;, &#39;gene_ID&#39;])).reset_index().drop(&#39;index&#39;, axis=1)</pre><pre>df_perGene[&#39;gene_name&#39;] = df_perGene[&#39;gene_ID&#39;].apply(<strong>lambda</strong> x: x.split(&quot;(&quot;)[0])<br>df_perGene[&#39;gene_coverage&#39;] = df_perGene[&#39;gene_ID&#39;].apply(<strong>lambda</strong> x: x.split(&quot;(&quot;)[1].replace(&quot;)&quot;, &quot;&quot;))</pre><pre>df_perGene = df_perGene.drop([&quot;genes&quot;, &quot;gene_ID&quot;], axis=1)<br>df_perGene.head()</pre><p><em>Here, the resulting dataframe — df_perGene will contain a single row for each gene. For genomic intervals with multiple overlapping genes, df_perGene dataframe will include duplicated rows that differ only from the contents of the columns — gene_name and gene_coverage.</em></p><h4>Section C: Find coordinates of a gene list</h4><p>As shown in the previous section, GENCODE source dataset can be used to find genes in a set of genomic coordinates. In this section, we’ll use the same source dataset to find genomic coordinates when we have a list of genes.</p><pre>gencode_genes = gencode_genes.set_index(&#39;gene_name&#39;)</pre><pre><strong>def</strong> fetch_gene_coords(g):</pre><pre><strong>if</strong> gencode_genes.index.contains(g): <br>        <strong>return</strong> gencode_genes.loc[g][&#39;seqname&#39;], gencode_genes.loc[g][&#39;start&#39;], gencode_genes.loc[g][&#39;end&#39;] <br>    <strong>else</strong>:<br>        <strong>return</strong> &quot;NA&quot;, &quot;NA&quot;, &quot;NA&quot;</pre><pre>df_perGene[&#39;g_chr&#39;], df_perGene[&#39;g_start&#39;], df_perGene[&#39;g_end&#39;] = zip(*df_perGene[&#39;gene_name&#39;].apply(lambda x: fetch_gene_coords(x)))</pre><p><em>Here, we’ll use the gencode_genes dataframe from section A to find genomic coordinates of an input gene list. First, we’ll set the gene_name column as the index of the gencode_genes dataframe. Next, we can write a function — fetch_gene_coords, that takes an input gene set. This function can search for those genes in gencode_genes dataframe and returns the coordinates when there is a match.</em></p><h3>PyScripts</h3><p>I wrote two python scripts that can run above-discussed tasks. These scripts will be useful to those who need to perform these tasks but not interested in writing python programs. You can run them as python command line programs (usage information is available in comments sections).</p><ol><li><a href="https://github.com/PubuduSaneth/intoTheGenomics/blob/master/pyScripts/gencode_format.py">Format GENCODE gff3 file</a></li><li><a href="https://github.com/PubuduSaneth/intoTheGenomics/blob/master/pyScripts/find_gencode_genes.py">Find genes in a set of genomic coordinates</a></li></ol><h3>References</h3><ol><li><a href="https://www.gencodegenes.org/pages/data_format.html">https://www.gencodegenes.org/pages/data_format.html</a></li><li><a href="https://en.wikipedia.org/wiki/GENCODE">https://en.wikipedia.org/wiki/GENCODE</a></li><li><a href="http://www.htslib.org/doc/tabix.html">http://www.htslib.org/doc/tabix.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9259efa6ffc2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intothegenomics/annotate-genes-and-genomic-coordinates-using-python-9259efa6ffc2">Annotating gene coordinates and gene lists — The python way</a> was originally published in <a href="https://medium.com/intothegenomics">Into the genomics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Genomic coordinates to gene lists and vice versa — Annotating gene coordinates and gene lists]]></title>
            <link>https://medium.com/intothegenomics/annotate-genes-and-genomic-coordinates-ecdad47d0c8e?source=rss----b37a6ec849b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/ecdad47d0c8e</guid>
            <category><![CDATA[genomics]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[genomic-concepts]]></category>
            <category><![CDATA[genome-annotation]]></category>
            <dc:creator><![CDATA[Pubudu samarakoon]]></dc:creator>
            <pubDate>Tue, 25 Dec 2018 21:18:17 GMT</pubDate>
            <atom:updated>2018-12-26T09:43:04.431Z</atom:updated>
            <content:encoded><![CDATA[<h3>Genomic coordinates to gene lists and vice versa — Annotating gene coordinates and gene lists</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-MYvdX53YbTQY3OblWaHA.png" /></figure><h3>Why do we need to annotate gene coordinates and gene lists?</h3><p>Since the advent of genetic tests, geneticists have been using various techniques to describe the location of genes (and genetic elements). One of the earliest techniques used was the cytogenetic location that characterised genes based on bands in stained chromosomes. However, with the availability of high-resolution genomic techniques, scientists have been able to describe specific locations of genes and other elements. This location — molecular location which is also known as genomic coordinates describes the precious start and end position of a gene (or genetic element) on a chromosome.</p><p>Today the vast majority of genetic tests and high-throughput genomic techniques use genomic coordinates to report their findings. One of the first steps in analysing these reports is to annotate the genomic coordinates with gene information. Although standard genomic pipelines used in the field can perform this task, scientists with specific requirements may end up with lists of genomic coordinates at various stages of their workflows (e.g. lists of CNV regions and list of co-localized genomic elements). Additionally, different bioinformatics software may produce lists of genes that need to be visualised using genomic coordinates (e.g. DeSeq2 differential gene expression analysis). Therefore, annotating lists of gene coordinates and gene lists are essential steps in current genomic studies.</p><h3>What are the commonly used methods?</h3><ol><li>UCSC genome browser</li><li>Ensembl BioMart</li><li>R Bioconductor packages</li><li>Biopython solution</li></ol><h3>How to?</h3><ol><li><strong>UCSC Table browser (</strong><a href="https://genome.ucsc.edu/"><strong>https://genome.ucsc.edu/</strong></a><strong>)</strong></li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DUUQnUJepyNOw0p8s2otX4RYQ&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRjB_N1GpT0U&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRjB_N1GpT0U%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6011904fa3461d43f6ad2117a699aff4/href">https://medium.com/media/6011904fa3461d43f6ad2117a699aff4/href</a></iframe><p><strong>2. Ensembl</strong> <strong>BioMart</strong> (<a href="https://www.ensembl.org/biomart">https://www.ensembl.org/biomart</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQZmfWa01Lu5e2dVpOCc3Q.jpeg" /><figcaption>Genes in a list of the genomic coordinates</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8PeyEX0Zd-j9yO5IOnJhyw.jpeg" /><figcaption>Gene list to genomic coordinates</figcaption></figure><p>UCSC Table Browser and Ensembl BioMart are web services that users can interact and retrieve necessary information. However, the main disadvantage of these services is that they are not scalable and cannot be automated robustly. Therefore, bioinformaticians have used R and Python solutions in their bioinformatics pipelines.</p><p><strong>3. R Bioconductor package — biomaRt</strong></p><pre>library(biomaRt)<br>mart &lt;- useMart(&quot;ensembl&quot;)<br>mart &lt;- useDataset(&quot;hsapiens_gene_ensembl&quot;, mart)<br>attributes &lt;- c(&quot;ensembl_gene_id&quot;,&quot;start_position&quot;,&quot;end_position&quot;,&quot;strand&quot;,&quot;hgnc_symbol&quot;,&quot;chromosome_name&quot;,&quot;entrezgene&quot;,&quot;ucsc&quot;,&quot;band&quot;)<br>filters &lt;- c(&quot;chromosome_name&quot;,&quot;start&quot;,&quot;end&quot;)<br>values &lt;- list(chromosome=&quot;1&quot;,start=&quot;1783590&quot;,end=&quot;2597819&quot;)<br>all.genes &lt;- getBM(attributes=attributes, filters=filters, values=values, mart=mart)</pre><pre>ref: <a href="https://www.biostars.org/p/44426/">https://www.biostars.org/p/44426/</a></pre><p><strong>4. Biopython solution</strong></p><p>Python programmers can use <a href="https://pythonhosted.org/gffutils/contents.html">the gffutil</a> package to annotate lists of genes and gene coordinates. Here, a database from a gff3 file can be created using <a href="https://pythonhosted.org/gffutils/contents.html">gffutil</a> package. Then this database can be used to access genes and gene coordinates. A description of the gffutil package with examples is available <a href="https://blog.liang2.tw/posts/2018/06/gene-annotation-using-gffutils/">here</a>.</p><p>Gffutil package is developed mainly to perform a generic task — reading GFF files that contain a wide range of genomic data. When users need only to access genes and gene coordinates (not to read large GFF files), gffutil may not provide the optimum solution. Therefore I have addressed this issue in my post “<a href="https://medium.com/@PubuduSamarakoon/annotate-genes-and-genomic-coordinates-using-python-9259efa6ffc2">Annotating gene coordinates and gene lists — The python way</a>”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecdad47d0c8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intothegenomics/annotate-genes-and-genomic-coordinates-ecdad47d0c8e">Genomic coordinates to gene lists and vice versa — Annotating gene coordinates and gene lists</a> was originally published in <a href="https://medium.com/intothegenomics">Into the genomics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>