{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "**Bioinformatics project academic year 2016-17 2nd Master Biomedical Sciences**\n",
    "\n",
    "Helena Crijns (r0309026)\n",
    "\n",
    "Marianna Decet (r0611267)\n",
    "\n",
    "Carmen Escalona (r0610932)\n",
    "\n",
    "Paper: Beane et al., 2011. https://www.ncbi.nlm.nih.gov/pubmed/?term=beane+characterizing+the+impact+of+smoking+and+lung+cancer\n",
    "\n",
    "Data set: \n",
    "\n",
    "-RNAseq https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE29006\n",
    "\n",
    "-microarray https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE28835\n",
    "\n",
    "The epithelial cells of the respiratory tract are damaged by cigarette smoking. By using microarray technology, alterations in smoking-related gene and miRNA expression have been found in the cytologically normal airway epithelium. In the epithelia of the nose and mouth of smokers, similar gene expression alterations have also been detected. Moreover, it has been shown that the airway transcriptome is significantly altered by lung cancer. \n",
    "Beane et al. used RNA-seq, microarrays and qRT-PCR to investigate the changes related to smoking and lung cancer in both the airway transcriptome and gene expression. The aim of their project was to compare the results obtained by DNA microarray and by RNA-Seq in order to detect the alterations in the gene transcription and expression that can be linked to lung cancer and cigarette smoke-induced damage. Furthermore, the authors compared two different approaches for RNA sequencing: a prototype NuGEN Ovation protocol and a standard Illumina mRNA-Seq protocol. \n",
    "In our case we chose to work with the samples generated from the Illumina protocol because, despite the NuGEN protocol is able to capture both polyadenylated and non-adenylated RNA, the Illumina protocol has a higher accuracy in quantifying gene expression levels. With the generated data on differential expression we performed functional analysis.\n",
    "Furthermore, we analyzed the microarray data obtained by hybridization of RNA, isolated from bronchial airway epithelium from smokers with and without cancer, to Affymetrix HGU133A 2.0 microarrays. We compared these results to those obtained by RNA-sequencing. \n",
    "\n",
    "Legenda:\n",
    "\n",
    "NS= never smoker\n",
    "S= healthy smoker\n",
    "NC= smoker with benign disease\n",
    "C= smoker with cancer\n",
    "\n",
    "Location of ipynb files: /mnt/storage/r0611267/jupyternotebooks/PROJECT "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0611267/work\r\n"
     ]
    }
   ],
   "source": [
    "#Create working directory and move into it\n",
    "mkdir -p /mnt/storage/r0611267/work\n",
    "cd /mnt/storage/r0611267/work\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 28216213 spots for SRR192333\r\n",
      "Written 28216213 spots for SRR192333\r\n"
     ]
    }
   ],
   "source": [
    "#Download files for RNAseq analysis\n",
    "fastq-dump --split-files SRR192333"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 17242781 spots for SRR192334\r\n",
      "Written 17242781 spots for SRR192334\r\n"
     ]
    }
   ],
   "source": [
    "fastq-dump --split-files SRR192334"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 22255836 spots for SRR192335\r\n",
      "Written 22255836 spots for SRR192335\r\n"
     ]
    }
   ],
   "source": [
    "fastq-dump --split-files SRR192335"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 20930670 spots for SRR192336\r\n",
      "Written 20930670 spots for SRR192336\r\n"
     ]
    }
   ],
   "source": [
    "fastq-dump --split-files SRR192336"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of NS1.fastq\r\n",
      "Approx 5% complete for NS1.fastq\r\n",
      "Approx 10% complete for NS1.fastq\r\n",
      "Approx 15% complete for NS1.fastq\r\n",
      "Approx 20% complete for NS1.fastq\r\n",
      "Approx 25% complete for NS1.fastq\r\n",
      "Approx 30% complete for NS1.fastq\r\n",
      "Approx 35% complete for NS1.fastq\r\n",
      "Approx 40% complete for NS1.fastq\r\n",
      "Approx 45% complete for NS1.fastq\r\n",
      "Approx 50% complete for NS1.fastq\r\n",
      "Approx 55% complete for NS1.fastq\r\n",
      "Approx 60% complete for NS1.fastq\r\n",
      "Approx 65% complete for NS1.fastq\r\n",
      "Approx 70% complete for NS1.fastq\r\n",
      "Approx 75% complete for NS1.fastq\r\n",
      "Approx 80% complete for NS1.fastq\r\n",
      "Approx 85% complete for NS1.fastq\r\n",
      "Approx 90% complete for NS1.fastq\r\n",
      "Approx 95% complete for NS1.fastq\r\n",
      "Analysis complete for NS1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "#Perform quality control of the fastq files using the FASTQC tool. \n",
    "#We first renamed the files for convenience\n",
    "/usr/local/bin/FastQC/fastqc -o . /mnt/storage/r0611267/work/NS1.fastq"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The general quality of the sample is good. However the tool detected some abnormalities in the GC content of each sample (here we show as an example the report for the NS1 sample, Fig. 1). Indeed the distribution of the GC counts per read is not perfectly following a Gaussian distribution but it shows overrepresented sequences probably belonging to the adapters. Ideally the files require a trimming step that however we do not perform because it is beyond the scope of this project. \n",
    "\n",
    "<img width=\"50%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/GC_content_NS1.JPG\"> \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of S1.fastq\r\n",
      "Approx 5% complete for S1.fastq\r\n",
      "Approx 10% complete for S1.fastq\r\n",
      "Approx 15% complete for S1.fastq\r\n",
      "Approx 20% complete for S1.fastq\r\n",
      "Approx 25% complete for S1.fastq\r\n",
      "Approx 30% complete for S1.fastq\r\n",
      "Approx 35% complete for S1.fastq\r\n",
      "Approx 40% complete for S1.fastq\r\n",
      "Approx 45% complete for S1.fastq\r\n",
      "Approx 50% complete for S1.fastq\r\n",
      "Approx 55% complete for S1.fastq\r\n",
      "Approx 60% complete for S1.fastq\r\n",
      "Approx 65% complete for S1.fastq\r\n",
      "Approx 70% complete for S1.fastq\r\n",
      "Approx 75% complete for S1.fastq\r\n",
      "Approx 80% complete for S1.fastq\r\n",
      "Approx 85% complete for S1.fastq\r\n",
      "Approx 90% complete for S1.fastq\r\n",
      "Approx 95% complete for S1.fastq\r\n",
      "Analysis complete for S1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/S1.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of NC1.fastq\r\n",
      "Approx 5% complete for NC1.fastq\r\n",
      "Approx 10% complete for NC1.fastq\r\n",
      "Approx 15% complete for NC1.fastq\r\n",
      "Approx 20% complete for NC1.fastq\r\n",
      "Approx 25% complete for NC1.fastq\r\n",
      "Approx 30% complete for NC1.fastq\r\n",
      "Approx 35% complete for NC1.fastq\r\n",
      "Approx 40% complete for NC1.fastq\r\n",
      "Approx 45% complete for NC1.fastq\r\n",
      "Approx 50% complete for NC1.fastq\r\n",
      "Approx 55% complete for NC1.fastq\r\n",
      "Approx 60% complete for NC1.fastq\r\n",
      "Approx 65% complete for NC1.fastq\r\n",
      "Approx 70% complete for NC1.fastq\r\n",
      "Approx 75% complete for NC1.fastq\r\n",
      "Approx 80% complete for NC1.fastq\r\n",
      "Approx 85% complete for NC1.fastq\r\n",
      "Approx 90% complete for NC1.fastq\r\n",
      "Approx 95% complete for NC1.fastq\r\n",
      "Analysis complete for NC1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/NC1.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of C1.fastq\r\n",
      "Approx 5% complete for C1.fastq\r\n",
      "Approx 10% complete for C1.fastq\r\n",
      "Approx 15% complete for C1.fastq\r\n",
      "Approx 20% complete for C1.fastq\r\n",
      "Approx 25% complete for C1.fastq\r\n",
      "Approx 30% complete for C1.fastq\r\n",
      "Approx 35% complete for C1.fastq\r\n",
      "Approx 40% complete for C1.fastq\r\n",
      "Approx 45% complete for C1.fastq\r\n",
      "Approx 50% complete for C1.fastq\r\n",
      "Approx 55% complete for C1.fastq\r\n",
      "Approx 60% complete for C1.fastq\r\n",
      "Approx 65% complete for C1.fastq\r\n",
      "Approx 70% complete for C1.fastq\r\n",
      "Approx 75% complete for C1.fastq\r\n",
      "Approx 80% complete for C1.fastq\r\n",
      "Approx 85% complete for C1.fastq\r\n",
      "Approx 90% complete for C1.fastq\r\n",
      "Approx 95% complete for C1.fastq\r\n",
      "Analysis complete for C1.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/C1.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of C2.fastq\r\n",
      "Approx 5% complete for C2.fastq\r\n",
      "Approx 10% complete for C2.fastq\r\n",
      "Approx 15% complete for C2.fastq\r\n",
      "Approx 20% complete for C2.fastq\r\n",
      "Approx 25% complete for C2.fastq\r\n",
      "Approx 30% complete for C2.fastq\r\n",
      "Approx 35% complete for C2.fastq\r\n",
      "Approx 40% complete for C2.fastq\r\n",
      "Approx 45% complete for C2.fastq\r\n",
      "Approx 50% complete for C2.fastq\r\n",
      "Approx 55% complete for C2.fastq\r\n",
      "Approx 60% complete for C2.fastq\r\n",
      "Approx 65% complete for C2.fastq\r\n",
      "Approx 70% complete for C2.fastq\r\n",
      "Approx 75% complete for C2.fastq\r\n",
      "Approx 80% complete for C2.fastq\r\n",
      "Approx 85% complete for C2.fastq\r\n",
      "Approx 90% complete for C2.fastq\r\n",
      "Approx 95% complete for C2.fastq\r\n",
      "Analysis complete for C2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/C2.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of NC2.fastq\r\n",
      "Approx 5% complete for NC2.fastq\r\n",
      "Approx 10% complete for NC2.fastq\r\n",
      "Approx 15% complete for NC2.fastq\r\n",
      "Approx 20% complete for NC2.fastq\r\n",
      "Approx 25% complete for NC2.fastq\r\n",
      "Approx 30% complete for NC2.fastq\r\n",
      "Approx 35% complete for NC2.fastq\r\n",
      "Approx 40% complete for NC2.fastq\r\n",
      "Approx 45% complete for NC2.fastq\r\n",
      "Approx 50% complete for NC2.fastq\r\n",
      "Approx 55% complete for NC2.fastq\r\n",
      "Approx 60% complete for NC2.fastq\r\n",
      "Approx 65% complete for NC2.fastq\r\n",
      "Approx 70% complete for NC2.fastq\r\n",
      "Approx 75% complete for NC2.fastq\r\n",
      "Approx 80% complete for NC2.fastq\r\n",
      "Approx 85% complete for NC2.fastq\r\n",
      "Approx 90% complete for NC2.fastq\r\n",
      "Approx 95% complete for NC2.fastq\r\n",
      "Analysis complete for NC2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/NC2.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of S2.fastq\r\n",
      "Approx 5% complete for S2.fastq\r\n",
      "Approx 10% complete for S2.fastq\r\n",
      "Approx 15% complete for S2.fastq\r\n",
      "Approx 20% complete for S2.fastq\r\n",
      "Approx 25% complete for S2.fastq\r\n",
      "Approx 30% complete for S2.fastq\r\n",
      "Approx 35% complete for S2.fastq\r\n",
      "Approx 40% complete for S2.fastq\r\n",
      "Approx 45% complete for S2.fastq\r\n",
      "Approx 50% complete for S2.fastq\r\n",
      "Approx 55% complete for S2.fastq\r\n",
      "Approx 60% complete for S2.fastq\r\n",
      "Approx 65% complete for S2.fastq\r\n",
      "Approx 70% complete for S2.fastq\r\n",
      "Approx 75% complete for S2.fastq\r\n",
      "Approx 80% complete for S2.fastq\r\n",
      "Approx 85% complete for S2.fastq\r\n",
      "Approx 90% complete for S2.fastq\r\n",
      "Approx 95% complete for S2.fastq\r\n",
      "Analysis complete for S2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/S2.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of NS2.fastq\r\n",
      "Approx 5% complete for NS2.fastq\r\n",
      "Approx 10% complete for NS2.fastq\r\n",
      "Approx 15% complete for NS2.fastq\r\n",
      "Approx 20% complete for NS2.fastq\r\n",
      "Approx 25% complete for NS2.fastq\r\n",
      "Approx 30% complete for NS2.fastq\r\n",
      "Approx 35% complete for NS2.fastq\r\n",
      "Approx 40% complete for NS2.fastq\r\n",
      "Approx 45% complete for NS2.fastq\r\n",
      "Approx 50% complete for NS2.fastq\r\n",
      "Approx 55% complete for NS2.fastq\r\n",
      "Approx 60% complete for NS2.fastq\r\n",
      "Approx 65% complete for NS2.fastq\r\n",
      "Approx 70% complete for NS2.fastq\r\n",
      "Approx 75% complete for NS2.fastq\r\n",
      "Approx 80% complete for NS2.fastq\r\n",
      "Approx 85% complete for NS2.fastq\r\n",
      "Approx 90% complete for NS2.fastq\r\n",
      "Approx 95% complete for NS2.fastq\r\n",
      "Analysis complete for NS2.fastq\r\n"
     ]
    }
   ],
   "source": [
    "/usr/local/bin/FastQC/fastqc -o /mnt/storage/r0611267/work /mnt/storage/r0611267/work/NS2.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 18:48:04 ..... started STAR run\r\n",
      "Nov 20 18:48:04 ..... loading genome\r\n",
      "Nov 20 18:48:05 ..... started mapping\r\n",
      "Nov 20 18:57:25 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "#we then map the reads to the reference genome. we use the pregenerated reference genome hg_19_star_db\n",
    "#we repeat the command for all the samples\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/NS1.fastq \\\n",
    "     --outFileNamePrefix NS1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 19:02:47 ..... started STAR run\r\n",
      "Nov 20 19:02:47 ..... loading genome\r\n",
      "Nov 20 19:02:47 ..... started mapping\r\n",
      "Nov 20 19:12:07 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/NS2.fastq \\\n",
    "     --outFileNamePrefix NS2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 19:12:29 ..... started STAR run\r\n",
      "Nov 20 19:12:29 ..... loading genome\r\n",
      "Nov 20 19:12:29 ..... started mapping\r\n",
      "Nov 20 19:18:53 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/S1.fastq \\\n",
    "     --outFileNamePrefix S1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 19:18:58 ..... started STAR run\r\n",
      "Nov 20 19:18:58 ..... loading genome\r\n",
      "Nov 20 19:18:58 ..... started mapping\r\n",
      "Nov 20 19:24:49 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/S2.fastq \\\n",
    "     --outFileNamePrefix S2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 19:24:54 ..... started STAR run\r\n",
      "Nov 20 19:24:54 ..... loading genome\r\n",
      "Nov 20 19:24:55 ..... started mapping\r\n",
      "Nov 20 19:32:31 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/NC1.fastq \\\n",
    "     --outFileNamePrefix NC1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 19:33:24 ..... started STAR run\r\n",
      "Nov 20 19:33:24 ..... loading genome\r\n",
      "Nov 20 19:33:24 ..... started mapping\r\n",
      "Nov 20 19:41:18 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/NC2.fastq \\\n",
    "     --outFileNamePrefix NC2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 19:41:24 ..... started STAR run\r\n",
      "Nov 20 19:41:24 ..... loading genome\r\n",
      "Nov 20 19:41:24 ..... started mapping\r\n",
      "Nov 20 19:48:20 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/C1.fastq \\\n",
    "     --outFileNamePrefix C1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nov 20 20:58:14 ..... started STAR run\r\n",
      "Nov 20 20:58:14 ..... loading genome\r\n",
      "Nov 20 20:58:14 ..... started mapping\r\n",
      "Nov 20 21:05:20 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn /mnt/storage/r0611267/work/C2.fastq \\\n",
    "     --outFileNamePrefix C2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "@HD\tVN:1.4\r\n",
      "@SQ\tSN:chrM\tLN:16571\r\n",
      "@SQ\tSN:chr1\tLN:249250621\r\n",
      "@SQ\tSN:chr2\tLN:243199373\r\n",
      "@SQ\tSN:chr3\tLN:198022430\r\n",
      "@SQ\tSN:chr4\tLN:191154276\r\n",
      "@SQ\tSN:chr5\tLN:180915260\r\n",
      "@SQ\tSN:chr6\tLN:171115067\r\n",
      "@SQ\tSN:chr7\tLN:159138663\r\n",
      "@SQ\tSN:chr8\tLN:146364022\r\n"
     ]
    }
   ],
   "source": [
    "#we print the head of the sam file to check if the format is correct\n",
    "head -10 NS1.Aligned.out.sam | grep '^@'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 13 files...\r\n"
     ]
    }
   ],
   "source": [
    "#sort and compress the sam file into bam file\n",
    "#we repeat this for all the samples\n",
    "samtools sort -o NS1_sorted.bam NS1.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 12 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o NS2_sorted.bam NS2.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 7 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o S2_sorted.bam S2.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 8 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o S1_sorted.bam S1.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 10 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o C1_sorted.bam C1.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 10 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o C2_sorted.bam C2.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 10 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o NC2_sorted.bam NC2.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 10 files...\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -o NC1_sorted.bam NC1.Aligned.out.sam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "#index the sorted file\n",
    "samtools index NC1_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index NC2_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index C1_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index C2_sorted.bam  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index NS2_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index NS1_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index S2_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools index S1_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t2627430\t0\r\n",
      "chr1\t249250621\t3258190\t0\r\n",
      "chr2\t243199373\t1541418\t0\r\n",
      "chr3\t198022430\t1458430\t0\r\n",
      "chr4\t191154276\t797546\t0\r\n",
      "chr5\t180915260\t1276297\t0\r\n",
      "chr6\t171115067\t1598236\t0\r\n",
      "chr7\t159138663\t1244022\t0\r\n",
      "chr8\t146364022\t811130\t0\r\n",
      "chr9\t141213431\t1253880\t0\r\n",
      "chr10\t135534747\t883925\t0\r\n",
      "chr11\t135006516\t1888495\t0\r\n",
      "chr12\t133851895\t1406733\t0\r\n",
      "chr13\t115169878\t448703\t0\r\n",
      "chr14\t107349540\t782243\t0\r\n",
      "chr15\t102531392\t891266\t0\r\n",
      "chr16\t90354753\t1226652\t0\r\n",
      "chr17\t81195210\t1533589\t0\r\n",
      "chr18\t78077248\t330891\t0\r\n",
      "chr19\t59128983\t1577206\t0\r\n",
      "chr20\t63025520\t960867\t0\r\n",
      "chr21\t48129895\t259468\t0\r\n",
      "chr22\t51304566\t565671\t0\r\n",
      "chrX\t155270560\t689087\t0\r\n",
      "chrY\t59373566\t69035\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "#we check how many reads map on each chromosome\n",
    "samtools idxstats NS2_sorted.bam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We visualize in IGV the reads coverage of the gene S100A8 (involved in the inflammatory response in the lung) and we compare the sample from smoker and non-smoker. As the screenshot shows, the coverage in the sample from the smoker is higher than the one from the non-smoker. This is reasonable since more inflammation is expected in the lung of a smoker person. Moreover, this is in line to what is shown in the paper (Fig. 2).\n",
    "\n",
    "<img width=\"200%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/IGV_S100A8.jpg\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lrwxrwxrwx 1 r0611267 domain users 71 nov 14 20:13 gencode.v19.nopseudo.plus.sort.chr21.gtf -> /mnt/nfs/data/RNA-seq/GSE47042/gencode.v19.nopseudo.plus.sort.chr21.gtf\r\n",
      "lrwxrwxrwx 1 r0611267 domain users 56 nov 14 20:14 gencode.v19.nopseudo.plus.sort.gtf -> /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\r\n"
     ]
    }
   ],
   "source": [
    "#we create a symbolic link to the full human annotation \n",
    "ln -sf /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf ~ /mnt/storage/r0611267/work\n",
    "ls -l *gtf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "       \u001b[44;37m ========== \u001b[0m\u001b[36m    _____ _    _ ____  _____  ______          _____  \r\n",
      "       \u001b[44;37m =====      \u001b[0m\u001b[36m   / ____| |  | |  _ \\|  __ \\|  ____|   /\\   |  __ \\ \r\n",
      "       \u001b[44;37m   =====    \u001b[0m\u001b[36m  | (___ | |  | | |_) | |__) | |__     /  \\  | |  | |\r\n",
      "       \u001b[44;37m     ====   \u001b[0m\u001b[36m   \\___ \\| |  | |  _ <|  _  /|  __|   / /\\ \\ | |  | |\r\n",
      "       \u001b[44;37m       ==== \u001b[0m\u001b[36m   ____) | |__| | |_) | | \\ \\| |____ / ____ \\| |__| |\r\n",
      "       \u001b[44;37m ========== \u001b[0m\u001b[36m  |_____/ \\____/|____/|_|  \\_\\______/_/    \\_\\_____/\u001b[0m\r\n",
      "\tv1.5.0-p1\r\n",
      "\r\n",
      "//==========================\u001b[36m featureCounts setting \u001b[0m===========================\\\\\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Input files : \u001b[36m4 BAM files  \u001b[0m \u001b[0m                                   ||\r\n",
      "||                           \u001b[32mS\u001b[36m NS1_sorted.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mS\u001b[36m NS2_sorted.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mS\u001b[36m S1_sorted.bam\u001b[0m \u001b[0m                                 ||\r\n",
      "||                           \u001b[32mS\u001b[36m S2_sorted.bam\u001b[0m \u001b[0m                                 ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Output file : \u001b[36msmoker.counts\u001b[0m \u001b[0m                                   ||\r\n",
      "||             Annotations : \u001b[36mgencode.v19.nopseudo.plus.sort.gtf (GTF)\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 gencode.v19.nopseudo.plus.sort.gtf \u001b[0m... \u001b[0m               ||\r\n",
      "||    Features : \u001b[36m1156385\u001b[0m \u001b[0m                                                     ||\r\n",
      "||    Meta-features : \u001b[36m41863\u001b[0m \u001b[0m                                                  ||\r\n",
      "||    Chromosomes/contigs : \u001b[36m25\u001b[0m \u001b[0m                                               ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file NS1_sorted.bam... \u001b[0m                                        ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m29684646\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m19862463 (66.9%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.65 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file NS2_sorted.bam... \u001b[0m                                        ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m29380410\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m19607417 (66.7%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.67 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file S1_sorted.bam... \u001b[0m                                         ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m17271381\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m11727382 (67.9%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.35 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file S2_sorted.bam... \u001b[0m                                         ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m17164649\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m11616135 (67.7%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.38 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": [
    "#we run featureCounts which allows to assign sequence reads to genomic features\n",
    "#the order of the input files is important for the gene expression comparison that is done with DESeq\n",
    "#we run the command twice to compare separately non-smoker/smoker and non-cancer/cancer\n",
    "featureCounts -Q 10 -g gene_name -a gencode.v19.nopseudo.plus.sort.gtf -o smoker.counts NS1_sorted.bam NS2_sorted.bam S1_sorted.bam S2_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "       \u001b[44;37m ========== \u001b[0m\u001b[36m    _____ _    _ ____  _____  ______          _____  \r\n",
      "       \u001b[44;37m =====      \u001b[0m\u001b[36m   / ____| |  | |  _ \\|  __ \\|  ____|   /\\   |  __ \\ \r\n",
      "       \u001b[44;37m   =====    \u001b[0m\u001b[36m  | (___ | |  | | |_) | |__) | |__     /  \\  | |  | |\r\n",
      "       \u001b[44;37m     ====   \u001b[0m\u001b[36m   \\___ \\| |  | |  _ <|  _  /|  __|   / /\\ \\ | |  | |\r\n",
      "       \u001b[44;37m       ==== \u001b[0m\u001b[36m   ____) | |__| | |_) | | \\ \\| |____ / ____ \\| |__| |\r\n",
      "       \u001b[44;37m ========== \u001b[0m\u001b[36m  |_____/ \\____/|____/|_|  \\_\\______/_/    \\_\\_____/\u001b[0m\r\n",
      "\tv1.5.0-p1\r\n",
      "\r\n",
      "//==========================\u001b[36m featureCounts setting \u001b[0m===========================\\\\\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Input files : \u001b[36m4 BAM files  \u001b[0m \u001b[0m                                   ||\r\n",
      "||                           \u001b[32mS\u001b[36m NC1_sorted.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mS\u001b[36m NC2_sorted.bam\u001b[0m \u001b[0m                                ||\r\n",
      "||                           \u001b[32mS\u001b[36m C1_sorted.bam\u001b[0m \u001b[0m                                 ||\r\n",
      "||                           \u001b[32mS\u001b[36m C2_sorted.bam\u001b[0m \u001b[0m                                 ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Output file : \u001b[36mcancer.counts\u001b[0m \u001b[0m                                   ||\r\n",
      "||             Annotations : \u001b[36mgencode.v19.nopseudo.plus.sort.gtf (GTF)\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 gencode.v19.nopseudo.plus.sort.gtf \u001b[0m... \u001b[0m               ||\r\n",
      "||    Features : \u001b[36m1156385\u001b[0m \u001b[0m                                                     ||\r\n",
      "||    Meta-features : \u001b[36m41863\u001b[0m \u001b[0m                                                  ||\r\n",
      "||    Chromosomes/contigs : \u001b[36m25\u001b[0m \u001b[0m                                               ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file NC1_sorted.bam... \u001b[0m                                        ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m23655207\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m15682116 (66.3%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.49 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file NC2_sorted.bam... \u001b[0m                                        ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m23467510\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m15505019 (66.1%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.52 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file C1_sorted.bam... \u001b[0m                                         ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m22371454\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m14969356 (66.9%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.48 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file C2_sorted.bam... \u001b[0m                                         ||\r\n",
      "||    Single-end reads are included. \u001b[0m                                         ||\r\n",
      "||    Assign reads to features... \u001b[0m                                            ||\r\n",
      "||    Total reads : \u001b[36m22200468\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m14811491 (66.7%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.52 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||                         \u001b[36mRead assignment finished.\u001b[0m \u001b[0m                         ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "\\\\=====================\u001b[36m http://subread.sourceforge.net/ \u001b[0m======================//\r\n",
      "\r\n"
     ]
    }
   ],
   "source": [
    "featureCounts -Q 10 -g gene_name -a gencode.v19.nopseudo.plus.sort.gtf -o cancer.counts NC1_sorted.bam NC2_sorted.bam C1_sorted.bam C2_sorted.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "#we prepare the files for the subsequent analysis and we visualize the format with 'head'\n",
    "cut -f-6 smoker.counts > smoker.genedata.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f-6 cancer.counts > cancer.genedata.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Geneid\tNS1_sorted.bam\tNS2_sorted.bam\tS1_sorted.bam\tS2_sorted.bam\r\n",
      "MIR1302-11\t0\t0\t0\t0\r\n",
      "FAM138A\t0\t0\t0\t0\r\n",
      "OR4F5\t0\t0\t0\t0\r\n",
      "RP11-34P13.7\t0\t0\t0\t0\r\n",
      "RP11-34P13.8\t0\t0\t0\t0\r\n",
      "AL627309.1\t91\t73\t62\t70\r\n",
      "RP11-34P13.14\t0\t0\t0\t0\r\n",
      "RP11-34P13.13\t5\t8\t0\t0\r\n",
      "RNU6-1100P\t0\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "cut -f1,7- smoker.counts | grep -v '^#' > all.smoker.counts\n",
    "head all.smoker.counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Geneid\tNC1_sorted.bam\tNC2_sorted.bam\tC1_sorted.bam\tC2_sorted.bam\r\n",
      "MIR1302-11\t0\t0\t0\t0\r\n",
      "FAM138A\t0\t0\t0\t0\r\n",
      "OR4F5\t0\t0\t0\t0\r\n",
      "RP11-34P13.7\t0\t0\t3\t3\r\n",
      "RP11-34P13.8\t0\t0\t0\t0\r\n",
      "AL627309.1\t109\t101\t85\t74\r\n",
      "RP11-34P13.14\t0\t0\t0\t0\r\n",
      "RP11-34P13.13\t2\t6\t0\t0\r\n",
      "RNU6-1100P\t0\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "cut -f1,7- cancer.counts | grep -v '^#' > all.cancer.counts\n",
    "head all.cancer.counts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We proceed with the analysis in R (see code in notebook 2)\n",
    "\n",
    "**DESeq ANALYSIS**\n",
    "\n",
    "Since we wanted to compare non-smokers (NS) to healthy smokers (S) and smokers with benign diseases (NC) to smokers suffering from cancer (C), we ran in parallel the same commands for both sets of data. \n",
    "We first organized the data and defined the experimental conditions to make it suitable for the subsequent DESeq analysis. This allowed us to graphically (see Notebook 2) check several features of our dataset:\n",
    "- The library size barplot provides with information about the total number of reads corresponding to each sample.\n",
    "- The scatter plot of sample vs. sample allows us to compare the variation between each pair of samples. \n",
    "- The Principal Component Analysis (PCA) plot serves to evaluate the intersample variation. \n",
    "- In the mean plot the differentially expressed genes are visualized.\n",
    "\n",
    "Finally, we calculated the number of differentially expressed genes for each pair of samples and we plotted few of them as an example.\n",
    "\n",
    "**Plot interpretation**\n",
    "\n",
    "The variation shown in the DESeq2 barplots is larger between NS and S than between NC and C. Counts are also more scattered between NS and S in the sample vs. sample scatter plots. In the PCA plot we can observe, as expected, that the variance between NS and S is much larger that the intrasample variation, which is less than 0.4% in every case. This difference exists as well in the case of NC and C. Furthermore, in line with the previous observations in the DESeq2 barplots and the sample vs. sample plots, there is more variation between healthy smokers (S) and non-smokers (NS) than when we compare smokers with benign diseases (NC) and smokers suffering from cancer (C). In the mean expression plot the scattering is again increased when NS and S are compared, meaning that the number of significantly differentially expressed genes is larger in this pair of samples.\n",
    "We then calculated the number of differentially expressed genes for NS vs. S and NC vs. C and we found  6400 and 3072 genes, respectively. Those values are higher than those reported in the paper. However, the ratio is approximately the same. This difference is likely to be due to the fact that we did not perform any trimming or additional correction on the dataset, which they did in the paper.\n",
    "Finally, we manually checked some differentially expressed genes, which were mentioned in the paper. As an example of the NS/S couple we show the differences in the expression of S100A8, a gene involved in the inflammatory response in the lung. This gene is upregulated in smokers (S) as it is also reported in the paper and as we previously showed in IGV. As an example of the NC/C couple, we checked the expression levels of NFkBIA, which participates in NFkB signaling network and is mentioned to be upregulated in the paper. Additionally we looked at the expression of CYP1A1, a protein involved in the xenobiotic metabolism, which we expect to be upregulated in smokers. A relevant fraction of the upregulated genes cluster in the family of genes encoding proteins involved in the metabolism of xenobiotics, as shown in the functional analysis (see further). Likewise, in the case of the NC/C couple, the chemokine CCL20 is upregulated in cancer patients. Interesting the case of MUC5AC, which is upregulated in smokers compared to non-smokers, but donwregulated in cancer  vs. non-cancer samples. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "**FUNCTIONAL ANALYSIS AND MOTIF ENRICHMENT**\n",
    "\n",
    "After having performed the analysis of the RNAseq data, functional analysis was carried out by using the following online tools: HumanMine (http://www.humanmine.org/) and GOrilla (http://cbl-gorilla.cs.technion.ac.il/). These tools allow to associate genes to the biological scenarios in which they are likely to play a role. This association can be done at different levels: biological processes, cellular components and molecular functions.\n",
    "\n",
    "The analysis in **HumanMine** revealed that in the case of the healthy smoker (S) vs non-smoker (NS) comparison, among the enriched gene ontology (GO) terms the guanylate cyclase is found, which is known to be increased in smokers (Arnold WP, 1977 *Science*). Also, as previously mentioned, we found enrichment in the oxidation-reduction related genes (Fig.3). \n",
    "\n",
    "<img width=\"50%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/smoker_GO1.JPG\"/> <img width=\"50%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/smoker_GO2.JPG\">\n",
    "\n",
    "Among the enriched GO terms in cancer, as expected we found the involvement of signalling pathways that play a role in cancer, such as MAPK and NFkB, and immune-related processes (Fig.4). \n",
    "\n",
    "<img width=\"50%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/cancer_GO1.JPG\"> \n",
    "<img width=\"50%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/cancer_GO2.JPG\">\n",
    "\n",
    "For a more detailed overview we used **GOrilla**.\n",
    "\n",
    "The analysis in GOrilla (visualized with REVIGO).\n",
    "\n",
    "The following two images refer to NS-S comparison (Fig.5 and 6)\n",
    "\n",
    "<img width=\"100%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/revigo_smokers.JPG\">\n",
    "<img width=\"100%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/revigo_smokers2.JPG\">\n",
    "\n",
    "As reported in the paper, we found relevant enrichment on the oxidation-reduction processes, as we also found using HumanMine.\n",
    "\n",
    "We also checked which are the most down-regulated genes in the S samples compared to the NS (Fig.7)\n",
    "\n",
    "<img width=\"100%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/DOWN_NS-S.jpg\">\n",
    "\n",
    "In the case of NS vs S, the downregulated genes are those involved in the monovalent inorganic cation transport that play a role in a wide range of cellular processes and to which belong also those associated with the cilium-based cell motility. The reduced ciliar function is indeed known to be a side effect of the sigarette smoke.\n",
    "\n",
    "The following two images refer to NC-C comparison (Fig.8 and 9)\n",
    "\n",
    "<img width=\"100%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/revigo_cancer.JPG\">\n",
    "<img width=\"100%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/revigo_cancer2.JPG\">\n",
    "In the case of smokers with cancer we see larger differences in genes related to inflammation and immune response, cell proliferation and cell adhesion. Indeed, cancer cells undergo changes in their surface adhesion molecules to invade other niches. \n",
    "\n",
    "In the same way we evaluate the cluster of genes which are mostly down-regulate in the C samples compared with the NS one (Fig. 10).\n",
    "\n",
    "<img width=\"100%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/DOWN_NC-C.jpg\">\n",
    "\n",
    "For this couple, genes involved in the regulaiton of immune system process and defense response are the most downregulated. Which is also expected from patients with cancer. \n",
    "\n",
    "Finally, since the transcription factor NFkB1A is one of the upregulated genes in smokers suffering from lung cancer (C) compared to those suffering from benign diseases (NC) and it is involved in a signaling pathway associated with cancer development, we decided to perform the *motif enrichment analysis* on this gene. In order to do so, we used the online tool **GeneMania** to obtain a list of genes related to our gene of interest (in terms of protein and genetic interactions, pathways, co-expression, co-localization and protein domain similarity). Based on this list of genes, the subsequent analysis was carried out in Cytoscape using the **iRegulon** tool.\n",
    "As a result, we obtained the following map with the main targets of NFkB (Fig. 11):\n",
    "<img width=\"50%\" src=\"https://jupyter.gbiomed.kuleuven.be/user/r0611267/files/PROJECT/Connectome.png\">\n",
    "\n",
    "Among the targets of NFK1B we found genes involved in the immune response such as IL1B or CXCL10, but also proto-oncogenes (BCL3) and genes related to cell cycle control (CDKN1A). Additionally, also CCL20 and NFKBIA are among the targets gene, which we found to be up-regulated in the sample of smokers with cancer (C). Since NFkB has been proposed to constitute a critical link between inflammation and cancer (Karin M. 2009, *Cold Spring Harbor Perspectives in Biology*), it seems logical that its regulatory activity affects genes implicated both in cell proliferation and the immune system."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Microarray**\n",
    "\n",
    "For the microarray analysis we focused on the cancer/non-cancer comparison because the smoker/non-smoker data had been obtained by using a different type of platform (Affymetrix Exon 1.0 ST), which cannot be analyzed using the affy package. In the case of the cancer/non-cancer analysis the data originated from Affymetrix HGU133A 2.0. The samples correspond to bronchial airway epithelial cells from eight smokers with cancer and five smokers without cancer. Aiming to reproduce the analysis carried out in the paper, we selected a subset of samples (three non-cancer and two cancer), that were used for the RNAseq library preparation. However, we could not find any significantly differentially expressed genes among these samples. This could be due to the reduced sample size or the fact that the cancers here analysed are very different in terms of histology (exp. Adenocarcinoma or Squamous cell carcinoma). Moreover, as they mention in the paper, numerous genes that are differentially expressed according to RNAseq are not interrogated in the microarray (e.g: MUC5AC). Therefore, it is not possible to establish an appropriate comparison. Additionally, the microarray used in this case is an older platform and only a subset of the cancer samples used in the pool had microarray data. Indeed, in the paper they show a weak correlation between the RNAseq-derived fold changes between NC/C and those measured by microarray. Due to these negative results, we checked the original publication of the group that first deposited those microarray data (Spira, A. 2007, *Nature Med*.), nevertheless the .RAW files were not available."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Conclusion**\n",
    "\n",
    "The RNAseq analysis combined with the functional analysis revealed that the clusters of genes that are differentially expressed between the samples are in line with our expectation of genes up and down-regulated in case of healthy smokers (S) and smokers with cancer (C). \n",
    "On the other hand, the microarray analysis did not give consistent results, due to the poor quality of the data set. \n",
    "Generally, the RNAseq technology is considered to be more powerful than the microarray one. Indeed, it is a good tool for discovery-based experiments since, differently from microarray, it is able to investigate both novel and known transcripts. Additionally, the background signal generated is lower and easily eliminated during analysis. This is due to the fact that this technology allows a better hybridization, and therefore mapping, or the DNA sequences onto the reference sequence. This also allows a better quantification of the expression levels. "
   ]
  }
 ],
 "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
}
