{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# REST ChIP-seq analyse\n",
    "dataset: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE49570"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "mkdir ~/data/ncbi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "vdb-config -s /repository/user/main/public/root=~/data/ncbi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "mkdir ~/data/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "cd ~/data/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# download REST_ChIPSeq\n",
    "fastq-dump --split-files SRR948187"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#aligneer de reads van fastq file tov het referentiegenoom\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 SRR948187_1.fastq -S ChIP_REST.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#converteer naar bam file\n",
    "samtools view -S -b ChIP_REST.sam > ChIP_REST.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#sorteer en indexeer bam file\n",
    "samtools sort -O bam -o ChIP_REST.sorted.bam ChIP_REST.bam \n",
    "samtools index ChIP_REST.sorted.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# download input DNA\n",
    "fastq-dump --split-files SRR948188"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#aligneer de reads van fastq file tov het referentiegenoom\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 SRR948188_1.fastq -S Input_DNA.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#converteer naar bam file\n",
    "samtools view -S -b Input_DNA.sam > Input_DNA.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#sorteer en indexeer bam file\n",
    "samtools sort -O bam -o Input_DNA.sorted.bam Input_DNA.bam \n",
    "samtools index Input_DNA.sorted.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#bepalen van significante pieken (commando werd ook aangepast naar q = 0.05 ter vergelijking)\n",
    "macs2 callpeak -t  ChIP_REST.sorted.bam -c Input_DNA.sorted.bam --outdir macs2_REST -n REST -g mm -q 0.0005"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ls macs2_REST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "head macs2_REST/REST_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#tellen van aantal pieken\n",
    "wc -l macs2_REST/REST_peaks.narrowPeak"
   ]
  }
 ],
 "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
}
