{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# Bioinformatics and Systems Biology: Expression, Regulation and Networks\n",
    "\n",
    "## Benno Verbelen - r0301806\n",
    "## Ruben Weckx - r0304814                                                            "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reference paper:\n",
    "K Suknuntha, Y Ishii, L Tao, K Hu, BE McIntosh, D Yang, S Swanson, R Stewart, JYJ Wang, J Thomson, I Slukvin. Discovery of survival factor for primitive chronic myeloid leukemia cells using induced pluripotent stem cells. Stem Cell Res 2015. 15(3): 678-693.\n",
    "\n",
    "GEO accession number: GSE60065\n",
    "\n",
    "The original ipynb files can be found at Benno Verbelen (r0301806) in /mnt/storage/r0301806/jupyternotebooks\n",
    "\n",
    "All resulting data obtained or produced during this assignment can be found at the following locations: \n",
    "/mnt/storage/r0301806/RNAseqgroepswerk/ (Benno Verbelen)\n",
    "/mnt/storage/r0304814/RNAseqgroepswerk/ (Ruben Weckx)\n",
    "/mnt/storage/r0304814/chip/ (Ruben Weckx)\n",
    "\n",
    "# Introduction\n",
    "\n",
    "Chronic myeloid leukemia (CML) originates in hematopoietic stem cells (HSC) within the bone marrow by a chromosomal t(9;22)(q34;q11.2) translocation, known as the Philadelphia translocation. This causes the constitutive expression of the oncogenic BCR-ABL fusion protein, a serine/threonine and tyrosine kinase. Tyrosine kinase inhibitors (TKI), like imatinib, have previously been found to induce complete cytogenetic response in most patients, however relapse of the disease is commonly seen when TKI treatment is discontinued. It was suggested that HSCs could carry leukemic stem cell (LSC) features, including innate resistance to TKI therapy. Therefore, research of primitive LSCs is needed for a better understanding of CML pathogenesis, as well as therapeutic strategies of the disease. \n",
    "Human somatic induced pluripotent stem cells (iPSCs) were generated and used as a model for primitive HSCs. iPSCs could also be generated from primary CML cells. Subsequently, these iPSCs were differentiated back into blood cells, resulting in unlimited production of primitive HSC carrying LCS features. \n",
    "CML LSCs  were derived from a patient with CML in chronic phase and remodeled into iPSCs (CML15 iPSCs and CML17 iPSCs). Bone-marrow (BM) derived iPSCs (BM1K and BM9) were used as control. CML and control iPSCs were pushed towards becoming CML iPSC-derived lin-CD34+CD90+CD117+CD45+38+/−, referred to as induced CD34+ cells (iCD34+).\n",
    "Two different conditions were tested for BM and CML samples:\n",
    " \n",
    "BM1K iCD34+ untreated\n",
    "BM9 iCD34+ untreated\n",
    "CML15 iCD34+ untreated\n",
    "CML17 iCD34+ untreated\n",
    "BM1K iCD34+ treated with imatinib\n",
    "BM9 iCD34+ treated with imatinib\n",
    "CML15 iCD34+ treated with imatinib\n",
    "CML17 iCD34+ treated with imatinib \n",
    "\n",
    "# Results\n",
    "\n",
    "For our project we will look for genes that have altered expression levels in CML samples after imatinib treatment, which is not seen in healthy BM samples. \n",
    "\n",
    "We uploaded our dataset from the GEO browser in order to perform RNAseq analysis (as was done in the article). We first performed a quality control (QC) regarding our data. No unexpected abnormalities were found (fastqc.html-files). Afterwards, all sequences were mapped (STAR), aligned (sam-files), compressed, sorted and indexed (bam-files). Next, by using the idxstats command from samtools we showed the number of mapped reads per chromosome. Via flagstat, we looked at the QC-passed and -failed reads. The output showed no QC-failed reads, which confirms good quality of our initial samples. The number of reads per gene were counted using the featureCounts command and stored in the output file for BM (/mnt/storage/r0304814/RNAseqgroepswerk/all.CMLcounts1)) and CML samples (/mnt/storage/r0301806/RNAseqgroepswerk/all.CMLcounts2). To look at the gene expression levels, we first converted this file to an excel-accessible file (tsv-file). \n",
    "We now wanted to calculate the log2 fold change for bone marrow and CML tissue samples, via differential expression sequence analysis. We looked for candidate genes which could provide imatinib resistance in CML cells. In the article they mention their inclusion and exclusion criteria: \n",
    "“From the list of upregulated genes, we chose 137 that were induced ≥2 fold by imatinib treatment (…). Then, we selected genes that were upregulated in CML iCD34+ cells, but suppressed in BM iCD34+ cells (…). A similar algorithm was applied for down-regulated genes. From the list of significantly downregulated genes, we chose those that were suppressed ≥2 fold by imatinib in CML iCD34+ (16 genes). We then selected genes that were suppressed in CML iCD34+ cells, but upregulated in BM iCD34+ cells (…).”  \n",
    "In BM samples 618 genes were upregulated and 762 were downregulated. For CML samples 200 genes were upregulated and 39 were downregulated. We applied the same criteria to our resulting dataset, leaving us with 133 upregulated genes and 39 downregulated genes associated with imatinib treatment for CML samples. In the article, BCL2A1, ALOX15 and SMAD7 were found to be upregulated. In addition, their research showed OLFM4 to be the top-ranking upregulated gene. However, according to their criteria, our results excluded these genes from the list of candidate target genes i.e. a gene upregulated in CML samples, but downregulated in BM samples and vice versa. The researchers of this article used EBseq(v.1.1.6) software (http://www.biostat.wisc.edu/~kendzior/EBSEQ/). We performed all our calculations as taught in class, this was the only difference between our conduct of work. We tried to reproduce their results by using the same software they used, but we were unable to do so due to technical difficulties. We continued with our data.\n",
    "\n",
    "We then ran our data in GSEA. A ranked file (.rnk) was made, which consisted of 2 columns (gene symbols, expression score). KEGG was used as the gene set database. As a control we looked at the hematopoietic cell lineage enrichment for the CML samples, which showed that a number of upregulated genes were positively correlated with differentiation of precursor bone marrow cells to the hematopoietic cell lineage. This can be explained by the concept of CML, an overproduction of white blood cells. We also looked at cell cycle enrichment in CML samples and showed an enrichment at the negative side, meaning that downregulated genes are involved in the cell cycle. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0301806/files/GSEAlineage.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0301806/files/GSEAcycle.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Furthermore, we ran our list of up- and downregulated genes to the background list of all genes generated by RNAseq in GOrilla (http://cbl-gorilla.cs.technion.ac.il/GOrilla/shmnv4uj/GOResults.html). These genes were significantly involved in the following processes which we considered to be associated with CML: Regulation of apoptotic processes, positive regulation of macrophage chemotaxis, positive regulation of Ras protein signal transduction, … . "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"80%\" src=\"/user/r0301806/files/GOrilla.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To visualize the changes in gene expression due to imatinib (the 133 upregulated genes and 39 downregulated genes), we generated a heat map using the Multi-Experiment Viewer tool. (only a part of the heat map is shown in the figure)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"90%\" src=\"/user/r0301806/files/HeatMap2.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Subsequently, we predicted possible regulators and targets of the transcription factor within our set of genes via the Cytoscape iRegulon application. For the upregulated genes, PITX3 had the highest NES score of 4.007 (closely followed by BRCA1 and MYBL2). The transcription factor SRF had the highest NES score of 5.656 for the downregulated genes (followed by SIN3A and HOXA3). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0301806/files/PITX3.jpg\"> \n",
    "<img width=\"30%\" src=\"/user/r0301806/files/SRF.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lastly, the most enriched motives for these two transcription factors were discovered. Transfec_public-M00021 and tiapale-NNMCCATATAWGGKNN-SRF-full for PITX3 and SRF respectively."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0301806/files/PITX3motive.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"30%\" src=\"/user/r0301806/files/SRFmotive.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ChIPseq\n",
    "\n",
    "We went to ChIP-Atlas to look for ChIPseq data concerning PITX3 and SRF. Apparently, no ChIPseq studies are conducted for PITX3. Therefore, we looked at studies done on BRCA1 and MYBL2 but came to the conclusion that none of our upregulated target genes generated by iRegulon were listed as potential target genes for BRCA1 or MYBL2 in any of the studies. However, available SRF ChIPseq studies did mention some of our target downregulated genes (EGR1, FOS, DUSP2) as potential target genes. We therefore decided to only analyze ChIP data for SRF. The most relevant study available used blood cells as cell type (GSM803350). However, they did not analyze any cancerous cells nor did they apply any particular treatment or protocols to their samples. The files containing the narrowpeaks (bed-files) were obtained using the bowtie2 command. The generated reads and the peaks were uploaded in igv. We looked at the above mentioned downregulated genes which are potential targets for SRF. The goal of the ChIPseq was to find peaks in the  promotor regions targeted genes involved in imatinib resistance. And indeed, Peaks were found in the promotor regions of all three genes (EGR1, FOS and DUSP2 respectively, as seen in the figures below). This confirms our hypothesis that SRF affects the expression of these three genes. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img width=\"50%\" src=\"/user/r0301806/files/EGR1igv.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0301806/files/FOSigv.jpg\">\n",
    "<img width=\"50%\" src=\"/user/r0301806/files/DUSP2igv.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Discussion\n",
    "\n",
    "After analysis of our data we found possible target genes involved in imatinib resistance in treatment of CML. After comparison with the article, however, we did not find OLFM4, ALOX15, BCL2A1 and SMAD7 to be conform with their inclusion criteria. In other words, these genes did not have a significantly altered expression, so were not included in our analysis. Nonetheless, we continued with our data, which consisted of 133 upregulated and 39 downregulated genes. Based upon these genes, we predicted the transcription factors (and their associated motif) which are involved in the regulation of these target genes. For all significantly upregulated genes, PITX3 emerged as the most enriched transcription factor. For all significantly downregulated genes, SRF was predicted to be the most promising transcription factor. ChIPseq studies were not available for PITX3. Since BRCA1 and MYBL2 did not show possible target genes identical to our own upregulated target genes, we were not able to run a ChIPseq on these transcription factors. But, we were able to run a ChIPseq on SRF, because studies did show three genes matching with our own downregulated genes. The promotor regions of these genes had a high coverage. This implies that they could be used as a possible target for therapy for patients with an imatinib restistant CML profile."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Code:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RNAseq analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/storage/r0301806/jupyternotebooks\r\n"
     ]
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mkdir: cannot create directory ‘/home/luna.kuleuven.be/r0301806/data/ncbi’: File exists\r\n"
     ]
    }
   ],
   "source": [
    "mkdir /home/luna.kuleuven.be/r0301806/data/ncbi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /home/luna.kuleuven.be/r0301806/data/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0301806/data/work\r\n"
     ]
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# To convert our sra sample data link from GEO to fastq files, we need to use the sra toolkit.\n",
    "# But first, this toolkit needs a cache directory (which cannot be the home directory!), so we create one: \n",
    "vdb-config -s /repository/user/main/public/root=~/data/ncbi\n",
    "# Now we can use the sra toolkit. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mkdir /home/luna.kuleuven.be/r0301806/data/work"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~  LS252.fastq\tLS287.fastq  LS292.fastq  NL251.fastq  NL287.fastq  NL292.fastq\r\n"
     ]
    }
   ],
   "source": [
    "cd /home/luna.kuleuven.be/r0301806/data/work\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read 33119445 spots for SRR1536061\r\n",
      "Written 33119445 spots for SRR1536061\r\n",
      "Read 37665353 spots for SRR1536062\r\n",
      "Written 37665353 spots for SRR1536062\r\n",
      "Read 34659684 spots for SRR1536063\r\n",
      "Written 34659684 spots for SRR1536063\r\n",
      "Read 51339306 spots for SRR1536064\r\n",
      "Written 51339306 spots for SRR1536064\r\n",
      "Read 42107774 spots for SRR1536065\r\n",
      "Written 42107774 spots for SRR1536065\r\n",
      "Read 41614191 spots for SRR1536066\r\n",
      "Written 41614191 spots for SRR1536066\r\n",
      "Read 45392472 spots for SRR1536067\r\n",
      "Written 45392472 spots for SRR1536067\r\n",
      "Read 44282036 spots for SRR1536068\r\n",
      "Written 44282036 spots for SRR1536068\r\n"
     ]
    }
   ],
   "source": [
    "fastq-dump --split-files SRR1536061\n",
    "fastq-dump --split-files SRR1536062\n",
    "fastq-dump --split-files SRR1536063\n",
    "fastq-dump --split-files SRR1536064\n",
    "fastq-dump --split-files SRR1536065\n",
    "fastq-dump --split-files SRR1536066\n",
    "fastq-dump --split-files SRR1536067\n",
    "fastq-dump --split-files SRR1536068"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# Give the fastq files another name, which is more recognizable\n",
    "mv SRR1536061_1.fastq BM1KiCD34ctrl.fastq\n",
    "mv SRR1536062_1.fastq BM9iCD34ctrl.fastq\n",
    "mv SRR1536063_1.fastq CML15iCD34ctrl.fastq\n",
    "mv SRR1536064_1.fastq CML17iCD34ctrl.fastq\n",
    "mv SRR1536065_1.fastq BM1KiCD34Imatinib.fastq\n",
    "mv SRR1536066_1.fastq BM9iCD34Imatinib.fastq\n",
    "mv SRR1536067_1.fastq CML15iCD34Imatinib.fastq\n",
    "mv SRR1536068_1.fastq CML17iCD34Imatinib.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~\t\t\t CML15iCD34ctrl.fastq\t   LS287.fastq\r\n",
      "BM1KiCD34ctrl.fastq\t CML15iCD34Imatinib.fastq  LS292.fastq\r\n",
      "BM1KiCD34Imatinib.fastq  CML17iCD34ctrl.fastq\t   NL251.fastq\r\n",
      "BM9iCD34ctrl.fastq\t CML17iCD34Imatinib.fastq  NL287.fastq\r\n",
      "BM9iCD34Imatinib.fastq\t LS252.fastq\t\t   NL292.fastq\r\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mkdir -p /home/luna.kuleuven.be/r0301806/data/RNAseqgroepswerk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/luna.kuleuven.be/r0301806/data/RNAseqgroepswerk\r\n"
     ]
    }
   ],
   "source": [
    "cd ~/data/RNAseqgroepswerk\n",
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 50773608\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8893494 nov 21 16:02 all.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        581 nov 21 16:02 all.counts.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8236287 nov 21 16:03 all.genedatapsoriasis.tsv\r\n",
      "-rw-r--r-- 1 r0301806 domain users    1042835 nov 21 16:03 all.genepsoriasis.counts.tsv\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         42 dec  4 22:00 BM1KiCD34ctrl.fastq -> /mnt/nfs/r0301806/work/BM1KiCD34ctrl.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         46 dec  4 22:00 BM1KiCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/BM1KiCD34Imatinib.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         41 dec  4 22:00 BM9iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/BM9iCD34ctrl.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         45 dec  4 22:00 BM9iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/BM9iCD34Imatinib.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         43 dec  4 22:00 CML15iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/CML15iCD34ctrl.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         47 dec  4 22:00 CML15iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/CML15iCD34Imatinib.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         43 dec  4 22:00 CML17iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/CML17iCD34ctrl.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         47 dec  4 22:00 CML17iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/CML17iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3650241 nov 23 14:32 deseq.results.tsv\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         30 dec  4 21:58 *.fastq -> /mnt/nfs/r0304814/work/*.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         56 nov 21 15:48 gencode.v19.nopseudo.plus.sort.gtf -> /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\r\n",
      "-rw-r--r-- 1 r0301806 domain users 6454489687 nov 21 01:56 LS252.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1789388164 nov 21 12:30 LS252.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3400288 nov 21 14:11 LS252.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8344733 nov 21 15:53 LS252.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        296 nov 21 15:53 LS252.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         34 dec  4 22:00 LS252.fastq -> /mnt/nfs/r0301806/work/LS252.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users     360945 nov 21 00:07 LS252_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users     488111 nov 21 00:07 LS252_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1861 nov 21 01:56 LS252.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users      15529 nov 21 01:56 LS252.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1662 nov 21 01:56 LS252.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users    4764141 nov 21 01:56 LS252.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 7415056438 nov 21 02:08 LS287.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1664684723 nov 21 14:23 LS287.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3314240 nov 21 14:30 LS287.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8347231 nov 21 15:54 LS287.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        296 nov 21 15:54 LS287.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         34 dec  4 22:00 LS287.fastq -> /mnt/nfs/r0301806/work/LS287.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users     347480 nov 21 00:16 LS287_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users     398871 nov 21 00:16 LS287_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1862 nov 21 02:08 LS287.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users      15529 nov 21 02:08 LS287.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1544 nov 21 02:08 LS287.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users    5397055 nov 21 02:08 LS287.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 7007092341 nov 21 02:29 LS292.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1533098382 nov 21 14:45 LS292.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3333560 nov 21 14:50 LS292.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8345888 nov 21 15:54 LS292.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        296 nov 21 15:54 LS292.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         34 dec  4 22:00 LS292.fastq -> /mnt/nfs/r0301806/work/LS292.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users     352315 nov 21 00:26 LS292_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users     407732 nov 21 00:26 LS292_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1862 nov 21 02:29 LS292.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users      15529 nov 21 02:29 LS292.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1544 nov 21 02:29 LS292.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users    5091426 nov 21 02:29 LS292.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 7350612418 nov 21 02:45 NL251.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1632509502 nov 21 14:59 NL251.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3291184 nov 21 15:01 NL251.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8345311 nov 21 15:55 NL251.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        296 nov 21 15:55 NL251.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         34 dec  4 22:00 NL251.fastq -> /mnt/nfs/r0301806/work/NL251.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users     366906 nov 21 00:55 NL251_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users     425938 nov 21 00:55 NL251_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1862 nov 21 02:45 NL251.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users      15529 nov 21 02:45 NL251.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1662 nov 21 02:45 NL251.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users    4902687 nov 21 02:45 NL251.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users          0 nov 21 02:51 NL286.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1541773300 nov 21 15:21 NL286.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3387208 nov 21 15:22 NL286.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8345371 nov 21 15:56 NL286.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        296 nov 21 15:56 NL286.counts.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users      13128 nov 21 02:51 NL286.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users          0 nov 21 02:51 NL286.Log.progress.out\r\n",
      "drwx------ 2 r0301806 domain users       4096 nov 21 02:51 NL286._STARtmp\r\n",
      "-rw-r--r-- 1 r0301806 domain users 7218709786 nov 21 03:04 NL287.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         34 dec  4 22:00 NL287.fastq -> /mnt/nfs/r0301806/work/NL287.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users     343862 nov 21 01:11 NL287_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users     397127 nov 21 01:11 NL287_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1862 nov 21 03:04 NL287.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users      15529 nov 21 03:04 NL287.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1662 nov 21 03:04 NL287.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users    4939340 nov 21 03:04 NL287.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1456424671 nov 21 15:30 NL291.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3334656 nov 21 15:31 NL291.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users    8345915 nov 21 15:56 NL291.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users        296 nov 21 15:56 NL291.counts.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users 6801108258 nov 21 03:21 NL292.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users         34 dec  4 22:00 NL292.fastq -> /mnt/nfs/r0301806/work/NL292.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users     368992 nov 21 01:28 NL292_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users     434603 nov 21 01:28 NL292_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1862 nov 21 03:21 NL292.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users      15529 nov 21 03:21 NL292.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       1544 nov 21 03:21 NL292.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users    5139326 nov 21 03:21 NL292.SJ.out.tab\r\n"
     ]
    }
   ],
   "source": [
    "# Create a symbolic (-s) link to the fastq files in your RNAseqgroepswerk directory, by using the ln command.\n",
    "# -f : remove existing destination files\n",
    "ln -sf /mnt/nfs/r0301806/work/*.fastq ~/data/RNAseqgroepswerk/\n",
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started analysis of BM1KiCD34ctrl.fastq\r\n",
      "Approx 5% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 10% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 15% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 20% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 25% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 30% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 35% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 40% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 45% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 50% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 55% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 60% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 65% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 70% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 75% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 80% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 85% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 90% complete for BM1KiCD34ctrl.fastq\r\n",
      "Approx 95% complete for BM1KiCD34ctrl.fastq\r\n",
      "Analysis complete for BM1KiCD34ctrl.fastq\r\n",
      "Started analysis of BM9iCD34ctrl.fastq\r\n",
      "Approx 5% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 10% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 15% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 20% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 25% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 30% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 35% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 40% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 45% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 50% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 55% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 60% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 65% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 70% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 75% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 80% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 85% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 90% complete for BM9iCD34ctrl.fastq\r\n",
      "Approx 95% complete for BM9iCD34ctrl.fastq\r\n",
      "Analysis complete for BM9iCD34ctrl.fastq\r\n",
      "Started analysis of CML15iCD34ctrl.fastq\r\n",
      "Approx 5% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 10% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 15% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 20% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 25% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 30% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 35% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 40% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 45% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 50% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 55% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 60% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 65% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 70% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 75% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 80% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 85% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 90% complete for CML15iCD34ctrl.fastq\r\n",
      "Approx 95% complete for CML15iCD34ctrl.fastq\r\n",
      "Analysis complete for CML15iCD34ctrl.fastq\r\n",
      "Started analysis of CML17iCD34ctrl.fastq\r\n",
      "Approx 5% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 10% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 15% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 20% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 25% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 30% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 35% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 40% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 45% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 50% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 55% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 60% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 65% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 70% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 75% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 80% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 85% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 90% complete for CML17iCD34ctrl.fastq\r\n",
      "Approx 95% complete for CML17iCD34ctrl.fastq\r\n",
      "Analysis complete for CML17iCD34ctrl.fastq\r\n",
      "Started analysis of BM1KiCD34Imatinib.fastq\r\n",
      "Approx 5% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 10% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 15% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 20% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 25% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 30% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 35% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 40% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 45% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 50% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 55% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 60% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 65% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 70% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 75% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 80% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 85% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 90% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Approx 95% complete for BM1KiCD34Imatinib.fastq\r\n",
      "Analysis complete for BM1KiCD34Imatinib.fastq\r\n",
      "Started analysis of BM9iCD34Imatinib.fastq\r\n",
      "Approx 5% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 10% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 15% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 20% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 25% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 30% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 35% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 40% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 45% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 50% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 55% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 60% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 65% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 70% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 75% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 80% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 85% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 90% complete for BM9iCD34Imatinib.fastq\r\n",
      "Approx 95% complete for BM9iCD34Imatinib.fastq\r\n",
      "Analysis complete for BM9iCD34Imatinib.fastq\r\n",
      "Started analysis of CML15iCD34Imatinib.fastq\r\n",
      "Approx 5% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 10% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 15% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 20% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 25% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 30% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 35% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 40% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 45% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 50% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 55% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 60% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 65% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 70% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 75% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 80% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 85% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 90% complete for CML15iCD34Imatinib.fastq\r\n",
      "Approx 95% complete for CML15iCD34Imatinib.fastq\r\n",
      "Analysis complete for CML15iCD34Imatinib.fastq\r\n",
      "Started analysis of CML17iCD34Imatinib.fastq\r\n",
      "Approx 5% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 10% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 15% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 20% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 25% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 30% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 35% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 40% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 45% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 50% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 55% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 60% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 65% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 70% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 75% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 80% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 85% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 90% complete for CML17iCD34Imatinib.fastq\r\n",
      "Approx 95% complete for CML17iCD34Imatinib.fastq\r\n",
      "Analysis complete for CML17iCD34Imatinib.fastq\r\n"
     ]
    }
   ],
   "source": [
    "# Produce a quality analysis report of the fastq files: \n",
    "/usr/local/bin/FastQC/fastqc -o . BM1KiCD34ctrl.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . BM9iCD34ctrl.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . CML15iCD34ctrl.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . CML17iCD34ctrl.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . BM1KiCD34Imatinib.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . BM9iCD34Imatinib.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . CML15iCD34Imatinib.fastq\n",
    "/usr/local/bin/FastQC/fastqc -o . CML17iCD34Imatinib.fastq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dec 05 01:11:41 ..... started STAR run\r\n",
      "Dec 05 01:11:43 ..... loading genome\r\n",
      "Dec 05 01:11:43 ..... started mapping\r\n",
      "Dec 05 01:20:32 ..... finished successfully\r\n",
      "Dec 05 01:20:34 ..... started STAR run\r\n",
      "Dec 05 01:20:36 ..... loading genome\r\n",
      "Dec 05 01:20:36 ..... started mapping\r\n",
      "Dec 05 01:30:22 ..... finished successfully\r\n",
      "Dec 05 01:30:30 ..... started STAR run\r\n",
      "Dec 05 01:30:30 ..... loading genome\r\n",
      "Dec 05 01:30:30 ..... started mapping\r\n",
      "Dec 05 01:36:36 ..... finished successfully\r\n",
      "Dec 05 01:36:37 ..... started STAR run\r\n",
      "Dec 05 01:36:38 ..... loading genome\r\n",
      "Dec 05 01:36:38 ..... started mapping\r\n",
      "Dec 05 01:46:37 ..... finished successfully\r\n",
      "Dec 05 01:46:39 ..... started STAR run\r\n",
      "Dec 05 01:46:39 ..... loading genome\r\n",
      "Dec 05 01:46:39 ..... started mapping\r\n",
      "Dec 05 01:58:11 ..... finished successfully\r\n",
      "Dec 05 01:58:13 ..... started STAR run\r\n",
      "Dec 05 01:58:13 ..... loading genome\r\n",
      "Dec 05 01:58:13 ..... started mapping\r\n",
      "Dec 05 02:09:33 ..... finished successfully\r\n",
      "Dec 05 02:09:35 ..... started STAR run\r\n",
      "Dec 05 02:09:35 ..... loading genome\r\n",
      "Dec 05 02:09:35 ..... started mapping\r\n",
      "Dec 05 02:17:49 ..... finished successfully\r\n",
      "Dec 05 02:17:51 ..... started STAR run\r\n",
      "Dec 05 02:17:51 ..... loading genome\r\n",
      "Dec 05 02:17:51 ..... started mapping\r\n",
      "Dec 05 02:26:15 ..... finished successfully\r\n"
     ]
    }
   ],
   "source": [
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn BM1KiCD34ctrl.fastq \\\n",
    "     --outFileNamePrefix BM1KiCD34ctrl.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn BM9iCD34ctrl.fastq \\\n",
    "     --outFileNamePrefix BM9iCD34ctrl.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn CML15iCD34ctrl.fastq \\\n",
    "     --outFileNamePrefix CML15iCD34ctrl.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn CML17iCD34ctrl.fastq \\\n",
    "     --outFileNamePrefix CML17iCD34ctrl.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn BM1KiCD34Imatinib.fastq \\\n",
    "     --outFileNamePrefix BM1KiCD34Imatinib.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn BM9iCD34Imatinib.fastq \\\n",
    "     --outFileNamePrefix BM9iCD34Imatinib.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn CML15iCD34Imatinib.fastq \\\n",
    "     --outFileNamePrefix CML15iCD34Imatinib.\n",
    "STAR --genomeDir /mnt/nfs/mfiers/STAR/hg19_star_db \\\n",
    "     --genomeLoad LoadAndKeep \\\n",
    "     --runThreadN 2 \\\n",
    "     --readFilesIn CML17iCD34Imatinib.fastq \\\n",
    "     --outFileNamePrefix CML17iCD34Imatinib."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 128532772\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8893494 nov 21 16:02 all.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         581 nov 21 16:02 all.counts.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8236287 nov 21 16:03 all.genedatapsoriasis.tsv\r\n",
      "-rw-r--r-- 1 r0301806 domain users     1042835 nov 21 16:03 all.genepsoriasis.counts.tsv\r\n",
      "-rw-r--r-- 1 r0301806 domain users  8377020745 dec  5 01:20 BM1KiCD34ctrl.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          42 dec  4 22:00 BM1KiCD34ctrl.fastq -> /mnt/nfs/r0301806/work/BM1KiCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      368099 dec  4 22:30 BM1KiCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      465337 dec  4 22:30 BM1KiCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1860 dec  5 01:20 BM1KiCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15617 dec  5 01:20 BM1KiCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1190 dec  5 01:20 BM1KiCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7070891 dec  5 01:20 BM1KiCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10687129697 dec  5 01:58 BM1KiCD34Imatinib.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          46 dec  4 22:00 BM1KiCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/BM1KiCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      378459 dec  4 22:44 BM1KiCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      481856 dec  4 22:44 BM1KiCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1865 dec  5 01:58 BM1KiCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15661 dec  5 01:58 BM1KiCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 dec  5 01:58 BM1KiCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7944769 dec  5 01:58 BM1KiCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  9607237505 dec  5 01:30 BM9iCD34ctrl.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          41 dec  4 22:00 BM9iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/BM9iCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      377620 dec  4 22:34 BM9iCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      480229 dec  4 22:34 BM9iCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1861 dec  5 01:30 BM9iCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15606 dec  5 01:30 BM9iCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1308 dec  5 01:30 BM9iCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7285756 dec  5 01:30 BM9iCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10551475129 dec  5 02:09 BM9iCD34Imatinib.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          45 dec  4 22:00 BM9iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/BM9iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      371200 dec  4 22:48 BM9iCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      472125 dec  4 22:48 BM9iCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1865 dec  5 02:09 BM9iCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15650 dec  5 02:09 BM9iCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 dec  5 02:09 BM9iCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7916917 dec  5 02:09 BM9iCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  7937668022 dec  5 01:36 CML15iCD34ctrl.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          43 dec  4 22:00 CML15iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/CML15iCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      347429 dec  4 22:36 CML15iCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      464894 dec  4 22:36 CML15iCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 01:36 CML15iCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15628 dec  5 01:36 CML15iCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users         954 dec  5 01:36 CML15iCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     6368408 dec  5 01:36 CML15iCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10396446591 dec  5 02:17 CML15iCD34Imatinib.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          47 dec  4 22:00 CML15iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/CML15iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      354469 dec  4 22:51 CML15iCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      476716 dec  4 22:51 CML15iCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 02:17 CML15iCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15672 dec  5 02:17 CML15iCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1190 dec  5 02:17 CML15iCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     6745982 dec  5 02:17 CML15iCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 11890085438 dec  5 01:46 CML17iCD34ctrl.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          43 dec  4 22:00 CML17iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/CML17iCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      353308 dec  4 22:40 CML17iCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      474168 dec  4 22:40 CML17iCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 01:46 CML17iCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15628 dec  5 01:46 CML17iCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1308 dec  5 01:46 CML17iCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7040471 dec  5 01:46 CML17iCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10114207357 dec  5 02:26 CML17iCD34Imatinib.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          47 dec  4 22:00 CML17iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/CML17iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      374390 dec  4 22:54 CML17iCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      506195 dec  4 22:54 CML17iCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 02:26 CML17iCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15672 dec  5 02:26 CML17iCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1190 dec  5 02:26 CML17iCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     6711559 dec  5 02:26 CML17iCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3650241 nov 23 14:32 deseq.results.tsv\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          30 dec  4 21:58 *.fastq -> /mnt/nfs/r0304814/work/*.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          56 nov 21 15:48 gencode.v19.nopseudo.plus.sort.gtf -> /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\r\n",
      "-rw-r--r-- 1 r0301806 domain users  6454489687 nov 21 01:56 LS252.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1789388164 nov 21 12:30 LS252.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3400288 nov 21 14:11 LS252.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8344733 nov 21 15:53 LS252.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         296 nov 21 15:53 LS252.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          34 dec  4 22:00 LS252.fastq -> /mnt/nfs/r0301806/work/LS252.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      360945 nov 21 00:07 LS252_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      488111 nov 21 00:07 LS252_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1861 nov 21 01:56 LS252.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15529 nov 21 01:56 LS252.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1662 nov 21 01:56 LS252.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     4764141 nov 21 01:56 LS252.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  7415056438 nov 21 02:08 LS287.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1664684723 nov 21 14:23 LS287.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3314240 nov 21 14:30 LS287.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8347231 nov 21 15:54 LS287.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         296 nov 21 15:54 LS287.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          34 dec  4 22:00 LS287.fastq -> /mnt/nfs/r0301806/work/LS287.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      347480 nov 21 00:16 LS287_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      398871 nov 21 00:16 LS287_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 nov 21 02:08 LS287.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15529 nov 21 02:08 LS287.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 nov 21 02:08 LS287.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     5397055 nov 21 02:08 LS287.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  7007092341 nov 21 02:29 LS292.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1533098382 nov 21 14:45 LS292.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3333560 nov 21 14:50 LS292.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8345888 nov 21 15:54 LS292.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         296 nov 21 15:54 LS292.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          34 dec  4 22:00 LS292.fastq -> /mnt/nfs/r0301806/work/LS292.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      352315 nov 21 00:26 LS292_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      407732 nov 21 00:26 LS292_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 nov 21 02:29 LS292.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15529 nov 21 02:29 LS292.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 nov 21 02:29 LS292.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     5091426 nov 21 02:29 LS292.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  7350612418 nov 21 02:45 NL251.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1632509502 nov 21 14:59 NL251.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3291184 nov 21 15:01 NL251.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8345311 nov 21 15:55 NL251.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         296 nov 21 15:55 NL251.counts.summary\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          34 dec  4 22:00 NL251.fastq -> /mnt/nfs/r0301806/work/NL251.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      366906 nov 21 00:55 NL251_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      425938 nov 21 00:55 NL251_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 nov 21 02:45 NL251.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15529 nov 21 02:45 NL251.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1662 nov 21 02:45 NL251.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     4902687 nov 21 02:45 NL251.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users           0 nov 21 02:51 NL286.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1541773300 nov 21 15:21 NL286.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3387208 nov 21 15:22 NL286.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8345371 nov 21 15:56 NL286.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         296 nov 21 15:56 NL286.counts.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users       13128 nov 21 02:51 NL286.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users           0 nov 21 02:51 NL286.Log.progress.out\r\n",
      "drwx------ 2 r0301806 domain users        4096 nov 21 02:51 NL286._STARtmp\r\n",
      "-rw-r--r-- 1 r0301806 domain users  7218709786 nov 21 03:04 NL287.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          34 dec  4 22:00 NL287.fastq -> /mnt/nfs/r0301806/work/NL287.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      343862 nov 21 01:11 NL287_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      397127 nov 21 01:11 NL287_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 nov 21 03:04 NL287.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15529 nov 21 03:04 NL287.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1662 nov 21 03:04 NL287.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     4939340 nov 21 03:04 NL287.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1456424671 nov 21 15:30 NL291.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3334656 nov 21 15:31 NL291.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users     8345915 nov 21 15:56 NL291.counts\r\n",
      "-rw-r--r-- 1 r0301806 domain users         296 nov 21 15:56 NL291.counts.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users  6801108258 nov 21 03:21 NL292.Aligned.out.sam\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          34 dec  4 22:00 NL292.fastq -> /mnt/nfs/r0301806/work/NL292.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      368992 nov 21 01:28 NL292_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      434603 nov 21 01:28 NL292_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 nov 21 03:21 NL292.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15529 nov 21 03:21 NL292.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 nov 21 03:21 NL292.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     5139326 nov 21 03:21 NL292.SJ.out.tab\r\n"
     ]
    }
   ],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SRR1536065.1\t16\tchr2\t191878752\t255\t73M\t*\t0\t0\tCAGGATCCGGAAGGGCTAGGCGGGGGCGCGGCGGTGCAGCCTCTCCCGAGCGCGCTGGGTCGCCTCTGCTCGG\t@CC>55-5939CA9>3<6:1BCCBBB@8==89(CCBBCBBB<EBEGGB@EGHGCFGGDHGHFHAFDFAFD@@@\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.2\t0\tchr18\t33619185\t255\t73M\t*\t0\t0\tCTGTAAGTTTCCTGAGGCCTCCCCAGCAATGCAGAACTGTGAGTCAATTAAATTTCTTTTCTTCAAAAATTAC\tCCCFFFFDHHHHHJJJJJJJJJJJIJJJJJJJGGJJJJJHIIJGIIIJJJJJJJJJJJJJJIJIGIJIJJJIG\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.3\t0\tchrX\t109419058\t255\t73M\t*\t0\t0\tCTCTTATCTTGGGCCAAGCCAACGTGGAGAGAAGCAACCCAACCAGACTCTTGGCAGCCTGCCTTACAGGGTA\tBCCFFFFFHGHHHJJJJJJJIJJJFHHFIIIIIGIIEIIIJJIIJIJJJJJIJJJEIJHHHHFFFFFFECCAC\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.4\t0\tchr7\t938258\t255\t1S72M\t*\t0\t0\tCCGGGAGCCAGACTGGGCCCTGGAGGAAAGGGGGCCCCGGGTCAGGGAGGGGCAGGTTGGCTGGGTGTGGTCA\t@C@FFFDFFFHHHFFFEGIEHII?FHAHIHGGEEHGIHGHF5=CACB?@?@?@5<8<C<BCABDD355<<3>>\tNH:i:1\tHI:i:1\tAS:i:70\tnM:i:0\r\n",
      "SRR1536065.6\t16\tchr22\t30736758\t255\t44M879N29M\t*\t0\t0\tGGGGGTGGGGGCACTTTCTGCCCTTCTTCTTCATCATCTGAACCCTCATCCATATCTTGTACTTGGGTGTCCT\tDCDBDAHEJIHF@JJIJIHDGHHJIGJHFHHDDJJJIHHG?FJJJJJIJJIGJJJJJIHGFHHHHFDFFFCC@\tNH:i:1\tHI:i:1\tAS:i:73\tnM:i:0\r\n",
      "SRR1536065.7\t0\tchr5\t81572333\t255\t5M1174N68M\t*\t0\t0\tCTCCTACTTTTTCCAGCACGATTCCTTTTGCATGAGAAGCACCTCCAAAAGGGTTGGCCTTTAGGGCTGTGCC\tCCCFFFFFHHHHHJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJIJJJIJJJJJJJJJJJJHHHFFFF\tNH:i:1\tHI:i:1\tAS:i:72\tnM:i:0\r\n",
      "SRR1536065.8\t0\tchr1\t224621800\t255\t73M\t*\t0\t0\tGCCTGCATGATGCTGCCGCTGACCAGGCTGTGGCCGCTACTTCGGTGGGGGACAGCAGCGGCGGCGGGAGGGG\t@CCFFFF:DHHHHJJJJJJJJJJJJJJJJJJJJIIHIIJJHIJJJ;FHHHFCDDDDDDDDDDDDDDDD7@BDD\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.9\t16\tchr22\t38203034\t255\t73M\t*\t0\t0\tTGGTTTGGTGGGGCTGCGGCCACTTAAAACCTCCCGATCTCTTTTTGAGTCCTTTATTATAAGTAGTTGTAGC\tABBADDDDDDAFFHHIIHFC@EIGIHFB7IIGAIGHGGIIHCGIJJJIGJJIJGGIJIHHFFHHDFDFFF@@@\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.10\t0\tchr20\t1903207\t3\t73M\t*\t0\t0\tCATGACGGGCAGCCAGCGGTCAGCAAAAGCCATGACCTGAAGGTCTCAGCCCACCCGAAGGAGCAGGGCTCAA\t@CCFFFFFGHHHHJGIIIJCDGHGIIJIIIIJIGIJJJIIJJJCHGIGIGJCEFHFFFDDDBDBDDBDDBDDD\tNH:i:2\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.10\t272\tchr20\t1584468\t3\t73M\t*\t0\t0\tTTGAGCCCTGCTCCTTCGGGTGGGCTGAGACCTTCAGGTCATGGCTTTTGCTGACCGCTGGCTGCCCGTCATG\tDDDBDDBDDBDBDDDFFFHFECJGIGIGHCJJJIIJJJIGIJIIIIJIIGHGDCJIIIGJHHHHGFFFFFCC@\tNH:i:2\tHI:i:2\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.11\t16\tchr2\t242062181\t255\t73M\t*\t0\t0\tACGAAGCCGAAGGCCCCACTGCCCAGCGGGCTCATGGTACTGTACTTTTGGGAGTACTCGCCCTCACAGGCCG\tCDDDDDDDDDDDDDFFFFHHHHJJJJJJJJJIGJJIIIIIJIIGJJJJJJJJJIHHJJJJHHHHHFFFFFCCC\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n",
      "SRR1536065.12\t16\tchr9\t128003503\t255\t73M\t*\t0\t0\tTCACAAGGCGCCACGAACCAGGCGAAGGGCAGGTCTAGAAATACAGGCCGCGGCGCTTCCCTCTCACACTCGC\tDDDDDDDDDDDDDDDDDDDDDDDEEFFFFHHHHHHIJJJJIJIIJJJJJJJJJJJJJJJJHHHHHDDDFFCCB\tNH:i:1\tHI:i:1\tAS:i:71\tnM:i:0\r\n"
     ]
    }
   ],
   "source": [
    "# SAM file structure:\n",
    "# A SAM file is a text file containing the alignment of all reads. \n",
    "# SAM files start with a header:(Please do not use `cat` as this will crash your notebook!!)\n",
    "head -40 BM1KiCD34Imatinib.Aligned.out.sam | grep -v '^@'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[bam_sort_core] merging from 15 files...\r\n",
      "[bam_sort_core] merging from 18 files...\r\n",
      "[bam_sort_core] merging from 13 files...\r\n",
      "[bam_sort_core] merging from 22 files...\r\n",
      "[bam_sort_core] merging from 19 files...\r\n",
      "[bam_sort_core] merging from 19 files...\r\n",
      "[bam_sort_core] merging from 19 files...\r\n",
      "[bam_sort_core] merging from 18 files...\r\n"
     ]
    }
   ],
   "source": [
    "# SAM files are unsorted and uncompressed. To solve this, we will sort the SAM files and convert them to a BAM file.\n",
    "# This BAM file is a smaller / more compressed version of the SAM file.\n",
    "# Afterwards we will create an index for quick access. We will use samtools to do this. \n",
    "# In the first step we will sort and output BAM files: \n",
    "samtools sort -o BM1KiCD34ctrl.bam BM1KiCD34ctrl.Aligned.out.sam\n",
    "samtools index BM1KiCD34ctrl.bam\n",
    "samtools sort -o BM9iCD34ctrl.bam BM9iCD34ctrl.Aligned.out.sam\n",
    "samtools index BM9iCD34ctrl.bam\n",
    "samtools sort -o CML15iCD34ctrl.bam CML15iCD34ctrl.Aligned.out.sam\n",
    "samtools index CML15iCD34ctrl.bam\n",
    "samtools sort -o CML17iCD34ctrl.bam CML17iCD34ctrl.Aligned.out.sam\n",
    "samtools index CML17iCD34ctrl.bam\n",
    "samtools sort -o BM1KiCD34Imatinib.bam BM1KiCD34Imatinib.Aligned.out.sam\n",
    "samtools index BM1KiCD34Imatinib.bam\n",
    "samtools sort -o BM9iCD34Imatinib.bam BM9iCD34Imatinib.Aligned.out.sam\n",
    "samtools index BM9iCD34Imatinib.bam\n",
    "samtools sort -o CML15iCD34Imatinib.bam CML15iCD34Imatinib.Aligned.out.sam\n",
    "samtools index CML15iCD34Imatinib.bam\n",
    "samtools sort -o CML17iCD34Imatinib.bam CML17iCD34Imatinib.Aligned.out.sam\n",
    "samtools index CML17iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 90730780\r\n",
      "-rw-r--r-- 1 r0301806 domain users  8377020745 dec  5 01:20 BM1KiCD34ctrl.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1351412315 dec  5 17:34 BM1KiCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3133208 dec  5 17:35 BM1KiCD34ctrl.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          42 dec  4 22:00 BM1KiCD34ctrl.fastq -> /mnt/nfs/r0301806/work/BM1KiCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      368099 dec  4 22:30 BM1KiCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      465337 dec  4 22:30 BM1KiCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1860 dec  5 01:20 BM1KiCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15617 dec  5 01:20 BM1KiCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1190 dec  5 01:20 BM1KiCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7070891 dec  5 01:20 BM1KiCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10687129697 dec  5 01:58 BM1KiCD34Imatinib.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1794427349 dec  5 18:14 BM1KiCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3148552 dec  5 18:14 BM1KiCD34Imatinib.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          46 dec  4 22:00 BM1KiCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/BM1KiCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      378459 dec  4 22:44 BM1KiCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      481856 dec  4 22:44 BM1KiCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1865 dec  5 01:58 BM1KiCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15661 dec  5 01:58 BM1KiCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 dec  5 01:58 BM1KiCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7944769 dec  5 01:58 BM1KiCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  9607237505 dec  5 01:30 BM9iCD34ctrl.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1605362021 dec  5 17:44 BM9iCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3030368 dec  5 17:44 BM9iCD34ctrl.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          41 dec  4 22:00 BM9iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/BM9iCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      377620 dec  4 22:34 BM9iCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      480229 dec  4 22:34 BM9iCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1861 dec  5 01:30 BM9iCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15606 dec  5 01:30 BM9iCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1308 dec  5 01:30 BM9iCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7285756 dec  5 01:30 BM9iCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10551475129 dec  5 02:09 BM9iCD34Imatinib.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1756297414 dec  5 18:25 BM9iCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3015256 dec  5 18:26 BM9iCD34Imatinib.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          45 dec  4 22:00 BM9iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/BM9iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      371200 dec  4 22:48 BM9iCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      472125 dec  4 22:48 BM9iCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1865 dec  5 02:09 BM9iCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15650 dec  5 02:09 BM9iCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1544 dec  5 02:09 BM9iCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7916917 dec  5 02:09 BM9iCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users  7937668022 dec  5 01:36 CML15iCD34ctrl.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1353637052 dec  5 17:52 CML15iCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3491712 dec  5 17:52 CML15iCD34ctrl.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          43 dec  4 22:00 CML15iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/CML15iCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      347429 dec  4 22:36 CML15iCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      464894 dec  4 22:36 CML15iCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 01:36 CML15iCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15628 dec  5 01:36 CML15iCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users         954 dec  5 01:36 CML15iCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     6368408 dec  5 01:36 CML15iCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10396446591 dec  5 02:17 CML15iCD34Imatinib.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1752153628 dec  5 18:37 CML15iCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3628768 dec  5 18:37 CML15iCD34Imatinib.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          47 dec  4 22:00 CML15iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/CML15iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      354469 dec  4 22:51 CML15iCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      476716 dec  4 22:51 CML15iCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 02:17 CML15iCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15672 dec  5 02:17 CML15iCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1190 dec  5 02:17 CML15iCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     6745982 dec  5 02:17 CML15iCD34Imatinib.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 11890085438 dec  5 01:46 CML17iCD34ctrl.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1954045833 dec  5 18:03 CML17iCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3693024 dec  5 18:04 CML17iCD34ctrl.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          43 dec  4 22:00 CML17iCD34ctrl.fastq -> /mnt/nfs/r0301806/work/CML17iCD34ctrl.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      353308 dec  4 22:40 CML17iCD34ctrl_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      474168 dec  4 22:40 CML17iCD34ctrl_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 01:46 CML17iCD34ctrl.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15628 dec  5 01:46 CML17iCD34ctrl.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1308 dec  5 01:46 CML17iCD34ctrl.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     7040471 dec  5 01:46 CML17iCD34ctrl.SJ.out.tab\r\n",
      "-rw-r--r-- 1 r0301806 domain users 10114207357 dec  5 02:26 CML17iCD34Imatinib.Aligned.out.sam\r\n",
      "-rw-r--r-- 1 r0301806 domain users  1688825705 dec  5 18:48 CML17iCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users     3572904 dec  5 18:49 CML17iCD34Imatinib.bam.bai\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          47 dec  4 22:00 CML17iCD34Imatinib.fastq -> /mnt/nfs/r0301806/work/CML17iCD34Imatinib.fastq\r\n",
      "-rw-r--r-- 1 r0301806 domain users      374390 dec  4 22:54 CML17iCD34Imatinib_fastqc.html\r\n",
      "-rw-r--r-- 1 r0301806 domain users      506195 dec  4 22:54 CML17iCD34Imatinib_fastqc.zip\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1862 dec  5 02:26 CML17iCD34Imatinib.Log.final.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users       15672 dec  5 02:26 CML17iCD34Imatinib.Log.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users        1190 dec  5 02:26 CML17iCD34Imatinib.Log.progress.out\r\n",
      "-rw-r--r-- 1 r0301806 domain users     6711559 dec  5 02:26 CML17iCD34Imatinib.SJ.out.tab\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          30 dec  4 21:58 *.fastq -> /mnt/nfs/r0304814/work/*.fastq\r\n",
      "lrwxrwxrwx 1 r0301806 domain users          56 nov 21 15:48 gencode.v19.nopseudo.plus.sort.gtf -> /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\r\n",
      "drwx------ 2 r0301806 domain users        4096 nov 21 02:51 NL286._STARtmp\r\n"
     ]
    }
   ],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0301806 domain users 1351412315 dec  5 17:34 BM1KiCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3133208 dec  5 17:35 BM1KiCD34ctrl.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1794427349 dec  5 18:14 BM1KiCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3148552 dec  5 18:14 BM1KiCD34Imatinib.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1605362021 dec  5 17:44 BM9iCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3030368 dec  5 17:44 BM9iCD34ctrl.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1756297414 dec  5 18:25 BM9iCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3015256 dec  5 18:26 BM9iCD34Imatinib.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1353637052 dec  5 17:52 CML15iCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3491712 dec  5 17:52 CML15iCD34ctrl.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1752153628 dec  5 18:37 CML15iCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3628768 dec  5 18:37 CML15iCD34Imatinib.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1954045833 dec  5 18:03 CML17iCD34ctrl.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3693024 dec  5 18:04 CML17iCD34ctrl.bam.bai\r\n",
      "-rw-r--r-- 1 r0301806 domain users 1688825705 dec  5 18:48 CML17iCD34Imatinib.bam\r\n",
      "-rw-r--r-- 1 r0301806 domain users    3572904 dec  5 18:49 CML17iCD34Imatinib.bam.bai\r\n"
     ]
    }
   ],
   "source": [
    "# Inspecting the BAM files:\n",
    "ls -l *.ba[mi]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SRR1536061.53846\t0\tchrM\t1\t255\t5S68M\t*\t0\t0\tCGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGG\tBCCFFFFFHHHHGJHHIJJJJJJJJJJJJJJIIJIIJJJJIIJIJJJJJJJJJIIJJJIFGHJJJJHHGFFFF\tNH:i:1\tHI:i:1\tAS:i:66\tnM:i:0\r\n",
      "SRR1536061.1957653\t0\tchrM\t1\t255\t6S67M\t*\t0\t0\tCCGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGG\tCCCFFFDDDFHHHJJHHGIGHIJJJJIJIGGIGIJJJJJJIJJJIGIJJJJJJJGJIIJGCEHGHEHHHFFEC\tNH:i:1\tHI:i:1\tAS:i:65\tnM:i:0\r\n",
      "SRR1536061.4270660\t0\tchrM\t1\t255\t9S64M\t*\t0\t0\tATCACGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTC\tCCCFFFFFHHHHHJJJJJHGIJJJJJJIJJJJJJJIJJJJJJJJJJJJJJJJJJJJJJJJJJJEHHHHHHFFF\tNH:i:1\tHI:i:1\tAS:i:62\tnM:i:0\r\n",
      "samtools view: writing to standard output failed: Broken pipe\r\n",
      "samtools view: error closing standard output: -1\r\n"
     ]
    }
   ],
   "source": [
    "# If we look at one of them (via head!! Otherwise it will crash), we can see some of the aligned reads:\n",
    "samtools view BM1KiCD34ctrl.bam | head -3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t2423932\t0\r\n",
      "chr1\t249250621\t3724864\t0\r\n",
      "chr2\t243199373\t1975278\t0\r\n",
      "chr3\t198022430\t1565883\t0\r\n",
      "chr4\t191154276\t847480\t0\r\n",
      "chr5\t180915260\t1584134\t0\r\n",
      "chr6\t171115067\t1681343\t0\r\n",
      "chr7\t159138663\t1731045\t0\r\n",
      "chr8\t146364022\t1005674\t0\r\n",
      "chr9\t141213431\t1370783\t0\r\n",
      "chr10\t135534747\t1086201\t0\r\n",
      "chr11\t135006516\t2092541\t0\r\n",
      "chr12\t133851895\t2424916\t0\r\n",
      "chr13\t115169878\t492436\t0\r\n",
      "chr14\t107349540\t818455\t0\r\n",
      "chr15\t102531392\t1025571\t0\r\n",
      "chr16\t90354753\t1660501\t0\r\n",
      "chr17\t81195210\t2582774\t0\r\n",
      "chr18\t78077248\t341374\t0\r\n",
      "chr19\t59128983\t2749573\t0\r\n",
      "chr20\t63025520\t859694\t0\r\n",
      "chr21\t48129895\t369593\t0\r\n",
      "chr22\t51304566\t863832\t0\r\n",
      "chrX\t155270560\t1136491\t0\r\n",
      "chrY\t59373566\t114167\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "# The format of the BAM output is the same as that of the SAM output.\n",
    "# Via idxstats you can see how many reads map to each chromosome:\n",
    "# 4 columns: the reference sequence name, the sequence length, the number of mapped reads and number of unmapped reads\n",
    "\n",
    "samtools idxstats BM1KiCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t2448618\t0\r\n",
      "chr1\t249250621\t4634220\t0\r\n",
      "chr2\t243199373\t2748754\t0\r\n",
      "chr3\t198022430\t2169814\t0\r\n",
      "chr4\t191154276\t1206978\t0\r\n",
      "chr5\t180915260\t2075143\t0\r\n",
      "chr6\t171115067\t2276670\t0\r\n",
      "chr7\t159138663\t2286451\t0\r\n",
      "chr8\t146364022\t1203576\t0\r\n",
      "chr9\t141213431\t1824734\t0\r\n",
      "chr10\t135534747\t1498865\t0\r\n",
      "chr11\t135006516\t2541813\t0\r\n",
      "chr12\t133851895\t3042908\t0\r\n",
      "chr13\t115169878\t669595\t0\r\n",
      "chr14\t107349540\t1215391\t0\r\n",
      "chr15\t102531392\t1451207\t0\r\n",
      "chr16\t90354753\t2033719\t0\r\n",
      "chr17\t81195210\t3264250\t0\r\n",
      "chr18\t78077248\t478072\t0\r\n",
      "chr19\t59128983\t2983153\t0\r\n",
      "chr20\t63025520\t1082395\t0\r\n",
      "chr21\t48129895\t405299\t0\r\n",
      "chr22\t51304566\t1111538\t0\r\n",
      "chrX\t155270560\t1814735\t0\r\n",
      "chrY\t59373566\t88609\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats BM1KiCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t2940103\t0\r\n",
      "chr1\t249250621\t4252628\t0\r\n",
      "chr2\t243199373\t2210641\t0\r\n",
      "chr3\t198022430\t1815239\t0\r\n",
      "chr4\t191154276\t970944\t0\r\n",
      "chr5\t180915260\t1844703\t0\r\n",
      "chr6\t171115067\t1982142\t0\r\n",
      "chr7\t159138663\t1982452\t0\r\n",
      "chr8\t146364022\t1141345\t0\r\n",
      "chr9\t141213431\t1576072\t0\r\n",
      "chr10\t135534747\t1245949\t0\r\n",
      "chr11\t135006516\t2408763\t0\r\n",
      "chr12\t133851895\t2734455\t0\r\n",
      "chr13\t115169878\t574165\t0\r\n",
      "chr14\t107349540\t927776\t0\r\n",
      "chr15\t102531392\t1181059\t0\r\n",
      "chr16\t90354753\t1859445\t0\r\n",
      "chr17\t81195210\t2952721\t0\r\n",
      "chr18\t78077248\t391497\t0\r\n",
      "chr19\t59128983\t3119460\t0\r\n",
      "chr20\t63025520\t976693\t0\r\n",
      "chr21\t48129895\t398584\t0\r\n",
      "chr22\t51304566\t981033\t0\r\n",
      "chrX\t155270560\t1299639\t0\r\n",
      "chrY\t59373566\t132010\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats BM9iCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t2532861\t0\r\n",
      "chr1\t249250621\t4576196\t0\r\n",
      "chr2\t243199373\t2694952\t0\r\n",
      "chr3\t198022430\t2127437\t0\r\n",
      "chr4\t191154276\t1174529\t0\r\n",
      "chr5\t180915260\t2036603\t0\r\n",
      "chr6\t171115067\t2252667\t0\r\n",
      "chr7\t159138663\t2224495\t0\r\n",
      "chr8\t146364022\t1178883\t0\r\n",
      "chr9\t141213431\t1814060\t0\r\n",
      "chr10\t135534747\t1462155\t0\r\n",
      "chr11\t135006516\t2496213\t0\r\n",
      "chr12\t133851895\t2985442\t0\r\n",
      "chr13\t115169878\t654677\t0\r\n",
      "chr14\t107349540\t1181820\t0\r\n",
      "chr15\t102531392\t1446279\t0\r\n",
      "chr16\t90354753\t1973230\t0\r\n",
      "chr17\t81195210\t3235389\t0\r\n",
      "chr18\t78077248\t470002\t0\r\n",
      "chr19\t59128983\t2973468\t0\r\n",
      "chr20\t63025520\t1066902\t0\r\n",
      "chr21\t48129895\t400492\t0\r\n",
      "chr22\t51304566\t1098591\t0\r\n",
      "chrX\t155270560\t1811927\t0\r\n",
      "chrY\t59373566\t90265\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats BM9iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t3921728\t0\r\n",
      "chr1\t249250621\t4562188\t0\r\n",
      "chr2\t243199373\t2361501\t0\r\n",
      "chr3\t198022430\t1917332\t0\r\n",
      "chr4\t191154276\t1137532\t0\r\n",
      "chr5\t180915260\t2039193\t0\r\n",
      "chr6\t171115067\t1924827\t0\r\n",
      "chr7\t159138663\t2009158\t0\r\n",
      "chr8\t146364022\t1039499\t0\r\n",
      "chr9\t141213431\t1634808\t0\r\n",
      "chr10\t135534747\t1256826\t0\r\n",
      "chr11\t135006516\t2117889\t0\r\n",
      "chr12\t133851895\t2656888\t0\r\n",
      "chr13\t115169878\t637737\t0\r\n",
      "chr14\t107349540\t1012502\t0\r\n",
      "chr15\t102531392\t1292377\t0\r\n",
      "chr16\t90354753\t1739558\t0\r\n",
      "chr17\t81195210\t2781670\t0\r\n",
      "chr18\t78077248\t451269\t0\r\n",
      "chr19\t59128983\t2523633\t0\r\n",
      "chr20\t63025520\t944286\t0\r\n",
      "chr21\t48129895\t336343\t0\r\n",
      "chr22\t51304566\t925771\t0\r\n",
      "chrX\t155270560\t1320811\t0\r\n",
      "chrY\t59373566\t101469\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats CML15iCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t4407509\t0\r\n",
      "chr1\t249250621\t5914564\t0\r\n",
      "chr2\t243199373\t3107560\t0\r\n",
      "chr3\t198022430\t2613746\t0\r\n",
      "chr4\t191154276\t1554411\t0\r\n",
      "chr5\t180915260\t2708814\t0\r\n",
      "chr6\t171115067\t2584384\t0\r\n",
      "chr7\t159138663\t2639032\t0\r\n",
      "chr8\t146364022\t1440857\t0\r\n",
      "chr9\t141213431\t2163922\t0\r\n",
      "chr10\t135534747\t1767453\t0\r\n",
      "chr11\t135006516\t2941344\t0\r\n",
      "chr12\t133851895\t3581635\t0\r\n",
      "chr13\t115169878\t880348\t0\r\n",
      "chr14\t107349540\t1335422\t0\r\n",
      "chr15\t102531392\t1809984\t0\r\n",
      "chr16\t90354753\t2132110\t0\r\n",
      "chr17\t81195210\t3582046\t0\r\n",
      "chr18\t78077248\t599512\t0\r\n",
      "chr19\t59128983\t3144318\t0\r\n",
      "chr20\t63025520\t1287982\t0\r\n",
      "chr21\t48129895\t439303\t0\r\n",
      "chr22\t51304566\t1183385\t0\r\n",
      "chrX\t155270560\t1842582\t0\r\n",
      "chrY\t59373566\t140380\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats CML15iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t4784721\t0\r\n",
      "chr1\t249250621\t6658417\t0\r\n",
      "chr2\t243199373\t3640794\t0\r\n",
      "chr3\t198022430\t2966055\t0\r\n",
      "chr4\t191154276\t1764557\t0\r\n",
      "chr5\t180915260\t3137986\t0\r\n",
      "chr6\t171115067\t3072552\t0\r\n",
      "chr7\t159138663\t3039195\t0\r\n",
      "chr8\t146364022\t1622578\t0\r\n",
      "chr9\t141213431\t2545818\t0\r\n",
      "chr10\t135534747\t1886831\t0\r\n",
      "chr11\t135006516\t3392428\t0\r\n",
      "chr12\t133851895\t3989660\t0\r\n",
      "chr13\t115169878\t976725\t0\r\n",
      "chr14\t107349540\t1543591\t0\r\n",
      "chr15\t102531392\t2041557\t0\r\n",
      "chr16\t90354753\t2535756\t0\r\n",
      "chr17\t81195210\t4264742\t0\r\n",
      "chr18\t78077248\t687298\t0\r\n",
      "chr19\t59128983\t3778754\t0\r\n",
      "chr20\t63025520\t1374573\t0\r\n",
      "chr21\t48129895\t489333\t0\r\n",
      "chr22\t51304566\t1404643\t0\r\n",
      "chrX\t155270560\t2035964\t0\r\n",
      "chrY\t59373566\t163420\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats CML17iCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chrM\t16571\t3628615\t0\r\n",
      "chr1\t249250621\t5629005\t0\r\n",
      "chr2\t243199373\t3034395\t0\r\n",
      "chr3\t198022430\t2550732\t0\r\n",
      "chr4\t191154276\t1499595\t0\r\n",
      "chr5\t180915260\t2601427\t0\r\n",
      "chr6\t171115067\t2556533\t0\r\n",
      "chr7\t159138663\t2612734\t0\r\n",
      "chr8\t146364022\t1427909\t0\r\n",
      "chr9\t141213431\t2142621\t0\r\n",
      "chr10\t135534747\t1706361\t0\r\n",
      "chr11\t135006516\t2980791\t0\r\n",
      "chr12\t133851895\t3464962\t0\r\n",
      "chr13\t115169878\t840544\t0\r\n",
      "chr14\t107349540\t1287069\t0\r\n",
      "chr15\t102531392\t1774950\t0\r\n",
      "chr16\t90354753\t2117487\t0\r\n",
      "chr17\t81195210\t3639391\t0\r\n",
      "chr18\t78077248\t570364\t0\r\n",
      "chr19\t59128983\t3312195\t0\r\n",
      "chr20\t63025520\t1286123\t0\r\n",
      "chr21\t48129895\t434038\t0\r\n",
      "chr22\t51304566\t1206153\t0\r\n",
      "chrX\t155270560\t1819299\t0\r\n",
      "chrY\t59373566\t140029\t0\r\n",
      "*\t0\t0\t0\r\n"
     ]
    }
   ],
   "source": [
    "samtools idxstats CML17iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36528535 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "3994477 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "36528535 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "# Running samtools flagstat tells us what the distribution of mapping flags (column 2 in the sam/bam file) is:\n",
    "\n",
    "# 0x0001    p    the read is paired in sequencing\n",
    "# 0x0002    P    the read is mapped in a proper pair\n",
    "# 0x0004    u    the query sequence itself is unmapped\n",
    "# 0x0008    U    the mate is unmapped\n",
    "# 0x0010    r    strand of the query (1 for reverse)\n",
    "# 0x0020    R    strand of the mate\n",
    "# 0x0040    1    the read is the first read in a pair\n",
    "# 0x0080    2    the read is the second read in a pair\n",
    "# 0x0100    s    the alignment is not primary\n",
    "# 0x0200    f    the read fails platform/vendor quality checks\n",
    "# 0x0400    d    the read is either a PCR or an optical duplicate\n",
    "# 0x0800    S    the alignment is supplementary\n",
    "\n",
    "# info : http://www.htslib.org/doc/samtools.html\n",
    "\n",
    "samtools flagstat BM1KiCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "46556507 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "4901155 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "46556507 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat BM1KiCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41899518 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "4800570 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "41899518 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat BM9iCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45959535 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "4837686 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "45959535 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat BM9iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42646795 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "8509125 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "42646795 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat CML15iCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "55802603 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "11004048 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "55802603 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat CML15iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "63797948 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "13224757 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "63797948 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat CML17iCD34ctrl.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "54263322 + 0 in total (QC-passed reads + QC-failed reads)\r\n",
      "10637089 + 0 secondary\r\n",
      "0 + 0 supplementary\r\n",
      "0 + 0 duplicates\r\n",
      "54263322 + 0 mapped (100.00% : N/A)\r\n",
      "0 + 0 paired in sequencing\r\n",
      "0 + 0 read1\r\n",
      "0 + 0 read2\r\n",
      "0 + 0 properly paired (N/A : N/A)\r\n",
      "0 + 0 with itself and mate mapped\r\n",
      "0 + 0 singletons (N/A : N/A)\r\n",
      "0 + 0 with mate mapped to a different chr\r\n",
      "0 + 0 with mate mapped to a different chr (mapQ>=5)\r\n"
     ]
    }
   ],
   "source": [
    "samtools flagstat CML17iCD34Imatinib.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lrwxrwxrwx 1 r0301806 domain users 56 dec  5 19:20 gencode.v19.nopseudo.plus.sort.gtf -> /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\r\n"
     ]
    }
   ],
   "source": [
    "# reads to gene counts: \n",
    "# First we'll make a symbolic link to (a part of!) the human annotation.\n",
    "ln -sf /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\n",
    "ls -l *gtf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "##description: evidence-based annotation of the human genome (GRCh37), version 19 (Ensembl 74)\r\n",
      "##provider: GENCODE\r\n",
      "##contact: gencode@sanger.ac.uk\r\n"
     ]
    }
   ],
   "source": [
    "head -3 gencode.v19.nopseudo.plus.sort.gtf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "featureCounts: unrecognized option '--help'\r\n",
      "\r\n",
      "Version 1.5.0-p1\r\n",
      "\r\n",
      "Usage: featureCounts [options] -a <annotation_file> -o <output_file> input_file1 [input_file2] ... \r\n",
      "\r\n",
      "Required arguments:\r\n",
      "\r\n",
      "  -a <string>         Name of an annotation file. GTF format by default. See -F \r\n",
      "                      option for more formats.\r\n",
      "\r\n",
      "  -o <string>         Name of the output file including read counts. A separate \r\n",
      "                      file including summary statistics of counting results is \r\n",
      "                      also included in the output (`<string>.summary')\r\n",
      "\r\n",
      "  input_files         List of input files in BAM or SAM format. Users do not \r\n",
      "                      need to specify it is BAM or SAM.\r\n",
      "\r\n",
      "Optional arguments:\r\n",
      "\r\n",
      "  -A <string>         Name of a comma delimited file including chromosome alias \r\n",
      "                      names used to match chromosome names used in annotation \r\n",
      "                      with those used in BAM/SAM input, if they are different. \r\n",
      "                      See Users Guide for file format.\r\n",
      "\r\n",
      "  -F <string>         Specify format of provided annotation file. Acceptable \r\n",
      "                      formats include `GTF' and `SAF'. `GTF' by default. See \r\n",
      "                      Users Guide for description of SAF format.\r\n",
      "\r\n",
      "  -t <string>         Specify feature type in GTF annotation. `exon' by \r\n",
      "                      default. Features used for read counting will be \r\n",
      "                      extracted from annotation using the provided value.\r\n",
      "\r\n",
      "  -g <string>         Specify attribute type in GTF annotation. `gene_id' by \r\n",
      "                      default. Meta-features used for read counting will be \r\n",
      "                      extracted from annotation using the provided value.\r\n",
      "\r\n",
      "  -f                  Perform read counting at feature level (eg. counting \r\n",
      "                      reads for exons rather than genes).\r\n",
      "\r\n",
      "  -O                  Assign reads to all their overlapping meta-features (or \r\n",
      "                      features if -f is specified).\r\n",
      "\r\n",
      "  -s <int>            Perform strand-specific read counting. Possible values:  \r\n",
      "                      0 (unstranded), 1 (stranded) and 2 (reversely stranded). \r\n",
      "                      0 by default.\r\n",
      "\r\n",
      "  -M                  Multi-mapping reads will also be counted. For a multi-\r\n",
      "                      mapping read, all its reported alignments will be \r\n",
      "                      counted. The `NH' tag in BAM/SAM input is used to detect \r\n",
      "                      multi-mapping reads.\r\n",
      "\r\n",
      "  -Q <int>            The minimum mapping quality score a read must satisfy in\r\n",
      "                      order to be counted. For paired-end reads, at least one\r\n",
      "                      end should satisfy this criteria. 0 by default.\r\n",
      "\r\n",
      "  -T <int>            Number of the threads. 1 by default.\r\n",
      "\r\n",
      "  -v                  Output version of the program.\r\n",
      "\r\n",
      "  -J                  Count number of reads supporting each exon-exon junction.\r\n",
      "                      Junctions were identified from those exon-spanning reads\r\n",
      "                      in the input (containing 'N' in CIGAR string). Counting\r\n",
      "                      results are saved to a file named '<output_file>.jcounts'\r\n",
      "\r\n",
      "  -G <string>         The Fasta file containing the reference genome used in\r\n",
      "                      generating the input SAM or BAM files. This argument is\r\n",
      "                      only needed when doing junction counting.\r\n",
      "\r\n",
      "  -R                  Output detailed assignment result for each read. A text \r\n",
      "                      file will be generated for each input file, including \r\n",
      "                      names of reads and meta-features/features reads were \r\n",
      "                      assigned to. See Users Guide for more details.\r\n",
      "\r\n",
      "  --largestOverlap    Assign reads to a meta-feature/feature that has the \r\n",
      "                      largest number of overlapping bases.\r\n",
      "\r\n",
      "  --minOverlap <int>  Specify minimum number of overlapping bases requried \r\n",
      "                      between a read and a meta-feature/feature that the read \r\n",
      "                      is assigned to. 1 by default.\r\n",
      "\r\n",
      "  --read2pos <5:3>    Reduce reads to their 5' most base or 3' most base. Read\r\n",
      "                      counting is then performed based on the single base the \r\n",
      "                      read is reduced to.\r\n",
      "\r\n",
      "  --readExtension5 <int> Reads are extended upstream by <int> bases from their\r\n",
      "                      5' end.\r\n",
      "\r\n",
      "  --readExtension3 <int> Reads are extended upstream by <int> bases from their\r\n",
      "                      3' end.\r\n",
      "\r\n",
      "  --fraction          Use a fractional count 1/n, instead of 1 (one) count, for \r\n",
      "                      each reported alignment of a multi-mapping read in read \r\n",
      "                      counting. n is total number of alignments reported for \r\n",
      "                      the multi-mapping read. This option must be used together \r\n",
      "                      with '-M' option.\r\n",
      "\r\n",
      "  --primary           Count primary alignments only. Primary alignments are \r\n",
      "                      identified using bit 0x100 in SAM/BAM FLAG field.\r\n",
      "\r\n",
      "  --ignoreDup         Ignore duplicate reads in read counting. Duplicate reads \r\n",
      "                      are identified using bit Ox400 in BAM/SAM FLAG field. The \r\n",
      "                      whole read pair is ignored if one of the reads is a \r\n",
      "                      duplicate read for paired end data.\r\n",
      "\r\n",
      "  --countSplitAlignmentsOnly Count split alignments only (ie. alignments with \r\n",
      "                      CIGAR string containing `N'). An example of split \r\n",
      "                      alignments is exon-spanning reads in RNA-seq data.\r\n",
      "\r\n",
      "  -p                  Count fragments (read pairs) instead of individual reads. \r\n",
      "                      For each read pair, its two reads must be adjacent to \r\n",
      "                      each other in BAM/SAM input.\r\n",
      "\r\n",
      "  -P                  Check validity of paired-end distance when counting read \r\n",
      "                      pairs. Use -d and -D to set thresholds.\r\n",
      "\r\n",
      "  -d <int>            Minimum fragment/template length, 50 by default.\r\n",
      "\r\n",
      "  -D <int>            Maximum fragment/template length, 600 by default.\r\n",
      "\r\n",
      "  -B                  Count read pairs that have both ends successfully aligned \r\n",
      "                      only.\r\n",
      "\r\n",
      "  -S <ff:fr:rf>       Specify orientation of two reads from the same pair, 'fr' \r\n",
      "                      by by default (forward/reverse).\r\n",
      "\r\n",
      "  -C                  Do not count read pairs that have their two ends mapping \r\n",
      "                      to different chromosomes or mapping to same chromosome \r\n",
      "                      but on different strands.\r\n",
      "\r\n",
      "  --donotsort         Do not sort reads in BAM/SAM input. Note that reads from \r\n",
      "                      the same pair are required to be located next to each \r\n",
      "                      other in the input.\r\n",
      "\r\n",
      "  --maxMOp <int>      Maximum number of 'M' operations allowed in a CIGAR string\r\n",
      "                      . 10 by default. Both 'X' and '=' are treated as 'M' and\r\n",
      "                      adjacent 'M' operations are merged in the CIGAR string.\r\n",
      "\r\n"
     ]
    }
   ],
   "source": [
    "featureCounts --help"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cd /mnt/storage/r0301806/RNAseqgroepswerk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "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 CML15iCD34ctrl.bam\u001b[0m \u001b[0m                            ||\r\n",
      "||                           \u001b[32mS\u001b[36m CML15iCD34Imatinib.bam\u001b[0m \u001b[0m                        ||\r\n",
      "||                           \u001b[32mS\u001b[36m CML17iCD34ctrl.bam\u001b[0m \u001b[0m                            ||\r\n",
      "||                           \u001b[32mS\u001b[36m CML17iCD34Imatinib.bam\u001b[0m \u001b[0m                        ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||             Output file : \u001b[36mall.CMLcounts2\u001b[0m \u001b[0m                                  ||\r\n",
      "||             Annotations : \u001b[36m/mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.p\u001b[0m ...\u001b[0m \u001b[0m||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "||                 Threads : \u001b[36m1\u001b[0m \u001b[0m                                               ||\r\n",
      "||                   Level : \u001b[36mmeta-feature level\u001b[0m \u001b[0m                              ||\r\n",
      "||              Paired-end : \u001b[36mno\u001b[0m \u001b[0m                                              ||\r\n",
      "||         Strand specific : \u001b[36mno\u001b[0m \u001b[0m                                              ||\r\n",
      "||      Multimapping reads : \u001b[36mnot counted\u001b[0m \u001b[0m                                     ||\r\n",
      "|| Multi-overlapping reads : \u001b[36mnot counted\u001b[0m \u001b[0m                                     ||\r\n",
      "||       Read orientations : \u001b[36mfr\u001b[0m \u001b[0m                                              ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "\\\\=====================\u001b[36m http://subread.sourceforge.net/ \u001b[0m======================//\r\n",
      "\r\n",
      "//=================================\u001b[36m Running \u001b[0m==================================\\\\\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Load annotation file /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.s\u001b[0m ... \u001b[0m||\r\n",
      "||    Features : \u001b[36m1156385\u001b[0m \u001b[0m                                                     ||\r\n",
      "||    Meta-features : \u001b[36m41863\u001b[0m \u001b[0m                                                  ||\r\n",
      "||    Chromosomes/contigs : \u001b[36m25\u001b[0m \u001b[0m                                               ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file CML15iCD34ctrl.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[36m42646795\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m25158804 (59.0%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m0.92 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file CML15iCD34Imatinib.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[36m55802603\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m33355831 (59.8%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m1.14 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file CML17iCD34ctrl.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[36m63797948\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m37581905 (58.9%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m1.27 minutes\u001b[0m \u001b[0m                                            ||\r\n",
      "||  \u001b[0m                                                                          ||\r\n",
      "|| Process BAM file CML17iCD34Imatinib.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[36m54263322\u001b[0m \u001b[0m                                                 ||\r\n",
      "||    Successfully assigned reads : \u001b[36m32760947 (60.4%)\u001b[0m \u001b[0m                         ||\r\n",
      "||    Running time : \u001b[36m1.12 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 = read summarization program that counts mapped reads for genomic features such as genes, exons, \n",
    "# promoter, gene bodies, genomic bins and chromosomal locations. It can be used to count both RNA-seq and \n",
    "# genomic DNA-seq reads.\n",
    "\n",
    "    # -Q: The minimum mapping quality score (10)\n",
    "    # -g: gene name \n",
    "    # -a: name of the annotation file (gtf)\n",
    "    # -o: output file name\n",
    "    \n",
    " featureCounts \\\n",
    "        -Q 10 \\\n",
    "        -g gene_name \\\n",
    "        -a /mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf \\\n",
    "        -o all.CMLcounts2 \\\n",
    "        CML15iCD34ctrl.bam CML15iCD34Imatinib.bam CML17iCD34ctrl.bam CML17iCD34Imatinib.bam\n",
    "        \n",
    "# Note: This was also done for bone marrow bam files! (/mnt/storage/r0304814/RNAseqgroepswerk)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 r0301806 domain users 9172909 dec  5 19:28 all.CMLcounts\r\n",
      "-rw-r--r-- 1 r0301806 domain users 8707003 jan 25 18:14 all.CMLcounts2\r\n",
      "-rw-r--r-- 1 r0301806 domain users     515 jan 25 18:14 all.CMLcounts2.summary\r\n",
      "-rw-r--r-- 1 r0301806 domain users     781 dec  5 19:28 all.CMLcounts.summary\r\n"
     ]
    }
   ],
   "source": [
    "ls -l *.CMLcounts*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Status                     CML15iCD34ctrl.bam  CML15iCD34Imatinib.bam  CML17iCD34ctrl.bam  CML17iCD34Imatinib.bam\r\n",
      "Assigned                   25158804            33355831                37581905            32760947\r\n",
      "Unassigned_Ambiguity       1659080             2295545                 2645369             2336646\r\n",
      "Unassigned_MultiMapping    0                   0                       0                   0\r\n",
      "Unassigned_NoFeatures      2742696             3360548                 3471454             2999157\r\n",
      "Unassigned_Unmapped        0                   0                       0                   0\r\n",
      "Unassigned_MappingQuality  13086215            16790679                20099220            16166572\r\n",
      "Unassigned_FragmentLength  0                   0                       0                   0\r\n",
      "Unassigned_Chimera         0                   0                       0                   0\r\n",
      "Unassigned_Secondary       0                   0                       0                   0\r\n",
      "Unassigned_Nonjunction     0                   0                       0                   0\r\n",
      "Unassigned_Duplicate       0                   0                       0                   0\r\n"
     ]
    }
   ],
   "source": [
    "head -20 all.CMLcounts2.summary | column -t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Program:featureCounts v1.5.0-p1; Command:\"featureCounts\" \"-Q\" \"10\" \"-g\" \"gene_name\" \"-a\" \"/mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\" \"-o\" \"all.CMLcounts2\" \"CML15iCD34ctrl.bam\" \"CML15iCD34Imatinib.bam\" \"CML17iCD34ctrl.bam\" \"CML17iCD34Imatinib.bam\" \r\n",
      "Geneid\tChr\tStart\tEnd\tStrand\tLength\tCML15iCD34ctrl.bam\tCML15iCD34Imatinib.bam\tCML17iCD34ctrl.bam\tCML17iCD34Imatinib.bam\r\n",
      "MIR1302-11\tchr1;chr1;chr1\t29554;30267;30976\t30039;30667;31109\t+;+;+\t1021\t0\t0\t0\t0\r\n",
      "FAM138A\tchr1;chr1;chr1\t34554;35245;35721\t35174;35481;36081\t-;-;-\t1219\t0\t0\t0\t0\r\n",
      "OR4F5\tchr1\t69091\t70008\t+\t918\t0\t0\t0\t0\r\n",
      "RP11-34P13.7\tchr1;chr1;chr1;chr1;chr1;chr1;chr1\t89295;92091;110953;112700;120721;129055;133374\t91629;92240;111357;112804;120932;129223;133566\t-;-;-;-;-;-;-\t3569\t0\t3\t0\t2\r\n",
      "RP11-34P13.8\tchr1;chr1\t89551;90287\t90050;91105\t-;-\t1319\t0\t0\t0\t0\r\n",
      "AL627309.1\tchr1;chr1\t134901;137621\t135802;139379\t-;-\t2661\t150\t188\t204\t176\r\n",
      "RP11-34P13.14\tchr1;chr1\t139790;140075\t139847;140339\t-;-\t323\t4\t2\t11\t4\r\n",
      "RP11-34P13.13\tchr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1\t141474;146386;155767;164263;165884;168100;168610;169049;172557;173753\t143011;149707;155831;164791;165942;168165;168767;169264;172688;173862\t-;-;-;-;-;-;-;-;-;-\t6195\t8\t28\t22\t20\r\n"
     ]
    }
   ],
   "source": [
    "head all.CMLcounts2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f-6 all.CMLcounts2 > all.genedataCML2.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Program:featureCounts v1.5.0-p1; Command:\"featureCounts\" \"-Q\" \"10\" \"-g\" \"gene_name\" \"-a\" \"/mnt/nfs/data/RNA-seq/gencode.v19.nopseudo.plus.sort.gtf\" \"-o\" \"all.CMLcounts2\" \"CML15iCD34ctrl.bam\" \"CML15iCD34Imatinib.bam\" \"CML17iCD34ctrl.bam\" \"CML17iCD34Imatinib.bam\" \r\n",
      "Geneid\tChr\tStart\tEnd\tStrand\tLength\r\n",
      "MIR1302-11\tchr1;chr1;chr1\t29554;30267;30976\t30039;30667;31109\t+;+;+\t1021\r\n",
      "FAM138A\tchr1;chr1;chr1\t34554;35245;35721\t35174;35481;36081\t-;-;-\t1219\r\n",
      "OR4F5\tchr1\t69091\t70008\t+\t918\r\n",
      "RP11-34P13.7\tchr1;chr1;chr1;chr1;chr1;chr1;chr1\t89295;92091;110953;112700;120721;129055;133374\t91629;92240;111357;112804;120932;129223;133566\t-;-;-;-;-;-;-\t3569\r\n",
      "RP11-34P13.8\tchr1;chr1\t89551;90287\t90050;91105\t-;-\t1319\r\n",
      "AL627309.1\tchr1;chr1\t134901;137621\t135802;139379\t-;-\t2661\r\n",
      "RP11-34P13.14\tchr1;chr1\t139790;140075\t139847;140339\t-;-\t323\r\n",
      "RP11-34P13.13\tchr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1;chr1\t141474;146386;155767;164263;165884;168100;168610;169049;172557;173753\t143011;149707;155831;164791;165942;168165;168767;169264;172688;173862\t-;-;-;-;-;-;-;-;-;-\t6195\r\n"
     ]
    }
   ],
   "source": [
    "head all.genedataCML2.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "cut -f1,7- all.CMLcounts2 | grep -v '^#' > all.geneCML.counts2.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Geneid\tCML15iCD34ctrl.bam\tCML15iCD34Imatinib.bam\tCML17iCD34ctrl.bam\tCML17iCD34Imatinib.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\t3\t0\t2\r\n",
      "RP11-34P13.8\t0\t0\t0\t0\r\n",
      "AL627309.1\t150\t188\t204\t176\r\n",
      "RP11-34P13.14\t4\t2\t11\t4\r\n",
      "RP11-34P13.13\t8\t28\t22\t20\r\n",
      "RNU6-1100P\t0\t0\t0\t0\r\n",
      "RP11-34P13.9\t0\t2\t1\t1\r\n",
      "AP006222.2\t4\t5\t6\t2\r\n",
      "RP4-669L17.10\t18\t15\t24\t14\r\n",
      "OR4F29\t0\t0\t0\t0\r\n",
      "RP4-669L17.2\t0\t0\t1\t0\r\n",
      "RP5-857K21.15\t0\t0\t0\t0\r\n",
      "RP5-857K21.1\t0\t1\t0\t0\r\n",
      "RP5-857K21.2\t0\t0\t0\t1\r\n",
      "RP5-857K21.3\t0\t0\t0\t0\r\n",
      "RP5-857K21.4\t0\t0\t0\t0\r\n",
      "RP5-857K21.5\t0\t0\t0\t0\r\n",
      "OR4F16\t0\t0\t0\t0\r\n",
      "RP11-206L10.3\t18\t18\t13\t11\r\n",
      "RNU6-1199P\t0\t0\t0\t0\r\n",
      "RP11-206L10.5\t0\t0\t0\t0\r\n",
      "RP11-206L10.4\t0\t0\t0\t0\r\n",
      "RP11-206L10.2\t23\t27\t30\t16\r\n",
      "RP11-206L10.9\t22\t52\t37\t40\r\n",
      "AL669831.1\t0\t1\t0\t0\r\n",
      "RP11-206L10.10\t5\t3\t3\t2\r\n",
      "FAM87B\t7\t2\t6\t6\r\n",
      "LINC00115\t33\t41\t36\t45\r\n",
      "RP11-206L10.11\t349\t369\t446\t414\r\n",
      "FAM41C\t0\t2\t4\t1\r\n",
      "AL645608.2\t0\t0\t0\t0\r\n",
      "RP11-54O7.16\t9\t3\t6\t3\r\n",
      "RP11-54O7.1\t229\t251\t328\t285\r\n",
      "RP11-54O7.2\t0\t0\t0\t0\r\n",
      "RP11-54O7.3\t21\t18\t22\t15\r\n",
      "SAMD11\t5\t6\t2\t9\r\n",
      "AL645608.1\t0\t1\t1\t0\r\n",
      "NOC2L\t5137\t4834\t7488\t4932\r\n",
      "KLHL17\t876\t782\t917\t723\r\n",
      "PLEKHN1\t4\t0\t3\t0\r\n",
      "C1orf170\t1\t0\t0\t0\r\n",
      "RP11-54O7.17\t0\t0\t0\t0\r\n",
      "HES4\t3\t3\t9\t10\r\n",
      "RP11-54O7.11\t0\t0\t0\t0\r\n",
      "ISG15\t571\t932\t829\t1849\r\n",
      "AGRN\t431\t396\t698\t524\r\n"
     ]
    }
   ],
   "source": [
    "head -50 all.geneCML.counts2.tsv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OLFM4\t1251\t4088\t2988\t4785\r\n"
     ]
    }
   ],
   "source": [
    "# Because OLFM4 was mentioned as upregulated gene in the article, we did a quick check.\n",
    "grep OLFM4 all.geneCML.counts2.tsv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## (The DESeq code in R can be found in the addendum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Obtaining .rnk file for GSEA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cut -f1,3 deseq.CML1results.tsv > deseqcut.rnk # bone marrow samples\n",
    "cut -f1,3 deseq2.CMLresults.tsv > deseq2cut.rnk # CML samples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "sed 1d deseqcut.rnk > deseqcutbm.rnk\n",
    "sed 1d deseq2cut.rnk > deseqcutcml.rnk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "grep -v \"NA\" deseqcutbm.rnk > deseqcutcleanbm.rnk\n",
    "grep -v \"NA\" deseqcutcml.rnk > deseqcutcleancml.rnk\n",
    "# files are now compatible to be uploaded in GSEA."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# ChIPseq \n",
    "\n",
    "#### (Data can be found in /mnt/storage/r0304814/chip/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "mkdir -p /mnt/nfs/r0301806/RNAseqgroepswerk/SMAD7/\n",
    "cd /mnt/nfs/r0301806/RNAseqgroepswerk/SMAD7/\n",
    "ln -sf /mnt/nfs/storage/r0301806/RNAseqgroepswerk/*.fastq ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Now we align our reads to the human genome:\n",
    "cd /mnt/nfs/r0301806/RNAseqgroepswerk/SMAD7/\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 chipseq1.fastq -S chipseq1.sam\n",
    "bowtie2-align -x /mnt/nfs/data/resources/bowtie2/hg19 chipseq2.fastq -S chipseq2.sam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "samtools view -S -b chipseq1.sam > chipseq1.bam\n",
    "samtools view -S -b chipseq2.sam > chipseq2.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n"
     ]
    }
   ],
   "source": [
    "samtools sort -O bam -o chipseq1.sorted.bam chipseq1.bam \n",
    "samtools sort -O bam -o chipseq2.sorted.bam chipseq2.bam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "samtools index chipseq1.sorted.bam \n",
    "samtools index chipseq2.sorted.bam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mkdir -p mymacs2\n",
    "\n",
    "# we want to call peaks to the entire genome (-g hs) with a minimum FDR (q-value) cutoff for peak detection of 0.005:\n",
    "macs2 callpeak -t  chipseq1.sorted.bam --outdir mymacs2 -n chipseq1 -g hs -q 0.005\n",
    "macs2 callpeak -t  chipseq2.sorted.bam --outdir mymacs2 -n chipseq2 -g hs -q 0.005"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "wc -l mymacs2_SMAD7/BM1Kctrl_SMAD7_peaks.narrowPeak\n",
    "wc -l mymacs2_SMAD7/BM1Kimatinib_SMAD7_peaks.narrowPeak"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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
}
