{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bioinformatics and Systems Biology: Expression, Regulation and Networks - Exam project\n",
    "\n",
    "By Anouk Vinckier\n",
    "Louis Desmet\n",
    "Robbe Naert"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The correct formation of heart valves during embryonic development is critical for normal functioning of the heart. Abnormally formed heart valves are responsible for 1/3 of cardiovascular birth defects and valve defects are correlated with an increased disease susceptibility. \n",
    "\n",
    "Heart valves develop at two locations in the embryonic heart. The first location is between the atria and ventricles also known as the atrioventricular canal (AVC) where the mitral and tricuspud valves are formed. The second location is at the base of the aorta and pulmonary trunk also known as the outflow tract (OFT) where the aortic and pulmonary valves are formed. During heart valve development endothelial cells transform into mesenchymal cells and move to the cardiac cushions. Here these mesenchymal cells proliferate and differentate to eventually form valve leaflets.\n",
    "\n",
    "Sox9 is highly expressed in the mesenchyme of these cardiac cushions. The essential role of sox9 in valve development in mice has been shown by several research groups. The loss of sox9 interferes with normal valve development and is embryonically lethal. In humans, several sox9 mutations have been described resulting in a condition called campomelic dysplasia. This disease is characterized by skeletal abnormalties, sex reversal and multiple organ defects such as defects in the pancreas and heart. \n",
    "\n",
    "Sox9 is also highly expressed in cartilage containing tissues such as the limb that differentiates from sox9-positive mesenchyme. Loss of sox9 leads to loss of bone formation in this case. \n",
    "Despite the importance of sox9 in valve development, not much is known about its transcription targets or action mechanism. To study this, reseachers have combined ChIP-Seq with RNA-seq to determine DNA-binding sites in mouse embryonic AVC and limb. Moreover they also determined which genes in the embryonic heart are affected by knocking-out sox9 via RNA-seq.\n",
    "\n",
    "We will first use the RNA sequencing data provided to see which genes are down - and upregulated in the AVC when sox9 is knocked out in the heart. Then we will also use the provided ChIP sequencing data to try to determine binding targets for sox9 in the heart and limb.\n",
    "\n",
    "Article used: https://www.ncbi.nlm.nih.gov/pubmed/26525672\n",
    "\n",
    "Dataset used: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE73225\n",
    "\n",
    "All the commands and data were performed under the account of Robbe Naert (r0305394)\n",
    "\n",
    "Path to the original notebook: /mnt/storage/r0305394/jupyternotebooks/groepswerk/Exam_project_SOX9.ipynb\n",
    "\n",
    "Path to the R notebook: /mnt/storage/r0305394/jupyternotebooks/groepswerk/Exam_project_SOX9_R.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RNA sequencing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We first made a folder (data) to store the sra files in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/Groepwerk\r\n"
     ]
    }
   ],
   "source": [
    "pwd\n",
    "cd /mnt/storage/r0305394/jupyternotebooks/Groepwerk\n",
    "mkdir -p /mnt/storage/r0305394/jupyternotebooks/Groepwerk/data\n",
    "cd /mnt/storage/r0305394/jupyternotebooks/Groepwerk/data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Following command was used to convert the sra files into fastaq files. This generates two fastq files per SRA files since these were paired-end reads. The commands are shown below. This wasn't performed in jupyter but in the terminal because it took some time and in this way we could detach the process. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "fastq-dump --split-files SRR2479801\n",
    "fastq-dump --split-files SRR2479802\n",
    "fastq-dump --split-files SRR2479803\n",
    "fastq-dump --split-files SRR2479804\n",
    "fastq-dump --split-files SRR2479805\n",
    "fastq-dump --split-files SRR2479806\n",
    "fastq-dump --split-files SRR2479807\n",
    "fastq-dump --split-files SRR2479808\t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then we made a new folder to store the results obtained from the RNA-sequencing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk\n",
    "pwd\n",
    "mkdir -p /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also made a new folder to store all the output from the quality control of the fastq files generated earlier (this folder was later removed because there were storage problems). \n",
    "\n",
    "Then we performed quality control on all the fastq files. In class we have seen that the three most important parameters during quality analysis are: per base sequence quality, sequence duplication levels and overrepresented sequences."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "mkdir -p /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479801_1.fastq\r\n",
      "Approx 5% complete for SRR2479801_1.fastq\r\n",
      "Approx 10% complete for SRR2479801_1.fastq\r\n",
      "Approx 15% complete for SRR2479801_1.fastq\r\n",
      "Approx 20% complete for SRR2479801_1.fastq\r\n",
      "Approx 25% complete for SRR2479801_1.fastq\r\n",
      "Approx 30% complete for SRR2479801_1.fastq\r\n",
      "Approx 35% complete for SRR2479801_1.fastq\r\n",
      "Approx 40% complete for SRR2479801_1.fastq\r\n",
      "Approx 45% complete for SRR2479801_1.fastq\r\n",
      "Approx 50% complete for SRR2479801_1.fastq\r\n",
      "Approx 55% complete for SRR2479801_1.fastq\r\n",
      "Approx 60% complete for SRR2479801_1.fastq\r\n",
      "Approx 65% complete for SRR2479801_1.fastq\r\n",
      "Approx 70% complete for SRR2479801_1.fastq\r\n",
      "Approx 75% complete for SRR2479801_1.fastq\r\n",
      "Approx 80% complete for SRR2479801_1.fastq\r\n",
      "Approx 85% complete for SRR2479801_1.fastq\r\n",
      "Approx 90% complete for SRR2479801_1.fastq\r\n",
      "Approx 95% complete for SRR2479801_1.fastq\r\n",
      "Analysis complete for SRR2479801_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479801_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The overall quality of the reads seems to be good. The per base sequence quality is good although there is warning for sequence duplication levels and overrepresented sequences. There is a warning for the sequence duplication levels. This warning is generated when non-unique sequences make up for more than 20% of the total number of sequences. In this case the percentage of sequences that remain after removing duplicates is 62,56%. The sequence duplication levels are most likely the result of oversequencing to be able to detect lowly expressed transcripts. There is also a warning for overrepresented sequences. This warning is triggered when a sequence is found that represent more than 0.1% of the total amount of sequences. These overrepresented sequences are either very important for biological functioning or are caused by contamination. We blasted all the overrepresented sequences. All of them led us to practically the same results (shown under the fastq quality output). The blast result seems to indicate that this overrepresented sequence is human or rat contamination. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479801_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/BLAST.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479801_2.fastq\r\n",
      "Approx 5% complete for SRR2479801_2.fastq\r\n",
      "Approx 10% complete for SRR2479801_2.fastq\r\n",
      "Approx 15% complete for SRR2479801_2.fastq\r\n",
      "Approx 20% complete for SRR2479801_2.fastq\r\n",
      "Approx 25% complete for SRR2479801_2.fastq\r\n",
      "Approx 30% complete for SRR2479801_2.fastq\r\n",
      "Approx 35% complete for SRR2479801_2.fastq\r\n",
      "Approx 40% complete for SRR2479801_2.fastq\r\n",
      "Approx 45% complete for SRR2479801_2.fastq\r\n",
      "Approx 50% complete for SRR2479801_2.fastq\r\n",
      "Approx 55% complete for SRR2479801_2.fastq\r\n",
      "Approx 60% complete for SRR2479801_2.fastq\r\n",
      "Approx 65% complete for SRR2479801_2.fastq\r\n",
      "Approx 70% complete for SRR2479801_2.fastq\r\n",
      "Approx 75% complete for SRR2479801_2.fastq\r\n",
      "Approx 80% complete for SRR2479801_2.fastq\r\n",
      "Approx 85% complete for SRR2479801_2.fastq\r\n",
      "Approx 90% complete for SRR2479801_2.fastq\r\n",
      "Approx 95% complete for SRR2479801_2.fastq\r\n",
      "Analysis complete for SRR2479801_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479801_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality is ok but there are two warnings again concerning the duplication levels and overrepresented sequences. In this case the percentage of sequences that remain after removing duplicates is 62.2%. The sequence duplication levels are most likely the result of oversequencing to be able to detect lowly expressed transcripts. Several overrepresented sequences were detected. We blasted these sequences and all of them lead us to practically the same results (shown under the fastq quality output). BLAST output also seem to point to human or rat contamination as in the previous fastq file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479801_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/BLAST2.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479802_1.fastq\r\n",
      "Approx 5% complete for SRR2479802_1.fastq\r\n",
      "Approx 10% complete for SRR2479802_1.fastq\r\n",
      "Approx 15% complete for SRR2479802_1.fastq\r\n",
      "Approx 20% complete for SRR2479802_1.fastq\r\n",
      "Approx 25% complete for SRR2479802_1.fastq\r\n",
      "Approx 30% complete for SRR2479802_1.fastq\r\n",
      "Approx 35% complete for SRR2479802_1.fastq\r\n",
      "Approx 40% complete for SRR2479802_1.fastq\r\n",
      "Approx 45% complete for SRR2479802_1.fastq\r\n",
      "Approx 50% complete for SRR2479802_1.fastq\r\n",
      "Approx 55% complete for SRR2479802_1.fastq\r\n",
      "Approx 60% complete for SRR2479802_1.fastq\r\n",
      "Approx 65% complete for SRR2479802_1.fastq\r\n",
      "Approx 70% complete for SRR2479802_1.fastq\r\n",
      "Approx 75% complete for SRR2479802_1.fastq\r\n",
      "Approx 80% complete for SRR2479802_1.fastq\r\n",
      "Approx 85% complete for SRR2479802_1.fastq\r\n",
      "Approx 90% complete for SRR2479802_1.fastq\r\n",
      "Approx 95% complete for SRR2479802_1.fastq\r\n",
      "Analysis complete for SRR2479802_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479802_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and duplication levels are both good. There is warning about overrepresented sequences. One of sequences was an adapter. Ideally we would trim the reads to remove the adapter and re-run the fastq quality control again. But since in this case the overrepresented sequence was less then 0.9% and because we didn't want to risks trimming to much, we decided not to do this. There was another overrepresented sequence with no hit which we blasted. BLAST was unable to match this sequence."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479802_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479802_2.fastq\r\n",
      "Approx 5% complete for SRR2479802_2.fastq\r\n",
      "Approx 10% complete for SRR2479802_2.fastq\r\n",
      "Approx 15% complete for SRR2479802_2.fastq\r\n",
      "Approx 20% complete for SRR2479802_2.fastq\r\n",
      "Approx 25% complete for SRR2479802_2.fastq\r\n",
      "Approx 30% complete for SRR2479802_2.fastq\r\n",
      "Approx 35% complete for SRR2479802_2.fastq\r\n",
      "Approx 40% complete for SRR2479802_2.fastq\r\n",
      "Approx 45% complete for SRR2479802_2.fastq\r\n",
      "Approx 50% complete for SRR2479802_2.fastq\r\n",
      "Approx 55% complete for SRR2479802_2.fastq\r\n",
      "Approx 60% complete for SRR2479802_2.fastq\r\n",
      "Approx 65% complete for SRR2479802_2.fastq\r\n",
      "Approx 70% complete for SRR2479802_2.fastq\r\n",
      "Approx 75% complete for SRR2479802_2.fastq\r\n",
      "Approx 80% complete for SRR2479802_2.fastq\r\n",
      "Approx 85% complete for SRR2479802_2.fastq\r\n",
      "Approx 90% complete for SRR2479802_2.fastq\r\n",
      "Approx 95% complete for SRR2479802_2.fastq\r\n",
      "Analysis complete for SRR2479802_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479802_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see below, this fastq file has a fail for per base sequence quality. This module gives a fail when the lower quartile for any base is less than 5 or if the median for any base is less than 20. In our case the fail was generated because the median of the last base was lower then 20. We believe that is caused because the reads have different lengths leading to a lower coverage for this base position. We then checked the sequence length distribution graph. As you can see there are quite some sequence that have only 74 and 75 reads. This leads to a lower converage of the 76th base location leading to the drop in quality. Therefore we believe it is not necessary to trim this last base location. There is also a warning concerning overrepresented sequences. There was one overrepresented sequence with no hit. We blasted this sequence but this also gave us no hit."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479802_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/Sequence_length_SRR2479802_2_fastqc.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479803_1.fastq\r\n",
      "Approx 5% complete for SRR2479803_1.fastq\r\n",
      "Approx 10% complete for SRR2479803_1.fastq\r\n",
      "Approx 15% complete for SRR2479803_1.fastq\r\n",
      "Approx 20% complete for SRR2479803_1.fastq\r\n",
      "Approx 25% complete for SRR2479803_1.fastq\r\n",
      "Approx 30% complete for SRR2479803_1.fastq\r\n",
      "Approx 35% complete for SRR2479803_1.fastq\r\n",
      "Approx 40% complete for SRR2479803_1.fastq\r\n",
      "Approx 45% complete for SRR2479803_1.fastq\r\n",
      "Approx 50% complete for SRR2479803_1.fastq\r\n",
      "Approx 55% complete for SRR2479803_1.fastq\r\n",
      "Approx 60% complete for SRR2479803_1.fastq\r\n",
      "Approx 65% complete for SRR2479803_1.fastq\r\n",
      "Approx 70% complete for SRR2479803_1.fastq\r\n",
      "Approx 75% complete for SRR2479803_1.fastq\r\n",
      "Approx 80% complete for SRR2479803_1.fastq\r\n",
      "Approx 85% complete for SRR2479803_1.fastq\r\n",
      "Approx 90% complete for SRR2479803_1.fastq\r\n",
      "Approx 95% complete for SRR2479803_1.fastq\r\n",
      "Analysis complete for SRR2479803_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479803_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and sequence duplication levels are good. There is a warning about the overrepresented sequences. One of them was an adapter and accounted for less then 0.9% of the total. We decided not to trim this because we didn't want to risk overtrimming. There was another overrepresented sequence with no hit. We blasted this sequence but we found no hit. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479803_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479803_2.fastq\r\n",
      "Approx 5% complete for SRR2479803_2.fastq\r\n",
      "Approx 10% complete for SRR2479803_2.fastq\r\n",
      "Approx 15% complete for SRR2479803_2.fastq\r\n",
      "Approx 20% complete for SRR2479803_2.fastq\r\n",
      "Approx 25% complete for SRR2479803_2.fastq\r\n",
      "Approx 30% complete for SRR2479803_2.fastq\r\n",
      "Approx 35% complete for SRR2479803_2.fastq\r\n",
      "Approx 40% complete for SRR2479803_2.fastq\r\n",
      "Approx 45% complete for SRR2479803_2.fastq\r\n",
      "Approx 50% complete for SRR2479803_2.fastq\r\n",
      "Approx 55% complete for SRR2479803_2.fastq\r\n",
      "Approx 60% complete for SRR2479803_2.fastq\r\n",
      "Approx 65% complete for SRR2479803_2.fastq\r\n",
      "Approx 70% complete for SRR2479803_2.fastq\r\n",
      "Approx 75% complete for SRR2479803_2.fastq\r\n",
      "Approx 80% complete for SRR2479803_2.fastq\r\n",
      "Approx 85% complete for SRR2479803_2.fastq\r\n",
      "Approx 90% complete for SRR2479803_2.fastq\r\n",
      "Approx 95% complete for SRR2479803_2.fastq\r\n",
      "Analysis complete for SRR2479803_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479803_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and duplication levels look fine. But again we get a warning for overrepresented sequences. This overrepresented sequence had no hit so we decided to blast the sequence. BLAST was also unable to find a hit for the overrepresented sequence."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479803_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479804_1.fastq\r\n",
      "Approx 5% complete for SRR2479804_1.fastq\r\n",
      "Approx 10% complete for SRR2479804_1.fastq\r\n",
      "Approx 15% complete for SRR2479804_1.fastq\r\n",
      "Approx 20% complete for SRR2479804_1.fastq\r\n",
      "Approx 25% complete for SRR2479804_1.fastq\r\n",
      "Approx 30% complete for SRR2479804_1.fastq\r\n",
      "Approx 35% complete for SRR2479804_1.fastq\r\n",
      "Approx 40% complete for SRR2479804_1.fastq\r\n",
      "Approx 45% complete for SRR2479804_1.fastq\r\n",
      "Approx 50% complete for SRR2479804_1.fastq\r\n",
      "Approx 55% complete for SRR2479804_1.fastq\r\n",
      "Approx 60% complete for SRR2479804_1.fastq\r\n",
      "Approx 65% complete for SRR2479804_1.fastq\r\n",
      "Approx 70% complete for SRR2479804_1.fastq\r\n",
      "Approx 75% complete for SRR2479804_1.fastq\r\n",
      "Approx 80% complete for SRR2479804_1.fastq\r\n",
      "Approx 85% complete for SRR2479804_1.fastq\r\n",
      "Approx 90% complete for SRR2479804_1.fastq\r\n",
      "Approx 95% complete for SRR2479804_1.fastq\r\n",
      "Analysis complete for SRR2479804_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479804_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and sequence duplication levels are good. But this time there is also a warning for overrepresented sequences. One of the overrepresented sequences is an adaptor which represent less than 0.8% of the total sequences. We didn't trim this because of reasons mentioned earlier (only 0.8% and fear of overtrimming). The other overrepresented sequence had no hit. We blasted this sequence and also found no hits."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479804_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479804_2.fastq\r\n",
      "Approx 5% complete for SRR2479804_2.fastq\r\n",
      "Approx 10% complete for SRR2479804_2.fastq\r\n",
      "Approx 15% complete for SRR2479804_2.fastq\r\n",
      "Approx 20% complete for SRR2479804_2.fastq\r\n",
      "Approx 25% complete for SRR2479804_2.fastq\r\n",
      "Approx 30% complete for SRR2479804_2.fastq\r\n",
      "Approx 35% complete for SRR2479804_2.fastq\r\n",
      "Approx 40% complete for SRR2479804_2.fastq\r\n",
      "Approx 45% complete for SRR2479804_2.fastq\r\n",
      "Approx 50% complete for SRR2479804_2.fastq\r\n",
      "Approx 55% complete for SRR2479804_2.fastq\r\n",
      "Approx 60% complete for SRR2479804_2.fastq\r\n",
      "Approx 65% complete for SRR2479804_2.fastq\r\n",
      "Approx 70% complete for SRR2479804_2.fastq\r\n",
      "Approx 75% complete for SRR2479804_2.fastq\r\n",
      "Approx 80% complete for SRR2479804_2.fastq\r\n",
      "Approx 85% complete for SRR2479804_2.fastq\r\n",
      "Approx 90% complete for SRR2479804_2.fastq\r\n",
      "Approx 95% complete for SRR2479804_2.fastq\r\n",
      "Analysis complete for SRR2479804_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479804_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and duplication levels are okay. There is a warning concerning overrepresented sequences. This overrepresented sequence had no hit so we blasted the sequence. Blast was unable to find any hits."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479804_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479805_1.fastq\r\n",
      "Approx 5% complete for SRR2479805_1.fastq\r\n",
      "Approx 10% complete for SRR2479805_1.fastq\r\n",
      "Approx 15% complete for SRR2479805_1.fastq\r\n",
      "Approx 20% complete for SRR2479805_1.fastq\r\n",
      "Approx 25% complete for SRR2479805_1.fastq\r\n",
      "Approx 30% complete for SRR2479805_1.fastq\r\n",
      "Approx 35% complete for SRR2479805_1.fastq\r\n",
      "Approx 40% complete for SRR2479805_1.fastq\r\n",
      "Approx 45% complete for SRR2479805_1.fastq\r\n",
      "Approx 50% complete for SRR2479805_1.fastq\r\n",
      "Approx 55% complete for SRR2479805_1.fastq\r\n",
      "Approx 60% complete for SRR2479805_1.fastq\r\n",
      "Approx 65% complete for SRR2479805_1.fastq\r\n",
      "Approx 70% complete for SRR2479805_1.fastq\r\n",
      "Approx 75% complete for SRR2479805_1.fastq\r\n",
      "Approx 80% complete for SRR2479805_1.fastq\r\n",
      "Approx 85% complete for SRR2479805_1.fastq\r\n",
      "Approx 90% complete for SRR2479805_1.fastq\r\n",
      "Approx 95% complete for SRR2479805_1.fastq\r\n",
      "Analysis complete for SRR2479805_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479805_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality is good but there are warnings about the duplication levels and overrepresented sequences. In this case the percentage of sequences that remain after removing duplicates is 58.09%. The sequence duplication levels are most likely the result of oversequencing to be able to detect lowly expressed transcripts. There are also several overrepresented sequences without hit. We blasted these sequences and it possible that there is contamination from human, rat or wolf."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479805_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/BLAST9.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479805_2.fastq\r\n",
      "Approx 5% complete for SRR2479805_2.fastq\r\n",
      "Approx 10% complete for SRR2479805_2.fastq\r\n",
      "Approx 15% complete for SRR2479805_2.fastq\r\n",
      "Approx 20% complete for SRR2479805_2.fastq\r\n",
      "Approx 25% complete for SRR2479805_2.fastq\r\n",
      "Approx 30% complete for SRR2479805_2.fastq\r\n",
      "Approx 35% complete for SRR2479805_2.fastq\r\n",
      "Approx 40% complete for SRR2479805_2.fastq\r\n",
      "Approx 45% complete for SRR2479805_2.fastq\r\n",
      "Approx 50% complete for SRR2479805_2.fastq\r\n",
      "Approx 55% complete for SRR2479805_2.fastq\r\n",
      "Approx 60% complete for SRR2479805_2.fastq\r\n",
      "Approx 65% complete for SRR2479805_2.fastq\r\n",
      "Approx 70% complete for SRR2479805_2.fastq\r\n",
      "Approx 75% complete for SRR2479805_2.fastq\r\n",
      "Approx 80% complete for SRR2479805_2.fastq\r\n",
      "Approx 85% complete for SRR2479805_2.fastq\r\n",
      "Approx 90% complete for SRR2479805_2.fastq\r\n",
      "Approx 95% complete for SRR2479805_2.fastq\r\n",
      "Analysis complete for SRR2479805_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479805_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality is good but there are issues with the duplication levels and overrepresented sequences. In this case the percentage of sequences that remained after removing duplicates is 59.33%. The sequence duplication levels are most likely the result of oversequencing to be able to detect lowly expressed transcripts. There were several overrepresented sequences with no hit. We therefore blasted these sequences and found evidence pointing to contamination with human, rat or wolf."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479805_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/BLAST10.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479806_1.fastq\r\n",
      "Approx 5% complete for SRR2479806_1.fastq\r\n",
      "Approx 10% complete for SRR2479806_1.fastq\r\n",
      "Approx 15% complete for SRR2479806_1.fastq\r\n",
      "Approx 20% complete for SRR2479806_1.fastq\r\n",
      "Approx 25% complete for SRR2479806_1.fastq\r\n",
      "Approx 30% complete for SRR2479806_1.fastq\r\n",
      "Approx 35% complete for SRR2479806_1.fastq\r\n",
      "Approx 40% complete for SRR2479806_1.fastq\r\n",
      "Approx 45% complete for SRR2479806_1.fastq\r\n",
      "Approx 50% complete for SRR2479806_1.fastq\r\n",
      "Approx 55% complete for SRR2479806_1.fastq\r\n",
      "Approx 60% complete for SRR2479806_1.fastq\r\n",
      "Approx 65% complete for SRR2479806_1.fastq\r\n",
      "Approx 70% complete for SRR2479806_1.fastq\r\n",
      "Approx 75% complete for SRR2479806_1.fastq\r\n",
      "Approx 80% complete for SRR2479806_1.fastq\r\n",
      "Approx 85% complete for SRR2479806_1.fastq\r\n",
      "Approx 90% complete for SRR2479806_1.fastq\r\n",
      "Approx 95% complete for SRR2479806_1.fastq\r\n",
      "Analysis complete for SRR2479806_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479806_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and duplication levels good. But now we have a failure in the overrepresented sequences because there is an overrepresented sequence that represent more than 1% of the total sequences. This overrepresented sequence is an adaptor and we decide not to trim this because we didn't want to risk overtrimming."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479806_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479806_2.fastq\r\n",
      "Approx 5% complete for SRR2479806_2.fastq\r\n",
      "Approx 10% complete for SRR2479806_2.fastq\r\n",
      "Approx 15% complete for SRR2479806_2.fastq\r\n",
      "Approx 20% complete for SRR2479806_2.fastq\r\n",
      "Approx 25% complete for SRR2479806_2.fastq\r\n",
      "Approx 30% complete for SRR2479806_2.fastq\r\n",
      "Approx 35% complete for SRR2479806_2.fastq\r\n",
      "Approx 40% complete for SRR2479806_2.fastq\r\n",
      "Approx 45% complete for SRR2479806_2.fastq\r\n",
      "Approx 50% complete for SRR2479806_2.fastq\r\n",
      "Approx 55% complete for SRR2479806_2.fastq\r\n",
      "Approx 60% complete for SRR2479806_2.fastq\r\n",
      "Approx 65% complete for SRR2479806_2.fastq\r\n",
      "Approx 70% complete for SRR2479806_2.fastq\r\n",
      "Approx 75% complete for SRR2479806_2.fastq\r\n",
      "Approx 80% complete for SRR2479806_2.fastq\r\n",
      "Approx 85% complete for SRR2479806_2.fastq\r\n",
      "Approx 90% complete for SRR2479806_2.fastq\r\n",
      "Approx 95% complete for SRR2479806_2.fastq\r\n",
      "Analysis complete for SRR2479806_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479806_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see the per base sequence quality and overrepresented sequences both have a fail. There were four represented sequences which differed in only one amino acid. We blasted the one which caused the failure but we found no similarities. The fail concerning the per base sequence quality is generated because the mean value of the last base position is below 20. We believe that this is caused because the reads have different lengths leading to a lower coverage for this base position. We then checked the sequence lenght distribution graph. As you can see there quit some sequence that have only 74 and 75 reads. This leads to a lower converage of the 76th base location leading to the drop in quality. Therefore we believe it is not necessary to trim this last base location."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479806_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/Sequence_lengt_SRR2479806_2_fastqc.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479807_1.fastq\r\n",
      "Approx 5% complete for SRR2479807_1.fastq\r\n",
      "Approx 10% complete for SRR2479807_1.fastq\r\n",
      "Approx 15% complete for SRR2479807_1.fastq\r\n",
      "Approx 20% complete for SRR2479807_1.fastq\r\n",
      "Approx 25% complete for SRR2479807_1.fastq\r\n",
      "Approx 30% complete for SRR2479807_1.fastq\r\n",
      "Approx 35% complete for SRR2479807_1.fastq\r\n",
      "Approx 40% complete for SRR2479807_1.fastq\r\n",
      "Approx 45% complete for SRR2479807_1.fastq\r\n",
      "Approx 50% complete for SRR2479807_1.fastq\r\n",
      "Approx 55% complete for SRR2479807_1.fastq\r\n",
      "Approx 60% complete for SRR2479807_1.fastq\r\n",
      "Approx 65% complete for SRR2479807_1.fastq\r\n",
      "Approx 70% complete for SRR2479807_1.fastq\r\n",
      "Approx 75% complete for SRR2479807_1.fastq\r\n",
      "Approx 80% complete for SRR2479807_1.fastq\r\n",
      "Approx 85% complete for SRR2479807_1.fastq\r\n",
      "Approx 90% complete for SRR2479807_1.fastq\r\n",
      "Approx 95% complete for SRR2479807_1.fastq\r\n",
      "Analysis complete for SRR2479807_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479807_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and duplication levels are good. But there is a failure concering overrepresented sequences. Four of these overrepresented sequences are adaptors and we decided not to trim this because we didn't want to risk overtrimming (one of these adaptars generated the failure). Another overrepresented sequence without hit was blasted. BLAST was also unable to find any hits. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479807_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479807_2.fastq\r\n",
      "Approx 5% complete for SRR2479807_2.fastq\r\n",
      "Approx 10% complete for SRR2479807_2.fastq\r\n",
      "Approx 15% complete for SRR2479807_2.fastq\r\n",
      "Approx 20% complete for SRR2479807_2.fastq\r\n",
      "Approx 25% complete for SRR2479807_2.fastq\r\n",
      "Approx 30% complete for SRR2479807_2.fastq\r\n",
      "Approx 35% complete for SRR2479807_2.fastq\r\n",
      "Approx 40% complete for SRR2479807_2.fastq\r\n",
      "Approx 45% complete for SRR2479807_2.fastq\r\n",
      "Approx 50% complete for SRR2479807_2.fastq\r\n",
      "Approx 55% complete for SRR2479807_2.fastq\r\n",
      "Approx 60% complete for SRR2479807_2.fastq\r\n",
      "Approx 65% complete for SRR2479807_2.fastq\r\n",
      "Approx 70% complete for SRR2479807_2.fastq\r\n",
      "Approx 75% complete for SRR2479807_2.fastq\r\n",
      "Approx 80% complete for SRR2479807_2.fastq\r\n",
      "Approx 85% complete for SRR2479807_2.fastq\r\n",
      "Approx 90% complete for SRR2479807_2.fastq\r\n",
      "Approx 95% complete for SRR2479807_2.fastq\r\n",
      "Analysis complete for SRR2479807_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479807_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality score and duplication levels are fine. There is a warning about overrepresented sequences. One of the two overrepresented sequences is an adaptor. But since this overrepresented sequence only represent 0.4% of the total sequences and because of the risk for overtrimming we decided not to trim this. The other overrepresented sequence had no hit and was blasted. This blast step did not found any hits. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479807_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479808_1.fastq\r\n",
      "Approx 5% complete for SRR2479808_1.fastq\r\n",
      "Approx 10% complete for SRR2479808_1.fastq\r\n",
      "Approx 15% complete for SRR2479808_1.fastq\r\n",
      "Approx 20% complete for SRR2479808_1.fastq\r\n",
      "Approx 25% complete for SRR2479808_1.fastq\r\n",
      "Approx 30% complete for SRR2479808_1.fastq\r\n",
      "Approx 35% complete for SRR2479808_1.fastq\r\n",
      "Approx 40% complete for SRR2479808_1.fastq\r\n",
      "Approx 45% complete for SRR2479808_1.fastq\r\n",
      "Approx 50% complete for SRR2479808_1.fastq\r\n",
      "Approx 55% complete for SRR2479808_1.fastq\r\n",
      "Approx 60% complete for SRR2479808_1.fastq\r\n",
      "Approx 65% complete for SRR2479808_1.fastq\r\n",
      "Approx 70% complete for SRR2479808_1.fastq\r\n",
      "Approx 75% complete for SRR2479808_1.fastq\r\n",
      "Approx 80% complete for SRR2479808_1.fastq\r\n",
      "Approx 85% complete for SRR2479808_1.fastq\r\n",
      "Approx 90% complete for SRR2479808_1.fastq\r\n",
      "Approx 95% complete for SRR2479808_1.fastq\r\n",
      "Analysis complete for SRR2479808_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479808_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality is good. There is warning for duplication levels. In this case the percentage of sequences that remained after removing duplicates is 69.89%. The sequence duplication levels are most likely the result of oversequencing to be able to detect lowly expressed transcripts. There is also a failure regarding overrepresented sequences. Three of them are adaptors. These weren't trimmed for reasons mentioned earlier. The other overrepresented sequence had no hit and BLAST was unable to find any hits."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479808_1.fastq.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479808_2.fastq\r\n",
      "Approx 5% complete for SRR2479808_2.fastq\r\n",
      "Approx 10% complete for SRR2479808_2.fastq\r\n",
      "Approx 15% complete for SRR2479808_2.fastq\r\n",
      "Approx 20% complete for SRR2479808_2.fastq\r\n",
      "Approx 25% complete for SRR2479808_2.fastq\r\n",
      "Approx 30% complete for SRR2479808_2.fastq\r\n",
      "Approx 35% complete for SRR2479808_2.fastq\r\n",
      "Approx 40% complete for SRR2479808_2.fastq\r\n",
      "Approx 45% complete for SRR2479808_2.fastq\r\n",
      "Approx 50% complete for SRR2479808_2.fastq\r\n",
      "Approx 55% complete for SRR2479808_2.fastq\r\n",
      "Approx 60% complete for SRR2479808_2.fastq\r\n",
      "Approx 65% complete for SRR2479808_2.fastq\r\n",
      "Approx 70% complete for SRR2479808_2.fastq\r\n",
      "Approx 75% complete for SRR2479808_2.fastq\r\n",
      "Approx 80% complete for SRR2479808_2.fastq\r\n",
      "Approx 85% complete for SRR2479808_2.fastq\r\n",
      "Approx 90% complete for SRR2479808_2.fastq\r\n",
      "Approx 95% complete for SRR2479808_2.fastq\r\n",
      "Analysis complete for SRR2479808_2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479808_2.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/quality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality and duplication levels are good. There is a warning concerning overrepresented sequences. One of those hits is an adaptor. For reasons earlier mentioned, this wasn't trimmed. The other overrepresented sequence had no hit. We decided to BLAST this sequence but this give no hits."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/data/Images/SRR2479808_2.fastq.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that we have the reads and checked the quality, we need to look at what we are going to use to map them. In the paper they have used Tophat2 but we opted to go with STAR since STAR delivers the best results according to several papers and fora on the internet and is really fast. In class we used STAR but there we already had a human reference genome to work with. We are working with mus musculus so we need to generate our own reference genome. In the paper they use the mm9 genome. We have opted to work with the mm10 as this is the most recent version. We obtained a mus musculus genome and corresponding annotation file from NCBI (link: https://www.ncbi.nlm.nih.gov/genome?term=mus%20musculus). \n",
    "\n",
    "The first step was to unpack the reference genome."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence\n",
    "pwd\n",
    "gunzip -c GCF_000001635.25_GRCm38.p5_genomic.fna.gz > reference.fa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then we also unpacked the annotation file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence\n",
    "gunzip GCF_000001635.25_GRCm38.p5_genomic.gff.gz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then using the command below, we used the mus musculus genome and corresponding annotation file to generate a reference genome. \n",
    "\n",
    "runThreadN is the number of processors that will be used. \n",
    "\n",
    "genomeDir is the directory in which all the output will be stored.\n",
    "\n",
    "genomeFastaFiles shows the path to the mus musculus genome.\n",
    "\n",
    "sjdbGTFfile shows the path to the mus musculus annotation file.\n",
    "\n",
    "sjdgOverhang tells STAR how many bases to link from donor and acceptor sides of the junctions. We used the standard value of 100 since we read on fora that this should work fine for us. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR\r\n",
      "Jan 03 21:15:25 ..... started STAR run\r\n",
      "Jan 03 21:15:25 ... starting to generate Genome files\r\n",
      "Jan 03 21:16:44 ... starting to sort Suffix Array. This may take a long time...\r\n",
      "Jan 03 21:17:02 ... sorting Suffix Array chunks and saving them to disk...\r\n",
      "Jan 03 21:40:18 ... loading chunks from disk, packing SA...\r\n",
      "Jan 03 21:43:49 ... finished generating suffix array\r\n",
      "Jan 03 21:43:49 ... generating Suffix Array index\r\n",
      "Jan 03 21:48:06 ... completed Suffix Array index\r\n",
      "Jan 03 21:48:06 ..... processing annotations GTF\r\n",
      "Jan 03 21:48:29 ..... inserting junctions into the genome indices\r\n",
      "Jan 03 21:52:04 ... writing Genome to disk ...\r\n",
      "Jan 03 21:52:07 ... writing Suffix Array to disk ...\r\n",
      "Jan 03 21:52:52 ... writing SAindex to disk\r\n",
      "Jan 03 21:52:58 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR\n",
    "pwd\n",
    "STAR --runThreadN 8 --runMode genomeGenerate --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --genomeFastaFiles /mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence/reference.fa --sjdbGTFfile /mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence/GCF_000001635.25_GRCm38.p5_genomic.gff --sjdbOverhang 100  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then the different fasta files containing the reads can be mapped to the reference genome generated in the previous\n",
    "step. We created a new folder for every samples (e.g. SSR2479801). For each samples two fastq files were mapped at the same time since these files are paired-end reads.\n",
    "\n",
    "genomeDir is the path to the mus musculus reference genome generated earlier.\n",
    "\n",
    "runThreadN is the number of processors used. \n",
    "\n",
    "readFilesIn is the path to the fastq files that we want map.\n",
    "\n",
    "outFileNamePrefix is the name that will be given to output file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\r\n",
      "Jan 03 21:53:54 ..... started STAR run\r\n",
      "Jan 03 21:53:54 ..... loading genome\r\n",
      "Jan 03 21:54:22 ..... started mapping\r\n",
      "Jan 03 21:57:22 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479801_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479801_2.fastq --outFileNamePrefix SRR2479801"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479802\r\n",
      "Jan 03 21:58:02 ..... started STAR run\r\n",
      "Jan 03 21:58:02 ..... loading genome\r\n",
      "Jan 03 21:58:18 ..... started mapping\r\n",
      "Jan 03 22:01:22 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479802\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479802_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479802_2.fastq --outFileNamePrefix SRR2479802"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479803\r\n",
      "Jan 03 22:01:41 ..... started STAR run\r\n",
      "Jan 03 22:01:41 ..... loading genome\r\n",
      "Jan 03 22:02:17 ..... started mapping\r\n",
      "Jan 03 22:06:36 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479803\n",
    "pwd \n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479803_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479803_2.fastq --outFileNamePrefix SRR2479803"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479804\r\n",
      "Jan 03 22:06:57 ..... started STAR run\r\n",
      "Jan 03 22:06:57 ..... loading genome\r\n",
      "Jan 03 22:07:14 ..... started mapping\r\n",
      "Jan 03 22:11:46 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479804\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479804_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479804_2.fastq --outFileNamePrefix SRR2479804"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479805\r\n",
      "Jan 03 22:23:25 ..... started STAR run\r\n",
      "Jan 03 22:23:25 ..... loading genome\r\n",
      "Jan 03 22:23:39 ..... started mapping\r\n",
      "Jan 03 22:28:27 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479805\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479805_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479805_2.fastq --outFileNamePrefix SRR2479805"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479806\r\n",
      "Jan 03 22:29:26 ..... started STAR run\r\n",
      "Jan 03 22:29:26 ..... loading genome\r\n",
      "Jan 03 22:29:39 ..... started mapping\r\n",
      "Jan 03 22:32:37 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479806\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479806_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479806_2.fastq --outFileNamePrefix SRR2479806"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479807\r\n",
      "Jan 03 22:33:26 ..... started STAR run\r\n",
      "Jan 03 22:33:26 ..... loading genome\r\n",
      "Jan 03 22:33:40 ..... started mapping\r\n",
      "Jan 03 22:37:09 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479807\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479807_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479807_2.fastq --outFileNamePrefix SRR2479807"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479808\r\n",
      "Jan 03 22:38:09 ..... started STAR run\r\n",
      "Jan 03 22:38:09 ..... loading genome\r\n",
      "Jan 03 22:38:22 ..... started mapping\r\n",
      "Jan 03 22:42:27 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479808\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479808_1.fastq /mnt/storage/r0305394/jupyternotebooks/groepswerk/data/SRR2479808_2.fastq --outFileNamePrefix SRR2479808"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The next step was to convert these sam files to bam files using samtools."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\r\n",
      "[bam_sort_core] merging from 11 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\n",
    "pwd\n",
    "samtools sort -o SRR2479801.bam SRR2479801Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479802\r\n",
      "[bam_sort_core] merging from 8 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479802\n",
    "pwd\n",
    "samtools sort -o SRR2479802.bam SRR2479802Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479803\r\n",
      "[bam_sort_core] merging from 10 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479803\n",
    "pwd\n",
    "samtools sort -o SRR2479803.bam SRR2479803Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479804\r\n",
      "[bam_sort_core] merging from 11 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479804\n",
    "pwd\n",
    "samtools sort -o SRR2479804.bam SRR2479804Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479805\r\n",
      "[bam_sort_core] merging from 19 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479805\n",
    "pwd\n",
    "samtools sort -o SRR2479805.bam SRR2479805Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479806\r\n",
      "[bam_sort_core] merging from 7 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479806\n",
    "pwd\n",
    "samtools sort -o SRR2479806.bam SRR2479806Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479807\r\n",
      "[bam_sort_core] merging from 9 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479807\n",
    "pwd\n",
    "samtools sort -o SRR2479807.bam SRR2479807Aligned.out.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479808\r\n",
      "[bam_sort_core] merging from 9 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479808\n",
    "pwd\n",
    "samtools sort -o SRR2479808.bam SRR2479808Aligned.out.sam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then we also generated an index file of each bam file in case we wanted to check our bam file in IGV."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\n",
    "pwd\n",
    "samtools index SRR2479801.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479802\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479802\n",
    "pwd\n",
    "samtools index SRR2479802.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479803\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479803\n",
    "pwd\n",
    "samtools index SRR2479803.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479804\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479804\n",
    "pwd\n",
    "samtools index SRR2479804.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479805\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479805\n",
    "pwd\n",
    "samtools index SRR2479805.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479806\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479806\n",
    "pwd\n",
    "samtools index SRR2479806.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479807\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479807\n",
    "pwd\n",
    "samtools index SRR2479807.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479808\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479808\n",
    "pwd\n",
    "samtools index SRR2479808.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then looked at one of the bam files to check whether everything looked good. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\r\n",
      "SRR2479801.6451707\t419\tNC_000067.6\t3069571\t0\t68M\t=\t3069571\t68\tTCTATCCAGGCTCTTCTGGCTTTCATAGTCTCTGGTGAAAAGTCTGGTGTAATTCTGATAGGCCTGCC\t<CC9CGFCFCFGGFCCF@FF88CCEGGGGGC,CCFCF,F9<FFEFCA@FGGGFFEFEDF<FFGGGGGF\tNH:i:5\tHI:i:4\tAS:i:134\tnM:i:0\r\n",
      "SRR2479801.6451707\t339\tNC_000067.6\t3069571\t0\t68M\t=\t3069571\t-68\tTCTATCCAGGCTCTTCTGGCTTTCATAGTCTCTGGTGAAAAGTCTGGTGTAATTCTGATAGGCCTGCC\tA@CFFDGGEFFD8FF<FFFDGFCFGF<CEGFFC;,@<GGEEF,EFC,FFGFGCGGGFCGCC@FCCB@9\tNH:i:5\tHI:i:4\tAS:i:134\tnM:i:0\r\n",
      "SRR2479801.7305973\t99\tNC_000067.6\t3093063\t255\t75M\t=\t3242712\t149724\tGGAGTTTGGCTGGGTATAGTAGCCTGGGCTGCAGTTTGTGTTCTCTTAGTGTCTGTATAACATCTGTCCAGGCTC\tCCCCCGGCFGGGGGGCF<EFFGGGGGCFGGEGGFGGGGGGFGGGGGGGGGFGGGGGGGGGGGGGGGGGGCC8FGG\tNH:i:1\tHI:i:1\tAS:i:134\tnM:i:6\r\n",
      "samtools view: writing to standard output failed: Broken pipe\r\n",
      "samtools view: error closing standard output: -1\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\n",
    "pwd\n",
    "samtools view SRR2479801.bam | head -3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then used idxstats to see how many reads were mapped per chromosome. \n",
    "\n",
    "From left to right: reference sequence name, sequence length, # mapped reads and # unmapped reads. \n",
    "\n",
    "Al the NC files seen below represent a chromosome. The exact chromosome can be found by looking up the NC number on https://www.ncbi.nlm.nih.gov/genome/?term=mus+musculus+9. \n",
    "\n",
    "As you can see there are also a lot of NT numbers. These files are can be looked up in the nucleotide database of NCBI. For example NT_166280.1, the first NT number, is an unlocalized genomic contig. This means that it is a sequence found in an assembly that is associated with a specific chromosome but cannot be ordered or oriented on that chromosome (explanation was found on https://www.ncbi.nlm.nih.gov/grc/help/definitions). \n",
    "\n",
    "There are also some NW numbers. These are patches. Patches are accessioned scaffold sequences that represent assembly updates ( explanation was found on https://www.ncbi.nlm.nih.gov/grc/help/patches).\n",
    "\n",
    "As you can see the largest number of mapped reads corresponds to the chromosomes while only a small number of reads are mapped to the NT and NW numbers. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\r\n",
      "NC_000067.6\t195471971\t1438010\t0\r\n",
      "NT_166280.1\t169725\t62\t0\r\n",
      "NT_166281.1\t241735\t38\t0\r\n",
      "NT_166282.1\t153618\t42\t0\r\n",
      "NT_166283.1\t39340\t20\t0\r\n",
      "NT_162750.1\t206961\t62\t0\r\n",
      "NC_000068.7\t182113224\t2029458\t0\r\n",
      "NC_000069.6\t160039680\t937147\t0\r\n",
      "NC_000070.6\t156508116\t1134691\t0\r\n",
      "NT_166291.1\t66673\t262\t0\r\n",
      "NT_187052.1\t14945\t12\t0\r\n",
      "NT_166434.1\t227966\t540\t0\r\n",
      "NT_187053.1\t207968\t764\t0\r\n",
      "NT_187054.1\t191905\t1174\t0\r\n",
      "NT_187055.1\t1976\t28\t0\r\n",
      "NC_000071.6\t151834684\t1191860\t0\r\n",
      "NT_187056.1\t199368\t78\t0\r\n",
      "NT_187057.1\t205776\t82\t0\r\n",
      "NT_187058.1\t184189\t12\t0\r\n",
      "NT_166438.1\t195993\t4\t0\r\n",
      "NT_187059.1\t953012\t22\t0\r\n",
      "NC_000072.6\t149736546\t1181158\t0\r\n",
      "NC_000073.6\t145441459\t1378743\t0\r\n",
      "NT_166307.1\t175968\t6\t0\r\n",
      "NC_000074.6\t129401213\t903793\t0\r\n",
      "NC_000075.6\t124595110\t1683239\t0\r\n",
      "NC_000076.6\t130694993\t924781\t0\r\n",
      "NC_000077.6\t122082543\t1702516\t0\r\n",
      "NC_000078.6\t120129022\t3881403\t0\r\n",
      "NC_000079.6\t120421639\t829048\t0\r\n",
      "NC_000080.6\t124902244\t972834\t0\r\n",
      "NC_000081.6\t104043685\t923456\t0\r\n",
      "NC_000082.6\t98207768\t597741\t0\r\n",
      "NC_000083.6\t94987271\t1011260\t0\r\n",
      "NC_000084.6\t90702639\t601852\t0\r\n",
      "NC_000085.6\t61431566\t706907\t0\r\n",
      "NC_000086.7\t171031299\t658975\t0\r\n",
      "NT_165789.2\t336933\t970\t0\r\n",
      "NC_000087.7\t91744698\t11098\t0\r\n",
      "NT_187060.1\t182347\t8\t0\r\n",
      "NT_187061.1\t259875\t4\t0\r\n",
      "NT_187062.1\t155838\t0\t0\r\n",
      "NT_187063.1\t158099\t0\t0\r\n",
      "NT_166338.1\t40056\t4\t0\r\n",
      "NT_166451.1\t42057\t0\t0\r\n",
      "NT_166462.1\t31602\t14\t0\r\n",
      "NT_166465.1\t25871\t0\t0\r\n",
      "NT_166466.1\t23158\t852\t0\r\n",
      "NT_166467.1\t38659\t0\t0\r\n",
      "NT_166469.1\t35240\t0\t0\r\n",
      "NT_166474.1\t24668\t0\t0\r\n",
      "NT_166476.1\t23629\t0\t0\r\n",
      "NT_166477.1\t55711\t0\t0\r\n",
      "NT_166478.1\t24323\t0\t0\r\n",
      "NT_166443.1\t22974\t2\t0\r\n",
      "NT_166444.1\t31704\t4\t0\r\n",
      "NT_166480.1\t21240\t0\t0\r\n",
      "NT_166456.1\t28664\t4\t0\r\n",
      "NT_166471.1\t24685\t0\t0\r\n",
      "NT_166473.1\t28772\t0\t0\r\n",
      "NT_166454.1\t26764\t52\t0\r\n",
      "NT_166463.1\t72385\t140\t0\r\n",
      "NT_166450.1\t47073\t18\t0\r\n",
      "NT_166452.1\t20208\t6\t0\r\n",
      "NT_187064.1\t114452\t1580\t0\r\n",
      "NW_016097314.1\t686942\t890\t0\r\n",
      "NW_006763128.1\t456798\t222\t0\r\n",
      "NW_016097312.1\t200008\t12267\t0\r\n",
      "NW_016097313.1\t266016\t2322\t0\r\n",
      "NW_016097315.1\t195735\t9178\t0\r\n",
      "NW_016097316.1\t166096\t1006\t0\r\n",
      "NW_012132900.1\t214957\t2\t0\r\n",
      "NW_012132901.1\t185548\t32\t0\r\n",
      "NW_012132902.1\t399265\t16\t0\r\n",
      "NW_012132903.1\t316842\t72\t0\r\n",
      "NW_012132904.1\t45901\t1154\t0\r\n",
      "NW_012132905.1\t188269\t3928\t0\r\n",
      "NW_004058050.1\t368286\t826\t0\r\n",
      "NW_004058051.1\t205713\t228\t0\r\n",
      "NW_016097317.1\t1224174\t17937\t0\r\n",
      "NW_006763130.1\t620323\t40\t0\r\n",
      "NW_006763129.1\t154766\t6206\t0\r\n",
      "NW_004058052.1\t473738\t2460\t0\r\n",
      "NW_016097318.1\t414410\t532\t0\r\n",
      "NW_016097319.1\t71460\t6\t0\r\n",
      "NW_016097320.1\t171859\t2564\t0\r\n",
      "NW_012132906.1\t120154\t6256\t0\r\n",
      "NW_004450259.3\t210641\t1012\t0\r\n",
      "NW_012132907.1\t129865\t978\t0\r\n",
      "NW_004450260.1\t331111\t7248\t0\r\n",
      "NW_004450261.1\t316140\t10123\t0\r\n",
      "NW_012132908.1\t166012\t26\t0\r\n",
      "NW_016097321.1\t211337\t3190\t0\r\n",
      "NW_012132909.1\t269476\t2052\t0\r\n",
      "NW_004450262.2\t505876\t8581\t0\r\n",
      "NW_004450263.1\t1059955\t502\t0\r\n",
      "NW_004058053.1\t352455\t110\t0\r\n",
      "NW_004058054.1\t246751\t10826\t0\r\n",
      "NW_012132910.1\t506812\t10323\t0\r\n",
      "NW_016097322.1\t299789\t9741\t0\r\n",
      "NW_012132912.1\t260447\t0\t0\r\n",
      "NW_012132913.1\t219721\t6\t0\r\n",
      "NW_004058055.1\t182256\t74\t0\r\n",
      "NW_012132911.1\t490000\t906\t0\r\n",
      "NW_004058056.1\t544189\t4\t0\r\n",
      "NW_004058058.1\t331480\t2\t0\r\n",
      "NW_004058057.1\t221588\t0\t0\r\n",
      "NT_039697.1\t46440\t1284\t0\r\n",
      "NT_039223.3\t410905\t1440\t0\r\n",
      "NT_039256.1\t273369\t1646\t0\r\n",
      "NT_039248.1\t320308\t306\t0\r\n",
      "NT_080257.1\t124933\t18\t0\r\n",
      "NT_109599.1\t180394\t246\t0\r\n",
      "NT_039373.1\t145152\t16\t0\r\n",
      "NT_039382.4\t636141\t7876\t0\r\n",
      "NT_078572.1\t91251\t684\t0\r\n",
      "NT_114988.1\t84250\t30\t0\r\n",
      "NT_114985.3\t1714434\t7273\t0\r\n",
      "NT_187006.1\t179252\t980\t0\r\n",
      "NT_039614.1\t1666365\t1217\t0\r\n",
      "NT_187007.1\t480699\t5006\t0\r\n",
      "NT_187008.1\t250595\t3492\t0\r\n",
      "NT_187009.1\t1154078\t2702\t0\r\n",
      "NT_187010.1\t273566\t14\t0\r\n",
      "NT_187011.1\t162935\t16\t0\r\n",
      "NT_039744.2\t194271\t82\t0\r\n",
      "NT_039747.4\t78689\t168\t0\r\n",
      "NT_111920.1\t247850\t4318\t0\r\n",
      "NT_039443.1\t34498\t0\t0\r\n",
      "NT_039198.1\t272653\t1590\t0\r\n",
      "NT_039192.2\t281255\t1322\t0\r\n",
      "NT_039194.5\t120856\t28\t0\r\n",
      "NT_039291.1\t170592\t18\t0\r\n",
      "NT_039334.1\t262166\t522\t0\r\n",
      "NT_039469.1\t183135\t2254\t0\r\n",
      "NT_039470.1\t251056\t1882\t0\r\n",
      "NT_078683.1\t170397\t12\t0\r\n",
      "NT_039594.3\t138435\t1775\t0\r\n",
      "NT_039622.1\t88442\t164\t0\r\n",
      "NT_187012.1\t261336\t7645\t0\r\n",
      "NT_187013.1\t189707\t386\t0\r\n",
      "NT_187014.1\t184044\t1476\t0\r\n",
      "NT_039634.4\t1618162\t18315\t0\r\n",
      "NT_187015.1\t374389\t13521\t0\r\n",
      "NT_187016.1\t170763\t12\t0\r\n",
      "NT_039661.4\t28130\t0\t0\r\n",
      "NT_039666.2\t285971\t128\t0\r\n",
      "NT_039739.2\t414761\t24\t0\r\n",
      "NT_099024.1\t123835\t142\t0\r\n",
      "NT_187017.1\t220020\t40\t0\r\n",
      "NT_039195.1\t154284\t22\t0\r\n",
      "NT_039296.1\t76099\t0\t0\r\n",
      "NT_039372.2\t312568\t908\t0\r\n",
      "NT_039367.1\t198515\t22\t0\r\n",
      "NT_039525.1\t161334\t896\t0\r\n",
      "NT_096797.1\t105813\t1584\t0\r\n",
      "NT_039630.5\t176974\t1084\t0\r\n",
      "NT_039662.3\t1934410\t54114\t0\r\n",
      "NT_039593.1\t100803\t26\t0\r\n",
      "NT_166394.1\t191521\t0\t0\r\n",
      "NT_166397.1\t185346\t0\t0\r\n",
      "NT_166400.1\t209635\t6\t0\r\n",
      "NT_095534.1\t55856\t22761\t0\r\n",
      "NT_096355.1\t59641\t2\t0\r\n",
      "NT_187028.1\t247497\t11440\t0\r\n",
      "NT_187029.1\t186379\t1844\t0\r\n",
      "NT_187030.1\t231969\t70\t0\r\n",
      "NT_166396.1\t189119\t0\t0\r\n",
      "NT_166398.1\t204663\t0\t0\r\n",
      "NT_166399.1\t196014\t2\t0\r\n",
      "NT_187019.1\t1003859\t2670\t0\r\n",
      "NT_187020.1\t3760957\t12636\t0\r\n",
      "NT_187021.1\t326027\t218\t0\r\n",
      "NT_039252.1\t292416\t184\t0\r\n",
      "NT_039247.2\t161821\t1151\t0\r\n",
      "NT_039257.4\t243366\t64\t0\r\n",
      "NT_187022.1\t1153325\t7616\t0\r\n",
      "NT_166287.2\t466430\t6572\t0\r\n",
      "NT_114257.4\t689363\t3384\t0\r\n",
      "NT_187023.1\t3050841\t35216\t0\r\n",
      "NT_187024.1\t215601\t6458\t0\r\n",
      "NT_166299.2\t3205425\t43054\t0\r\n",
      "NT_187025.1\t1625541\t25635\t0\r\n",
      "NT_187026.1\t1550185\t41530\t0\r\n",
      "NT_166317.2\t1462311\t4396\t0\r\n",
      "NT_187027.1\t4256209\t82321\t0\r\n",
      "NT_080256.1\t142341\t10\t0\r\n",
      "NT_187002.1\t1759414\t148\t0\r\n",
      "NT_166305.2\t5956088\t24853\t0\r\n",
      "NT_187003.1\t3086744\t23387\t0\r\n",
      "NT_187005.1\t1908920\t35387\t0\r\n",
      "NT_187004.1\t4910976\t82003\t0\r\n",
      "NT_166433.1\t83612\t6\t0\r\n",
      "NT_165784.1\t85548\t14\t0\r\n",
      "NT_039292.1\t138473\t2\t0\r\n",
      "NT_109318.2\t240498\t1226\t0\r\n",
      "NT_078651.1\t77891\t10\t0\r\n",
      "NT_097336.1\t138490\t19042\t0\r\n",
      "NT_187018.1\t25407\t18\t0\r\n",
      "NT_187000.1\t284739\t478\t0\r\n",
      "NT_186999.1\t69753\t12\t0\r\n",
      "NT_166295.1\t83218\t4\t0\r\n",
      "NT_166293.1\t264822\t16\t0\r\n",
      "NT_166294.1\t191695\t302\t0\r\n",
      "NT_166322.1\t99963\t9293\t0\r\n",
      "NT_187001.1\t89177\t28\t0\r\n",
      "NC_005089.1\t16299\t522544\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/SRR2479801\n",
    "pwd\n",
    "samtools idxstats SRR2479801.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then stored all the bam files in one folder because it is easier to work with during the upcoming steps.\n",
    "\n",
    "Path to the bam files: /mnt/storage/r0305394/jupyternotebooks/r0305394/groepswerk/Rnaseq/Bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The next step was to count all the mapped reads per gene. First we looked at the annotation file we used earlier when generating the reference genome so that we were able to see what word we had to use to filter the gene names with the according mapped reads. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "##gff-version 3\r\n",
      "#!gff-spec-version 1.21\r\n",
      "#!processor NCBI annotwriter\r\n",
      "#!genome-build GRCm38.p5\r\n",
      "#!genome-build-accession NCBI_Assembly:GCF_000001635.25\r\n",
      "##sequence-region NC_000067.6 1 195471971\r\n",
      "##species https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=10090\r\n",
      "NC_000067.6\tRefSeq\tregion\t1\t195471971\t.\t+\t.\tID=id0;Dbxref=taxon:10090;Name=1;chromosome=1;gbkey=Src;genome=chromosome;mol_type=genomic DNA;strain=C57BL/6J\r\n",
      "NC_000067.6\tBestRefSeq%2CGnomon\tgene\t3199733\t3672278\t.\t-\t.\tID=gene0;Dbxref=GeneID:497097,MGI:MGI:3528744;Name=Xkr4;description=X-linked Kx blood group related 4;gbkey=Gene;gene=Xkr4;gene_biotype=protein_coding;gene_synonym=AY534250,Gm210,mKIAA1889,XRG4\r\n"
     ]
    }
   ],
   "source": [
    "head -9 /mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence/GCF_000001635.25_GRCm38.p5_genomic.gff"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The command below compiles the number of mapped reads per gene of all the samples together in one file.\n",
    "\n",
    "Q is the quality controle. We used the same filter as in class.\n",
    "\n",
    "g shows us the mapped reads per gene,\n",
    "\n",
    "a is the path to the annotation file,\n",
    "\n",
    "o determines the output file followed by all the bam files that are the input of this command."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "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[36m8 BAM files  \u001b[0m \u001b[0m                                   ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479801.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479802.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479803.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479804.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479805.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479806.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479807.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mP\u001b[36m SRR2479808.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Output file : \u001b[36mall.counts\u001b[0m \u001b[0m                                      ||\r\n",
      "||             Annotations : \u001b[36m/mnt/storage/r0305394/jupyternotebooks/groep\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/storage/r0305394/jupyternotebooks/groepswerk\u001b[0m ... \u001b[0m||\r\n",
      "||    Features : \u001b[36m1225991\u001b[0m \u001b[0m                                                     ||\r\n",
      "||    Meta-features : \u001b[36m41575\u001b[0m \u001b[0m                                                  ||\r\n",
      "||    Chromosomes/contigs : \u001b[36m185\u001b[0m \u001b[0m                                              ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479801.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m26017423\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m12297493 (47.3%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.50 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479802.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m19182638\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m11259603 (58.7%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.41 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479803.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m23767113\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m13872095 (58.4%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.46 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479804.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m25594149\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m14887072 (58.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 SRR2479805.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m44214858\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m20524669 (46.4%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.85 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479806.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m16075200\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m9324449 (58.0%)\u001b[0m \u001b[0m                          ||\r\n",
      "||    Running time : \u001b[36m0.34 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479807.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m19935706\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m11499503 (57.7%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.41 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file SRR2479808.bam... \u001b[0m                                        ||\r\n",
      "||    Paired-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m21478065\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m12346368 (57.5%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.44 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": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/Bam\n",
    "featureCounts -Q 10 -g gene -a /mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence/GCF_000001635.25_GRCm38.p5_genomic.gff -o all.counts SRR2479801.bam SRR2479802.bam SRR2479803.bam SRR2479804.bam SRR2479805.bam SRR2479806.bam SRR2479807.bam SRR2479808.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then took a look at the output file generated by featurecounts. As you can see it looks really chaotic. The following steps are to clean up this file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Program:featureCounts v1.5.0-p1; Command:\"featureCounts\" \"-Q\" \"10\" \"-g\" \"gene\" \"-a\" \"/mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence/GCF_000001635.25_GRCm38.p5_genomic.gff\" \"-o\" \"all.counts\" \"SRR2479801.bam\" \"SRR2479802.bam\" \"SRR2479803.bam\" \"SRR2479804.bam\" \"SRR2479805.bam\" \"SRR2479806.bam\" \"SRR2479807.bam\" \"SRR2479808.bam\" \r\n",
      "Geneid\tChr\tStart\tEnd\tStrand\tLength\tSRR2479801.bam\tSRR2479802.bam\tSRR2479803.bam\tSRR2479804.bam\tSRR2479805.bam\tSRR2479806.bam\tSRR2479807.bam\tSRR2479808.bam\r\n",
      "Xkr4\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t3199733;3213439;3322816;3421702;3670552\t3207317;3216968;3323760;3421901;3672278\t-;-;-;-;-\t13987\t47\t68\t76\t118\t66\t24\t36\t32\r\n",
      "Gm39585\tNC_000067.6;NC_000067.6\t3361552;3368342\t3366505;3377812\t+;+\t14425\t49\t4\t4\t6\t36\t0\t2\t0\r\n",
      "LOC108167595\tNC_000067.6\t3671524\t3672264\t-\t741\t0\t0\t0\t0\t0\t0\t0\t0\r\n",
      "Gm38717\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4115673;4119668;4120015;4142612;4147812;4148612;4163855;4170205;4197534;4206660;4226611;4228443;4231053;4233184;4243133\t4115948;4119712;4120073;4142766;4147963;4148744;4163941;4170404;4197641;4206837;4226823;4228619;4231144;4233728;4243365\t-;-;-;-;-;-;-;-;-;-;-;-;-;-;-\t2653\t0\t8\t1\t0\t3\t0\t0\t1\r\n",
      "Rp1\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4290846;4343507;4351910;4352202;4360200;4409170\t4293012;4350091;4352081;4352837;4360314;4409266\t-;-;-;-;-;-\t9772\t4\t4\t3\t9\t0\t2\t8\t2\r\n",
      "Sox17\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4490928;4493100;4493772;4496291\t4492668;4493490;4495942;4497386\t-;-;-;-\t5399\t37\t95\t71\t88\t95\t78\t94\t103\r\n",
      "Gm7357\tNC_000067.6;NC_000067.6\t4522817;4524432\t4523591;4526931\t+;+\t3275\t4\t12\t10\t14\t2\t4\t14\t12\r\n",
      "LOC108167609\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4583127;4583406;4598113;4608720\t4583243;4583478;4598958;4608781\t-;-;-;-\t1098\t0\t1\t0\t0\t1\t0\t1\t0\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/Bam\n",
    "head all.counts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first we did was to generate a file that gives us the exact location of each gene without looking at the total amount of mapped reads. To do this we only kept the first six rows and cut the rest."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f-6 all.counts > all.genedata.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Program:featureCounts v1.5.0-p1; Command:\"featureCounts\" \"-Q\" \"10\" \"-g\" \"gene\" \"-a\" \"/mnt/storage/r0305394/jupyternotebooks/groepswerk/Sequence/GCF_000001635.25_GRCm38.p5_genomic.gff\" \"-o\" \"all.counts\" \"SRR2479801.bam\" \"SRR2479802.bam\" \"SRR2479803.bam\" \"SRR2479804.bam\" \"SRR2479805.bam\" \"SRR2479806.bam\" \"SRR2479807.bam\" \"SRR2479808.bam\" \r\n",
      "Geneid\tChr\tStart\tEnd\tStrand\tLength\r\n",
      "Xkr4\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t3199733;3213439;3322816;3421702;3670552\t3207317;3216968;3323760;3421901;3672278\t-;-;-;-;-\t13987\r\n",
      "Gm39585\tNC_000067.6;NC_000067.6\t3361552;3368342\t3366505;3377812\t+;+\t14425\r\n",
      "LOC108167595\tNC_000067.6\t3671524\t3672264\t-\t741\r\n",
      "Gm38717\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4115673;4119668;4120015;4142612;4147812;4148612;4163855;4170205;4197534;4206660;4226611;4228443;4231053;4233184;4243133\t4115948;4119712;4120073;4142766;4147963;4148744;4163941;4170404;4197641;4206837;4226823;4228619;4231144;4233728;4243365\t-;-;-;-;-;-;-;-;-;-;-;-;-;-;-\t2653\r\n",
      "Rp1\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4290846;4343507;4351910;4352202;4360200;4409170\t4293012;4350091;4352081;4352837;4360314;4409266\t-;-;-;-;-;-\t9772\r\n",
      "Sox17\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4490928;4493100;4493772;4496291\t4492668;4493490;4495942;4497386\t-;-;-;-\t5399\r\n",
      "Gm7357\tNC_000067.6;NC_000067.6\t4522817;4524432\t4523591;4526931\t+;+\t3275\r\n",
      "LOC108167609\tNC_000067.6;NC_000067.6;NC_000067.6;NC_000067.6\t4583127;4583406;4598113;4608720\t4583243;4583478;4598958;4608781\t-;-;-;-\t1098\r\n"
     ]
    }
   ],
   "source": [
    "head all.genedata.tsv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see we now have file containing the gene name, the chromosome on which the gene is located, the start and end of the gene, which strand is located on and the length of the gene."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also want a file containing the gene names with the corresponding number of mapped reads. To do this we only take the first row containing the gene name and all the rows starting from row 7 which contain the number of mapped reads per sample."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f1,7- all.counts | grep -v '^#' > all.gene.counts.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Geneid        SRR2479801.bam  SRR2479802.bam  SRR2479803.bam  SRR2479804.bam  SRR2479805.bam  SRR2479806.bam  SRR2479807.bam  SRR2479808.bam\r\n",
      "Xkr4          47              68              76              118             66              24              36              32\r\n",
      "Gm39585       49              4               4               6               36              0               2               0\r\n",
      "LOC108167595  0               0               0               0               0               0               0               0\r\n",
      "Gm38717       0               8               1               0               3               0               0               1\r\n",
      "Rp1           4               4               3               9               0               2               8               2\r\n",
      "Sox17         37              95              71              88              95              78              94              103\r\n",
      "Gm7357        4               12              10              14              2               4               14              12\r\n",
      "LOC108167609  0               1               0               0               1               0               1               0\r\n",
      "Gm39586       1               6               2               1               6               0               0               4\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/Rnaseq/Bam\n",
    "head all.gene.counts.tsv | column -t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see this file now shows the gene names with their corresponding number of mapped reads per sample."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DESeq2 analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The next step is to use this output to look at the differential expression using DESeq2. This will be done in R so this has to be done in a new notebook which is named Exam_project_SOX9_R.ipynb (path: /mnt/storage/r0305394/jupyternotebooks/groepswerk/Exam_project_SOX9_R.ipynb)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This generated a file with 666 differentially expressed genes. In the paper they mention the downregulation of several important transcription factors that are known to play a role in heart valve development such as Twist 1, Sox4, Hand2, Foxp4, Pitx2 and Mecom. We were able to confirm the downregulation of Twist1, Hand2, Mecom and Pitx2 in our results. Sox4 was also downregulated in our samples but it had a p-value of 0.13 so it was not significant. Foxp4 was also downregulated but had a p-value of 0.84 so it was not significant. It is possible that these results differ due a different alignment method (STAR vs. Tophat) and a different version of the mus musculus genome (mm10 vs. mm9)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/Twist1.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we determined the ontology of all the differently expressed by genes via humanmine.org. We extracted the results as a tsv file and used excel to study them. \n",
    "\n",
    "The first thing we did was to check several processes in which sox9 is involved (heart valve development and limb formation). \n",
    "\n",
    "The processes we checked included epithelial-to-mesenchymal transition, cardiac cushion, valve development, chondrogenesis, limb formation, cartilage formation and mesenchyme development,.... These are all processes involved in heart valve formation and/or limb formation and/or bone development and have been linked to sox9. We further also found a paper in which dysfunctional sox9 has been linked to disorders linked to sex development (https://www.ncbi.nlm.nih.gov/pubmed/24115316). \n",
    "\n",
    "We then copied the genes that played a role in these processes and made a new list in excel. We then selected only those genes that had a 2log fold change equal to/higher than 0.58 or equal to/lower than -0.58. In this way we were able to generate a list of 111 up - and downregulated genes that play a role in processes such as aortic valve morphogenesis (Twist1), chondrocyt development/differentation (Shox2), endocardial cushion formation (Errb2),female gonad development (Serpine1) and cartilage development (Sfrp2). \n",
    "\n",
    "These results seem to indicate that sox9 KO affects processes linked to sex development, heart valve development and cartilage formation. As mentioned in the previous markdown box, we were able to confirm three important downregulated TFs that are mentioned in the paper (Twist1, Hand2, Pitx2 and Mecom). Because Hand2 had log2 fold changes higher that -0.58 we discarded it from the list shown above. According to our gene ontology Mecom has no role in heart development although in the paper it is mentioned as an important TF for heart valve development. In our gene ontology report Mecom was shown to play a role in embryonic forelimb morphogenesis. We therefore searched pubmed and found a paper in which Mecom is shown to regulate cardiac development(https://www.ncbi.nlm.nih.gov/pubmed/?term=Mice+Carrying+a+Hypomorphic+Evi1+Allele+Are+Embryonic+Viable+but+Exhibit+Severe+Congenital+Heart+Defects)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/Heart_and_bones.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/Heart_and_bones2.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/Heart_and_bones3.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When we went through the original gene ontology list (containing the 666 up - and downregulated genes), we noticed that a lot of the up - and downreglated genes seemed to play a role in neuronal development and functioning. We searched pubmed to whether we could find any role for sox9 in neuronal development. We found an article that indicated that sox9 to be involved in neurogenesis (https://www.ncbi.nlm.nih.gov/pubmed/25888505). \n",
    "\n",
    "A lot of genes were also involved in astrocyte development, formation and functioning. We searched pubmed and found a paper in which researchers state that sox9 plays a role in de start of gliogenesis, a process in which glial cells are formed. These glial cells have the potential to differentiate into astrocytes (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3543821/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/Neuron.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this paper, they refer to two papers that show that sox9 also is important during lung development in the lung epithelium during branching morphogenesis (https://www.ncbi.nlm.nih.gov/pubmed/?term=sox9+plays+multiple+roles+in+the+lung+epithelium) and cochlea development (https://www.ncbi.nlm.nih.gov/pubmed/?term=loss+of+sox9+in+the+periotic+mesenchyme). We checked the gene ontology list to see if any genes were affected that play a role in these processes.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/cochlea_and_lung.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Overall, we can conclude from this RNA sequencing that KO of sox9 affects a number of genes that play a role in heart valve formation, cartilage development but also in neuronal differentation. We were able to confirm some of the results obtained in the paper. We were able to show a downregulation of Twist1, Pitx2 and Mecom which are all TF that are important for normal heart valve and heart development."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ChIP sequencing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have two ChIP seq samples. The first sample is from the AVC and will tell us something about the genes that are regulated by sox9 in the heart. The second samples is from the limb mesenchyme and will tell which genes are bound and regulated by sox9 in the limb. This will allows us to see whether the downregulated genes found in the heart during RNA seq are due to a direct effect of sox9 which means that sox9 binds directly to the transcription site of this gene. Or whether this gene is downregulated through an indirect effect meaning that sox9 binds a gene X that controls the transcription of a gene Y. Secondly this data will allow to determine binding motifs in the heart and in the limb and will shows us if there are any similar binding motifs in the heart and limb. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Fist we made a new folder to store all data related to the ChIP sequencing. Then we made two folders inside this folder where we stored the original ChIP seq data that we downloaded from https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE73225."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk\r\n",
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk\n",
    "pwd\n",
    "mkdir -p ChIPseq\n",
    "cd ChIPseq \n",
    "pwd\n",
    "mkdir -p AVC\n",
    "mkdir -p limb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 337,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\r\n",
      "Read 275437743 spots for SRR2479798\r\n",
      "Written 275437743 spots for SRR2479798\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "pwd\n",
    "fastq-dump --split-files SRR2479798"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then checked the quality of the ChIP seq data (AVC sample)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 314,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479798_1.fastq\r\n",
      "Approx 5% complete for SRR2479798_1.fastq\r\n",
      "Approx 10% complete for SRR2479798_1.fastq\r\n",
      "Approx 15% complete for SRR2479798_1.fastq\r\n",
      "Approx 20% complete for SRR2479798_1.fastq\r\n",
      "Approx 25% complete for SRR2479798_1.fastq\r\n",
      "Approx 30% complete for SRR2479798_1.fastq\r\n",
      "Approx 35% complete for SRR2479798_1.fastq\r\n",
      "Approx 40% complete for SRR2479798_1.fastq\r\n",
      "Approx 45% complete for SRR2479798_1.fastq\r\n",
      "Approx 50% complete for SRR2479798_1.fastq\r\n",
      "Approx 55% complete for SRR2479798_1.fastq\r\n",
      "Approx 60% complete for SRR2479798_1.fastq\r\n",
      "Approx 65% complete for SRR2479798_1.fastq\r\n",
      "Approx 70% complete for SRR2479798_1.fastq\r\n",
      "Approx 75% complete for SRR2479798_1.fastq\r\n",
      "Approx 80% complete for SRR2479798_1.fastq\r\n",
      "Approx 85% complete for SRR2479798_1.fastq\r\n",
      "Approx 90% complete for SRR2479798_1.fastq\r\n",
      "Approx 95% complete for SRR2479798_1.fastq\r\n",
      "Analysis complete for SRR2479798_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see this quality report is bad. The per sequence quality is bad for every base position. Trimming this would mean to trim the entire reads. In the next steps we will work with this fastq file. Later on we will try to clean this fastq file and will repeat everything with this cleaned fastq file to see the effect."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/AVC/Original.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The fastq file generated during the step above was over 50 GB large. We therefore deleted the file after we had used it to map in the following steps."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we downloaded the ChIP seq data for the second sample (limb sample)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 319,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\r\n",
      "Read 83367566 spots for SRR2479799\r\n",
      "Written 83367566 spots for SRR2479799\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\n",
    "pwd\n",
    "fastq-dump --split-files SRR2479799"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Quality control was performed on the second ChIP seq data set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 321,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479799_1.fastq\r\n",
      "Approx 5% complete for SRR2479799_1.fastq\r\n",
      "Approx 10% complete for SRR2479799_1.fastq\r\n",
      "Approx 15% complete for SRR2479799_1.fastq\r\n",
      "Approx 20% complete for SRR2479799_1.fastq\r\n",
      "Approx 25% complete for SRR2479799_1.fastq\r\n",
      "Approx 30% complete for SRR2479799_1.fastq\r\n",
      "Approx 35% complete for SRR2479799_1.fastq\r\n",
      "Approx 40% complete for SRR2479799_1.fastq\r\n",
      "Approx 45% complete for SRR2479799_1.fastq\r\n",
      "Approx 50% complete for SRR2479799_1.fastq\r\n",
      "Approx 55% complete for SRR2479799_1.fastq\r\n",
      "Approx 60% complete for SRR2479799_1.fastq\r\n",
      "Approx 65% complete for SRR2479799_1.fastq\r\n",
      "Approx 70% complete for SRR2479799_1.fastq\r\n",
      "Approx 75% complete for SRR2479799_1.fastq\r\n",
      "Approx 80% complete for SRR2479799_1.fastq\r\n",
      "Approx 85% complete for SRR2479799_1.fastq\r\n",
      "Approx 90% complete for SRR2479799_1.fastq\r\n",
      "Approx 95% complete for SRR2479799_1.fastq\r\n",
      "Analysis complete for SRR2479799_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence, dupplication levels and overrepresented sequences are looking good."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/limb/Limb.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The fastq file generated during the step above was over 15 GB large. We therefore deleted the file after we had used it to map in the following steps."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The next step is to align the reads to the reference genome. In this case we will use STAR to align to the reference genome we made earlier in RNA sequencing. The first file that we are mapping contains Chip seq data from the AVC from mice hearts."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\r\n",
      "Jan 06 13:49:46 ..... started STAR run\r\n",
      "Jan 06 13:49:50 ..... loading genome\r\n",
      "Jan 06 13:52:58 ..... started mapping\r\n",
      "Jan 06 15:06:23 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798_1.fastq  --outFileNamePrefix SRR2479798"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The sam file generated in the step above was over 30 GB large. We therefore deleted the sam file after converting it into a bam file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we converted the sam file into a bam file using samtools."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\r\n",
      "[bam_sort_core] merging from 40 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "pwd\n",
    "samtools sort -o SRR2479798.bam SRR2479798Aligned.out.sam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then repeated the same steps for the second Chip Sequencing fasta file. This file contains the ChIP seq data from limb mesenchyme. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 269,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\r\n",
      "Jan 06 15:44:42 ..... started STAR run\r\n",
      "Jan 06 15:44:42 ..... loading genome\r\n",
      "Jan 06 15:47:38 ..... started mapping\r\n",
      "Jan 06 16:04:03 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799_1.fastq  --outFileNamePrefix SRR2479799"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The sam file generated in the step above was over 15 GB large. We therefore deleted the sam file after converting it into a bam file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 270,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\r\n",
      "[bam_sort_core] merging from 21 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\n",
    "pwd\n",
    "samtools sort -o SRR2479799.bam SRR2479799Aligned.out.sam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we generated two index files, one for each bam file generated in the previous steps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "pwd\n",
    "samtools index SRR2479798.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\n",
    "pwd\n",
    "samtools index SRR2479799.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Peak calling with macs2. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We performed peak calling two times on each bam file (once without control and once without controle) to see the effect of the control files wich normally should filter out false positives."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "mkdir -p macs2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:42: \r\n",
      "# Command line: callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2 -n sox9AVC -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = sox9AVC\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798.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  @ Fri, 06 Jan 2017 16:21:42: #1 read tag files... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:42: #1 read treatment tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:42: Detected format is: BAM \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:42: * Input file is gzipped. \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:46:  1000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:50:  2000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:53:  3000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:21:57:  4000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:01:  5000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:04:  6000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:08:  7000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:12:  8000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:16:  9000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:19:  10000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:23:  11000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:27:  12000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:31:  13000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:34:  14000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:38:  15000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:41:  16000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:44:  17000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:47:  18000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:51:  19000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:55:  20000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:22:58:  21000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:02:  22000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:06:  23000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:10:  24000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:13:  25000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:17:  26000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:21:  27000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:25:  28000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:28:  29000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:32:  30000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:36:  31000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:40:  32000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:44:  33000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:47:  34000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:51:  35000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:55:  36000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:23:59:  37000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:02:  38000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:05:  39000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:09:  40000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:13:  41000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:17:  42000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:20:  43000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:24:  44000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:28:  45000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:31:  46000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:35:  47000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:39:  48000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:42:  49000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:46:  50000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:50:  51000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:54:  52000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:24:57:  53000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:01:  54000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:04:  55000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:07:  56000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:11:  57000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:15:  58000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:19:  59000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:22:  60000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:26:  61000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:30:  62000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:34:  63000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:37:  64000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:41:  65000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:45:  66000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:48:  67000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:52:  68000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:56:  69000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:25:59:  70000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:01:  71000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:04:  72000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:07:  73000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:11:  74000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:15:  75000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:19:  76000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:22:  77000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:26:  78000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:30:  79000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:34:  80000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:38:  81000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:42:  82000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:45:  83000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:49:  84000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:53:  85000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:26:57:  86000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:01:  87000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:05:  88000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:08:  89000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:12:  90000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:16:  91000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:20:  92000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:23:  93000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:27:  94000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:31:  95000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:34:  96000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:38:  97000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:42:  98000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:45:  99000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:49:  100000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:53:  101000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:27:57:  102000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:00:  103000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:04:  104000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:07:  105000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:10:  106000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:14:  107000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:17:  108000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:21:  109000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:25:  110000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:29:  111000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:33:  112000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:36:  113000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:40:  114000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:44:  115000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:48:  116000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:52:  117000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:55:  118000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:28:59:  119000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:03:  120000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:07:  121000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:10:  122000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:14:  123000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:18:  124000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:22:  125000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:25:  126000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:29:  127000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:33:  128000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:37:  129000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:41:  130000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:44:  131000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:48:  132000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:52:  133000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:56:  134000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:29:59:  135000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:02:  136000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:06:  137000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:09:  138000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:13:  139000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:16:  140000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:19:  141000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:23:  142000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:26:  143000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:28:  144000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:31:  145000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:34:  146000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:36:  147000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:39:  148000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:42:  149000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:44:  150000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:47:  151000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:49:  152000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:52:  153000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:55:  154000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:57:  155000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:30:59:  156000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:01:  157000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:04:  158000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:06:  159000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:11: #1 tag size is determined as 50 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:11: #1 tag size = 50 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:11: #1  total tags in treatment: 120182971 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:11: #1 user defined the maximum tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:11: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:13: #1  tags after filtering in treatment: 12888304 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:13: #1  Redundant rate of treatment: 0.89 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:13: #1 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:13: #2 Build Peak Model... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:13: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: #2 number of paired peaks: 2593 \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: start model_add_line... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: start X-correlation... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: end of X-cor \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: #2 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: #2 predicted fragment length is 46 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: #2 alternative fragment length(s) may be 46,110,567 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: #2.2 Generate R script for model : /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVC_model.r \r\n",
      "WARNING @ Fri, 06 Jan 2017 16:31:15: #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 @ Fri, 06 Jan 2017 16:31:15: #2 You may need to consider one of the other alternative d(s): 46,110,567 \r\n",
      "WARNING @ Fri, 06 Jan 2017 16:31:15: #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  @ Fri, 06 Jan 2017 16:31:15: #3 Call peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:15: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:31:47: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:32:04: #4 Write output xls file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVC_peaks.xls \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:32:05: #4 Write peak in narrowPeak format file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVC_peaks.narrowPeak \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:32:05: #4 Write summits bed file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVC_summits.bed \r\n",
      "INFO  @ Fri, 06 Jan 2017 16:32:05: Done! \r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "pwd\n",
    "macs2 callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2  -n sox9AVC -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then checked the amount of peaks that have been called in the AVC sample."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 287,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "52848 sox9AVC_peaks.narrowPeak\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "wc -l sox9AVC_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now want to perform another peak calling on the same sample but now we use a control sample to filter out false positives. This control sample contains DNA from the whole heart and has been crosslinked and sonicated but has not been immunoprecipitated. The first step is to download and convert the control files with fastq dump."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq\n",
    "mkdir -p controle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 91856920 spots for SRR2479800\r\n",
      "Written 91856920 spots for SRR2479800\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle\n",
    "fastq-dump --split-files SRR2479800"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also checked the quality of the control sample."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479800_1.fastq\r\n",
      "Approx 5% complete for SRR2479800_1.fastq\r\n",
      "Approx 10% complete for SRR2479800_1.fastq\r\n",
      "Approx 15% complete for SRR2479800_1.fastq\r\n",
      "Approx 20% complete for SRR2479800_1.fastq\r\n",
      "Approx 25% complete for SRR2479800_1.fastq\r\n",
      "Approx 30% complete for SRR2479800_1.fastq\r\n",
      "Approx 35% complete for SRR2479800_1.fastq\r\n",
      "Approx 40% complete for SRR2479800_1.fastq\r\n",
      "Approx 45% complete for SRR2479800_1.fastq\r\n",
      "Approx 50% complete for SRR2479800_1.fastq\r\n",
      "Approx 55% complete for SRR2479800_1.fastq\r\n",
      "Approx 60% complete for SRR2479800_1.fastq\r\n",
      "Approx 65% complete for SRR2479800_1.fastq\r\n",
      "Approx 70% complete for SRR2479800_1.fastq\r\n",
      "Approx 75% complete for SRR2479800_1.fastq\r\n",
      "Approx 80% complete for SRR2479800_1.fastq\r\n",
      "Approx 85% complete for SRR2479800_1.fastq\r\n",
      "Approx 90% complete for SRR2479800_1.fastq\r\n",
      "Approx 95% complete for SRR2479800_1.fastq\r\n",
      "Analysis complete for SRR2479800_1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800_1.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality, duplication levels and overrepresented sequences look good."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/controle/Controle.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next the control sample is mapped to the reference genome using STAR."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 275,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jan 06 16:48:45 ..... started STAR run\r\n",
      "Jan 06 16:48:49 ..... loading genome\r\n",
      "Jan 06 16:49:02 ..... started mapping\r\n",
      "Jan 06 17:05:29 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800_1.fastq --outFileNamePrefix SRR2479800"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then converted the sam file to a bam file using samtools."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 276,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 26 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle\n",
    "samtools sort -o SRR2479800.bam SRR2479800Aligned.out.sam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we performd a second peak calling on the AVC bam file to see the effect of the control file on the peaks called."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 277,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:30: \r\n",
      "# Command line: callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798.bam -c /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2 -n sox9AVCControle -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = sox9AVCControle\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798.bam']\r\n",
      "# control file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.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  @ Fri, 06 Jan 2017 17:26:30: #1 read tag files... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:30: #1 read treatment tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:30: Detected format is: BAM \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:30: * Input file is gzipped. \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:34:  1000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:37:  2000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:40:  3000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:43:  4000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:46:  5000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:49:  6000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:52:  7000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:55:  8000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:26:58:  9000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:00:  10000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:03:  11000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:06:  12000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:09:  13000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:12:  14000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:15:  15000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:18:  16000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:20:  17000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:23:  18000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:25:  19000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:28:  20000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:31:  21000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:34:  22000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:37:  23000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:40:  24000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:43:  25000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:46:  26000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:49:  27000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:52:  28000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:55:  29000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:27:58:  30000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:01:  31000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:04:  32000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:07:  33000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:10:  34000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:13:  35000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:16:  36000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:19:  37000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:22:  38000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:24:  39000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:27:  40000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:30:  41000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:33:  42000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:36:  43000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:39:  44000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:42:  45000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:45:  46000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:48:  47000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:51:  48000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:54:  49000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:28:57:  50000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:00:  51000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:03:  52000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:06:  53000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:08:  54000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:11:  55000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:13:  56000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:16:  57000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:19:  58000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:22:  59000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:25:  60000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:28:  61000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:31:  62000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:34:  63000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:37:  64000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:40:  65000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:43:  66000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:46:  67000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:49:  68000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:52:  69000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:54:  70000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:56:  71000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:29:58:  72000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:01:  73000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:04:  74000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:08:  75000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:12:  76000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:15:  77000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:18:  78000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:21:  79000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:24:  80000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:27:  81000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:30:  82000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:33:  83000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:36:  84000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:40:  85000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:44:  86000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:47:  87000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:50:  88000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:53:  89000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:56:  90000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:30:59:  91000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:02:  92000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:04:  93000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:07:  94000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:10:  95000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:14:  96000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:17:  97000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:20:  98000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:23:  99000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:26:  100000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:29:  101000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:32:  102000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:35:  103000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:38:  104000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:41:  105000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:43:  106000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:46:  107000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:49:  108000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:52:  109000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:55:  110000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:31:58:  111000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:01:  112000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:04:  113000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:07:  114000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:10:  115000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:13:  116000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:16:  117000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:19:  118000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:22:  119000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:25:  120000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:28:  121000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:31:  122000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:34:  123000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:37:  124000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:40:  125000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:43:  126000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:46:  127000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:49:  128000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:52:  129000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:55:  130000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:32:58:  131000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:01:  132000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:04:  133000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:07:  134000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:10:  135000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:12:  136000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:15:  137000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:18:  138000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:21:  139000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:24:  140000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:26:  141000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:29:  142000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:31:  143000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:33:  144000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:35:  145000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:37:  146000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:39:  147000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:42:  148000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:44:  149000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:46:  150000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:47:  151000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:50:  152000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:52:  153000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:54:  154000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:56:  155000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:57:  156000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:33:59:  157000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:01:  158000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:03:  159000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:07: #1.2 read input tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:07: Detected format is: BAM \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:07: * Input file is gzipped. \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:10:  1000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:13:  2000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:16:  3000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:19:  4000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:23:  5000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:26:  6000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:29:  7000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:32:  8000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:35:  9000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:38:  10000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:40:  11000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:43:  12000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:46:  13000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:49:  14000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:52:  15000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:55:  16000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:34:59:  17000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:02:  18000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:05:  19000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:08:  20000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:11:  21000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:15:  22000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:18:  23000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:21:  24000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:24:  25000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:27:  26000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:30:  27000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:33:  28000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:36:  29000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:39:  30000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:43:  31000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:46:  32000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:49:  33000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:52:  34000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:55:  35000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:35:58:  36000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:01:  37000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:04:  38000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:07:  39000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:10:  40000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:13:  41000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:17:  42000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:20:  43000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:22:  44000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:24:  45000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:26:  46000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:30:  47000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:33:  48000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:36:  49000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:39:  50000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:42:  51000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:46:  52000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:49:  53000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:52:  54000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:55:  55000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:36:59:  56000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:02:  57000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:05:  58000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:08:  59000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:11:  60000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:14:  61000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:18:  62000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:22:  63000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:25:  64000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:28:  65000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:31:  66000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:34:  67000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:37:  68000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:40:  69000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:43:  70000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:47:  71000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:50:  72000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:53:  73000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:56:  74000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:37:59:  75000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:03:  76000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:06:  77000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:09:  78000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:12:  79000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:15:  80000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:19:  81000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:22:  82000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:25:  83000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:28:  84000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:31:  85000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:34:  86000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:37:  87000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:39:  88000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:42:  89000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:44:  90000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:46:  91000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:48:  92000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:51:  93000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:53:  94000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:54:  95000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:57:  96000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:38:59:  97000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:01:  98000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:02:  99000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:04:  100000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:06:  101000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:08: #1 tag size is determined as 50 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:08: #1 tag size = 50 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:08: #1  total tags in treatment: 120182971 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:08: #1 user defined the maximum tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:08: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:10: #1  tags after filtering in treatment: 12888304 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:10: #1  Redundant rate of treatment: 0.89 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:10: #1  total tags in control: 74893481 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:10: #1 user defined the maximum tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:10: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:11: #1  tags after filtering in control: 67875293 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:11: #1  Redundant rate of control: 0.09 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:11: #1 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:11: #2 Build Peak Model... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:11: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: #2 number of paired peaks: 2593 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: start model_add_line... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: start X-correlation... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: end of X-cor \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: #2 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: #2 predicted fragment length is 46 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: #2 alternative fragment length(s) may be 46,110,567 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: #2.2 Generate R script for model : /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVCControle_model.r \r\n",
      "WARNING @ Fri, 06 Jan 2017 17:39:13: #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 @ Fri, 06 Jan 2017 17:39:13: #2 You may need to consider one of the other alternative d(s): 46,110,567 \r\n",
      "WARNING @ Fri, 06 Jan 2017 17:39:13: #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  @ Fri, 06 Jan 2017 17:39:13: #3 Call peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:39:13: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:42:32: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:44:09: #4 Write output xls file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVCControle_peaks.xls \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:44:09: #4 Write peak in narrowPeak format file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVCControle_peaks.narrowPeak \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:44:09: #4 Write summits bed file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2/sox9AVCControle_summits.bed \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:44:09: Done! \r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "pwd\n",
    "macs2 callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798.bam -c /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2  -n sox9AVCControle -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then again checked the amount of peaks called. As you can see, the amount of peaks called has decreased from 52848 to 15486 because the control file has filtered out false positives. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15486 sox9AVCControle_peaks.narrowPeak\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "wc -l sox9AVCControle_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the following commands we do the same for the limb samples as we have done for the AVC sample. We will call peaks two times: once without control samples and once with control samples."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb\n",
    "mkdir -p macs2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 278,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:17: \r\n",
      "# Command line: callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2 -n sox9limb -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = sox9limb\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799.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  @ Fri, 06 Jan 2017 17:46:17: #1 read tag files... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:17: #1 read treatment tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:17: Detected format is: BAM \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:17: * Input file is gzipped. \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:21:  1000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:25:  2000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:29:  3000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:33:  4000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:37:  5000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:41:  6000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:45:  7000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:49:  8000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:52:  9000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:55:  10000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:46:59:  11000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:03:  12000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:07:  13000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:11:  14000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:15:  15000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:19:  16000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:24:  17000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:28:  18000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:32:  19000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:36:  20000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:39:  21000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:43:  22000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:47:  23000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:51:  24000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:55:  25000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:47:59:  26000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:03:  27000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:07:  28000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:11:  29000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:15:  30000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:19:  31000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:23:  32000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:27:  33000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:31:  34000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:35:  35000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:39:  36000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:41:  37000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:44:  38000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:48:  39000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:52:  40000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:48:56:  41000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:00:  42000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:04:  43000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:08:  44000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:12:  45000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:17:  46000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:21:  47000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:25:  48000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:28:  49000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:33:  50000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:37:  51000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:41:  52000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:45:  53000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:49:  54000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:52:  55000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:49:56:  56000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:00:  57000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:04:  58000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:08:  59000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:12:  60000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:16:  61000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:20:  62000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:24:  63000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:28:  64000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:32:  65000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:36:  66000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:40:  67000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:45:  68000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:49:  69000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:52:  70000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:50:56:  71000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:00:  72000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:03:  73000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:06:  74000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:09:  75000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:12:  76000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:15:  77000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:17:  78000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:20:  79000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:23:  80000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:25:  81000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:27:  82000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:29:  83000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:33: #1 tag size is determined as 50 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:33: #1 tag size = 50 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:33: #1  total tags in treatment: 62110360 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:33: #1 user defined the maximum tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:33: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:34: #1  tags after filtering in treatment: 55849999 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:34: #1  Redundant rate of treatment: 0.10 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:34: #1 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:34: #2 Build Peak Model... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:34: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:39: #2 number of paired peaks: 1333 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:39: start model_add_line... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: start X-correlation... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: end of X-cor \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: #2 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: #2 predicted fragment length is 75 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: #2 alternative fragment length(s) may be 75 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: #2.2 Generate R script for model : /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limb_model.r \r\n",
      "WARNING @ Fri, 06 Jan 2017 17:51:40: #2 Since the d (75) calculated from paired-peaks are smaller than 2*tag length, it may be influenced by unknown sequencing problem! \r\n",
      "WARNING @ Fri, 06 Jan 2017 17:51:40: #2 You may need to consider one of the other alternative d(s): 75 \r\n",
      "WARNING @ Fri, 06 Jan 2017 17:51:40: #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  @ Fri, 06 Jan 2017 17:51:40: #3 Call peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:51:40: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:53:30: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:35: #4 Write output xls file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limb_peaks.xls \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:35: #4 Write peak in narrowPeak format file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limb_peaks.narrowPeak \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:35: #4 Write summits bed file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limb_summits.bed \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:35: Done! \r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "pwd\n",
    "macs2 callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2  -n sox9limb -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then determined the amount of peaks called by macs2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7948 sox9limb_peaks.narrowPeak\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "wc -l sox9limb_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then did a second peak calling on the limb sample but now with control samples."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 279,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:57: \r\n",
      "# Command line: callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799.bam -c /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2 -n sox9limbControle -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = sox9limbControle\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799.bam']\r\n",
      "# control file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.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  @ Fri, 06 Jan 2017 17:54:57: #1 read tag files... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:57: #1 read treatment tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:57: Detected format is: BAM \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:54:57: * Input file is gzipped. \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:01:  1000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:05:  2000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:09:  3000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:13:  4000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:17:  5000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:21:  6000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:26:  7000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:29:  8000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:32:  9000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:36:  10000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:40:  11000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:44:  12000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:48:  13000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:52:  14000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:55:56:  15000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:00:  16000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:05:  17000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:09:  18000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:13:  19000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:17:  20000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:21:  21000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:25:  22000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:29:  23000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:33:  24000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:37:  25000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:41:  26000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:45:  27000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:49:  28000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:53:  29000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:56:57:  30000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:01:  31000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:05:  32000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:09:  33000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:13:  34000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:17:  35000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:21:  36000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:24:  37000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:27:  38000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:31:  39000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:35:  40000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:39:  41000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:43:  42000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:47:  43000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:51:  44000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:57:56:  45000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:00:  46000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:04:  47000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:08:  48000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:12:  49000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:16:  50000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:20:  51000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:25:  52000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:29:  53000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:33:  54000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:36:  55000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:40:  56000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:44:  57000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:48:  58000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:52:  59000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:58:57:  60000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:01:  61000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:05:  62000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:09:  63000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:13:  64000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:17:  65000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:21:  66000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:26:  67000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:30:  68000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:34:  69000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:38:  70000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:42:  71000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:45:  72000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:49:  73000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:52:  74000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:55:  75000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 17:59:57:  76000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:00:  77000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:03:  78000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:05:  79000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:08:  80000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:11:  81000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:13:  82000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:15:  83000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:19: #1.2 read input tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:19: Detected format is: BAM \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:19: * Input file is gzipped. \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:23:  1000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:27:  2000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:31:  3000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:35:  4000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:40:  5000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:44:  6000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:48:  7000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:52:  8000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:56:  9000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:00:59:  10000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:02:  11000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:06:  12000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:09:  13000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:14:  14000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:18:  15000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:22:  16000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:26:  17000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:30:  18000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:34:  19000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:38:  20000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:43:  21000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:47:  22000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:51:  23000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:55:  24000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:01:59:  25000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:02:  26000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:07:  27000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:11:  28000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:15:  29000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:19:  30000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:23:  31000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:27:  32000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:31:  33000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:35:  34000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:39:  35000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:42:  36000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:46:  37000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:51:  38000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:55:  39000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:02:58:  40000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:03:  41000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:07:  42000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:11:  43000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:14:  44000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:17:  45000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:20:  46000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:24:  47000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:28:  48000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:32:  49000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:36:  50000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:40:  51000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:44:  52000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:49:  53000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:53:  54000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:03:57:  55000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:01:  56000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:05:  57000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:09:  58000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:13:  59000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:17:  60000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:22:  61000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:26:  62000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:30:  63000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:34:  64000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:38:  65000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:42:  66000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:45:  67000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:49:  68000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:53:  69000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:04:57:  70000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:01:  71000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:06:  72000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:10:  73000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:14:  74000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:18:  75000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:22:  76000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:26:  77000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:30:  78000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:34:  79000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:39:  80000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:43:  81000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:47:  82000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:51:  83000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:55:  84000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:05:59:  85000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:03:  86000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:07:  87000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:10:  88000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:13:  89000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:16:  90000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:19:  91000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:21:  92000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:24:  93000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:27:  94000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:29:  95000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:32:  96000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:35:  97000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:37:  98000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:39:  99000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:42:  100000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:45:  101000000 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:47: #1 tag size is determined as 50 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:47: #1 tag size = 50 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:47: #1  total tags in treatment: 62110360 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:47: #1 user defined the maximum tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:47: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:48: #1  tags after filtering in treatment: 55849999 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:48: #1  Redundant rate of treatment: 0.10 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:48: #1  total tags in control: 74893481 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:48: #1 user defined the maximum tags... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:48: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:50: #1  tags after filtering in control: 67875293 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:50: #1  Redundant rate of control: 0.09 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:50: #1 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:50: #2 Build Peak Model... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:50: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: #2 number of paired peaks: 1333 \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: start model_add_line... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: start X-correlation... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: end of X-cor \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: #2 finished! \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: #2 predicted fragment length is 75 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: #2 alternative fragment length(s) may be 75 bps \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: #2.2 Generate R script for model : /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limbControle_model.r \r\n",
      "WARNING @ Fri, 06 Jan 2017 18:06:55: #2 Since the d (75) calculated from paired-peaks are smaller than 2*tag length, it may be influenced by unknown sequencing problem! \r\n",
      "WARNING @ Fri, 06 Jan 2017 18:06:55: #2 You may need to consider one of the other alternative d(s): 75 \r\n",
      "WARNING @ Fri, 06 Jan 2017 18:06:55: #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  @ Fri, 06 Jan 2017 18:06:55: #3 Call peaks... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:06:55: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:11:39: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:14:21: #4 Write output xls file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limbControle_peaks.xls \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:14:21: #4 Write peak in narrowPeak format file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limbControle_peaks.narrowPeak \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:14:21: #4 Write summits bed file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2/sox9limbControle_summits.bed \r\n",
      "INFO  @ Fri, 06 Jan 2017 18:14:21: Done! \r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "pwd\n",
    "macs2 callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/SRR2479799.bam -c /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2  -n sox9limbControle -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next the amount of peaks is determined again. The amount of called peaks has decreased from 7948 to 4877 by using the control files to filter out false positives."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4877 sox9limbControle_peaks.narrowPeak\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "wc -l sox9limbControle_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 296,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\r\n",
      "NT_039247.2\t78931\t79068\tsox9limb_peak_1\t58\t.\t5.24696\t9.51248\t5.80235\t64\r\n",
      "NT_039257.4\t135028\t136204\tsox9limb_peak_2\t622\t.\t6.12638\t67.69081\t62.23330\t565\r\n",
      "NT_039257.4\t136278\t136496\tsox9limb_peak_3\t377\t.\t4.59856\t42.64519\t37.76172\t172\r\n",
      "NT_039257.4\t137679\t137895\tsox9limb_peak_4\t382\t.\t4.51395\t43.10199\t38.20818\t58\r\n",
      "NT_039257.4\t138803\t139177\tsox9limb_peak_5\t530\t.\t5.19123\t58.31994\t53.05914\t102\r\n",
      "NT_039257.4\t140814\t141012\tsox9limb_peak_6\t460\t.\t5.24723\t51.15353\t46.04527\t71\r\n",
      "NT_039257.4\t142563\t142700\tsox9limb_peak_7\t338\t.\t4.48069\t38.66857\t33.89186\t63\r\n",
      "NT_039257.4\t144792\t144900\tsox9limb_peak_8\t467\t.\t6.11834\t51.91118\t46.78747\t54\r\n",
      "NT_039257.4\t145044\t145517\tsox9limb_peak_9\t742\t.\t7.86744\t79.94833\t74.28191\t93\r\n",
      "NT_039257.4\t146669\t146770\tsox9limb_peak_10\t377\t.\t5.85187\t42.59619\t37.71386\t60\r\n"
     ]
    }
   ],
   "source": [
    "pwd\n",
    "head sox9limb_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then converted the peaks.narrowPeak files into bed files so they could be loaded into IGV. We first used head to determine which columns we needed to conserve into the bed file. We need to conserve the first four columns. The first column is the name of the chromosome, the second column is the start of the peak, third column is the end position of the peak and the fourth column is the name of the peak."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 281,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NT_039195.1\t1095\t1162\tsox9AVC_peak_1\t64\t.\t6.83351\t10.17349\t6.43060\t28\r\n",
      "NT_039195.1\t136741\t136787\tsox9AVC_peak_2\t51\t.\t6.07423\t8.71880\t5.13959\t13\r\n",
      "NT_039223.3\t19614\t19660\tsox9AVC_peak_3\t51\t.\t6.07423\t8.71880\t5.13959\t26\r\n",
      "NT_039223.3\t287225\t287271\tsox9AVC_peak_4\t51\t.\t6.07423\t8.71880\t5.13959\t41\r\n",
      "NT_039223.3\t324155\t324201\tsox9AVC_peak_5\t39\t.\t5.31495\t7.31485\t3.95571\t8\r\n",
      "NT_039247.2\t78934\t79096\tsox9AVC_peak_6\t257\t.\t15.97444\t30.52283\t25.71295\t28\r\n",
      "NT_039248.1\t252817\t252866\tsox9AVC_peak_7\t106\t.\t9.11135\t14.79398\t10.69148\t10\r\n",
      "NT_039256.1\t45543\t45590\tsox9AVC_peak_8\t51\t.\t6.07423\t8.71880\t5.13959\t25\r\n",
      "NT_039256.1\t107149\t107197\tsox9AVC_peak_9\t77\t.\t7.59279\t11.67366\t7.79515\t21\r\n",
      "NT_039257.4\t68154\t68204\tsox9AVC_peak_10\t64\t.\t6.83351\t10.17349\t6.43060\t29\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "head sox9AVC_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 282,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "cat sox9AVC_peaks.narrowPeak | cut -f 1-4 > sox9AVC_peaks.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 284,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "cat sox9limb_peaks.narrowPeak | cut -f 1-4 > sox9limb_peaks.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "cat sox9AVCControle_peaks.narrowPeak | cut -f 1-4 > sox9AVCControle_peaks.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 286,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "cat sox9limbControle_peaks.narrowPeak | cut -f 1-4 > sox9limbControle_peaks.bed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now have bed files that only contain the first four columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 283,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NT_039195.1\t1095\t1162\tsox9AVC_peak_1\r\n",
      "NT_039195.1\t136741\t136787\tsox9AVC_peak_2\r\n",
      "NT_039223.3\t19614\t19660\tsox9AVC_peak_3\r\n",
      "NT_039223.3\t287225\t287271\tsox9AVC_peak_4\r\n",
      "NT_039223.3\t324155\t324201\tsox9AVC_peak_5\r\n",
      "NT_039247.2\t78934\t79096\tsox9AVC_peak_6\r\n",
      "NT_039248.1\t252817\t252866\tsox9AVC_peak_7\r\n",
      "NT_039256.1\t45543\t45590\tsox9AVC_peak_8\r\n",
      "NT_039256.1\t107149\t107197\tsox9AVC_peak_9\r\n",
      "NT_039257.4\t68154\t68204\tsox9AVC_peak_10\r\n"
     ]
    }
   ],
   "source": [
    "head sox9AVC_peaks.bed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will use this bed files later to look at our peaks in IGV. First we'll perform a GREAT analysis of the peaks."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GREAT analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "GREAT allows to determine biological processes that are connected to the peaks determined in ChIP sequencing. We first have to remove the NT and NW lines of our bed files because GREAT does not recognize this and will not the process the files.\n",
    "\n",
    "GREAT was also not recognizing the chromosome names used in this file (the NC names to be exactly). \n",
    "\n",
    "To solve this we go to the STAR folder (path:/mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR) and click on the chrName.txt file. Here we then changed all the NC numbers into the correct chromosomes using the identifier on https://www.ncbi.nlm.nih.gov/genome/?term=mus+musculus. We then had to perform all the above steps again to obtain the correct chromosome identifier."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 297,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NT_039195.1\t1100\t1146\tsox9AVCControle_peak_1\r\n",
      "NT_039247.2\t78936\t79095\tsox9AVCControle_peak_2\r\n",
      "NT_039248.1\t252817\t252865\tsox9AVCControle_peak_3\r\n",
      "NT_039257.4\t135025\t136207\tsox9AVCControle_peak_4\r\n",
      "NT_039257.4\t136275\t136510\tsox9AVCControle_peak_5\r\n",
      "NT_039257.4\t137673\t137897\tsox9AVCControle_peak_6\r\n",
      "NT_039257.4\t138800\t139325\tsox9AVCControle_peak_7\r\n",
      "NT_039257.4\t140793\t141012\tsox9AVCControle_peak_8\r\n",
      "NT_039257.4\t142561\t142704\tsox9AVCControle_peak_9\r\n",
      "NT_039257.4\t143691\t143849\tsox9AVCControle_peak_10\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/macs2\n",
    "head sox9AVCControle_peaks.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 304,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "grep -v \"NT\" sox9AVCControle_peaks.bed > sox9AVCControle_peaksgrep.bed "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 306,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NW_004058051.1\t4089\t4154\tsox9AVCControle_peak_523\r\n",
      "NW_004058051.1\t29038\t29117\tsox9AVCControle_peak_524\r\n",
      "NW_004058051.1\t29221\t29275\tsox9AVCControle_peak_525\r\n",
      "NW_004058053.1\t142510\t142556\tsox9AVCControle_peak_526\r\n",
      "NW_004450263.1\t212967\t213013\tsox9AVCControle_peak_527\r\n",
      "NW_004450263.1\t294202\t294250\tsox9AVCControle_peak_528\r\n",
      "NW_004450263.1\t476588\t476638\tsox9AVCControle_peak_529\r\n",
      "NW_004450263.1\t486947\t486993\tsox9AVCControle_peak_530\r\n",
      "NW_004450263.1\t730720\t730766\tsox9AVCControle_peak_531\r\n",
      "NW_006763129.1\t142985\t143036\tsox9AVCControle_peak_532\r\n"
     ]
    }
   ],
   "source": [
    "head sox9AVCControle_peaksgrep.bed "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 307,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "grep -v \"NW\" sox9AVCControle_peaksgrep.bed > sox9AVCControle_peaksgrep2.bed "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 308,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chr1\t3015811\t3015857\tsox9AVCControle_peak_551\r\n",
      "chr1\t3041287\t3041353\tsox9AVCControle_peak_552\r\n",
      "chr1\t3043189\t3043249\tsox9AVCControle_peak_553\r\n",
      "chr1\t3139059\t3139111\tsox9AVCControle_peak_554\r\n",
      "chr1\t3241581\t3241638\tsox9AVCControle_peak_555\r\n",
      "chr1\t3440727\t3440776\tsox9AVCControle_peak_556\r\n",
      "chr1\t3715894\t3715965\tsox9AVCControle_peak_557\r\n",
      "chr1\t3764919\t3764965\tsox9AVCControle_peak_558\r\n",
      "chr1\t3767731\t3767778\tsox9AVCControle_peak_559\r\n",
      "chr1\t3768768\t3768819\tsox9AVCControle_peak_560\r\n"
     ]
    }
   ],
   "source": [
    "head sox9AVCControle_peaksgrep2.bed "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then did the same for the second file but now we did everything in one command."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/limb/macs2\n",
    "grep -v \"NT\" sox9limbControle_peaks.bed | grep -v \"NW\" > sox9limbControle_peaksgrep2.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 312,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chr1\t9564522\t9564679\tsox9limbControle_peak_66\r\n",
      "chr1\t10037881\t10038177\tsox9limbControle_peak_67\r\n",
      "chr1\t11774853\t11774976\tsox9limbControle_peak_68\r\n",
      "chr1\t12000626\t12000891\tsox9limbControle_peak_69\r\n",
      "chr1\t12192818\t12192954\tsox9limbControle_peak_70\r\n",
      "chr1\t12644765\t12644871\tsox9limbControle_peak_71\r\n",
      "chr1\t12692906\t12693022\tsox9limbControle_peak_72\r\n",
      "chr1\t12836210\t12836320\tsox9limbControle_peak_73\r\n",
      "chr1\t13771092\t13771193\tsox9limbControle_peak_74\r\n",
      "chr1\t14513616\t14513759\tsox9limbControle_peak_75\r\n"
     ]
    }
   ],
   "source": [
    "head sox9limbControle_peaksgrep2.bed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see, we now have to bed files that contain lines that GREAT will be able to read. The NT and NW lines have been removed and the NC lines have been converted to the correct chromosome name. We proceeded to upload both bed files to see which processes were linked to the peaks. \n",
    "\n",
    "The sox9limbControle_peaksgrep2.bed contains the peaks called in limb mesenchyme and shows results that match with what we know about sox9. As you can see the sox9 peaks in the limb are connected to processes such as cartilage development, limb development, gliogenesis and chondrocyt differentation. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/limb/2017-01-09 (5).png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unfortunately we did not find anything for sox9AVCControle_peaksgrep2.bed because there were to many peaks according to the site. Also remember that this was the fasta file with the overall very bad quality. In the next part we tried to improve the quality of this fastq file to re-run the MACS peak calling.\n",
    "\n",
    "Using the following command we filter sequences of which 80% of the bases have a quality score of 30 or higher. This will allow us to increase the per base sequence quality."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 336,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fastq_quality_filter: failed to open input file 'SRR2479798_1.fastq': No such file or directory\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "fastq_quality_filter -q 30 -p 80 -i SRR2479798_1.fastq -o SRR2479798_1.filtered.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 324,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479798_1.filtered.fastq\r\n",
      "Approx 5% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 10% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 15% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 20% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 25% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 30% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 35% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 40% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 45% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 50% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 55% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 60% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 65% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 70% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 75% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 80% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 85% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 90% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 95% complete for SRR2479798_1.filtered.fastq\r\n",
      "Approx 100% complete for SRR2479798_1.filtered.fastq\r\n",
      "Analysis complete for SRR2479798_1.filtered.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798_1.filtered.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see the per base sequence quality is much better but now we seem to have a lot of duplicated sequences. We thought about using fastx_collapser to remove duplicated sequences but this also converts the fastq file into a fasta upon which it impossible to apply fastq quality control. We therefore filtered the original fastq files again but with a lower threshhold (24) in the hope of obtaining high quality reads with a lower percentage of replicated sequences."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/AVC/30.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the next command, we filter the original fastq file again but now we apply a less strict filter of 24 instead of 30 which we used during the first filter step."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 339,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "fastq_quality_filter -q 24 -p 80 -i SRR2479798_1.fastq -o SRR2479798_1.filtered24.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 343,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of SRR2479798_1.filtered24.fastq\r\n",
      "Approx 5% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 10% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 15% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 20% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 25% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 30% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 35% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 40% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 45% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 50% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 55% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 60% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 65% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 70% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 75% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 80% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 85% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 90% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Approx 95% complete for SRR2479798_1.filtered24.fastq\r\n",
      "Analysis complete for SRR2479798_1.filtered24.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC\n",
    "/usr/local/bin/FastQC/fastqc /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798_1.filtered24.fastq -o /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The per base sequence quality is good but there is still a problem with the sequence duplication levels. We choose the continue working with SRR2479798_1.filtered24.fastq because it has the lowest duplication level. We had thought about fastx_collapser to remove duplicated sequences but this also converts the fastq file into a fasta upon which it impossible to apply fastq quality control."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/AVC/24.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We made a new folder in which we stored the output of the AVC sample after it has been filtered."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 326,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq\n",
    "mkdir -p AVC_Filtered"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 345,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\r\n",
      "Jan 09 16:51:48 ..... started STAR run\r\n",
      "Jan 09 16:51:48 ..... loading genome\r\n",
      "Jan 09 16:55:19 ..... started mapping\r\n",
      "Jan 09 17:20:49 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\n",
    "pwd\n",
    "STAR --genomeDir /mnt/storage/r0305394/jupyternotebooks/groepswerk/STAR --runThreadN 4 --readFilesIn /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC/SRR2479798_1.filtered24.fastq  --outFileNamePrefix SRR2479798_1.filtered24"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We converted the sam file into a bam using samtools."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 346,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 26 files...\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\n",
    "samtools sort -o SRR2479798_1.filtered24.bam SRR2479798_1.filtered24Aligned.out.sam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then generated an index file in orde to be able to read the bam file in IGV. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 347,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index SRR2479798_1.filtered24.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then performed another peak calling but this time we use the filtered fastq file of the AVC."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 348,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:28: \r\n",
      "# Command line: callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/SRR2479798_1.filtered24.bam -c /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered -n sox9AVCFilter24 -g mm -q 0.01\r\n",
      "# ARGUMENTS LIST:\r\n",
      "# name = sox9AVCFilter24\r\n",
      "# format = AUTO\r\n",
      "# ChIP-seq file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/SRR2479798_1.filtered24.bam']\r\n",
      "# control file = ['/mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.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  @ Mon, 09 Jan 2017 17:38:28: #1 read tag files... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:28: #1 read treatment tags... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:28: Detected format is: BAM \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:28: * Input file is gzipped. \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:32:  1000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:36:  2000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:39:  3000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:43:  4000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:47:  5000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:50:  6000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:54:  7000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:38:58:  8000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:01:  9000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:05:  10000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:08:  11000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:11:  12000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:15:  13000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:18:  14000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:22:  15000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:26:  16000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:29:  17000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:33:  18000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:37:  19000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:41:  20000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:44:  21000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:48:  22000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:51:  23000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:55:  24000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:39:58:  25000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:02:  26000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:06:  27000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:09:  28000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:13:  29000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:17:  30000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:20:  31000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:24:  32000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:28:  33000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:31:  34000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:35:  35000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:38:  36000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:41:  37000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:45:  38000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:48:  39000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:52:  40000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:56:  41000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:40:59:  42000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:03:  43000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:07:  44000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:10:  45000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:13:  46000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:15:  47000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:19:  48000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:22:  49000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:26:  50000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:30:  51000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:34:  52000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:38:  53000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:41:  54000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:45:  55000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:49:  56000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:53:  57000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:41:56:  58000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:00:  59000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:03:  60000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:07:  61000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:11:  62000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:14:  63000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:18:  64000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:22:  65000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:25:  66000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:29:  67000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:32:  68000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:35:  69000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:39:  70000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:43:  71000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:46:  72000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:50:  73000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:54:  74000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:42:58:  75000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:01:  76000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:05:  77000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:09:  78000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:12:  79000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:16:  80000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:20:  81000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:23:  82000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:27:  83000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:31:  84000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:34:  85000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:38:  86000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:41:  87000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:45:  88000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:48:  89000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:52:  90000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:55:  91000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:43:58:  92000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:00:  93000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:03:  94000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:06:  95000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:08:  96000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:10:  97000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:13:  98000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:16:  99000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:18:  100000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:20:  101000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:22:  102000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:24:  103000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:27:  104000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:29: #1.2 read input tags... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:29: Detected format is: BAM \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:29: * Input file is gzipped. \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:33:  1000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:38:  2000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:42:  3000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:46:  4000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:50:  5000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:54:  6000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:44:58:  7000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:03:  8000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:07:  9000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:10:  10000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:13:  11000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:16:  12000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:20:  13000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:24:  14000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:28:  15000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:32:  16000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:36:  17000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:40:  18000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:44:  19000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:48:  20000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:52:  21000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:45:56:  22000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:00:  23000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:04:  24000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:07:  25000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:11:  26000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:15:  27000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:19:  28000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:23:  29000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:27:  30000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:31:  31000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:35:  32000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:39:  33000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:43:  34000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:47:  35000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:51:  36000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:55:  37000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:46:59:  38000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:03:  39000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:07:  40000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:11:  41000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:15:  42000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:19:  43000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:22:  44000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:25:  45000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:27:  46000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:31:  47000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:35:  48000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:40:  49000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:44:  50000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:48:  51000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:52:  52000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:47:56:  53000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:00:  54000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:05:  55000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:09:  56000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:13:  57000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:17:  58000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:21:  59000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:25:  60000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:29:  61000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:33:  62000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:37:  63000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:41:  64000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:45:  65000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:48:  66000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:51:  67000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:55:  68000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:48:59:  69000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:03:  70000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:07:  71000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:11:  72000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:15:  73000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:20:  74000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:24:  75000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:28:  76000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:31:  77000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:36:  78000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:40:  79000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:44:  80000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:48:  81000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:53:  82000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:49:57:  83000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:01:  84000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:04:  85000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:08:  86000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:12:  87000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:15:  88000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:18:  89000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:21:  90000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:23:  91000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:26:  92000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:29:  93000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:32:  94000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:34:  95000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:37:  96000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:40:  97000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:42:  98000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:44:  99000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:46:  100000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:49:  101000000 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:52: #1 tag size is determined as 50 bps \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:52: #1 tag size = 50 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:52: #1  total tags in treatment: 78590830 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:52: #1 user defined the maximum tags... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:52: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:54: #1  tags after filtering in treatment: 5992296 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:54: #1  Redundant rate of treatment: 0.92 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:54: #1  total tags in control: 74893481 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:54: #1 user defined the maximum tags... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:54: #1 filter out redundant tags at the same location and the same strand by allowing at most 1 tag(s) \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:55: #1  tags after filtering in control: 67875293 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:55: #1  Redundant rate of control: 0.09 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:55: #1 finished! \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:55: #2 Build Peak Model... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:55: #2 looking for paired plus/minus strand peaks... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: #2 number of paired peaks: 2598 \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: start model_add_line... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: start X-correlation... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: end of X-cor \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: #2 finished! \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: #2 predicted fragment length is 46 bps \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: #2 alternative fragment length(s) may be 46,128 bps \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: #2.2 Generate R script for model : /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/sox9AVCFilter24_model.r \r\n",
      "WARNING @ Mon, 09 Jan 2017 17:50: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 @ Mon, 09 Jan 2017 17:50:56: #2 You may need to consider one of the other alternative d(s): 46,128 \r\n",
      "WARNING @ Mon, 09 Jan 2017 17:50: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  @ Mon, 09 Jan 2017 17:50:56: #3 Call peaks... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:50:56: #3 Pre-compute pvalue-qvalue table... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:55:03: #3 Call peaks for each chromosome... \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:56:55: #4 Write output xls file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/sox9AVCFilter24_peaks.xls \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:56:55: #4 Write peak in narrowPeak format file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/sox9AVCFilter24_peaks.narrowPeak \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:56:55: #4 Write summits bed file... /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/sox9AVCFilter24_summits.bed \r\n",
      "INFO  @ Mon, 09 Jan 2017 17:56:55: Done! \r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\n",
    "pwd\n",
    "macs2 callpeak -t /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered/SRR2479798_1.filtered24.bam -c /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/controle/SRR2479800.bam --outdir /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered  -n sox9AVCFilter24 -g mm -q 0.01"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see the AVC sample has lot less peaks compared to the sample that was not filtered. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 353,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1092 sox9AVCFilter24_peaks.narrowPeak\r\n"
     ]
    }
   ],
   "source": [
    "wc -l sox9AVCFilter24_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The file is then converted into a bed file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 349,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\n",
    "cat sox9AVCFilter24_peaks.narrowPeak | cut -f 1-4 > sox9AVCFilter24_peaks.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NT_039247.2\t78960\t79057\tsox9AVCFilter24_peak_1\r\n",
      "NT_039257.4\t135051\t136004\tsox9AVCFilter24_peak_2\r\n",
      "NT_039257.4\t136146\t136208\tsox9AVCFilter24_peak_3\r\n",
      "NT_039257.4\t136286\t136358\tsox9AVCFilter24_peak_4\r\n",
      "NT_039257.4\t136410\t136489\tsox9AVCFilter24_peak_5\r\n",
      "NT_039257.4\t137674\t137899\tsox9AVCFilter24_peak_6\r\n",
      "NT_039257.4\t138800\t139136\tsox9AVCFilter24_peak_7\r\n",
      "NT_039257.4\t139252\t139325\tsox9AVCFilter24_peak_8\r\n",
      "NT_039257.4\t140794\t141012\tsox9AVCFilter24_peak_9\r\n",
      "NT_039257.4\t142559\t142706\tsox9AVCFilter24_peak_10\r\n"
     ]
    }
   ],
   "source": [
    "cd /mnt/storage/r0305394/jupyternotebooks/groepswerk/ChIPseq/AVC_Filtered\n",
    "head sox9AVCFilter24_peaks.bed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the following command, we removed the NT and NW lines out of bed files. These lines prevent GREAT from running an analysis. Since the lines with chromosomes are kept this doesn't influence the results that much. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 350,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "grep -v \"NT\" sox9AVCFilter24_peaks.bed | grep -v \"NW\" > sox9AVCFilter24_peaksgrep2.bed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 352,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chr1\t8828433\t8828479\tsox9AVCFilter24_peak_187\r\n",
      "chr1\t9021840\t9021886\tsox9AVCFilter24_peak_188\r\n",
      "chr1\t10037889\t10037987\tsox9AVCFilter24_peak_189\r\n",
      "chr1\t10105763\t10105809\tsox9AVCFilter24_peak_190\r\n",
      "chr1\t12644761\t12644846\tsox9AVCFilter24_peak_191\r\n",
      "chr1\t17014076\t17014143\tsox9AVCFilter24_peak_192\r\n",
      "chr1\t23146780\t23146860\tsox9AVCFilter24_peak_193\r\n",
      "chr1\t31129934\t31129982\tsox9AVCFilter24_peak_194\r\n",
      "chr1\t37063233\t37063284\tsox9AVCFilter24_peak_195\r\n",
      "chr1\t38757840\t38757911\tsox9AVCFilter24_peak_196\r\n"
     ]
    }
   ],
   "source": [
    "head sox9AVCFilter24_peaksgrep2.bed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For some reason that is unknown to us, GREAT also gives us nothing when we upload the filtered AVC file. It is possible that the filtering was to harsh and filtered away most of the results. In the following part we use IGV to analyze our peaks. This will allow us to say something about the peaks in the AVC sample, the sample that did not give us in results in GREAT."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# IGV analysis of the peaks "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now have three bed files containing the peaks: 2 files with peaks in the AVC (without filter and with filter) and 1 file with peaks in the limb mesenchyme. We can now upload these files in IGV together with their corresponding bam files to study the peaks in IGV. \n",
    "\n",
    "The top three lines are our bam files:\n",
    "1. SRR247979.bam (= AVC file without filtering)\n",
    "2. SRR2479798_1.filtered24.bam (= AVC file with filtering)\n",
    "3. SRR2479799.bam (= limb mesenchyme file)\n",
    "\n",
    "The bottom three lines represent the bed fils containing the peaks:\n",
    "1. sox9AVCControle_peaks.bed (= peaks from the AVC file without filtering)\n",
    "2. sox9AVCFilter24_peaks.bed (= peaks from the AVC file with filtering)\n",
    "3. sox9limbControle_peaks.bed (= peaks from the limb file)\n",
    "\n",
    "As you can see the filtered AVC file shows a lot less peaks than the unfiltered AVC file. The limb file also contains a lot less peaks than the unfiltered AVC file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/IGV_overview.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the paper, the researchers mentioned several genes that have peaks. Although we have used a different mapping method (STAR) and a different genome (mm10), we first decided to see whether we were able to see peaks that are mentioned in the paper. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first gene that we are going to look at is Cops5 also known as Jab1. It has been shown that a loss of Cops5 leads to shortened limbs and this is the result of impaired chondrogenesis. This loss of Cops5 resulted in a decreased expression of several genes including sox9 indicating some sort of relationship between sox9 and cops5 important for bone development (https://www.ncbi.nlm.nih.gov/pubmed/24604556). As you can see in the image below, there are peaks in all of our bed files at the transcriptional site of Cops5. This shows us that sox9 binds this site and regulates the expression of Cops5 in both heart and limb."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/IGV_Cops5.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The next gene we looked at is Srpk2. This gene can promote cell proliferation and regulates progression of cell cycle (https://www.ncbi.nlm.nih.gov/pubmed/19592491). Again we can see peaks in all samples located at transcription site of Srpk2 indicating that sox9 regulates the expression of this gene in both heart and limb mesenchyme. This is also indicates that sox9 is an regulator of cell proliferation and cell cycle progression."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/IGV_srpk2.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another gene that was checked is Fols1. This gene generates a protein that is part of the AP-1 complex. This complex has a role in cell proliferation and cell survival (https://www.ncbi.nlm.nih.gov/pubmed/20060892). Again we see peaks in all samples that are located at the transcription site of Fosl1. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/IGV_Fosl1.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Several other genes that have been implicated in cell proliferation also had peaks in their transcriptional start site such as Eed, Hdac2, Trp53 (data not shown). Together with the data shown above, this indicates that Sox9 is an important regulator of cell proliferation. Moreover this function doesn't seem to be confined to a specific tissue as peaks were seen in both the heart (AVC) and limb. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Based on the GREAT analysis of the limb, we know that the peaks are associated with limb development and chondrogenesis. It has been shown that Sox9 regulates sox6 to regulate target genes in the developing limb (https://www.ncbi.nlm.nih.gov/pubmed/?term=L-sox5+and+sox+6+drive+expression). We therefore looked if we could find any peaks in sox6 to demonstrate that sox9 regulates sox6. We able to identify several peaks in sox6 in the limb showing that this gene has several binding locations for sox9."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/sox6_peaks.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another thing we did was to check for peaks in some of the genes that were downregulated (as shown in the RNA sequencing; see image below)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/Rnaseq/Image/Heart_and_bones.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We first looked at Papss2. There are several peaks in the limb. However these peaks are not located close to a transcriptional start site. It is possible that sox9 has no effect on the transciptional start of this gene but influences the elongation or splicing."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/Papps2_IGV.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another gene we checked is Col9a1. This gene is important for cartilage development. As you can see we have two peaks in Col9a1. These peaks are located between exon 7 and 8 and between exon 29-30."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/Col9a1_IGV.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also checked for peaks for Twist1. Twist1 plays an important role in heart valve development. unfortunately our data did not show any peaks for Twist although the researchers describe finding peaks in their data. Based on our data we would have to conclude that the decreased Twist1 expression we saw in the sox9KO (RNa sequencing data) is not due to a direct effect of sox9 on Twist1. It seems that sox9 regulates the expression of Twist 1 in an indirect way by downregulating an unknown transcription factor x which in turn influences Twist1 expression. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/Twist1_IGV.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also checked peaks for some other important TF mentioned earlier such as Mecom, Pitx2 and Hand2 (data not shown).\n",
    "\n",
    "Mecom had two peaks: one peak in the AVC (without filtering) and one in the limb. This peak wasn't there in the AVC (with filtering) meaning that the filter step removed the peak. \n",
    "\n",
    "We did not find any peaks in Pitx2 or Hand2. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Motif discovery"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another thing that can be done now that we have the bed files, is motif discovery to look at the binding motifs of sox9 in AVC and limb. To do this we first have to use fetch-sequence to the data of the bed file into a fasta file. This tool skipped the NT and NW files but since these files are only small areas we chose to go ahead and work with the fasta file only containing the chromosomes. After obtaining the faste files for both the AVC and limb we uploaded these to http://rsat-tagc.univ-mrs.fr/. \n",
    "\n",
    "We determined the binding motifs in AVC (before and after filtering) and limb."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will first take a look at the output generated by RSAT from the AVC file without filtering (AVCControle). RSAT gave us 20 motifs. The first 10 are shown in the image below. (http://rsat-tagc.univ-mrs.fr/rsat/tmp/www-data/2017/01/13/peak-motifs.2017-01-13.184048_2017-01-13.184048_BquuLv/peak-motifs_synthesis.html#discovered_motifs_10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/AVC/peaks_AVCControle.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then determined binding motifs for sox9 in the AVC file with filtering (ACVFilter24). RSAT give us 18 motifs of which the first 10 are shown below. (http://rsat-tagc.univ-mrs.fr/rsat/tmp/www-data/2017/01/13/peak-motifs.2017-01-13.190817_2017-01-13.190817_6qhObS/peak-motifs_synthesis.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/AVC/peaks_AVCFilter24.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then looked at the binding motifs for sox9 in the limb mesenchyme. RSAT was able to find 20 motifs. The first 10 are shown below. (http://rsat-tagc.univ-mrs.fr/rsat/tmp/www-data/2017/01/13/peak-motifs.2017-01-13.192155_2017-01-13.192155_3OccKz/peak-motifs_synthesis.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"100%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/limb/peaks_sox9limb.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that we have binding motifs of all of our samples, we first decided to compare what we found with what the researcher found in their paper. In the paper they show two binding motifs that they found: SOX monomer motif and SOX dimer motif. They do no mention if these binding motifs were found in the limb or in the AVC or in both. The binding motifs mentioned in the paper are shown in the image below."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/BindingMotifPaper.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then checked the binding motifs we had found to see if any were the same. We did not find any match for the SOX monomer motif in our AVCControle and AVCFilter24 samples. We did however find a motif similar to the SOX monomer motif in the limbControle sample. As you can see the motif belows, which was obtained from the limb mesenchyme, shows big similarities with SOX monomer motif. They both have AACAAAG motif. Moreover motif 5, 6 and 9 showed the same similar motif."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/BindingMotifLimbMatch.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The limb mesenchyme had another predicted motif binding site that was similar to the SOX monomer. As you can see this limb binding motif (image below) shares the AACAATG binding motif with the SOX monomer. Moreover motif 7 and 8 showed the same similar motif."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0305394/files/groepswerk/ChIPseq/Limb_binding_Motif_Match2.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We were unable to verify the SOX dimer binding motif in our samples as none of the predicted binding motifs that we found showed a dimer pattern. We also checked for identical binding motifs in the AVC and limb. We did not find any which leads us to the conclusion that based on our data is seems that SOX9 has different binding motifs in different tissues. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In conclusion, we were able to show the role of sox9 in the limb as we discovered several peaks linked to functions such as cartilage development, chondorocyte differentation and bone development. However we were unable to find similar results in the AVC sample. \n",
    "\n",
    "IGV allowed us to check the peaks in the AVC samples. We were able to confirm some results obtained in the paper but we did not find any peaks for the important genes involved in heart development such as Twist1, Pitx2, Hand2 and Sox4.\n",
    "\n",
    "Motif discovery also showed no similar binding motifs in the limb and heart leading us to the conclusion that sox9 binds different motifs depending on the tissue."
   ]
  }
 ],
 "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
}
