{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bioinformatics - Main report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Students: \n",
    "- Marieke Bamps r0618772\n",
    "- Lara Hemeryck r0638328\n",
    "- Hanne Hillen r0637408"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following data analysis (RNA-seq and ChIP-seq) is based on the following article.\n",
    "**RUNX1 contributes to higher-order chromatin organization and gene regulation in breast cancer cells**\n",
    "\n",
    "[Here](https://www.ncbi.nlm.nih.gov/pubmed/27514584), you can find the link to the pubmed page of the article (doi:  10.1016/j.bbagrm.2016.08.003)\n",
    "\n",
    "\n",
    "# Introduction and aim of the study\n",
    "\n",
    "RUNX is a family of mammalian transcription factors consisting of three members, RUNX1, RUNX2 and RUNX3. They each have tissue-specific expression patterns and cell-context dependent functions through interactions with their binding factors and each have another physiological function. The RUNX factors play a key role in different types of cancer.\n",
    "\n",
    "The article focuses on the contributions of RUNX1, which is involved in hematopoiesis and in the development in breast cancer. It functions both as a tumor suppressor and an oncogene, and is thus shown to be both down-regulated and upregulated in breast cancer. Whole genome sequencing has shown deletions and point mutations in the RUNX1 gene in human breast tumors.\n",
    "\n",
    "RUNX1 activates and represses target genes expression of different genes depending on its target partners. \n",
    "\n",
    "Cancer is characterized with changes gene expressions, mostly alterations in the folding of the genome. In breast cancer, alterations in the nuclear architecture are seen, such as alterations in the chromatin and at telomeres when comparing with epithelial cells. Through the importance of the higher-order genome folding and the involvement of RUNX1 in breast cancer, it is necessary to understand the relation between the function of RUNX1 in chromatin organization and its regulatory role in breast cancer.\n",
    "\n",
    "The aim of this study is to investigate the relationship between RUNX1 mediated transcription and genome organisation through the comparison of control and RUNX1-depleted MCF-7 breast cancer cells. In order to do this RNA-seq and ChIP-seq were performed.\n",
    "\n",
    "- RNAseq: suppression of RUNX1 in a human MCF-7 breast cancer cell line and evaluation of the gene expression through mRNA levels at a given moment in the cell. Additionally, a functional analysis was preformed using DESeq.\n",
    "- ChIP-seq: performed to gain insight into RUNX1-mediated regulation of chromatin organization. RUNX1 binding was probed by performing ChIP-seq. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## RNA-seq analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The RNA-seq analysis reveals the presence and quantity of RNA in a biological sample at a given moment in time. Four samples are compared: shNSR1, shNSR2, shRUNR1 and shRUNR2. The expression of genes in the RNA-seq analysis is quantified by counting the number of reads that mapped to each locus in the transcriptome assembly step.\n",
    "\n",
    "Subsequently, these results can be used in order to perform a functional analysis of the gene counts searching for differenctial gene expression between the different samples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 1**: Make a new directory (mkdir command)\n",
    "\n",
    "cd command (change directory) is used to go to another directory\n",
    "\n",
    "pwd command displays where you are (in which directory)\n",
    "\n",
    "ls command can be used to display the files present in the current directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data\r\n"
     ]
    }
   ],
   "source": [
    "cd /home/luna.kuleuven.be/r0637408/data\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data/work\r\n",
      "~\t      shNSR1._STARtmp  shNSR2._STARtmp\tshRUNR2.fastq\r\n",
      "shNSR1.fastq  shNSR2.fastq     shRUNR1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "mkdir -p ~/data/work\n",
    "cd ~/data/work\n",
    "pwd\n",
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 2**: Extract raw data\n",
    "\n",
    "The raw data of this experiment are available on the Gene Expression Omnibus (GEO) website under the accession number GSE75070. [(link)](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE75070)\n",
    "\n",
    "The subtitle 'Samples' indicates that 3 replicates are analysed: Replicate 1,2 and 3.\n",
    "For the analysis in this report, we will compare the raw data of replicate 1 and 2.\n",
    "Each sample has a specific GSM accession code and clicking on it, it redirects you to the page specific for that sample. \n",
    "\n",
    "- MCF-7 shNS RNA-seq \n",
    "        SSR2919468, named shNSR1\n",
    "        SSR2919469, named shNSR2\n",
    "- MCF-7 shRUNX1 RNA-seq\n",
    "        SSR2919471, named shRUNR1\n",
    "        SSR2919472, named shRUNR2\n",
    "\n",
    "On this webpage you click on the SRA = Sequence Read Archive relation link which will lead you to the next page. On this page the SRR number is indicated which can be used to convert this file to a fastq file.\n",
    "First we download the datafiles with the following commando's (in SSH, bitvise):\n",
    "\n",
    "mkdir ~/data/ncbi\n",
    "\n",
    "vdb-config -s /repository/user/main/public/root=~/data/ncbi\n",
    "\n",
    "In order to do the conversion we use the sra toolkit with the following commando:\n",
    "\n",
    "fastq-dump --split-files SRRnumber\n",
    "\n",
    "Now we have fastq files in our work directory."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 3**: Quality control\n",
    "\n",
    "Check the quality of the raw data by using the FastQC toolkit.\n",
    "\n",
    "General commando: fastqc fastqfile -o outputdir"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **shNSR1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of shNSR1.fastq\r\n",
      "Approx 5% complete for shNSR1.fastq\r\n",
      "Approx 10% complete for shNSR1.fastq\r\n",
      "Approx 15% complete for shNSR1.fastq\r\n",
      "Approx 20% complete for shNSR1.fastq\r\n",
      "Approx 25% complete for shNSR1.fastq\r\n",
      "Approx 30% complete for shNSR1.fastq\r\n",
      "Approx 35% complete for shNSR1.fastq\r\n",
      "Approx 40% complete for shNSR1.fastq\r\n",
      "Approx 45% complete for shNSR1.fastq\r\n",
      "Approx 50% complete for shNSR1.fastq\r\n",
      "Approx 55% complete for shNSR1.fastq\r\n",
      "Approx 60% complete for shNSR1.fastq\r\n",
      "Approx 65% complete for shNSR1.fastq\r\n",
      "Approx 70% complete for shNSR1.fastq\r\n",
      "Approx 75% complete for shNSR1.fastq\r\n",
      "Approx 80% complete for shNSR1.fastq\r\n",
      "Approx 85% complete for shNSR1.fastq\r\n",
      "Approx 90% complete for shNSR1.fastq\r\n",
      "Approx 95% complete for shNSR1.fastq\r\n",
      "Analysis complete for shNSR1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o ~/data shNSR1.fastq"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This analysis generates a html file in which the results are represented. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0637408/work\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shNSR1_fastqc.html  shRUNX1_R1_fastqc.html\r\n"
     ]
    }
   ],
   "source": [
    "ls *html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results shNSR1:\n",
    "\n",
    "Sequences flagged as poor quality: 0\n",
    "\n",
    "        - Per base sequence quality report: This report shows a boxplot for each position in the sequence. A boxplox consists of the following elements: The central red line is the median value, the yellow box represents the inter-quartile range (25-75%), the upper and lower whiskers represent the 10% and 90% points and the blue line represents the mean quality.\n",
    "        \n",
    "        The y-axis shows the quality scores. The higher the score, the better the base call. The background of the graph divides the y axis into very good quality calls (green), calls of reasonable quality (orange), and calls of poor quality (red). In this analysis the quality scores of the bases stay very high, which indicates a good base calling.\n",
    "        \n",
    "         Per base sequence content plots out the proportion of each base position in a file for which each of the four normal DNA bases has been called. In a random library you would expect that the proportions of the bases are equal. Also this analysis shows a good base calling. However, in many cases the results will point this out as 'not good' because of the presence of the adaptor sequences. These should be deleted, but this is not always working very well.\n",
    "          \n",
    "        - Sequences duplication levels report: The first 100 000 sequences are analysed and are representative for the duplication levels of the entire file. In a diverse library most sequences will occur only once in the final set. A low level of duplication may indicate a very high level of coverage of the target sequence, but a high level of duplication is more likely to indicate some kind of enrichment bias (technical duplicates due to PCR artefacts or biological duplicates.\n",
    "        \n",
    "        This module counts the degree of duplication for every sequence in a library and creates a plot showing the relative number of sequences with different degrees of duplication.\n",
    "        Even so, longer reads are more likely to contain sequencing errors, which will artificially increase the observed diversity and will tend to underrepresent highly duplicated sequences.\n",
    "        If it is a diverse library, most of the sequences will fall into the far left of the plot. The presence of spikes towards the right of the plot (which is the case here) indicate more specific enirchments or the presence of contaminants. This parameter will warn you if non-unique sequences make up of more than 20% of the total. (A failure indication is showed when the sequencs make up more than 50% of the total.\n",
    "        \n",
    "        - Overrepresented sequences report: A single sequence very overrepresented in the set means that it is highly biologically significant or that it means that the library is contaminated. The graph shows these sequences that make up more than 0,1% of the total. The analysis program searches for matches in a database of common contaminants and will report the best hit it finds. Important to mention is that adapter sequences are very similar to each other so you may get a hit reported that is not technically correct, but which has very similar sequence to the actual match.\n",
    "        In our data set, there are several overrepresented sequences but for non of them a possible source is found. Except for one that is a TruSeq adapter like pointed out above.\n",
    "        Longer reads are more likely to contain sequencing errors, that will artificially increase the observed diversity and will tend to underrepresent highly duplicated sequences.\n",
    "        The warning means that one sequence is found that represents more than 0,1% of the total.\n",
    "        \n",
    "In the figures below you can see some selected results of the quality control."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shNS.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 1: Summary of the quality control results of shNSR1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shNS_2.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 2: Per base sequence quality of shNSR1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shNS_3.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 3: Sequence duplication levels of shNSR1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **shNSR2**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of shNSR2.fastq\r\n",
      "Approx 5% complete for shNSR2.fastq\r\n",
      "Approx 10% complete for shNSR2.fastq\r\n",
      "Approx 15% complete for shNSR2.fastq\r\n",
      "Approx 20% complete for shNSR2.fastq\r\n",
      "Approx 25% complete for shNSR2.fastq\r\n",
      "Approx 30% complete for shNSR2.fastq\r\n",
      "Approx 35% complete for shNSR2.fastq\r\n",
      "Approx 40% complete for shNSR2.fastq\r\n",
      "Approx 45% complete for shNSR2.fastq\r\n",
      "Approx 50% complete for shNSR2.fastq\r\n",
      "Approx 55% complete for shNSR2.fastq\r\n",
      "Approx 60% complete for shNSR2.fastq\r\n",
      "Approx 65% complete for shNSR2.fastq\r\n",
      "Approx 70% complete for shNSR2.fastq\r\n",
      "Approx 75% complete for shNSR2.fastq\r\n",
      "Approx 80% complete for shNSR2.fastq\r\n",
      "Approx 85% complete for shNSR2.fastq\r\n",
      "Approx 90% complete for shNSR2.fastq\r\n",
      "Approx 95% complete for shNSR2.fastq\r\n",
      "Analysis complete for shNSR2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o ~/data shNSR2.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shNSR1_fastqc.html  shRUNX1_R1_fastqc.html\r\n",
      "shNSR2_fastqc.html  shRUNX1_R2_fastqc.html\r\n"
     ]
    }
   ],
   "source": [
    "ls *html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results shNSR2:\n",
    "\n",
    "Sequences flagged as poor quality: 0\n",
    "\n",
    "        - Per base sequence quality report: The higher the score the better the base call. In this analysis, the quality scores of the bases stay very high, which indicates a good base calling.\n",
    "        \n",
    "         Per base sequence content plots out the proportion of each base position in a file of which each of the four normal DNA bases has been called. This library shows equal proportions of the bases as expected. Also this analysis shows a good base calling. \n",
    "          \n",
    "        - Sequences duplication levels report: The trend of the curve shows a peak on the right side of the curve, which implements more specific enrichments or the presence of contaminants. \n",
    "        \n",
    "        - Overrepresented sequences report:  In our data set, there are several overrepresented sequences but for non of them a possible source is found.\n",
    "        The warning means that one sequence is found that represents more than 0,1% of the total.\n",
    "        \n",
    "In the figures below you can see some selected results of the quality control."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shNS2.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 4: Summary of the quality control results of shNSR2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shNS2_2.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 5: Per base sequence quality of shNSR2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shNS2_3.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 6: Sequence duplication levels of shNSR2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **shRUNX1_R1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of shRUNX1_R1.fastq\r\n",
      "Approx 5% complete for shRUNX1_R1.fastq\r\n",
      "Approx 10% complete for shRUNX1_R1.fastq\r\n",
      "Approx 15% complete for shRUNX1_R1.fastq\r\n",
      "Approx 20% complete for shRUNX1_R1.fastq\r\n",
      "Approx 25% complete for shRUNX1_R1.fastq\r\n",
      "Approx 30% complete for shRUNX1_R1.fastq\r\n",
      "Approx 35% complete for shRUNX1_R1.fastq\r\n",
      "Approx 40% complete for shRUNX1_R1.fastq\r\n",
      "Approx 45% complete for shRUNX1_R1.fastq\r\n",
      "Approx 50% complete for shRUNX1_R1.fastq\r\n",
      "Approx 55% complete for shRUNX1_R1.fastq\r\n",
      "Approx 60% complete for shRUNX1_R1.fastq\r\n",
      "Approx 65% complete for shRUNX1_R1.fastq\r\n",
      "Approx 70% complete for shRUNX1_R1.fastq\r\n",
      "Approx 75% complete for shRUNX1_R1.fastq\r\n",
      "Approx 80% complete for shRUNX1_R1.fastq\r\n",
      "Approx 85% complete for shRUNX1_R1.fastq\r\n",
      "Approx 90% complete for shRUNX1_R1.fastq\r\n",
      "Approx 95% complete for shRUNX1_R1.fastq\r\n",
      "Analysis complete for shRUNX1_R1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o ~/data shRUNX1_R1.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shNSR1_fastqc.html  shRUNX1_R1_fastqc.html\r\n",
      "shNSR2_fastqc.html  shRUNX1_R2_fastqc.html\r\n"
     ]
    }
   ],
   "source": [
    "ls *html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results shRUNX1:\n",
    "\n",
    "Sequences flagged as poor quality: 0\n",
    "\n",
    "        - Per base sequence quality report: The score of the base calling decreases a little bit along the sequence, however the scores still remain in the green section of the y-axis, which means that the base calling is of good quality.\n",
    "        \n",
    "        - Sequences duplication levels report: The trend of the curve is similar to the previous one with peak on the right side of the curve. This might implicate more specific enirchments or the presence of contaminants. The warning denotes that non-unique sequences make up of more than 20% of the total.\n",
    "        \n",
    "        - Overrepresented sequences report: A single sequence very overrepresented in the set means that it is highly biologically significant or that it means that the library is contaminated. \n",
    "        In our data set, there are several overrepresented sequences but for non of them a possible source is found. Except for one that is a TruSeq adapter, which can happen as pointed out above. The warning means that one sequence is found that represents more than 0,1% of the total.\n",
    "        \n",
    "In the figures below you can see some selected results of the quality control."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shRUNX1_R1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 7: Summary of the quality control results of shRUNX1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shRUNX1_R12.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 8: Per base sequence qualityof shRUNX1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shRUNX1_R13.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 9: Sequence duplication levels of shRUNX1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **shRUNX1_R2**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data/work\r\n"
     ]
    }
   ],
   "source": [
    "pwd\n",
    "cd ~/data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~\t\t\tshNSR1.Log.progress.out     shRUNX1_R1_fastqc.zip\r\n",
      "shNSR1.Aligned.out.sam\tshNSR1.SJ.out.tab\t    shRUNX1_R1.Log.final.out\r\n",
      "shNSR1.bam\t\tshNSR2.fastq\t\t    shRUNX1_R1.Log.out\r\n",
      "shNSR1.bam.bai\t\tshNSR3.fastq\t\t    shRUNX1_R1.Log.progress.out\r\n",
      "shNSR1.fastq\t\tshRUNX1_R1.Aligned.out.sam  shRUNX1_R1.SJ.out.tab\r\n",
      "shNSR1_fastqc.html\tshRUNX1_R1.bam\t\t    shRUNX1_R2.fastq\r\n",
      "shNSR1_fastqc.zip\tshRUNX1_R1.bam.bai\t    shRUNX1_R3.fastq\r\n",
      "shNSR1.Log.final.out\tshRUNX1_R1.fastq\r\n",
      "shNSR1.Log.out\t\tshRUNX1_R1_fastqc.html\r\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of shRUNX1_R2.fastq\r\n",
      "Approx 5% complete for shRUNX1_R2.fastq\r\n",
      "Approx 10% complete for shRUNX1_R2.fastq\r\n",
      "Approx 15% complete for shRUNX1_R2.fastq\r\n",
      "Approx 20% complete for shRUNX1_R2.fastq\r\n",
      "Approx 25% complete for shRUNX1_R2.fastq\r\n",
      "Approx 30% complete for shRUNX1_R2.fastq\r\n",
      "Approx 35% complete for shRUNX1_R2.fastq\r\n",
      "Approx 40% complete for shRUNX1_R2.fastq\r\n",
      "Approx 45% complete for shRUNX1_R2.fastq\r\n",
      "Approx 50% complete for shRUNX1_R2.fastq\r\n",
      "Approx 55% complete for shRUNX1_R2.fastq\r\n",
      "Approx 60% complete for shRUNX1_R2.fastq\r\n",
      "Approx 65% complete for shRUNX1_R2.fastq\r\n",
      "Approx 70% complete for shRUNX1_R2.fastq\r\n",
      "Approx 75% complete for shRUNX1_R2.fastq\r\n",
      "Approx 80% complete for shRUNX1_R2.fastq\r\n",
      "Approx 85% complete for shRUNX1_R2.fastq\r\n",
      "Approx 90% complete for shRUNX1_R2.fastq\r\n",
      "Approx 95% complete for shRUNX1_R2.fastq\r\n",
      "Analysis complete for shRUNX1_R2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o ~/data shRUNX1_R2.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shNSR1_fastqc.html  shRUNX1_R1_fastqc.html\r\n",
      "shNSR2_fastqc.html  shRUNX1_R2_fastqc.html\r\n"
     ]
    }
   ],
   "source": [
    "ls *html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results shRUNX2:\n",
    "\n",
    "Sequences flagged as poor quality: 0\n",
    "\n",
    "        - Per base sequence quality report: The score of the base calling decreases a little bit along the sequence, however the scores still remain in the green section of the y-axis which means that the base calling is of good quality.\n",
    "        \n",
    "        - Sequences duplication levels report: The trend of the curve is similar to the previous one with peak on the right side of the curve. This might implicate more specific enirchments or the presence of contaminants. The warning denotes that non-unique sequences make up of more than 20% of the total.\n",
    "        \n",
    "        - Overrepresented sequences report: A single sequence very overrepresented in the set means that it is highly biologically significant or that it means that the library is contaminated. \n",
    "        In our data set, there are several overrepresented sequences but for non of them a possible source is found. Except for one that is a TruSeq adapter which can happen as pointed out above. The warning means that one sequence is found that represents more than 0,1% of the total.\n",
    "        \n",
    "In the figures below you can see some selected results of the quality control."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shRUNX1_R2.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 10: Summary of the quality control results of shRUNXR2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shRUNX1_R22.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 11: Per base sequence quality of shRUNXR2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/Results_QualityControl_shRUNX1_R23.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 12: Sequence duplication levels of shRUNXR2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 55439644\r\n",
      "drwxr-xr-x 3 r0637408 domain users        4096 nov 16 12:04 ~\r\n",
      "-rw-r--r-- 1 r0637408 domain users  7537729432 nov 16 13:46 shNSR1.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users      364400 nov 26 14:41 shNSR1_fastqc.html\r\n",
      "-rw-r--r-- 1 r0637408 domain users      494039 nov 26 14:41 shNSR1_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0637408 domain users  8862217020 nov 16 13:27 shNSR2.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users  7288568384 nov 16 13:24 shNSR3.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users  8859434212 nov 16 12:42 shRUNX1_R1.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users      375672 nov 26 14:35 shRUNX1_R1_fastqc.html\r\n",
      "-rw-r--r-- 1 r0637408 domain users      511874 nov 26 14:35 shRUNX1_R1_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0637408 domain users 12681835778 nov 16 13:04 shRUNX1_R2.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users 11538621938 nov 16 13:05 shRUNX1_R3.fastq\r\n"
     ]
    }
   ],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Conclusion of step 3:** The quality control of the four samlpes had indicated a good quality, this implements that these samples can be used for the further analysis."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 4**: Mapping to the genome\n",
    "\n",
    "STAR toolkit is used to map the genome. This program also needs a database with the human genome (hg19) and gene annotation. Path of the datase that will be used: \n",
    "\n",
    "/mnt/nfs/mfiers/STAR/hg19_star_db\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrLength.txt\t   Genome\t\t       SAindex\r\n",
      "chrNameLength.txt  genomeParameters.txt        sjdbInfo.txt\r\n",
      "chrName.txt\t   JAZZYCHIP.Aligned.out.sam   sjdbList.fromGTF.out.tab\r\n",
      "chrStart.txt\t   JAZZYCHIP.Log.out\t       sjdbList.out.tab\r\n",
      "exonGeTrInfo.tab   JAZZYCHIP.Log.progress.out  transcriptInfo.tab\r\n",
      "exonInfo.tab\t   JAZZYCHIP._STARtmp\r\n",
      "geneInfo.tab\t   SA\r\n"
     ]
    }
   ],
   "source": [
    "ls /mnt/nfs/mfiers/STAR/hg19_star_db/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jan 24 14:16:11 ..... started STAR run\r\n",
      "Jan 24 14:16:11 ..... loading genome\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeLoad LoadAndExit --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/nfs/r0637408/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jan 24 14:16:15 ..... started STAR run\r\n",
      "Jan 24 14:16:15 ..... loading genome\r\n",
      "Jan 24 14:16:15 ..... started mapping\r\n",
      "Jan 24 14:27:36 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn shNSR1.fastq \\\n",
    "     --outFileNamePrefix shNSR1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The output file of the mapping is of the **.Aligned.out.sam** type. The mapping also generates some additional log files which we don't need now."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 7237134968 jan 24 14:27 shNSR1.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0637408 domain users 7537729432 jan 24 11:47 shNSR1.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users       1862 jan 24 14:27 shNSR1.Log.final.out\r\n",
      "-rw-r--r-- 1 r0637408 domain users      15540 jan 24 14:27 shNSR1.Log.out\r\n",
      "-rw-r--r-- 1 r0637408 domain users       1544 jan 24 14:27 shNSR1.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0637408 domain users    5897545 jan 24 14:27 shNSR1.SJ.out.tab\r\n"
     ]
    }
   ],
   "source": [
    "ls -l shNSR1.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "**Step 5**: Inspecting the structure of the SAM file\n",
    "\n",
    "The sam output file of the STAR analysis is a text file containing the alignment of all reads. \n",
    "\n",
    "The head commando reads the first few lines of text and displays them on the screen. This enables us to check if the file is  build up well - with the right structure.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SRR2919468.1\t0\tchr6\t74227928\t255\t1S60M89N40M\t*\t0\t0\tNGCAATCCAATACAGGGGCATAGCCGGCGCTTATTTGGCCTGGATGGTTCAGGATAATCACCTGAGCAGTGAAGCCAGCTGCTTCCATTGGTGGGTCATTT\t#0<FFFFFFFFFFIIIIIIIIIIFFFIIIIIIIIIIIIIIIIIIFFFBFFFFFFBFFFF77<<BBBFFFBBFFFBBFFFFFFBFFFFFFFFBBB<7BBFFF\tNH:i:1\tHI:i:1\tAS:i:100\tnM:i:0\r\n",
      "SRR2919468.2\t16\tchr6\t52860628\t255\t99M2S\t*\t0\t0\tCCTGCTAGAACCTCCAAACAAGCTCTCAAGGTCCATTTGTAGGAGAACGTAGGGTAGTCAAGCTTCCAAGACTCCAGACACATCCAAATGAGGCGCTGCGN\tFFBFFFBBB<BBFFFFFFFFBFFBFFFBFFFFFFFFBFFIIIIIFIFIIIFFIIFIIIIIIIFFFIIIIFFIIIIIIIIIIIIIIIIIFFFFFFFFFF<0#\tNH:i:1\tHI:i:1\tAS:i:97\tnM:i:0\r\n",
      "SRR2919468.3\t0\tchr15\t41282673\t255\t101M\t*\t0\t0\tCTCAGCTTCCCAAAGTGTTGGAATTACAGGTATGAGCCACTGCACCTGGCCAAAATGGTTTCCCTCCATTTTTAGCACAGGTTAGAATCCTTGGGAAGAAC\tBBBFFFFFFFFFFIIFFFIFFIIIIIIFFFFFFFIIIIIIIIIIIIIIIIIIIIIIIIFFFFIIIIIIIIIIFFFBFFFFFFFFBBFFBFFFFFBBBFFFB\tNH:i:1\tHI:i:1\tAS:i:99\tnM:i:0\r\n",
      "SRR2919468.4\t16\tchr17\t31149639\t255\t12S89M\t*\t0\t0\tTCCGATCTGTGGCGGTCCCCGTCCCGGGGGTTGGCCGCGCGGGCCCCGGTGGGGCGGCCACCCGGGGTCCCGGCCCTCGCGCGTCCTTCCTCCTCGCTCCT\t'''7''00''''''''00'''7<700700''''''0B7'770<<0'7B7<77'0<707''777B<7B<7''<07'7<FB'BB7FBBFFFFFFFFFFBBBBB\tNH:i:1\tHI:i:1\tAS:i:75\tnM:i:6\r\n",
      "SRR2919468.5\t16\tchr22\t21243207\t255\t101M\t*\t0\t0\tTTTGCTAAGGGGGCAAAAAGCCCAGATACCATTTTAACTGGCCCAGCTCATTTTCTCCTTTCATTTTACAAAAGAAATCATGCAGAAGCATCAATTAAAAC\tBBBBBBBBBBBBBBFFFFFFFFIFB<BFIIFBB<FIFFIIIIIIIIFFFFFFFFIFIIFF<IIIFFFIIIIIIFIIFIIFFFFFFBIIFFFBBBBFFFBBB\tNH:i:1\tHI:i:1\tAS:i:97\tnM:i:1\r\n",
      "SRR2919468.6\t0\tchr17\t40500418\t255\t1S100M\t*\t0\t0\tNCTCAATCCAAGGGGCCAGAAACTGCCGCAGCTCCATTGGGAAGCTGTCACTGTAGAGCTGATGGAGCTGCTCCAGGTACCGTGTGTCAAGCTGCTGTAGC\t#0<FFBFFFFBFBFFIIIIIFFFIBFFFFFFIIIIIIIIIIFFBFFFBBBFFFBFFFFFFFFFFFB<BFBBBB<B<B7<<BB7B7B<BBBBBBBBBBBBBB\tNH:i:1\tHI:i:1\tAS:i:98\tnM:i:0\r\n"
     ]
    }
   ],
   "source": [
    "head -34 shNSR1.Aligned.out.sam | grep -v '^@'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~\t\t\tshNSR1.Log.final.out\t shNSR2.Log.out\r\n",
      "Aligned.out.sam\t\tshNSR1.Log.out\t\t shNSR2.Log.progress.out\r\n",
      "Log.out\t\t\tshNSR1.Log.progress.out  shNSR2._STARtmp\r\n",
      "Log.progress.out\tshNSR1.SJ.out.tab\t shRUNR1.fastq\r\n",
      "shNSR1.Aligned.out.sam\tshNSR2.Aligned.out.sam\t shRUNR2.fastq\r\n",
      "shNSR1.fastq\t\tshNSR2.fastq\t\t _STARtmp\r\n"
     ]
    }
   ],
   "source": [
    "ls /mnt/nfs/r0637408/work"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The .sam files were analysed and showed a good structure. They contain additional information about the sequences, such as chromosone location and SRR number. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 6**: Sorting of the SAM file\n",
    "\n",
    "Sorting and conversion of the SAM file into a BAM file, sorts the data and compresses the file. In order to do this we use **samtools sort**.\n",
    "\n",
    "General command: samtools sort -o (output file name) (input file name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 11 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o shNSR1.bam shNSR1.Aligned.out.sam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "ls -l command to display the files in a specific directory + extra information about them, including the size of the file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 1063491935 jan 24 14:35 shNSR1.bam\r\n"
     ]
    }
   ],
   "source": [
    "ls -l shNSR1.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 7**: Indexing the bam file\n",
    "\n",
    "The tool **samtools index** is used to generate an index to visualise and to enable a fast access to the bam file. The resulting **.bai** file allows programs to jump directly to specific parts of the bam file without reading through all of the sequences and must always be kept together with the bam file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index shNSR1.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 2795216 jan 24 14:37 shNSR1.bam.bai\r\n"
     ]
    }
   ],
   "source": [
    "ls -l shNSR1.bam.bai"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 8**: Inspecting the BAM file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The square brackets are used to include the 2 possiblities at that position in the command. This is used in order to display  all the files with the suffix .bam or .bai"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shNSR1.bam  shNSR1.bam.bai\r\n"
     ]
    }
   ],
   "source": [
    "ls *.ba[mi]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SRR2919468.1257417\t0\tchrM\t1\t255\t1S95M5S\t*\t0\t0\tGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCGAGAGATCG\tBBBF<BFBB<BFFBF0FF0BFFBFBBF<BFIIFI<FF<FFFFFFFFFBBBFFIII'7B70BBF7BFFBFFBB77<<BBBB<BBBBBBB<BBBB<<BBBBBB\tNH:i:1\tHI:i:1\tAS:i:91\tnM:i:1\r\n",
      "SRR2919468.1307827\t0\tchrM\t1\t255\t3S98M\t*\t0\t0\tATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCGAGACGC\tBBBFFFFFFFFFFFIIIFIIIIIIIFIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIF7BFIIIIIFFFFFFFFF77BBFFFFFFFFBFFFFFFFBFFFFFF\tNH:i:1\tHI:i:1\tAS:i:94\tnM:i:1\r\n",
      "SRR2919468.2735860\t0\tchrM\t1\t255\t4S97M\t*\t0\t0\tGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCGAGACG\tBBBFFFFFFFFFFFFFFIIIIFIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIFFIIIIBFFIIIIIFFFFFFFFFFBFFFFBBBFBBFFFFFBFFFFF<<B\tNH:i:1\tHI:i:1\tAS:i:93\tnM:i:1\r\n",
      "samtools view: writing to standard output failed: Broken pipe\r\n",
      "samtools view: error closing standard output: -1\r\n"
     ]
    }
   ],
   "source": [
    "samtools view shNSR1.bam | head -3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The structure of the BAM and SAM file is the same."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualisation by using IGV"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Integrative Genomics Viewer (IGV) is a visualization tool which supports a large variety of data types, such as next-generation sequence data, genomic annotations and array-based data. It provides an interactive exploration of large, integrated genomic datasets. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To visualize the .bam and .bai files of both shNSR and shRUNX we used IGV. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/rna seq MALAT1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 13: Visualisation in IGV of the .bam and .bai files of both shNSR1 and shRUNX1. Zoomed in on MALAT1. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/rna seq NEAT1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 14: Visualisation in IGV of the .bam and .bai files of both shNSR1 and shRUNX1. Zoomed in on NEAT1. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We use **samtools idxstats** to calculate how many reads map to each chromosome:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t672011\t0\r\n",
      "chr1\t249250621\t2807106\t0\r\n",
      "chr2\t243199373\t1708269\t0\r\n",
      "chr3\t198022430\t1236724\t0\r\n",
      "chr4\t191154276\t366282\t0\r\n",
      "chr5\t180915260\t760904\t0\r\n",
      "chr6\t171115067\t1424282\t0\r\n",
      "chr7\t159138663\t556079\t0\r\n",
      "chr8\t146364022\t644763\t0\r\n",
      "chr9\t141213431\t1610494\t0\r\n",
      "chr10\t135534747\t458957\t0\r\n",
      "chr11\t135006516\t1071912\t0\r\n",
      "chr12\t133851895\t1345691\t0\r\n",
      "chr13\t115169878\t208785\t0\r\n",
      "chr14\t107349540\t4513376\t0\r\n",
      "chr15\t102531392\t404278\t0\r\n",
      "chr16\t90354753\t1295121\t0\r\n",
      "chr17\t81195210\t1300534\t0\r\n",
      "chr18\t78077248\t155624\t0\r\n",
      "chr19\t59128983\t577278\t0\r\n",
      "chr20\t63025520\t435843\t0\r\n",
      "chr21\t48129895\t422616\t0\r\n",
      "chr22\t51304566\t308276\t0\r\n",
      "chrX\t155270560\t624839\t0\r\n",
      "chrY\t59373566\t421548\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats shNSR1.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first colomn in the results shows the reference sequence name and the length of this sequence in the second column. In the third and fourth column the numer of mapped and unmapped reads respectively.\n",
    "In the chr 14 reference sequence name the most reads are mapped."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the tool **samtools flagstat** it is possible to display the distribution of mapping flags. This can also be found in the second column of the sam/bam file.\n",
    "\n",
    "The first column of output gives the total number of reads that are QC passed and failed (in second column) --> seperated with a +"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25331592 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "6182322 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "25331592 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat shNSR1.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are in total of 25.331.592 reads in the input file. All the reads are quality control (QC) passed and all of the reads are mapped."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***The procedure step 4-8 is exactly the same for the other RNA-seq files: shNSR2.fastq, shRUNR1.fastq, shRUNR2.fastq***\n",
    "\n",
    "The steps for the shRUNXR1.fastq are showed. The steps of the others are not included in this report.\n",
    "\n",
    "**Step 4**: Mapping to the genome  (tool: STAR)\n",
    "\n",
    "**Step 5**: Inspecting the structure of the sam file    (commando: head)\n",
    "\n",
    "**Step 6**: Sorting of the sam file --> output: Bam file   (commando: samtools sort)\n",
    "\n",
    "**Step 7**: Indexing --> output: bam.bai file     (commando: samtools index) \n",
    "\n",
    "**Step 8**: Inspecting the BAM file      (commando's: samtools idxstat, flagstat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jan 24 14:38:57 ..... started STAR run\r\n",
      "Jan 24 14:38:57 ..... loading genome\r\n",
      "Jan 24 14:38:57 ..... started mapping\r\n",
      "Jan 24 14:52:56 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn shRUNR1.fastq \\\n",
    "     --outFileNamePrefix shRUNR1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 8182917631 jan 24 14:52 shRUNR1.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0637408 domain users 8859434212 jan 24 11:53 shRUNR1.fastq\r\n",
      "-rw-r--r-- 1 r0637408 domain users       1864 jan 24 14:52 shRUNR1.Log.final.out\r\n",
      "-rw-r--r-- 1 r0637408 domain users      15551 jan 24 14:52 shRUNR1.Log.out\r\n",
      "-rw-r--r-- 1 r0637408 domain users       1780 jan 24 14:52 shRUNR1.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0637408 domain users    6254202 jan 24 14:52 shRUNR1.SJ.out.tab\r\n"
     ]
    }
   ],
   "source": [
    "ls -l shRUNR1.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SRR2919471.1\t0\tchr8\t144662711\t255\t2S99M\t*\t0\t0\tNGCCAGTGCAGGCTTCTTGGCCTTCTTCTCCGCGTACTGCCGTAGCCGCTCCTCCCGCAGCTGTGCCGCCTCCTTGTCCTCCTCCTCATTGTCACTGCCAA\t#0<FFFFFFFFFFIIIIIIIIIIIIIIIIIIIIIFFIIIIIIFIIIIIIIFFFFFFFFFBFFFFFBBFFFFFFBF<BBFFFFFFFFB<BBBFBBBFFFFFF\tNH:i:1\tHI:i:1\tAS:i:97\tnM:i:0\r\n",
      "SRR2919471.2\t16\tchr3\t10321639\t255\t18S82M1S\t*\t0\t0\tCGTGTGCTCTTCCGATCTGGCTGCTGTGTGGGTGTGTTAAGCTGATAAGGTTCAGTTTGCGGCGGAAACTACCTGCTAGTCTTGTGTCAGGGGCTGCCAGN\t7FFFFFFF<FFFFFFFFFFFFFBBBBFFFBFFFFFFFFFFFFFFFFFFFIIIFIIFFIIIIIIIIIIFIIIIFIIIIIIIIIIIIIIIFFFFFFFFFF<0#\tNH:i:1\tHI:i:1\tAS:i:80\tnM:i:0\r\n",
      "SRR2919471.3\t16\tchr3\t96777395\t255\t101M\t*\t0\t0\tCTTGGCCTCCCAAAGTGCTGGGATTACAGGTGTGAGCCACCATGCCCGGCCTGGAGTAAGGAGTTTTTAATCAAGTTCTTTTATTGTTACTTTCAATATAG\tFFFFFFFBFBFFFFFFBFFFFFFFFBFFFFFFFFFFFIIIIIIIIIIIFIFFBIIIIIIFFIIIIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFFFBBB\tNH:i:1\tHI:i:1\tAS:i:99\tnM:i:0\r\n",
      "SRR2919471.4\t16\tchr14\t45433630\t255\t2S41M31278N57M1S\t*\t0\t0\tTCTGGGAGAAAACCAGACCTCCACTTCCAAGGATATAGAGCAGTTTTCAACATATGATTTCATCCCATCTGCAAAATTAAAGCTTTCTCAAGGAATGCCAN\tBBBB<BFBFFFFFFBBBFFFFFBFIBIIFFIFIIIIIIIIIIIIIIIIIIIIIIIIIIIIIFFIIFIIIFIIIFIIIIIIIIIIFFIFFFFFFFFFFF<0#\tNH:i:1\tHI:i:1\tAS:i:96\tnM:i:0\r\n",
      "SRR2919471.5\t16\tchrX\t70517274\t255\t38M374N63M\t*\t0\t0\tAACCAAGAGGTGCAAAAACGAAAGCAACTGGAGCTCAGGCAGGAGGAAGAGCGCAGGCGCCGTGAAGAAGAGATGCGGCGGCAGCAAGAAGAAATGATGCG\tBBBBBBBBBB<B7<<7B<BBBBBB<0B<<B<BBBBBBBBBBBBBBB<<7B<FBBB<<FFBBFBBFFFFFFBB<BIFIFFB<IIFIIFIFFFBFFB<FFBBB\tNH:i:1\tHI:i:1\tAS:i:101\tnM:i:0\r\n",
      "SRR2919471.6\t16\tchr19\t33076803\t255\t11M950N72M323N16M2S\t*\t0\t0\tTAAGTGAGAAGGTATCAGAACAAGGTTTAATAGAAATCCTTAAAAAAGTAAGCCAACAAACAGAAAAGACAACAACAGTGAAATTCAACAGAAGAAAAGCN\t<FBBFFFFFBBBBFFFFFFFBFFBFBFIIIIIIFFFFFIIIIIIIIIFFIIIIFIIIIFFIIIIIIIFFFFIIIFIIIIIIIIIIIIIFFFFFFFFFF<0#\tNH:i:1\tHI:i:1\tAS:i:100\tnM:i:0\r\n"
     ]
    }
   ],
   "source": [
    "head -34 shRUNR1.Aligned.out.sam | grep -v '^@'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 12 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o shRUNR1.bam shRUNR1.Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 1226869972 jan 24 15:07 shRUNR1.bam\r\n"
     ]
    }
   ],
   "source": [
    "ls -l shRUNR1.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index shRUNR1.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shNSR1.bam\t\t\t      shRUNR2.Aligned.out.sam.tmp.0006.bam\r\n",
      "shNSR1.bam.bai\t\t\t      shRUNR2.Aligned.out.sam.tmp.0007.bam\r\n",
      "shNSR2.bam\t\t\t      shRUNR2.Aligned.out.sam.tmp.0008.bam\r\n",
      "shNSR2.bam.bai\t\t\t      shRUNR2.Aligned.out.sam.tmp.0009.bam\r\n",
      "shRUNR1.bam\t\t\t      shRUNR2.Aligned.out.sam.tmp.0010.bam\r\n",
      "shRUNR1.bam.bai\t\t\t      shRUNR2.Aligned.out.sam.tmp.0011.bam\r\n",
      "shRUNR2.Aligned.out.sam.tmp.0000.bam  shRUNR2.Aligned.out.sam.tmp.0012.bam\r\n",
      "shRUNR2.Aligned.out.sam.tmp.0001.bam  shRUNR2.Aligned.out.sam.tmp.0013.bam\r\n",
      "shRUNR2.Aligned.out.sam.tmp.0002.bam  shRUNR2.Aligned.out.sam.tmp.0014.bam\r\n",
      "shRUNR2.Aligned.out.sam.tmp.0003.bam  shRUNR2.Aligned.out.sam.tmp.0015.bam\r\n",
      "shRUNR2.Aligned.out.sam.tmp.0004.bam  shRUNR2.bam\r\n",
      "shRUNR2.Aligned.out.sam.tmp.0005.bam\r\n"
     ]
    }
   ],
   "source": [
    "ls *.ba[mi]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SRR2919471.40625\t0\tchrM\t1\t255\t9S92M\t*\t0\t0\tATCACGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCG\tBBBFFFFFFFFFFIIIIIFFIIIIFIIIIFIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFBFFFBBFFF7BBBBFFFFFBBFFFBFBBF<\tNH:i:1\tHI:i:1\tAS:i:88\tnM:i:1\r\n",
      "SRR2919471.1316495\t0\tchrM\t1\t255\t7S94M\t*\t0\t0\tCACGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCGAG\tBBBFFFFFFFFFFIIIIIIIIIIIIIIIIIIIIIIIIIIIIFFIIIIIIIIIIIIIIIIIIBFFIFFFFFFFFFFBFF7<FBFFFFFFFFBFFFFFFFFFF\tNH:i:1\tHI:i:1\tAS:i:90\tnM:i:1\r\n",
      "SRR2919471.7269090\t0\tchrM\t1\t255\t9S92M\t*\t0\t0\tATCACGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCG\tBBBFFFFFFFFFFFFIIIBFFFIFFIIIIIIFIIFFFFFIIIIFIIIIFFIIFFIIFFFFFIIBFBFFFFFFFBFBFBFF7<BFBFFFFBFBFBFF<<BBB\tNH:i:1\tHI:i:1\tAS:i:88\tnM:i:1\r\n",
      "samtools view: writing to standard output failed: Broken pipe\r\n",
      "samtools view: error closing standard output: -1\r\n"
     ]
    }
   ],
   "source": [
    "samtools view shRUNR1.bam | head -3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t271715\t0\r\n",
      "chr1\t249250621\t2910305\t0\r\n",
      "chr2\t243199373\t1539109\t0\r\n",
      "chr3\t198022430\t1494137\t0\r\n",
      "chr4\t191154276\t435757\t0\r\n",
      "chr5\t180915260\t870253\t0\r\n",
      "chr6\t171115067\t1764180\t0\r\n",
      "chr7\t159138663\t712821\t0\r\n",
      "chr8\t146364022\t751771\t0\r\n",
      "chr9\t141213431\t1833833\t0\r\n",
      "chr10\t135534747\t533973\t0\r\n",
      "chr11\t135006516\t1387154\t0\r\n",
      "chr12\t133851895\t1482013\t0\r\n",
      "chr13\t115169878\t228545\t0\r\n",
      "chr14\t107349540\t5657791\t0\r\n",
      "chr15\t102531392\t489108\t0\r\n",
      "chr16\t90354753\t910049\t0\r\n",
      "chr17\t81195210\t2028703\t0\r\n",
      "chr18\t78077248\t181599\t0\r\n",
      "chr19\t59128983\t723543\t0\r\n",
      "chr20\t63025520\t558481\t0\r\n",
      "chr21\t48129895\t469982\t0\r\n",
      "chr22\t51304566\t421055\t0\r\n",
      "chrX\t155270560\t725105\t0\r\n",
      "chrY\t59373566\t206506\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats shRUNR1.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28587488 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "7273525 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "28587488 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat shRUNR1.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are in total of 28.587.488 reads in the input file. All the reads are quality control (QC) passed and all of the reads are mapped."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 9**: Reads to gene counts\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is the conversion of the results of the analysis (the reads) to information about genes. In this way it is possible to relate certain gene expressions in the 2 conditions (presence / absence of RUNX1).\n",
    "\n",
    "For this conversion we use the tool: **featureCounts** \n",
    "\n",
    "General command:  FeatureCounts -Q 10 -g gene_name -a [human annotation of specific chromosome.gtf] -o output file input file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data/work\r\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/work\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "       \u001b[44;37m ========== \u001b[0m\u001b[36m    _____ _    _ ____  _____  ______          _____  \r\n",
      "       \u001b[44;37m =====      \u001b[0m\u001b[36m   / ____| |  | |  _ \\|  __ \\|  ____|   /\\   |  __ \\ \r\n",
      "       \u001b[44;37m   =====    \u001b[0m\u001b[36m  | (___ | |  | | |_) | |__) | |__     /  \\  | |  | |\r\n",
      "       \u001b[44;37m     ====   \u001b[0m\u001b[36m   \\___ \\| |  | |  _ <|  _  /|  __|   / /\\ \\ | |  | |\r\n",
      "       \u001b[44;37m       ==== \u001b[0m\u001b[36m   ____) | |__| | |_) | | \\ \\| |____ / ____ \\| |__| |\r\n",
      "       \u001b[44;37m ========== \u001b[0m\u001b[36m  |_____/ \\____/|____/|_|  \\_\\______/_/    \\_\\_____/\u001b[0m\r\n",
      "\tv1.5.0-p1\r\n",
      "\r\n",
      "//==========================\u001b[36m featureCounts setting \u001b[0m===========================\\\\\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Input files : \u001b[36m4 BAM files  \u001b[0m \u001b[0m                                   ||\r\n",
      "||                           \u001b[32mS\u001b[36m shNSR1.bam\u001b[0m \u001b[0m                                    ||\r\n",
      "||                           \u001b[32mS\u001b[36m shNSR2.bam\u001b[0m \u001b[0m                                    ||\r\n",
      "||                           \u001b[32mS\u001b[36m shRUNR1.bam\u001b[0m \u001b[0m                                   ||\r\n",
      "||                           \u001b[32mS\u001b[36m shRUNR2.bam\u001b[0m \u001b[0m                                   ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Output file : \u001b[36mall.counts.RUN\u001b[0m \u001b[0m                                  ||\r\n",
      "||             Annotations : \u001b[36m/mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.p\u001b[0m ...\u001b[0m \u001b[0m||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||                 Threads : \u001b[36m1\u001b[0m \u001b[0m                                               ||\r\n",
      "||                   Level : \u001b[36mmeta-feature level\u001b[0m \u001b[0m                              ||\r\n",
      "||              Paired-end : \u001b[36mno\u001b[0m \u001b[0m                                              ||\r\n",
      "||         Strand specific : \u001b[36mno\u001b[0m \u001b[0m                                              ||\r\n",
      "||      Multimapping reads : \u001b[36mnot counted\u001b[0m \u001b[0m                                     ||\r\n",
      "|| Multi-overlapping reads : \u001b[36mnot counted\u001b[0m \u001b[0m                                     ||\r\n",
      "||       Read orientations : \u001b[36mfr\u001b[0m \u001b[0m                                              ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "\\\\=====================\u001b[36m http://subread.sourceforge.net/ \u001b[0m======================//\r\n",
      "\r\n",
      "//=================================\u001b[36m Running \u001b[0m==================================\\\\\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Load annotation file /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.s\u001b[0m ... \u001b[0m||\r\n",
      "||    Features : \u001b[36m1156385\u001b[0m \u001b[0m                                                     ||\r\n",
      "||    Meta-features : \u001b[36m41863\u001b[0m \u001b[0m                                                  ||\r\n",
      "||    Chromosomes/contigs : \u001b[36m25\u001b[0m \u001b[0m                                               ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file shNSR1.bam... \u001b[0m                                            ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m25331592\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m9202975 (36.3%)\u001b[0m \u001b[0m                          ||\r\n",
      "||    Running time : \u001b[36m0.47 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file shNSR2.bam... \u001b[0m                                            ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m30966793\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m13072801 (42.2%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.53 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file shRUNR1.bam... \u001b[0m                                           ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m28587488\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m11202455 (39.2%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.60 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file shRUNR2.bam... \u001b[0m                                           ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m37045685\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m10788451 (29.1%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.68 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||                         \u001b[36mRead assignment finished.\u001b[0m \u001b[0m                         ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "\\\\=====================\u001b[36m http://subread.sourceforge.net/ \u001b[0m======================//\r\n",
      "\r\n"
     ]
    }
   ],
   "source": [
    "featureCounts -Q 10 -g gene_name \\\n",
    "-a /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf \\\n",
    "-o all.counts.RUN \\\n",
    "shNSR1.bam shNSR2.bam shRUNR1.bam shRUNR2.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 8673915 jan 24 15:18 all.counts.RUN\r\n",
      "-rw-r--r-- 1 r0637408 domain users     472 jan 24 15:18 all.counts.RUN.summary\r\n"
     ]
    }
   ],
   "source": [
    "ls -l *.counts*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Status                     shNSR1.bam  shNSR2.bam  shRUNR1.bam  shRUNR2.bam\r\n",
      "Assigned                   9202975     13072801    11202455     10788451\r\n",
      "Unassigned_Ambiguity       612021      861139      767761       696060\r\n",
      "Unassigned_MultiMapping    0           0           0            0\r\n",
      "Unassigned_NoFeatures      6080016     5722461     5458528      13720904\r\n",
      "Unassigned_Unmapped        0           0           0            0\r\n",
      "Unassigned_MappingQuality  9436580     11310392    11158744     11840270\r\n",
      "Unassigned_FragmentLength  0           0           0            0\r\n",
      "Unassigned_Chimera         0           0           0            0\r\n",
      "Unassigned_Secondary       0           0           0            0\r\n",
      "Unassigned_Nonjunction     0           0           0            0\r\n",
      "Unassigned_Duplicate       0           0           0            0\r\n"
     ]
    }
   ],
   "source": [
    "head -20 all.counts.RUN.summary | column -t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Program:featureCounts v1.5.0-p1; Command:\"featureCounts\" \"-Q\" \"10\" \"-g\" \"gene_name\" \"-a\" \"/mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\" \"-o\" \"all.counts.RUN\" \"shNSR1.bam\" \"shNSR2.bam\" \"shRUNR1.bam\" \"shRUNR2.bam\" \r\n",
      "Geneid\tChr\tStart\tEnd\tStrand\tLength\tshNSR1.bam\tshNSR2.bam\tshRUNR1.bam\tshRUNR2.bam\r\n",
      "MIR1302-11\tchr1;chr1;chr1\t29554;30267;30976\t30039;30667;31109\t+;+;+\t1021\t0\t0\t0\t0\r\n",
      "FAM138A\tchr1;chr1;chr1\t34554;35245;35721\t35174;35481;36081\t-;-;-\t1219\t0\t0\t0\t0\r\n",
      "OR4F5\tchr1\t69091\t70008\t+\t918\t0\t0\t0\t0\r\n",
      "RP11-34P13.7\tchr1;chr1;chr1;chr1;chr1;chr1;chr1\t89295;92091;110953;112700;120721;129055;133374\t91629;92240;111357;112804;120932;129223;133566\t-;-;-;-;-;-;-\t3569\t2\t0\t0\t0\r\n",
      "RP11-34P13.8\tchr1;chr1\t89551;90287\t90050;91105\t-;-\t1319\t0\t0\t0\t0\r\n",
      "AL627309.1\tchr1;chr1\t134901;137621\t135802;139379\t-;-\t2661\t13\t14\t6\t15\r\n",
      "RP11-34P13.14\tchr1;chr1\t139790;140075\t139847;140339\t-;-\t323\t0\t0\t0\t0\r\n",
      "RP11-34P13.13\tchr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1\t141474;146386;155767;164263;165884;168100;168610;169049;172557;173753\t143011;149707;155831;164791;165942;168165;168767;169264;172688;173862\t-;-;-;-;-;-;-;-;-;-\t6195\t9\t5\t5\t11\r\n"
     ]
    }
   ],
   "source": [
    "head -10 all.counts.RUN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the tool featurecounts we were able to merge the .bam files of the different samples in order to compare the gene counts. The output of the featurecounts is a document that lists the gene counts of specific genes. And gives additional information such as the chromosome location and the length. Hereafter, we will only continue with the gene counts of the different samples.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f-6 all.counts.RUN > all.genedata.RUN.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "all.genedata.RUN.tsv\r\n"
     ]
    }
   ],
   "source": [
    "ls *.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data/work\r\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/work\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Program:featureCounts v1.5.0-p1; Command:\"featureCounts\" \"-Q\" \"10\" \"-g\" \"gene_name\" \"-a\" \"/mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\" \"-o\" \"all.counts.RUN\" \"shNSR1.bam\" \"shNSR2.bam\" \"shRUNR1.bam\" \"shRUNR2.bam\" \r\n",
      "Geneid\tChr\tStart\tEnd\tStrand\tLength\r\n",
      "MIR1302-11\tchr1;chr1;chr1\t29554;30267;30976\t30039;30667;31109\t+;+;+\t1021\r\n",
      "FAM138A\tchr1;chr1;chr1\t34554;35245;35721\t35174;35481;36081\t-;-;-\t1219\r\n",
      "OR4F5\tchr1\t69091\t70008\t+\t918\r\n",
      "RP11-34P13.7\tchr1;chr1;chr1;chr1;chr1;chr1;chr1\t89295;92091;110953;112700;120721;129055;133374\t91629;92240;111357;112804;120932;129223;133566\t-;-;-;-;-;-;-\t3569\r\n",
      "RP11-34P13.8\tchr1;chr1\t89551;90287\t90050;91105\t-;-\t1319\r\n",
      "AL627309.1\tchr1;chr1\t134901;137621\t135802;139379\t-;-\t2661\r\n",
      "RP11-34P13.14\tchr1;chr1\t139790;140075\t139847;140339\t-;-\t323\r\n",
      "RP11-34P13.13\tchr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1\t141474;146386;155767;164263;165884;168100;168610;169049;172557;173753\t143011;149707;155831;164791;165942;168165;168767;169264;172688;173862\t-;-;-;-;-;-;-;-;-;-\t6195\r\n"
     ]
    }
   ],
   "source": [
    "head all.genedata.RUN.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f1,7- all.counts.RUN | grep -v '^#' > all.gene.counts.RUN.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Geneid\tshNSR1.bam\tshNSR2.bam\tshRUNR1.bam\tshRUNR2.bam\r\n",
      "MIR1302-11\t0\t0\t0\t0\r\n",
      "FAM138A\t0\t0\t0\t0\r\n",
      "OR4F5\t0\t0\t0\t0\r\n",
      "RP11-34P13.7\t2\t0\t0\t0\r\n",
      "RP11-34P13.8\t0\t0\t0\t0\r\n",
      "AL627309.1\t13\t14\t6\t15\r\n",
      "RP11-34P13.14\t0\t0\t0\t0\r\n",
      "RP11-34P13.13\t9\t5\t5\t11\r\n",
      "RNU6-1100P\t0\t0\t0\t0\r\n",
      "RP11-34P13.9\t0\t0\t0\t0\r\n",
      "AP006222.2\t1\t2\t2\t1\r\n",
      "RP4-669L17.10\t0\t1\t1\t0\r\n",
      "OR4F29\t0\t0\t0\t0\r\n",
      "RP4-669L17.2\t0\t0\t2\t0\r\n",
      "RP5-857K21.15\t0\t0\t0\t0\r\n",
      "RP5-857K21.1\t3\t4\t0\t4\r\n",
      "RP5-857K21.2\t0\t0\t0\t0\r\n",
      "RP5-857K21.3\t0\t0\t0\t0\r\n",
      "RP5-857K21.4\t0\t0\t1\t0\r\n",
      "RP5-857K21.5\t0\t0\t0\t0\r\n",
      "OR4F16\t0\t0\t0\t0\r\n",
      "RP11-206L10.3\t2\t0\t1\t1\r\n",
      "RNU6-1199P\t0\t1\t1\t0\r\n",
      "RP11-206L10.5\t0\t0\t1\t0\r\n",
      "RP11-206L10.4\t0\t0\t0\t0\r\n",
      "RP11-206L10.2\t12\t11\t3\t13\r\n",
      "RP11-206L10.9\t18\t32\t12\t19\r\n",
      "AL669831.1\t1\t1\t0\t2\r\n",
      "RP11-206L10.10\t6\t9\t5\t4\r\n",
      "FAM87B\t2\t5\t3\t0\r\n",
      "LINC00115\t8\t19\t2\t2\r\n",
      "RP11-206L10.11\t76\t115\t95\t46\r\n",
      "FAM41C\t0\t0\t0\t0\r\n",
      "AL645608.2\t0\t0\t0\t0\r\n",
      "RP11-54O7.16\t3\t1\t0\t1\r\n",
      "RP11-54O7.1\t4\t6\t6\t6\r\n",
      "RP11-54O7.2\t0\t0\t0\t0\r\n",
      "RP11-54O7.3\t42\t79\t72\t71\r\n",
      "SAMD11\t52\t107\t58\t86\r\n",
      "AL645608.1\t4\t3\t1\t2\r\n",
      "NOC2L\t729\t1095\t803\t1217\r\n",
      "KLHL17\t186\t288\t53\t41\r\n",
      "PLEKHN1\t26\t45\t14\t30\r\n",
      "C1orf170\t9\t6\t5\t7\r\n",
      "RP11-54O7.17\t7\t7\t6\t8\r\n",
      "HES4\t129\t176\t176\t132\r\n",
      "RP11-54O7.11\t1\t2\t1\t2\r\n",
      "ISG15\t318\t463\t257\t534\r\n",
      "AGRN\t1601\t2642\t1319\t1865\r\n"
     ]
    }
   ],
   "source": [
    "head -50 all.gene.counts.RUN.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data/work\r\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/work\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MALAT1\t126596\t195321\t74491\t36787\r\n"
     ]
    }
   ],
   "source": [
    "grep MALAT1 all.gene.counts.RUN.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NEAT1\t7768\t14094\t4295\t3736\r\n"
     ]
    }
   ],
   "source": [
    "grep NEAT1 all.gene.counts.RUN.tsv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The expression level of a lot of genes is lower in the mutated samples, this suggests that RUNX1 cannot activate these genes due to its inactivation.\n",
    "Through knockdown of RUNX1 in breast cancer cells, we find a downregulation of 2 important genes after inspection of the excel files (which are not shown), NEAT1 and MALAT1. These genes are involved in SC-35 speckle organisation. The 2 genes and their counts per file/condition are shown. Clearly the expression level is much lower in the cell lines with knockdown of RUNX1.\n",
    "\n",
    "- Function of NEAT1: This gene produces a long non-coding RNA (lncRNA). This lncRNA is retained in the nucleus where it forms the core structural component of the paraspeckle sub-organelles. It may act as a transcriptional regulator for numerous genes, including some genes involved in cancer progression.\n",
    "- Function of MALAT1: This gene also produces a long non-coding RNA (lncRNA).  This transcript is retained in the nucleus where it is thought to form molecular scaffolds for ribonucleoprotein complexes. It may act as a transcriptional regulator for numerous genes, including some genes involved in cancer metastasis and cell migration and it is involved in cell cycle regulation. Its upregulation in multiple cancerous tissues has been associated with the proliferation and metastasis of tumor cells. \n",
    "\n",
    "Therefore, the upregulation of these 2 genes by RUNX1 is beneficial for breast cancer cells."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Functional analysis of the RNAseq data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the functional analysis, we analyse which genes are most (and significantly) affected with knockdown of RUNX1 (shRUNX1). This is done in order to investigate the role of RUNX1 in breast cancer in MCF-7 breast cancer cell lines.\n",
    "\n",
    "RNA-Seq is generally used to compare gene expression between conditions, such as a drug treatment vs non-treated, and find out which genes are up- or down regulated in each condition. In principle, RNA-Seq will allow to account for all the transcripts in the cell for each condition. Differently expressed genes can be identified by using tools that count the sequencing reads per gene and compare them between samples. The most commonly used tools for this type of analysis are DESeq and edgeR. Both these tools use a model based on the negative binomial distribution.\n",
    "\n",
    "The functional analysis uses the results of the RNA-seq in order to look for significantly differentially expressed genes. These results can be represented in a heat map using the program 'Multi Experiment Viewer (MeV).  Before usage all data was normalized. The ouputs represent the top 24 of the most significant changes in gene expression. To do this the FeatureCounts results is uploaded and a specific genecluster is selected (= result DESeq)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DE-seq analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "For the DESeq - differential gene expression analysis a R-notebook was used. You can find the workflow in the other notebook file named **\"Bioinformatics_DESeq2.ipynb\"**. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Interpretatie**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0637408/data/work\r\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/work\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "baseMean   log2FoldChange    lfcSE             stat               pvalue            padj\r\n",
      "MIR663A    17657.6449167025  3.95057855902894  0.206539361749826  19.1274850738337  1.49095580537939e-81  1.51795745915827e-77\r\n",
      "MIR30A     613.735581696374  6.66475614114898  0.348909670370175  19.1016664401363  2.4455573693544e-81   1.51795745915827e-77\r\n",
      "ANKRD30BL  2306.08489269738  4.19799897436267  0.222470669667772  18.8698985831785  2.01685179250905e-79  8.34573271740243e-76\r\n",
      "RRM2       1012.72008544986  3.21630483725746  0.203776175804426  15.7835175017923  4.04030692060258e-56  1.25390925280901e-52\r\n",
      "MIR3687    589.413352493287  4.50184986826774  0.29287659418576   15.3711493428949  2.55594406268351e-53  6.34589791883062e-50\r\n",
      "HIST1H3B   1444.33335960224  2.90787104671683  0.201422769712973  14.4366550557344  3.04253521448053e-47  6.29500535876021e-44\r\n",
      "MIR3648    943.248473149307  3.40832276440333  0.241165508308419  14.1327123779431  2.38767626351928e-45  4.2343733050469e-42\r\n",
      "HIST1H1B   2348.42359361963  2.81889786479314  0.210060901962102  13.4194314051918  4.65269250746914e-41  7.21981559846524e-38\r\n",
      "HIST1H3F   1018.65342528922  2.63130496091174  0.199168988562413  13.2114190060626  7.53896796410326e-40  1.03987498118198e-36\r\n"
     ]
    }
   ],
   "source": [
    "head -10 deseq.results.RUN.tsv | column -t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "head -25 deseq.results.RUN.tsv | column -t > deseq.results.RUN.Top20.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "baseMean   log2FoldChange    lfcSE              stat               pvalue             padj\r\n",
      "MIR663A    17657.6449167025  3.95057855902894   0.206539361749826  19.1274850738337   1.49095580537939e-81  1.51795745915827e-77\r\n",
      "MIR30A     613.735581696374  6.66475614114898   0.348909670370175  19.1016664401363   2.4455573693544e-81   1.51795745915827e-77\r\n",
      "ANKRD30BL  2306.08489269738  4.19799897436267   0.222470669667772  18.8698985831785   2.01685179250905e-79  8.34573271740243e-76\r\n",
      "RRM2       1012.72008544986  3.21630483725746   0.203776175804426  15.7835175017923   4.04030692060258e-56  1.25390925280901e-52\r\n",
      "MIR3687    589.413352493287  4.50184986826774   0.29287659418576   15.3711493428949   2.55594406268351e-53  6.34589791883062e-50\r\n",
      "HIST1H3B   1444.33335960224  2.90787104671683   0.201422769712973  14.4366550557344   3.04253521448053e-47  6.29500535876021e-44\r\n",
      "MIR3648    943.248473149307  3.40832276440333   0.241165508308419  14.1327123779431   2.38767626351928e-45  4.2343733050469e-42\r\n",
      "HIST1H1B   2348.42359361963  2.81889786479314   0.210060901962102  13.4194314051918   4.65269250746914e-41  7.21981559846524e-38\r\n",
      "HIST1H3F   1018.65342528922  2.63130496091174   0.199168988562413  13.2114190060626   7.53896796410326e-40  1.03987498118198e-36\r\n",
      "HIST1H3G   848.885327202892  2.68921708605218   0.214346829606054  12.5461015261792   4.17567108885407e-36  5.18367808970345e-33\r\n",
      "HIST1H3C   495.886013819933  2.90337618699046   0.237520604184494  12.2236813810699   2.32320853593567e-34  2.6218464331914e-31\r\n",
      "XIST       193.158333912231  4.34282433038071   0.356601703026426  12.1783611618335   4.05344986833827e-34  4.19329388879594e-31\r\n",
      "ANLN       735.288618025918  2.45585390337792   0.213112357818148  11.5237517360374   1.00153176216165e-30  9.56385791959595e-28\r\n",
      "HIST1H2AJ  409.061790195616  2.62987414098246   0.231166973426073  11.3765132709301   5.47449873595696e-30  4.85431623629784e-27\r\n",
      "HIST1H2BH  849.591709187777  2.41746503393854   0.213156632012939  11.341261170761    8.19547758692224e-30  6.35866617275329e-27\r\n",
      "HIST1H3J   341.77401963615   2.79308864088033   0.246180840432552  11.345678388183    7.79195927494915e-30  6.35866617275329e-27\r\n",
      "NEURL4     684.487083595738  -2.33507477501541  0.209068905033253  -11.168924305812   5.787753634023e-29    4.22642197722127e-26\r\n",
      "HIST1H2BJ  495.31892500409   2.60216771950724   0.235137780538307  11.0665657962324   1.82251699615717e-28  1.25692922168306e-25\r\n",
      "HIST1H2BL  546.768269813001  2.74276602621427   0.248505594258671  11.0370393648334   2.53240232024346e-28  1.65459170544749e-25\r\n",
      "MYBL2      611.252806851485  3.01238707902343   0.27400972885721   10.9937230754067   4.09670864233363e-28  2.54282705429649e-25\r\n",
      "HIST1H2AH  648.827662309961  2.56104662222483   0.23519037286943   10.8892493811668   1.29704876717353e-27  7.66741114080582e-25\r\n",
      "GALNT5     123.603141841777  3.84835216656251   0.360310608489732  10.6806518483959   1.25388090932017e-26  7.07530800377299e-24\r\n",
      "CCNL2      2252.41318052693  -2.08661061177139  0.195806851324268  -10.6564739571643  1.62647471221833e-26  8.77872046846883e-24\r\n",
      "PRR11      737.550957206954  2.79092983363485   0.264030671571833  10.5704758353256   4.08417084899547e-26  2.11253737164291e-23\r\n"
     ]
    }
   ],
   "source": [
    "head -25 deseq.results.RUN.Top20.tsv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This files contains the 20 genes that have the most significantly changed gene expression."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 1836089 jan 27 18:53 deseq.results.RUN.posFOLD.tsv\r\n"
     ]
    }
   ],
   "source": [
    "cat deseq.results.RUN.tsv | awk '$3 > 0' > deseq.results.RUN.posFOLD.tsv\n",
    "ls -l deseq.results.RUN.posFOLD.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "baseMean   log2FoldChange    lfcSE             stat               pvalue            padj\r\n",
      "MIR663A    17657.6449167025  3.95057855902894  0.206539361749826  19.1274850738337  1.49095580537939e-81  1.51795745915827e-77\r\n",
      "MIR30A     613.735581696374  6.66475614114898  0.348909670370175  19.1016664401363  2.4455573693544e-81   1.51795745915827e-77\r\n",
      "ANKRD30BL  2306.08489269738  4.19799897436267  0.222470669667772  18.8698985831785  2.01685179250905e-79  8.34573271740243e-76\r\n",
      "RRM2       1012.72008544986  3.21630483725746  0.203776175804426  15.7835175017923  4.04030692060258e-56  1.25390925280901e-52\r\n",
      "MIR3687    589.413352493287  4.50184986826774  0.29287659418576   15.3711493428949  2.55594406268351e-53  6.34589791883062e-50\r\n",
      "HIST1H3B   1444.33335960224  2.90787104671683  0.201422769712973  14.4366550557344  3.04253521448053e-47  6.29500535876021e-44\r\n",
      "MIR3648    943.248473149307  3.40832276440333  0.241165508308419  14.1327123779431  2.38767626351928e-45  4.2343733050469e-42\r\n",
      "HIST1H1B   2348.42359361963  2.81889786479314  0.210060901962102  13.4194314051918  4.65269250746914e-41  7.21981559846524e-38\r\n",
      "HIST1H3F   1018.65342528922  2.63130496091174  0.199168988562413  13.2114190060626  7.53896796410326e-40  1.03987498118198e-36\r\n",
      "HIST1H3G   848.885327202892  2.68921708605218  0.214346829606054  12.5461015261792  4.17567108885407e-36  5.18367808970345e-33\r\n",
      "HIST1H3C   495.886013819933  2.90337618699046  0.237520604184494  12.2236813810699  2.32320853593567e-34  2.6218464331914e-31\r\n",
      "XIST       193.158333912231  4.34282433038071  0.356601703026426  12.1783611618335  4.05344986833827e-34  4.19329388879594e-31\r\n",
      "ANLN       735.288618025918  2.45585390337792  0.213112357818148  11.5237517360374  1.00153176216165e-30  9.56385791959595e-28\r\n",
      "HIST1H2AJ  409.061790195616  2.62987414098246  0.231166973426073  11.3765132709301  5.47449873595696e-30  4.85431623629784e-27\r\n",
      "HIST1H2BH  849.591709187777  2.41746503393854  0.213156632012939  11.341261170761   8.19547758692224e-30  6.35866617275329e-27\r\n",
      "HIST1H3J   341.77401963615   2.79308864088033  0.246180840432552  11.345678388183   7.79195927494915e-30  6.35866617275329e-27\r\n",
      "HIST1H2BJ  495.31892500409   2.60216771950724  0.235137780538307  11.0665657962324  1.82251699615717e-28  1.25692922168306e-25\r\n",
      "HIST1H2BL  546.768269813001  2.74276602621427  0.248505594258671  11.0370393648334  2.53240232024346e-28  1.65459170544749e-25\r\n",
      "MYBL2      611.252806851485  3.01238707902343  0.27400972885721   10.9937230754067  4.09670864233363e-28  2.54282705429649e-25\r\n"
     ]
    }
   ],
   "source": [
    "head -20 deseq.results.RUN.posFOLD.tsv | column -t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "head -20 deseq.results.RUN.posFOLD.tsv | column -t > deseq.results.RUN.Top20.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "baseMean   log2FoldChange    lfcSE             stat               pvalue            padj\r\n",
      "MIR663A    17657.6449167025  3.95057855902894  0.206539361749826  19.1274850738337  1.49095580537939e-81  1.51795745915827e-77\r\n",
      "MIR30A     613.735581696374  6.66475614114898  0.348909670370175  19.1016664401363  2.4455573693544e-81   1.51795745915827e-77\r\n",
      "ANKRD30BL  2306.08489269738  4.19799897436267  0.222470669667772  18.8698985831785  2.01685179250905e-79  8.34573271740243e-76\r\n",
      "RRM2       1012.72008544986  3.21630483725746  0.203776175804426  15.7835175017923  4.04030692060258e-56  1.25390925280901e-52\r\n",
      "MIR3687    589.413352493287  4.50184986826774  0.29287659418576   15.3711493428949  2.55594406268351e-53  6.34589791883062e-50\r\n",
      "HIST1H3B   1444.33335960224  2.90787104671683  0.201422769712973  14.4366550557344  3.04253521448053e-47  6.29500535876021e-44\r\n",
      "MIR3648    943.248473149307  3.40832276440333  0.241165508308419  14.1327123779431  2.38767626351928e-45  4.2343733050469e-42\r\n",
      "HIST1H1B   2348.42359361963  2.81889786479314  0.210060901962102  13.4194314051918  4.65269250746914e-41  7.21981559846524e-38\r\n",
      "HIST1H3F   1018.65342528922  2.63130496091174  0.199168988562413  13.2114190060626  7.53896796410326e-40  1.03987498118198e-36\r\n",
      "HIST1H3G   848.885327202892  2.68921708605218  0.214346829606054  12.5461015261792  4.17567108885407e-36  5.18367808970345e-33\r\n",
      "HIST1H3C   495.886013819933  2.90337618699046  0.237520604184494  12.2236813810699  2.32320853593567e-34  2.6218464331914e-31\r\n",
      "XIST       193.158333912231  4.34282433038071  0.356601703026426  12.1783611618335  4.05344986833827e-34  4.19329388879594e-31\r\n",
      "ANLN       735.288618025918  2.45585390337792  0.213112357818148  11.5237517360374  1.00153176216165e-30  9.56385791959595e-28\r\n",
      "HIST1H2AJ  409.061790195616  2.62987414098246  0.231166973426073  11.3765132709301  5.47449873595696e-30  4.85431623629784e-27\r\n",
      "HIST1H2BH  849.591709187777  2.41746503393854  0.213156632012939  11.341261170761   8.19547758692224e-30  6.35866617275329e-27\r\n",
      "HIST1H3J   341.77401963615   2.79308864088033  0.246180840432552  11.345678388183   7.79195927494915e-30  6.35866617275329e-27\r\n",
      "HIST1H2BJ  495.31892500409   2.60216771950724  0.235137780538307  11.0665657962324  1.82251699615717e-28  1.25692922168306e-25\r\n",
      "HIST1H2BL  546.768269813001  2.74276602621427  0.248505594258671  11.0370393648334  2.53240232024346e-28  1.65459170544749e-25\r\n",
      "MYBL2      611.252806851485  3.01238707902343  0.27400972885721   10.9937230754067  4.09670864233363e-28  2.54282705429649e-25\r\n"
     ]
    }
   ],
   "source": [
    "head -20 deseq.results.RUN.Top20.tsv | column -t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This files contains the 20 genes that have the most significantly changed gene expression, but only those with a positive log2FoldChange --> expression went up after RUNX1 knockdown."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cat deseq.results.RUN.tsv | awk '$3 < 0' > deseq.results.RUN.negFOLD.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "sed -i '1i  baseMean log2FoldChange lfcSE stat pvalue padj' deseq.results.RUN.negFOLD.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "baseMean  log2FoldChange    lfcSE              stat               pvalue             padj\r\n",
      "NEURL4    684.487083595738  -2.33507477501541  0.209068905033253  -11.168924305812   5.787753634023e-29    4.22642197722127e-26\r\n",
      "CCNL2     2252.41318052693  -2.08661061177139  0.195806851324268  -10.6564739571643  1.62647471221833e-26  8.77872046846883e-24\r\n",
      "CYP1A1    78.1809129285149  -3.96343897315976  0.396823442668725  -9.9879153976004   1.72164164783306e-23  6.67889356756239e-21\r\n",
      "PRPF39    1205.25731423419  -1.91781125853713  0.199211386604976  -9.62701626257953  6.14889914046102e-22  1.9572418956329e-19\r\n",
      "PCSK2     79.749148416811   -3.69997393787923  0.39243766898804   -9.42818243574878  4.17256343981929e-21  1.2332905367123e-18\r\n",
      "GDF15     1362.49359278684  -1.82805381183228  0.194442635627494  -9.40150706110772  5.37870602224722e-21  1.51752855818584e-18\r\n",
      "MME       289.6044331914    -2.79628158108627  0.299263148164472  -9.34388880902056  9.28593766423483e-21  2.50599196008285e-18\r\n",
      "CDK5RAP3  1881.66963690715  -1.87409617835637  0.201420208924523  -9.30440986216356  1.34738477241828e-20  3.55881586485118e-18\r\n",
      "PLCG1     3385.59236642117  -1.61614669802047  0.177554521545975  -9.10225593777395  8.84746515687227e-20  1.96129343673951e-17\r\n",
      "ST8SIA4   980.319731098971  -1.58987885154324  0.193532095264935  -8.21506556505155  2.12048367822143e-16  3.37483133095396e-14\r\n",
      "SCIN      372.530682231728  -2.43686212653378  0.298492391789327  -8.16390029885146  3.24376670524345e-16  5.09723036441673e-14\r\n",
      "TIMP3     1681.02117987098  -1.88766545615523  0.232438779051305  -8.12112963189581  4.6186437879571e-16   7.07849925724684e-14\r\n",
      "EPHA4     2067.48052100966  -1.67309125640371  0.20677414126846   -8.09139501748186  5.89852202864146e-16  8.9297868857994e-14\r\n",
      "TSPYL2    373.872528040766  -1.94377959079083  0.240546787239219  -8.08067159449435  6.44110537054065e-16  9.519033579749e-14\r\n",
      "TFPI      858.265076097687  -2.26150145968266  0.280007036724137  -8.0765879534331   6.66041274522324e-16  9.72733691990603e-14\r\n",
      "GOLGA8A   167.119497250549  -2.26745001393169  0.281699842604525  -8.04917032600169  8.33571739131325e-16  1.18942064018118e-13\r\n",
      "MAPK8IP3  602.537402157244  -1.74205157437545  0.216402144825404  -8.05006612009766  8.2749319198718e-16   1.18942064018118e-13\r\n",
      "PLK2      7082.71811917194  -1.38001092924027  0.17292517731476   -7.98039331617024  1.45867728939209e-15  1.97109093165529e-13\r\n",
      "KIFC2     419.817202593929  -1.75421440125648  0.222072521916109  -7.89928617066435  2.80505199614455e-15  3.48219154801384e-13\r\n"
     ]
    }
   ],
   "source": [
    "head -20 deseq.results.RUN.negFOLD.tsv | column -t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "head -25 deseq.results.RUN.negFOLD.tsv | column -t > deseq.results.RUN.Top20min.tsv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This files contains the 20 genes that have the most significantly changed gene expression, but only those with a positive log2FoldChange --> expression went up after RUNX1 knockdown."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Deletion of the lines that contain O counts for all the samples using awk command."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0637408 domain users 527381 jan 27 20:30 all.gene.counts.RUN.notZero.tsv\r\n"
     ]
    }
   ],
   "source": [
    "awk '(NR>1){s=0; for (i=3;i<=NF;i++) s+=$i; if (s!=0)print}' all.gene.counts.RUN.tsv > all.gene.counts.RUN.notZero.tsv\n",
    "ls -l all.gene.counts.RUN.notZero.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "sed -i '1i  Geneid shNSR1.bam shNSR2.bam shRUNR1.bam shRUNR2.bam' all.gene.counts.RUN.notZero.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Geneid shNSR1.bam shNSR2.bam shRUNR1.bam shRUNR2.bam\r\n",
      "AL627309.1\t13\t14\t6\t15\r\n",
      "RP11-34P13.13\t9\t5\t5\t11\r\n",
      "AP006222.2\t1\t2\t2\t1\r\n",
      "RP4-669L17.10\t0\t1\t1\t0\r\n",
      "RP4-669L17.2\t0\t0\t2\t0\r\n",
      "RP5-857K21.1\t3\t4\t0\t4\r\n",
      "RP5-857K21.4\t0\t0\t1\t0\r\n",
      "RP11-206L10.3\t2\t0\t1\t1\r\n",
      "RNU6-1199P\t0\t1\t1\t0\r\n",
      "RP11-206L10.5\t0\t0\t1\t0\r\n",
      "RP11-206L10.2\t12\t11\t3\t13\r\n",
      "RP11-206L10.9\t18\t32\t12\t19\r\n",
      "AL669831.1\t1\t1\t0\t2\r\n",
      "RP11-206L10.10\t6\t9\t5\t4\r\n",
      "FAM87B\t2\t5\t3\t0\r\n",
      "LINC00115\t8\t19\t2\t2\r\n",
      "RP11-206L10.11\t76\t115\t95\t46\r\n",
      "RP11-54O7.16\t3\t1\t0\t1\r\n",
      "RP11-54O7.1\t4\t6\t6\t6\r\n"
     ]
    }
   ],
   "source": [
    "head -20 all.gene.counts.RUN.notZero.tsv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following figures are the heatmaps that represent the differential expression of the four samples. The scale of the heatmap varies from 2 to 12, which is coloured from blue to red, respectively. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"40%\" src=\"/user/r0638328/files/Untitled Folder/heatmap1.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 15: Heatmap representing the individual values of the four samples. We selected a top 24 of the most significantly upregulated genes after RUNX knockdown. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The function of each of these genes is described below. We selected the most important and relevant genes for breast cancer.\n",
    "\n",
    "- MIR663A (MicroRNA 663a) and other MicroRNAs: microRNAs have an impact on both the stability and translation of mRNAs.  \n",
    "- MYBL2 (MYB Proto-Oncogene Like 2): involved in cell cycle progression.\n",
    "- HIST1H3B (Histone Cluster 1 H3 Family Member B): the protein encoded by this gene is a histone. A histone is a basic nuclear protein that has an influence on the nucleosome structure of the chromosal fiber (in eukaryotes). Note: Multiple other histones were found to be upregulated after knock down of RUNX, such as HIST1H3C and HIST1H2BJ.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"40%\" src=\"/user/r0638328/files/Untitled Folder/heatmap2.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 16: Heatmap representing the individual values of the four samples. We selected a top 24 of the most significantly downregulated genes after RUNX knockdown. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The function of the downregulated genes are discribed below. We selected the most relevant genes again.\n",
    "\n",
    "\n",
    "- PRPF39: protein involved in pre-mRNA splicing\n",
    "- GDF15: protein involved in the inflammatory and apoptotic pathways during injury and disease\n",
    "- CDK5RAP3: tumor suppressor \n",
    "- TIMP3: The proteins encoded by this gene family are inhibitors of the matrix metalloproteinases, a group of peptidases involved in degradation of the extracellular matrix (ECM). Expression of this gene is induced in response to mitogenic stimulation and this netrin domain-containing protein is localized to the ECM.\n",
    "- TSPYL2: The encoded protein is localized to the nucleolus where it functions in chromatin remodeling and as an inhibitor of cell-cycle progression. This protein may play a role in the suppression of tumor growth.\n",
    "- PLK2: This is a tumor suppressor serine/threonine-protein kinase involved in synaptic plasticity, centriole duplication and G1/S phase transition.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"40%\" src=\"/user/r0638328/files/Untitled Folder/HEATMAP3.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 17: Heat map with added hierarchial clustering. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We selected the genes which are most important in breast cancer, or general in cancer. We didn't display all genes in the heatmap, because it wouldn't be clear. We observed a downregulation of a lot of genes, further in the list are NEAT1 and MALAT1. But on the other hand, we observed an up-regulation of genes, the most important are associated with chromatin regulation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Further, we used the transcription factor RUNX1 to create a network of genes related to this TF in Genemania. This program gives the genes that are linked with the TF RUNX1. In figure 18, we can see that RUNX has an influence on chromatin remodelling(left column), which is the most important feature for our article, but RUNX1 is involved in many other functions. Here we retrieve the network of RUNX1 and use this as an input for iRegulon (Cytoscape). This sequence-based tool searches for Regulons. These may include TF, the targets and the motifs/tracks from a set of genes. We found RUNX1 as enriched transcription factor and made a network of related transcription factors. Figure 19 presents the output after using iRegulon. We found a list of related transcription factors to RUNX1.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/genemania.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 18: Transcription factor RUNX1 with its related genes in Genemania. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/iregulon.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 19: Sequence-based discovery of regulons for the TF RUNX1. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ChIP-seq analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "For the ChIP-seq analysis we will explain every step we did in this jupyternotebook and will refer to the **\"TaskChiP-seqFINAL.ipynb\"** notebook for the output of every step (agreed by Dr. Mark Fiers). \n",
    "\n",
    "Chromatin immunoprecipitation followed by high-throughput sequencing is the standard method\n",
    "to predict DNA binding sites from ChIP-seq read count data and thereby perform peak calling methods."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Aim of ChIP-seq\n",
    "\n",
    "ChIP-seq is performed to determine where a protein binds the genome, which can be transcription factors, DNA-binding enzymes, histones, chaperones, or nucleosomes.\n",
    "\n",
    "ChIP-seq first cross-links bound proteins to chromatin, fragments the chromatin, captures the DNA fragments bound to one protein using an RUNX1 antibody, and sequences the ends of the captured fragments using next-generation sequencing. Mapping of the sequenced DNA identifies the genomic locations of bound DNA-enzymes, modified histones, chaperones, nucleosomes and transcription factors, thereby illuminating the role of these protein-DNA interactions in gene expression and other cellular processes. The use of NGS provides relatively high solution, low noise, and high genomic coverage compared with ChIP-seq assays (ChIP followed by microarray hybridisation). ChIP-seq is the most widely used procedure for DNA-protein interaction.\n",
    "\n",
    "We performed ChIP-seq to determine RUNX1-dependent differences in gene expression. The RNA-seq results are directly related to the binding of RUNX1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### STEP 1: downloading the ChIP-seq data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Download the ChIP-seq data from the GEO site (analogue to RNA-seq). They performed ChIP-seq on 2 replicates, namely MCF-7 wildtype RUNX1 replicate 1 and 2. We downloaded the input and pulldown data of both replicates.\n",
    "\n",
    "SRA numbers:\n",
    "\n",
    "- SRR2919474, replicate 1 input named S1\n",
    "- SRR2919475, replicate 1 pulldown named S2\n",
    "- SRR2919476, replicate 2 input named S3 \n",
    "- SRR2919477, replicate 2 pulldown named S4\n",
    "\n",
    "The input files are used as control.\n",
    "\n",
    "**Note**: for the output of the following commands go to the title **STEP 1: dowloading the ChIP-seq data** in **TaskChIP-seqFINAL.ipynb** jupyternotebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cd ~/data/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ls "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before we map the reads to the reference genome, we should apply quality control to asses possible sequencing errors or biases. We performed quality control in bitvise with fastqc (same method as RNA-seq). See above for further details. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overview of the data quality after fastqc\n",
    "\n",
    "The phred quality scores are analysed for both input and pulldown data.\n",
    "\n",
    "Check the quality of the raw data by using the FastQC toolkit.\n",
    "General commando: fastqc fastqfile -o outputdir"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **S1**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results S1:\n",
    "\n",
    "Sequences flagged as poor quality: 0 \n",
    "-\tPer base sequence quality report: The graph represents a very good quality score of the bases, which is indicative for a good base calling. At the end of the sequence the score decreases a little bit, however the scores still remain in the green area of the y-axis. Therefore, it is still a good base calling of good quality. \n",
    "-\tSequences duplication levels report: The trend of the curve shows a peak on the right side of the curve, which implements more specific enrichments or the presence of contaminants. \n",
    "-\tOverrepresented sequences report: no overrepresented sequences had been found. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/summary S1.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 20: Summary of the quality control results of S1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/per base sequence quality S1.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 21: Per base sequence quality of S1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/sequence duplication levels S1 .png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 22: Sequence duplication levels of S1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **S2**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results S2:\n",
    "\n",
    "Sequences flagged as poor quality: 0 \n",
    "-\tPer base sequence quality report: The graph represents a very good quality score of the bases similar to the previous sample. At the end of the sequence the scores show a reduction of quality score, however the scores still remain in the green area of the y-axis. Therefore, it is still a good base calling of good quality. \n",
    "-\tSequences duplication levels report: There is a large peak on the right side, which represents more specific enrichments or the presence of contaminants\n",
    "-\tOverrepresented sequences report: There is one overrepresented sequence in S2 of which the suggested source could be TruSeq Adapter, Index 6. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/summary S2.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 23: Summary of the quality control results of S2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/per base sequence quality S2.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 24: Per base sequence quality of S2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/sequence duplication levels S2 .png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 25: Sequence duplication levels of S2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **S3**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results S3:\n",
    "\n",
    "Sequences flagged as poor quality: 0 \n",
    "-\tPer base sequence quality report: A very good quality score of all bases has been found (green area). However, a lower quality score has been observed in the end of the sequence. Nevertheless, since the scores still reside in the green area, it is related with a very high quality score. \n",
    "-\tSequences duplication levels report: A little peak at the right side is observed. This can represent more specific enrichments or contaminations. \n",
    "-\tOverrepresented sequences report: no overrepresented sequences had been found.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/summary S3.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 26: Summary of the quality control results of S3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/per base sequence quality S3.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 27: Per base sequence quality of S3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/sequence duplication levels S3 .png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 28: Sequence duplication levels of S3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* **S4**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Analysis of the Quality control results S4:\n",
    "\n",
    "Sequences flagged as poor quality: 0 \n",
    "-\tPer base sequence quality report: The quality scores across all bases show a very high quality. Same as all previous samples: at the end of the sequence the quality score decreases. However, all scores remain in the green area, which is related with a very good base calling. \n",
    "-\tSequences duplication levels report: The curve shows a small peak on the right side, which is associated with more specific enrichments or contaminations.  \n",
    "-\tOverrepresented sequences report: One overrepresented sequence has been found of which the possible source could be: TruSeq Adapter, Index 10. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"30%\" src=\"/user/r0638328/files/Untitled Folder/summary S4.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 29: Summary of the quality control results of S4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/per base sequence quality S4.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 30: Per base sequence quality of S4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<img width=\"50%\" src=\"/user/r0638328/files/Untitled Folder/sequence duplication levels S4 .png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 31: Sequence duplication levels of S4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " As a conclusion, we decided that the overall quality was good for all reads, since no sequences were ‘flagged as poor quality’. Nevertheless, multiple notifications were present in the quality report, especially those from the overrepresented sequences. However, if the overrepresented sequences are adapters, this could be solved by trimming of the reads. In practice, this step is skipped most of the time, as the reads will not be mapped anyway. In our cases, the overrepresented sequences were adapters, therefore we decided not to trim the reads. \n",
    "\n",
    "Note: You can find a more detailed information about every report in the paragraph of RNA-seq analysis (step 3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 2: alignment with BOWTIE\n",
    "\n",
    "The reads should be mapped using Bowtie, which allows gapped alignment, but detection of indels is not necessary for most ChIP-seq experiments. We use Bowtie for mapping, because it is ultra fast. Bowtie needs a reference genome to align each read and the genome has to be in an index for Bowtie to be able to use it. All the samples of our genome are human, so we choose the human reference genome hg19, which is not the latest but a stable version of human genome assembly."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alignment with Bowtie2 was performed whereafter the samfiles were converted to a bam file and were sorted.\n",
    "\n",
    "**Note**: for the output of the following commands go to the title **STEP 2: alignment with BOWTIE** in **TaskChIP-seqFINAL.ipynb** jupyternotebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cd ~/data/work\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 S1.fastq -S S1.sam\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 S2.fastq -S S2.sam\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 S3.fastq -S S3.sam\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 S4.fastq -S S4.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cd ~/data/work\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#evaluation of the mapped reads: view, sort and index files\n",
    "samtools view -S -b S1.sam > S1.bam\n",
    "samtools view -S -b S2.sam > S2.bam\n",
    "samtools view -S -b S3.sam > S3.bam\n",
    "samtools view -S -b S4.sam > S4.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#view the bamfiles to check the structure of the files (do this for every file)\n",
    "samtools view S4.bam | head -20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "samtools sort -O bam -o S1.sorted.bam S1.bam\n",
    "samtools sort -O bam -o S2.sorted.bam S2.bam\n",
    "samtools sort -O bam -o S3.sorted.bam S3.bam\n",
    "samtools sort -O bam -o S4.sorted.bam S4.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "samtools index S1.sorted.bam\n",
    "samtools index S2.sorted.bam\n",
    "samtools index S3.sorted.bam\n",
    "samtools index S4.sorted.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we look at the bam files in IGV. We see peaks in every sorted bam file in RUNX and other genes. Thereafter, the regions of the genome where the chipped protein, RUNX in our case, is bound have to be predicted. Thus we have to find regions in the genome with significant numbers of mapped reads or peaks."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 3: Peak calling with Macs2\n",
    "\n",
    "Macs (model-based analysis of ChIP-seq) is a peak caller which supports both single and paired-end sequencing. It uses cross-correlation to find the lag between the reads mapped to the minus and the plus strains as the size of actual protein-DNA interacting regions.\n",
    "\n",
    "- Remove duplicate tags\n",
    "- Find candidate peaks with a significant tag enrichment\n",
    "- Merge overlapping peaks \n",
    "- Look at background levels and eliminate peaks that are not significant with respect to local background \n",
    "- Use of the control sample to eliminate peaks that are also present there\n",
    "\n",
    "We used the input files, S1 and S3, of replicate 1 and 2 as control samples for peak calling of the pulldown files, S2 and S4, of replicate 1 and 2. Furthermore we used the whole human genome, hs, for performing the peak calling.\n",
    "\n",
    "**Note**: for the output of the following commands go to the title **STEP 3: Peak calling with Macs2** in **TaskChIP-seqFINAL.ipynb** jupyternotebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "macs2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mkdir macs2_RUNX\n",
    "macs2 callpeak -t  S2.sorted.bam -c S1.sorted.bam -f BAM -g hs -n RUNX"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "macs2 callpeak -t  S4.sorted.bam -c S3.sorted.bam -f BAM -g hs -n RUNX1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The file RUNX and RUNX1 are respectively replicate 1 and replicate 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cd macs2_RUNX\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# to count the total of peaks\n",
    "cat RUNX_summits.bed | wc -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cat RUNX_peaks.narrowPeak | sort -k9 -g -r | head -5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cat RUNX1_summits.bed | wc -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cat RUNX1_peaks.narrowPeak | sort -k9 -g -r | head -5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# load bed files to igv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/IGV.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 32: loading the bed files of RUNX in IGV"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/macsmalat1.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 33: Loading of .bam and .bai files in IGV of S2. Zoomed in on MALAT1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/macsneat1.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 34: Loading of .bam and .bai files in IGV of S2. Zoomed in on NEAT1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the results, we found peaks in the promotor region of different genes. Here we show as an example MALAT1 and NEAT1 (figure 26 and 27 respectively), because these are found to be downregulated in absence of RUNX1 in RNA-seq. Now we visualise these genes in the presence of RUNX1 and it is clear that RUNX1 binds to the genes themselves or their promotor region. In this way RUNX can have an influence on the expression of these genes. The results are analogous for replicate 2. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 4 : Motif analysis\n",
    "\n",
    "\n",
    "Motif analysis is useful for much more than just identifying the causal DNA-binding motif in TF ChIP-seq peaks. When the motif of the ChIPed protein is already known, motif analysis provides validation of the success of the experiment. Even when the motif is not known beforehand, identifying a centrally located motif in a large fraction of the peaks by motif analysis is indicative of a successful experiment. Motif analysis can also identify the DNA-binding motifs of other proteins that bind in complex or in conjunction with the ChIPed protein, illuminating the mechanisms of transcriptional regulation. Motif analysis is also useful with histone modification ChIP-seq because it can discover unanticipated sequence signals associated with such marks. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We loaded the bed files from replicate 1 and 2 (RUNX and RUNX1 are the names of the files respectively) in IGV. We found that RUNX1 binds to the promotor regions of NEAT1 and MALAT1, which corresponds with the results of the article. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/MALAT1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 35: Screenshot of IGV output with .bam and .bamCoverage files of S2 and S4. Zoomed in on MALAT1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/NEAT1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 36: Screenshot of IGV output with .bam and .bamCoverage files of S2 and S4. Zoomed in on NEAT1. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After loading our .bam and .bamCoverage files of both S2 and S4 in IGV, we could visually see that our data was of good quality (as there were high peaks). We also found that the peaks were higher in the promotor region of both genes NEAT1 and MALAT1. This corresponds with the findings of the article. \n",
    "\n",
    "Further, we perfomed icis-target, you can find the links for replicate 1 and 2 [Here](https://gbiomed.kuleuven.be/apps/lcb/i-cisTarget/reports/4823c681009bb3eae6bb6189fab55b96426ab95d/report.html) and [Here](https://gbiomed.kuleuven.be/apps/lcb/i-cisTarget/reports/e62ba80c6d20e39357d621d3aec666bd06e7be79/report.html) respectively. Here we didn't find the list of genes we expected, therefore we searched the genes of the article in IGV and later on in UCSC.\n",
    "\n",
    "Additionally, we used RSAT (Regulatory Sequence Analysis Tools) which is a software for the analysis of cis-regulatory elements in genome sequences. It can be used for motif discovery (used with genome-wide data sets like ChIP-seq), transcription factor binding motif analysis, comparative genomics and analysis of regulatory variations. \n",
    "\n",
    "We used the consensus sequence of RUNX to discover motifs. The consensus sequence of RUNX is AAACCACAAA. You can find the result of RSAT [Here](http://rsat.sb-roscoff.fr/tmp/apache/2017/01/26/gs-dna-pattern_2017-01-26.210204_LqJTDH.dnapat).\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 5: enhancer-to-gene association\n",
    "\n",
    "We have linked the peaks to genes with UCSC, you can find the link to the report [Here](https://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&lastVirtModeType=default&lastVirtModeExtraState=&virtModeType=default&virtMode=0&nonVirtPosition=&position=chr11%3A64073044%2D64084210&hgsid=576694635_ZuucNUI0Otw93sy1QbNEoDMiFaSK) .\n",
    "\n",
    "Although, we did not find the genes from the article via icis-target, we searched the set of genes from the article. Here we found that our gene RUNX1 has an influence on the expression level of the following set of genes: MALAT1, NEAT1, EBF1, EGR1, ESRR, FOXP3.\n",
    "\n",
    "Thus these results confirm again an influence on the expression of both MALAT1 and NEAT1 (and the other genes listed above) after the binding of RUNX. \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/ucscmalat1.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 37: UCSC report with a close up of the MALAT1 gene"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/ucscneat1.PNG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 38: UCSC report with a close up of the NEAT1 gene "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/EBF1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 39: UCSC report with a close up of the EBF1 gene"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/EGR1.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 40: UCSC report with a close up of the EGR1 gene"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/ESRR.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 41: UCSC report with a close up of the ESRR gene"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/FOXP3.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 42: UCSC report with a close up of the FOXP3 gene"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 6: link ChIP-seq data to RNA-seq data\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We loaded both RNA-seq data and ChIP-seq data in IGV. Based on the ChIP-seq data, we found that RUNX binds to the promotor region of NEAT1 and MALAT1. Additionally, from the RNA-seq data we could conclude that this binding of RUNX to both genes (NEAT1 and MALAT1) stimulates the expression of these genes (see Figure 32 and 33). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/conclusie MALAT.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 43: Both RNA-seq and ChIP-seq data loaded in IGV. Zoomed in at MALAT1 gene. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0638328/files/Untitled Folder/conclusie NEAT.JPG\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 44: Both RNA-seq and ChIP-seq data loaded in IGV. Zoomed in at NEAT1 gene. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conclusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "When we merge the RNA-seq data and the ChIP-seq data, we see the same result. Thus RUNX transcription factor has an influence on the expression level of different genes, which is proved by comparing the wild type sample with the sample where RUNX1 is knocked down in breast cancer MCF-7 cells. RUNX1 has a positive regulation on the expression of NEAT1 and MALAT1, which are involved in the nuclear structure and in cancer. Further ChIP-seq data showed that RUNX1 influences the expression of different genes by binding to their promotor regions, especially MALAT1 and NEAT1. By performing ChIP-seq we see that RUNX1 is important in chromatin regulation and folding. Thus different genes are upregulated and downregulated upon the protein binding of RUNX1. In breast cancer, through the dysfunction of RUNX1 there are effects on the nuclear structure and chromatine folding.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "References:\n",
    "\n",
    "http://www.bioinformatics.babraham.ac.uk/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "http://www.sthda.com/english/wiki/rna-sequencing-data-analysis-counting-normalization-and-differential-expression"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
