{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Reference: Williams K, Christensen J, Pedersen M, Johansen JV, Cloos PAC, Rappsilber J et al. Tet1 and hydroxymethylcytosine in transcription and DNA methylation fidelity. Nature 2011, 473(7347):343-348."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Summary of the article: Methylation of cytosines by DNA methyl transferases is an important factor contributing to the downregulation of gene expression. This epigenetic modification mostly occurs in CpG islands, expect in the ones of promotors. Tet1 katalyzes the hydoroxylation of methylated cytosines, which results in demethylation. Previous studies show that methylated cytosines frequently occur in embryonic stem cells and that this modification is a crucial factor in gene regulation.\n",
    "\n",
    "In this paper, mouse embryonic stem cells were used in order to unravel the function of Tet1 since these cells exhibit a high Tet1 expression level. By using ChIP-seq, they found out that Tet1 preferentially binds to transcription start sites and gene bodies of CpG-rich promotors. Microarray was performed on both normal and Tet1-knockdown embryonic stem cells and showed that Tet1 represses transcription. Next, they investigated the molecular pathway of this repression by using ChIP-seq and found out that Tet1 recrutes SIN3A, thereby inhibiting transcription."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "ChIP-seq analysis (GSE24841)\n",
    "\n",
    "Location of the original ipynb: /mnt/storage/r0368030/jupyternotebooks\n",
    "\n",
    "Files: /mnt/storage/r0368030/groepswerk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0368030/data/groepswerk\r\n"
     ]
    }
   ],
   "source": [
    "# Before starting, we created a working directory for our group work.\n",
    "mkdir ~/data/groepswerk\n",
    "cd ~/data/groepswerk\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 16486324 spots for SRR070941\r\n",
      "Written 16486324 spots for SRR070941\r\n",
      "Read 21688279 spots for SRR070940\r\n",
      "Written 21688279 spots for SRR070940\r\n",
      "~  SRR070940_1.fastq  SRR070941_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "# First, the SRA files were downloaded from the GEO database (GSE24841). We only downloaded the files we needed (for example, they testet two different antibodies against Tet1, but we only tested one).\n",
    "fastq-dump --split-files SRR070939\n",
    "fastq-dump --split-files SRR070938\n",
    "fastq-dump --split-files SRR070937\n",
    "fastq-dump --split-files SRR070936\n",
    "fastq-dump --split-files SRR070935\n",
    "fastq-dump --split-files SRR070934\n",
    "fastq-dump --split-files SRR070933\n",
    "fastq-dump --split-files SRR070932\n",
    "fastq-dump --split-files SRR070931\n",
    "fastq-dump --split-files SRR070930\n",
    "fastq-dump --split-files SRR070928\n",
    "fastq-dump --split-files SRR070927"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~  IgG_Dnmt.fastq  IgG.fastq\r\n"
     ]
    }
   ],
   "source": [
    "# Next, the files were renamed. \n",
    "# They were renamed in order to avoid confusion and to give them appropriate names instead of a list of numbers. \n",
    "mv SRR070939_1.fastq mC_Dnmt.fastq\n",
    "mv SRR070938_1.fastq mC_ShTet1.fastq\n",
    "mv SRR070937_1.fastq mC_shScr.fastq\n",
    "mv SRR070936_1.fastq mC.fastq\n",
    "mv SRR070935_1.fastq hmC_Dnmt.fastq\n",
    "mv SRR070934_1.fastq hmC_shTet1.fastq\n",
    "mv SRR070933_1.fastq hmC_shScr.fastq\n",
    "mv SRR070932_1.fastq hmC.fastq\n",
    "mv SRR070931_1.fastq IgG_Chip.fastq\n",
    "mv SRR070930_1.fastq SIN3A_Scruz.fastq\n",
    "mv SRR070928_1.fastq Tet1-N-shTet1.fastq\n",
    "mv SRR070927_1.fastq Tet1-N-shScr.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "mkdir ~/data/ncbi\n",
    "vdb-config -s /resository/user/main/public/root=~/data/ncbi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0368030/data/groepswerk\r\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/groepswerk\n",
    "pwd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "TET1 binds CpG transcription start sites"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first hypothesis of this article was to investigate which are the target genes of Tet1. Two different antibodies were used to make Tet1-knockdown cells: one antibody targeting the C-terminus and the other antibody targeting the N-terminus of the protein. We chose to only work with the ChIP-seq data of the N-terminus antibody. The analysis of the ChIP-seq data of the C-terminus antibody is similar to the analysis of data of the N-terminus antibody, and is therefore not showed in this group work. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of Tet1-N-shTet1.fastq\r\n",
      "Approx 5% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 10% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 15% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 20% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 25% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 30% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 35% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 40% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 45% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 50% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 55% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 60% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 65% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 70% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 75% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 80% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 85% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 90% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 95% complete for Tet1-N-shTet1.fastq\r\n",
      "Approx 100% complete for Tet1-N-shTet1.fastq\r\n",
      "Analysis complete for Tet1-N-shTet1.fastq\r\n",
      "Started analysis of Tet1-N-shScr.fastq\r\n",
      "Approx 5% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 10% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 15% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 20% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 25% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 30% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 35% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 40% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 45% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 50% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 55% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 60% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 65% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 70% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 75% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 80% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 85% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 90% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 95% complete for Tet1-N-shScr.fastq\r\n",
      "Approx 100% complete for Tet1-N-shScr.fastq\r\n",
      "Analysis complete for Tet1-N-shScr.fastq\r\n",
      "Started analysis of IgG_Chip.fastq\r\n",
      "Approx 5% complete for IgG_Chip.fastq\r\n",
      "Approx 10% complete for IgG_Chip.fastq\r\n",
      "Approx 15% complete for IgG_Chip.fastq\r\n",
      "Approx 20% complete for IgG_Chip.fastq\r\n",
      "Approx 25% complete for IgG_Chip.fastq\r\n",
      "Approx 30% complete for IgG_Chip.fastq\r\n",
      "Approx 35% complete for IgG_Chip.fastq\r\n",
      "Approx 40% complete for IgG_Chip.fastq\r\n",
      "Approx 45% complete for IgG_Chip.fastq\r\n",
      "Approx 50% complete for IgG_Chip.fastq\r\n",
      "Approx 55% complete for IgG_Chip.fastq\r\n",
      "Approx 60% complete for IgG_Chip.fastq\r\n",
      "Approx 65% complete for IgG_Chip.fastq\r\n",
      "Approx 70% complete for IgG_Chip.fastq\r\n",
      "Approx 75% complete for IgG_Chip.fastq\r\n",
      "Approx 80% complete for IgG_Chip.fastq\r\n",
      "Approx 85% complete for IgG_Chip.fastq\r\n",
      "Approx 90% complete for IgG_Chip.fastq\r\n",
      "Approx 95% complete for IgG_Chip.fastq\r\n",
      "Approx 100% complete for IgG_Chip.fastq\r\n",
      "Analysis complete for IgG_Chip.fastq\r\n"
     ]
    }
   ],
   "source": [
    "# Quality control of the Tet1-knockout and the normal embryonic stem cells.\n",
    "# Quality control is performed on the data of Tet1, Tet1-knockdown and IgG. IgG was used as a control/input. We did not perform quality controls for the other fastq-files because it very similar.\n",
    "fastqc Tet1-N-shTet1.fastq -o /mnt/storage/r0368030/groepswerk\n",
    "fastqc Tet1-N-shScr.fastq -o /mnt/storage/r0368030/groepswerk\n",
    "fastqc IgG_Chip.fastq -o /mnt/storage/r0368030/groepswerk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0368030/files/FastQC_IgG.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/FastQC_Tet1Sh.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/FastQC_Tet1ShScr.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The html files of the quality control showed a good quality of each parameter, except for the Kmer content and the sequence duplication levels. So we concluded that the quality of the fastq-files was good enough to be used in our further analysis. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, the Tet1, Tet1-knockdown and the IgG data were aligned with the mouse genome. MM9 was used in the article, therefore we used this version of the mouse genome in this group work. In order to do that, the correct mm9.bt2 had to be downloaded from the bowtie2 website."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tet1-knockdown:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36228317 reads; of these:\r\n",
      "  36228317 (100.00%) were unpaired; of these:\r\n",
      "    1661760 (4.59%) aligned 0 times\r\n",
      "    23684391 (65.38%) aligned exactly 1 time\r\n",
      "    10882166 (30.04%) aligned >1 times\r\n",
      "95.41% overall alignment rate\r\n"
     ]
    }
   ],
   "source": [
    "# Alignment of the Tet1-knockdown data with the MM9 mouse genome using the bowtie tool.\n",
    "bowtie2-align -x /mnt/storage/r0368030/groepswerk/mm9/mm9 Tet1-N-shTet1.fastq -S Tet1-N-ShTet1.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# The samfile has to be converted into a bamfile, using samtools. \n",
    "# This is because a samfile is too big, and convertion into a smaller bamfile is feasible to work with.\n",
    "samtools view -S -b Tet1-N-ShTet1.sam > Tet1-N-ShTet1.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 10 files...\r\n"
     ]
    }
   ],
   "source": [
    "# The bamfile has to be sorted.\n",
    "samtools sort -O bam -o Tet1-N-ShTet1.sorted.bam Tet1-N-ShTet1.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~\t\t    IgG_Dnmt.fastq   SIN3A_Abcam.fastq\r\n",
      "chromFa.tar.gz\t    IgG.fastq\t     SIN3A_Scruz.fastq\r\n",
      "genome.chrom.sizes  mC_Dnmt.fastq    Tet1-N-shScr.fastq\r\n",
      "hmC_Dnmt.fastq\t    mC.fastq\t     Tet1-N-ShTet1.bam\r\n",
      "hmC.fastq\t    mC_shScr.fastq   Tet1-N-shTet1.fastq\r\n",
      "hmC_shScr.fastq     mC_ShTet1.fastq  Tet1-N-ShTet1.sam\r\n",
      "hmC_shTet1.fastq    mm9\t\t     Tet1-N-ShTet1.sorted.bam\r\n",
      "IgG_Chip.fastq\t    mm9.fa\t     Tet1-N-ShTet1.sorted.bam.bai\r\n"
     ]
    }
   ],
   "source": [
    "# The sorted bamfile is converted into a indexed baifile.\n",
    "samtools index Tet1-N-ShTet1.sorted.bam \n",
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tet1:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "34481295 reads; of these:\r\n",
      "  34481295 (100.00%) were unpaired; of these:\r\n",
      "    1420383 (4.12%) aligned 0 times\r\n",
      "    24604724 (71.36%) aligned exactly 1 time\r\n",
      "    8456188 (24.52%) aligned >1 times\r\n",
      "95.88% overall alignment rate\r\n"
     ]
    }
   ],
   "source": [
    "# Alignment of the Tet1 data with the MM9 mouse genome using the bowtie tool.\n",
    "bowtie2-align -x /mnt/storage/r0368030/groepswerk/mm9/mm9 Tet1-N-shScr.fastq -S Tet1-N-shScr.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# The samfile has to be converted into a bamfile, using samtools. \n",
    "# This is because a samfile is too big, and convertion into a smaller bamfile is feasible to work with.\n",
    "samtools view -S -b Tet1-N-shScr.sam > Tet1-N-shScr.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 9 files...\r\n"
     ]
    }
   ],
   "source": [
    "# The bamfile has to be sorted.\n",
    "samtools sort -O bam -o Tet1-N-shScr.sorted.bam Tet1-N-shScr.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# The sorted bamfile is converted into a indexed baifile.\n",
    "samtools index Tet1-N-shScr.sorted.bam "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "IgG:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28745521 reads; of these:\r\n",
      "  28745521 (100.00%) were unpaired; of these:\r\n",
      "    1006683 (3.50%) aligned 0 times\r\n",
      "    19115953 (66.50%) aligned exactly 1 time\r\n",
      "    8622885 (30.00%) aligned >1 times\r\n",
      "96.50% overall alignment rate\r\n"
     ]
    }
   ],
   "source": [
    "# Alignment of the IgG data with the MM9 mouse genome using the bowtie tool.\n",
    "bowtie2-align -x /mnt/storage/r0368030/groepswerk/mm9/mm9 IgG_Chip.fastq -S IgG_Chip.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# The samfile has to be converted into a bamfile, using samtools. \n",
    "# This is because a samfile is too big, and convertion into a smaller bamfile is feasible to work with.\n",
    "samtools view -S -b IgG_Chip.sam > IgG_Chip.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 8 files...\r\n"
     ]
    }
   ],
   "source": [
    "# The bamfile has to be sorted.\n",
    "samtools sort -O bam -o IgG_Chip.sorted.bam IgG_Chip.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# The sorted bamfile is converted into a indexed baifile.\n",
    "samtools index IgG_Chip.sorted.bam "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All alignments show a high percentage, which means that the coverage is good. The sorted bamfiles were used in IGV (see printscreens below).\n",
    "\n",
    "The upper track is the Tet1 knockdown and the lower track is the Tet1 wild type. We looked at the three genes that were analysed in the paper: Ttc9, Ssbp2 and Sema6. All these genes showed higher peaks in the Tet1 wildtype cells than in the Tet1 knockdown cells, as expected (and as shown in the paper). IGV also showed that Tet1 mostly binds to the promotors (transcription start sites, TSS) of these genes."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0368030/files/Tet1KDvsWT_ttc9.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/Tet1KDvsWT_Ssbp2.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/Tet1KDvsWT_Sema6.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/Figuur1bd_1.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/Figuur1c.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The peaks in Tet1 and Tet1-knockdown data were quantified (i.e. peakcalling) using the MACS2 tool. We used the sorted IgG_ChIP bamfile as a control/input. The command was performed over the whole mouse genome with FDR <0.01 (as done in the article). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO  @ Sun, 29 Jan 2017 18:45:22: \r\n",
      "# Command line: callpeak -t Tet1-N-ShTet1.sorted.bam -c IgG_Chip.sorted.bam --outdir macs2_ShTet1_poging2 -n Tet1_poging2 -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = Tet1_poging2\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['Tet1-N-ShTet1.sorted.bam']\r\n",
      "# control file = ['IgG_Chip.sorted.bam']\r\n",
      "# effective genome size = 1.87e+09\r\n",
      "# band width = 300\r\n",
      "# model fold = [5, 50]\r\n",
      "# qvalue cutoff = 1.00e-02\r\n",
      "# Larger dataset will be scaled towards smaller dataset.\r\n",
      "# Range for calculating regional lambda is: 1000 bps and 10000 bps\r\n",
      "# Broad region calling is off\r\n",
      " \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:22: #1 read tag files... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:22: #1 read treatment tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:22: Detected format is: BAM \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:22: * Input file is gzipped. \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:26:  1000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:31:  2000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:35:  3000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:39:  4000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:43:  5000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:47:  6000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:52:  7000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:45:56:  8000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:00:  9000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:05:  10000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:09:  11000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:13:  12000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:17:  13000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:22:  14000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:26:  15000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:30:  16000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:35:  17000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:39:  18000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:44:  19000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:48:  20000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:52:  21000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:46:57:  22000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:01:  23000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:05:  24000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:09:  25000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:14:  26000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:18:  27000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:22:  28000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:27:  29000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:31:  30000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:35:  31000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:40:  32000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:44:  33000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:48:  34000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:52:  35000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:54:  36000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:55: #1.2 read input tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:55: Detected format is: BAM \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:55: * Input file is gzipped. \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:47:59:  1000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:03:  2000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:07:  3000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:11:  4000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:15:  5000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:19:  6000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:23:  7000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:27:  8000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:31:  9000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:36:  10000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:40:  11000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:44:  12000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:48:  13000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:52:  14000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:48:56:  15000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:01:  16000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:05:  17000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:09:  18000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:13:  19000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:17:  20000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:21:  21000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:25:  22000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:29:  23000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:34:  24000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:38:  25000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:42:  26000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:46:  27000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:50:  28000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:51: #1 tag size is determined as 36 bps \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:51: #1 tag size = 36 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:51: #1  total tags in treatment: 34566557 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:51: #1 user defined the maximum tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:51: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:52: #1  tags after filtering in treatment: 29951934 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:52: #1  Redundant rate of treatment: 0.13 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:52: #1  total tags in control: 27738838 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:52: #1 user defined the maximum tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:52: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:53: #1  tags after filtering in control: 24665059 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:53: #1  Redundant rate of control: 0.11 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:53: #1 finished! \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:53: #2 Build Peak Model... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:53: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #2 number of paired peaks: 1459 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: start model_add_line... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: start X-correlation... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: end of X-cor \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #2 finished! \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #2 predicted fragment length is 46 bps \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #2 alternative fragment length(s) may be 46 bps \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #2.2 Generate R script for model : macs2_ShTet1_poging2/Tet1_poging2_model.r \r\n",
      "WARNING @ Sun, 29 Jan 2017 18:49:56: #2 Since the d (46) calculated from paired-peaks are smaller than 2*tag length, it may be influenced by unknown sequencing problem! \r\n",
      "WARNING @ Sun, 29 Jan 2017 18:49:56: #2 You may need to consider one of the other alternative d(s): 46 \r\n",
      "WARNING @ Sun, 29 Jan 2017 18:49:56: #2 You can restart the process with --nomodel --extsize XXX with your choice or an arbitrary number. Nontheless, MACS will continute computing. \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #3 Call peaks... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:49:56: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:51:58: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:53:04: #4 Write output xls file... macs2_ShTet1_poging2/Tet1_poging2_peaks.xls \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:53:04: #4 Write peak in narrowPeak format file... macs2_ShTet1_poging2/Tet1_poging2_peaks.narrowPeak \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:53:04: #4 Write summits bed file... macs2_ShTet1_poging2/Tet1_poging2_summits.bed \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:53:05: Done! \r\n"
     ]
    }
   ],
   "source": [
    "# Peakcalling Tet1 knockdown.\n",
    "mkdir macs2_Tet1_poging2\n",
    "macs2 callpeak -t Tet1-N-ShTet1.sorted.bam -c IgG_Chip.sorted.bam --outdir macs2_ShTet1_poging2 -n Tet1_poging2 -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tet1_poging2_model.r\t       Tet1_poging2_peaks.xls\r\n",
      "Tet1_poging2_peaks.narrowPeak  Tet1_poging2_summits.bed\r\n"
     ]
    }
   ],
   "source": [
    "ls macs2_ShTet1_poging2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "314\r\n"
     ]
    }
   ],
   "source": [
    "cat macs2_ShTet1_poging2/Tet1_poging2_summits.bed | wc -l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The sorted bam-file of the Tet-knockdown was used as input, the bamfile of the normal embryonic stem cell was used as control. We performed this command over the whole mouse genome with FDR<0.01 (like the article). This results in 314 peaks for the Tet1 knockdown and 37518 peaks for the Tet1 wildtype. The narrowpeak and the bed files were analysed in IGV.\n",
    "\n",
    "In the paper, they used the MEDIPS tool to call peaks. This tool is specially designed for methylation (epigenetics) data. However, we were not able to install the MEDIPS package so we could not compare the MACS2 results with the MEDIPS results."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO  @ Sun, 29 Jan 2017 18:57:52: \r\n",
      "# Command line: callpeak -t Tet1-N-shScr.sorted.bam -c IgG_Chip.sorted.bam --outdir macs2_Tet1-N-ShScr -n Tet1_2_poging2 -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = Tet1_2_poging2\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['Tet1-N-shScr.sorted.bam']\r\n",
      "# control file = ['IgG_Chip.sorted.bam']\r\n",
      "# effective genome size = 1.87e+09\r\n",
      "# band width = 300\r\n",
      "# model fold = [5, 50]\r\n",
      "# qvalue cutoff = 1.00e-02\r\n",
      "# Larger dataset will be scaled towards smaller dataset.\r\n",
      "# Range for calculating regional lambda is: 1000 bps and 10000 bps\r\n",
      "# Broad region calling is off\r\n",
      " \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:57:52: #1 read tag files... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:57:52: #1 read treatment tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:57:52: Detected format is: BAM \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:57:52: * Input file is gzipped. \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:57:57:  1000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:02:  2000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:06:  3000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:10:  4000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:15:  5000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:19:  6000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:24:  7000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:28:  8000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:31:  9000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:35:  10000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:38:  11000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:42:  12000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:46:  13000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:50:  14000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:54:  15000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:58:59:  16000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:04:  17000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:08:  18000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:12:  19000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:17:  20000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:21:  21000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:26:  22000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:30:  23000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:35:  24000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:39:  25000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:43:  26000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:47:  27000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:51:  28000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:55:  29000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 18:59:59:  30000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:04:  31000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:08:  32000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:13:  33000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:15:  34000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:16: #1.2 read input tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:16: Detected format is: BAM \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:16: * Input file is gzipped. \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:21:  1000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:25:  2000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:29:  3000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:33:  4000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:37:  5000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:42:  6000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:46:  7000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:50:  8000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:54:  9000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:00:59:  10000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:03:  11000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:07:  12000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:12:  13000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:16:  14000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:20:  15000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:24:  16000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:29:  17000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:33:  18000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:37:  19000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:41:  20000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:44:  21000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:47:  22000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:51:  23000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:54:  24000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:01:57:  25000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:01:  26000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:04:  27000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:07:  28000000 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 tag size is determined as 36 bps \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 tag size = 36 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1  total tags in treatment: 33060912 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 user defined the maximum tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1  tags after filtering in treatment: 29132495 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1  Redundant rate of treatment: 0.12 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1  total tags in control: 27738838 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 user defined the maximum tags... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1  tags after filtering in control: 24665059 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1  Redundant rate of control: 0.11 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #1 finished! \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #2 Build Peak Model... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:09: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:12: #2 number of paired peaks: 20195 \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:12: start model_add_line... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: start X-correlation... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: end of X-cor \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: #2 finished! \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: #2 predicted fragment length is 143 bps \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: #2 alternative fragment length(s) may be 143 bps \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: #2.2 Generate R script for model : macs2_Tet1-N-ShScr/Tet1_2_poging2_model.r \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: #3 Call peaks... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:02:13: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:04:21: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:05:32: #4 Write output xls file... macs2_Tet1-N-ShScr/Tet1_2_poging2_peaks.xls \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:05:32: #4 Write peak in narrowPeak format file... macs2_Tet1-N-ShScr/Tet1_2_poging2_peaks.narrowPeak \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:05:33: #4 Write summits bed file... macs2_Tet1-N-ShScr/Tet1_2_poging2_summits.bed \r\n",
      "INFO  @ Sun, 29 Jan 2017 19:05:33: Done! \r\n"
     ]
    }
   ],
   "source": [
    "# Peakcalling wildtype Tet1.\n",
    "mkdir macs2_Tet1_2_poging2\n",
    "macs2 callpeak -t Tet1-N-shScr.sorted.bam -c IgG_Chip.sorted.bam --outdir macs2_Tet1-N-ShScr -n Tet1_2_poging2 -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "37518\r\n"
     ]
    }
   ],
   "source": [
    "cat macs2_Tet1-N-ShScr/Tet1_2_poging2_summits.bed | wc -l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We took a look at the narrowpeak files in IGV:\n",
    "\n",
    "The upper track is the Tet1 wildtype and the lower track is the Tet1 knockdown. The printscreens show that there are only peaks in the Tet1 wildtype cells and that these peaks are located in the TSS regions of the Ttc9, Ssbp2 and Sema6 genes."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0368030/files/Peak_ttc9.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/Peak_ssbp2.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0368030/files/Peak_sema6.jpg\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38532\r\n"
     ]
    }
   ],
   "source": [
    "cat macs2_Tet1-N-ShTet1/Tet1_2_2_summits.bed | wc -l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Motif analysis using RSAT.\n",
    "\n",
    "Since we did not find the bindingmotif of Tet1 in literature, we assumed that it is not known yet. Therefore, we chose to use RSAT instead of icis-target to determine the bindingmotif of Tet1. First, the fastasequences of the peaks were requested in UCSC. These sequences were then uploaded in RSAT, which resulted in 13 motifs including the one that is depicted below. \n",
    "<img width=\"75%\" src=\"/user/r0368030/files/Rsat.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, we used GREAT to link the peaks to genes. These graphs illustrate that Tet1 mostly binds to the transcription start sites of genes, as was shown in the paper. Gene Ontology (in GREAT) showed that most of the target genes of Tet1 have a function that is related to the mitochondrial energy production. In the paper, Gene Ontology showed that Ter1 target genes are involved in a variety of basic cellular processes, but no more details are given.\n",
    "\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/GREAT.png\">\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/GeneOntology.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The second hypothesis that was tested in the article was if Tet1 associates with the SIN3A complex. The Microarray data showed that Tet1 contributes to transcriptional repression and know they wanted to know the mechanism of the repression. The purification of protein associated with double-epitope Flag-haemagglutinin-tagged Tet1 resulted in the identification of SIN3A and other components of the SIN3A co-repressor complex. It has already been shown that this repressor complex contributes to transcriptional repression by mediating histone deacetylation. In the paper, they performed ChIP-seq analysis to investigate if SIN3A and Tet1 colocalize on target genes using two different antibodies directed against SIN3A. We only analysed the ChIP-seq data from one antibody (Santa Cruz).\n",
    "\n",
    "We first aligned the fastqfile of SIN3A-ChIP-seq data with the mm9 genome, which resulted in an alignment rate of 81.84%."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21672699 reads; of these:\r\n",
      "  21672699 (100.00%) were unpaired; of these:\r\n",
      "    3934818 (18.16%) aligned 0 times\r\n",
      "    12693630 (58.57%) aligned exactly 1 time\r\n",
      "    5044251 (23.27%) aligned >1 times\r\n",
      "81.84% overall alignment rate\r\n"
     ]
    }
   ],
   "source": [
    "bowtie2-align -x /mnt/storage/r0368030/groepswerk/mm9/mm9 SIN3A_Scruz.fastq -S SIN3A.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools view -S -b SIN3A.sam > SIN3A.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 6 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -O bam -o SIN3A.sorted.bam SIN3A.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index SIN3A.sorted.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we created bam and bai files, which were visualized in IGV together with the bam files of Tet1. Again, we looked at the same genes that are discussed in the paper and found that the peaks of SIN3A and Tet1 overlap, meaning that they have the same target genes."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"75%\" src=\"/user/r0368030/files/SIN3A_TET1_sema6a.jpg\">\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/SIN3A_TET1_Ttc9.jpg\">\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/SIN3A_TET1_ssbp2.jpg\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO  @ Wed, 11 Jan 2017 16:21:14: \r\n",
      "# Command line: callpeak -t SIN3A.sorted.bam --outdir macs2_SIN3A -n SIN3A -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = SIN3A\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['SIN3A.sorted.bam']\r\n",
      "# control file = None\r\n",
      "# effective genome size = 1.87e+09\r\n",
      "# band width = 300\r\n",
      "# model fold = [5, 50]\r\n",
      "# qvalue cutoff = 1.00e-02\r\n",
      "# Larger dataset will be scaled towards smaller dataset.\r\n",
      "# Range for calculating regional lambda is: 10000 bps\r\n",
      "# Broad region calling is off\r\n",
      " \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:14: #1 read tag files... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:14: #1 read treatment tags... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:14: Detected format is: BAM \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:14: * Input file is gzipped. \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:18:  1000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:21:  2000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:24:  3000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:28:  4000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:31:  5000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:34:  6000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:38:  7000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:41:  8000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:44:  9000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:48:  10000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:51:  11000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:54:  12000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:21:58:  13000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:01:  14000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:05:  15000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:08:  16000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:11:  17000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:14:  18000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:16:  19000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:18:  20000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:19:  21000000 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:20: #1 tag size is determined as 36 bps \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:20: #1 tag size = 36 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:20: #1  total tags in treatment: 17737881 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:20: #1 user defined the maximum tags... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:20: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:21: #1  tags after filtering in treatment: 15875371 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:21: #1  Redundant rate of treatment: 0.11 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:21: #1 finished! \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:21: #2 Build Peak Model... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:21: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:22: #2 number of paired peaks: 11244 \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:22: start model_add_line... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: start X-correlation... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: end of X-cor \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: #2 finished! \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: #2 predicted fragment length is 59 bps \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: #2 alternative fragment length(s) may be 59 bps \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: #2.2 Generate R script for model : macs2_SIN3A/SIN3A_model.r \r\n",
      "WARNING @ Wed, 11 Jan 2017 16:22:23: #2 Since the d (59) calculated from paired-peaks are smaller than 2*tag length, it may be influenced by unknown sequencing problem! \r\n",
      "WARNING @ Wed, 11 Jan 2017 16:22:23: #2 You may need to consider one of the other alternative d(s): 59 \r\n",
      "WARNING @ Wed, 11 Jan 2017 16:22:23: #2 You can restart the process with --nomodel --extsize XXX with your choice or an arbitrary number. Nontheless, MACS will continute computing. \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: #3 Call peaks... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:23: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:22:50: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:23:07: #4 Write output xls file... macs2_SIN3A/SIN3A_peaks.xls \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:23:07: #4 Write peak in narrowPeak format file... macs2_SIN3A/SIN3A_peaks.narrowPeak \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:23:07: #4 Write summits bed file... macs2_SIN3A/SIN3A_summits.bed \r\n",
      "INFO  @ Wed, 11 Jan 2017 16:23:07: Done! \r\n"
     ]
    }
   ],
   "source": [
    "# Peak calling SIN3A (without control) resulted in 9268 peaks.\n",
    "mkdir macs2_SIN3A\n",
    "macs2 callpeak -t SIN3A.sorted.bam --outdir macs2_SIN3A -n SIN3A -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9268\r\n"
     ]
    }
   ],
   "source": [
    "cat macs2_SIN3A/SIN3A_summits.bed | wc -l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The narrowpeak files of SIN3A and Tet1 were uploaded in IGV. This showed that the peaks of SIN3A and Tet1 overlap at het TSS of Ttc9, Ssbp2 and Sema6.\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/Peak_SIN3A_ttc9.jpg\">\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/Peak_SIN3A_ssbp2.jpg\">\n",
    "<img width=\"75%\" src=\"/user/r0368030/files/Peak_SIN3A_sema6.jpg\">"
   ]
  }
 ],
 "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
}
