{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# DESeq2: Create Data Objects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Objective: Create a DESeqDataSet object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initial note" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First step is to create a countData and colData object (see ? DESeqDataSet)\n", "\n", "countData: for matrix input: a matrix of non-negative integers\n", "\n", " colData: for matrix input: a ‘DataFrame’ or ‘data.frame’ with at least\n", " a single column. Rows of colData correspond to columns of\n", " countData\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Registered S3 methods overwritten by 'ggplot2':\n", " method from \n", " [.quosures rlang\n", " c.quosures rlang\n", " print.quosures rlang\n", "── \u001b[1mAttaching packages\u001b[22m ─────────────────────────────────────── tidyverse 1.2.1 ──\n", "\u001b[32m✔\u001b[39m \u001b[34mggplot2\u001b[39m 3.1.1 \u001b[32m✔\u001b[39m \u001b[34mpurrr \u001b[39m 0.3.2\n", "\u001b[32m✔\u001b[39m \u001b[34mtibble \u001b[39m 2.1.2 \u001b[32m✔\u001b[39m \u001b[34mdplyr \u001b[39m 0.8.1\n", "\u001b[32m✔\u001b[39m \u001b[34mtidyr \u001b[39m 0.8.3 \u001b[32m✔\u001b[39m \u001b[34mstringr\u001b[39m 1.4.0\n", "\u001b[32m✔\u001b[39m \u001b[34mreadr \u001b[39m 1.3.1 \u001b[32m✔\u001b[39m \u001b[34mforcats\u001b[39m 0.4.0\n", "── \u001b[1mConflicts\u001b[22m ────────────────────────────────────────── tidyverse_conflicts() ──\n", "\u001b[31m✖\u001b[39m \u001b[34mdplyr\u001b[39m::\u001b[32mfilter()\u001b[39m masks \u001b[34mstats\u001b[39m::filter()\n", "\u001b[31m✖\u001b[39m \u001b[34mdplyr\u001b[39m::\u001b[32mlag()\u001b[39m masks \u001b[34mstats\u001b[39m::lag()\n", "Loading required package: S4Vectors\n", "Loading required package: stats4\n", "Loading required package: BiocGenerics\n", "Loading required package: parallel\n", "\n", "Attaching package: ‘BiocGenerics’\n", "\n", "The following objects are masked from ‘package:parallel’:\n", "\n", " clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,\n", " clusterExport, clusterMap, parApply, parCapply, parLapply,\n", " parLapplyLB, parRapply, parSapply, parSapplyLB\n", "\n", "The following objects are masked from ‘package:dplyr’:\n", "\n", " combine, intersect, setdiff, union\n", "\n", "The following objects are masked from ‘package:stats’:\n", "\n", " IQR, mad, sd, var, xtabs\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " anyDuplicated, append, as.data.frame, basename, cbind, colnames,\n", " dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,\n", " grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,\n", " order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,\n", " rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,\n", " union, unique, unsplit, which, which.max, which.min\n", "\n", "\n", "Attaching package: ‘S4Vectors’\n", "\n", "The following objects are masked from ‘package:dplyr’:\n", "\n", " first, rename\n", "\n", "The following object is masked from ‘package:tidyr’:\n", "\n", " expand\n", "\n", "The following object is masked from ‘package:base’:\n", "\n", " expand.grid\n", "\n", "Loading required package: IRanges\n", "\n", "Attaching package: ‘IRanges’\n", "\n", "The following objects are masked from ‘package:dplyr’:\n", "\n", " collapse, desc, slice\n", "\n", "The following object is masked from ‘package:purrr’:\n", "\n", " reduce\n", "\n", "Loading required package: GenomicRanges\n", "Loading required package: GenomeInfoDb\n", "Loading required package: SummarizedExperiment\n", "Loading required package: Biobase\n", "Welcome to Bioconductor\n", "\n", " Vignettes contain introductory material; view with\n", " 'browseVignettes()'. To cite Bioconductor, see\n", " 'citation(\"Biobase\")', and for packages 'citation(\"pkgname\")'.\n", "\n", "Loading required package: DelayedArray\n", "Loading required package: matrixStats\n", "\n", "Attaching package: ‘matrixStats’\n", "\n", "The following objects are masked from ‘package:Biobase’:\n", "\n", " anyMissing, rowMedians\n", "\n", "The following object is masked from ‘package:dplyr’:\n", "\n", " count\n", "\n", "Loading required package: BiocParallel\n", "\n", "Attaching package: ‘DelayedArray’\n", "\n", "The following objects are masked from ‘package:matrixStats’:\n", "\n", " colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges\n", "\n", "The following object is masked from ‘package:purrr’:\n", "\n", " simplify\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " aperm, apply, rowsum\n", "\n" ] } ], "source": [ "library(tidyverse)\n", "library(DESeq2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load the 2019 pilot count objects from the image file" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "'/home/jovyan/work/scratch/analysis_output/img/pilotcnt2019.RData'" ], "text/latex": [ "'/home/jovyan/work/scratch/analysis\\_output/img/pilotcnt2019.RData'" ], "text/markdown": [ "'/home/jovyan/work/scratch/analysis_output/img/pilotcnt2019.RData'" ], "text/plain": [ "[1] \"/home/jovyan/work/scratch/analysis_output/img/pilotcnt2019.RData\"" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "/home/jovyan/work/scratch/analysis_output/img/pilotcnt2019.RData: '0d1cdfc8bb97baf52ca4f8f33e2c0ae4'" ], "text/latex": [ "\\textbf{/home/jovyan/work/scratch/analysis\\textbackslash{}\\_output/img/pilotcnt2019.RData:} '0d1cdfc8bb97baf52ca4f8f33e2c0ae4'" ], "text/markdown": [ "**/home/jovyan/work/scratch/analysis_output/img/pilotcnt2019.RData:** '0d1cdfc8bb97baf52ca4f8f33e2c0ae4'" ], "text/plain": [ "/home/jovyan/work/scratch/analysis_output/img/pilotcnt2019.RData \n", " \"0d1cdfc8bb97baf52ca4f8f33e2c0ae4\" " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
    \n", "\t
  1. 'cnt2019'
  2. \n", "\t
  3. 'mtdf2019'
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 'cnt2019'\n", "\\item 'mtdf2019'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 'cnt2019'\n", "2. 'mtdf2019'\n", "\n", "\n" ], "text/plain": [ "[1] \"cnt2019\" \"mtdf2019\"" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "curdir <- \"/home/jovyan/work/scratch/analysis_output\"\n", "\n", "imgdir <- file.path(curdir, \"img\")\n", "\n", "imgfile <- file.path(imgdir, \"pilotcnt2019.RData\")\n", "\n", "imgfile\n", "\n", "attach(imgfile)\n", "\n", "tools::md5sum(imgfile)\n", "\n", "### List the objects that have been attached\n", "ls(2)\n", "\n", "cnt2019 <- cnt2019\n", "mtdf2019 <- mtdf2019\n", "\n", "detach(pos = 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check dimensions of the two objects" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. 24
  2. \n", "\t
  3. 8500
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 24\n", "\\item 8500\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 24\n", "2. 8500\n", "\n", "\n" ], "text/plain": [ "[1] 24 8500" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
    \n", "\t
  1. 24
  2. \n", "\t
  3. 22
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 24\n", "\\item 22\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 24\n", "2. 22\n", "\n", "\n" ], "text/plain": [ "[1] 24 22" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dim(cnt2019)\n", "dim(mtdf2019)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A tibble: 6 × 22
Labelsample_yeargroupenrich_repRNA_sample_numgenotypeconditionlibprep_personenrichment_methodenrichment_shorti5_primeri7_primerlibrary_numbio_replicateNanodrop_260_280Nanodrop_260_230Nanodrop_concentration_ng_ulBioanalyzer_concentration_ng_ulRIN_normal_thresholdRIN_lowered_threshold
<chr><dbl><chr><dbl><dbl><chr><chr><chr><chr><chr><chr><chr><dbl><dbl><dbl><dbl><dbl><dbl><chr><dbl>
1_2019_P_M12019P11WTpH4CmRNAMi501i701112.141.52293197N/A 9.8
2_2019_P_M12019P12WTpH4CmRNAMi502i701222.121.79290225N/A 9.9
3_2019_P_M12019P13WTpH4CmRNAMi503i701332.112.49302241N/A 9.9
4_2019_P_M12019P14WTpH4PmRNAMi504i701442.131.15296189N/A 9.7
5_2019_P_M12019P15WTpH4PmRNAMi505i701552.092.4233726810 10.0
6_2019_P_M12019P16WTpH4PmRNAMi506i701662.082.4031927610 10.0
\n" ], "text/latex": [ "A tibble: 6 × 22\n", "\\begin{tabular}{r|llllllllllllllllllllll}\n", " Label & sample\\_year & group & enrich\\_rep & RNA\\_sample\\_num & genotype & condition & libprep\\_person & enrichment\\_method & enrichment\\_short & i7\\_index & i5\\_index & i5\\_primer & i7\\_primer & library\\_num & bio\\_replicate & Nanodrop\\_260\\_280 & Nanodrop\\_260\\_230 & Nanodrop\\_concentration\\_ng\\_ul & Bioanalyzer\\_concentration\\_ng\\_ul & RIN\\_normal\\_threshold & RIN\\_lowered\\_threshold\\\\\n", " & & & & & & & & & & & & & & & & & & & & & \\\\\n", "\\hline\n", "\t 1\\_2019\\_P\\_M1 & 2019 & P & 1 & 1 & WT & pH4 & C & mRNA & M & ATTACTCG & AGGCTATA & i501 & i701 & 1 & 1 & 2.14 & 1.52 & 293 & 197 & N/A & 9.8\\\\\n", "\t 2\\_2019\\_P\\_M1 & 2019 & P & 1 & 2 & WT & pH4 & C & mRNA & M & ATTACTCG & GCCTCTAT & i502 & i701 & 2 & 2 & 2.12 & 1.79 & 290 & 225 & N/A & 9.9\\\\\n", "\t 3\\_2019\\_P\\_M1 & 2019 & P & 1 & 3 & WT & pH4 & C & mRNA & M & ATTACTCG & AGGATAGG & i503 & i701 & 3 & 3 & 2.11 & 2.49 & 302 & 241 & N/A & 9.9\\\\\n", "\t 4\\_2019\\_P\\_M1 & 2019 & P & 1 & 4 & WT & pH4 & P & mRNA & M & ATTACTCG & TCAGAGCC & i504 & i701 & 4 & 4 & 2.13 & 1.15 & 296 & 189 & N/A & 9.7\\\\\n", "\t 5\\_2019\\_P\\_M1 & 2019 & P & 1 & 5 & WT & pH4 & P & mRNA & M & ATTACTCG & CTTCGCCT & i505 & i701 & 5 & 5 & 2.09 & 2.42 & 337 & 268 & 10 & 10.0\\\\\n", "\t 6\\_2019\\_P\\_M1 & 2019 & P & 1 & 6 & WT & pH4 & P & mRNA & M & ATTACTCG & TAAGATTA & i506 & i701 & 6 & 6 & 2.08 & 2.40 & 319 & 276 & 10 & 10.0\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A tibble: 6 × 22\n", "\n", "| Label <chr> | sample_year <dbl> | group <chr> | enrich_rep <dbl> | RNA_sample_num <dbl> | genotype <chr> | condition <chr> | libprep_person <chr> | enrichment_method <chr> | enrichment_short <chr> | ⋯ ⋯ | i5_primer <chr> | i7_primer <chr> | library_num <dbl> | bio_replicate <dbl> | Nanodrop_260_280 <dbl> | Nanodrop_260_230 <dbl> | Nanodrop_concentration_ng_ul <dbl> | Bioanalyzer_concentration_ng_ul <dbl> | RIN_normal_threshold <chr> | RIN_lowered_threshold <dbl> |\n", "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n", "| 1_2019_P_M1 | 2019 | P | 1 | 1 | WT | pH4 | C | mRNA | M | ⋯ | i501 | i701 | 1 | 1 | 2.14 | 1.52 | 293 | 197 | N/A | 9.8 |\n", "| 2_2019_P_M1 | 2019 | P | 1 | 2 | WT | pH4 | C | mRNA | M | ⋯ | i502 | i701 | 2 | 2 | 2.12 | 1.79 | 290 | 225 | N/A | 9.9 |\n", "| 3_2019_P_M1 | 2019 | P | 1 | 3 | WT | pH4 | C | mRNA | M | ⋯ | i503 | i701 | 3 | 3 | 2.11 | 2.49 | 302 | 241 | N/A | 9.9 |\n", "| 4_2019_P_M1 | 2019 | P | 1 | 4 | WT | pH4 | P | mRNA | M | ⋯ | i504 | i701 | 4 | 4 | 2.13 | 1.15 | 296 | 189 | N/A | 9.7 |\n", "| 5_2019_P_M1 | 2019 | P | 1 | 5 | WT | pH4 | P | mRNA | M | ⋯ | i505 | i701 | 5 | 5 | 2.09 | 2.42 | 337 | 268 | 10 | 10.0 |\n", "| 6_2019_P_M1 | 2019 | P | 1 | 6 | WT | pH4 | P | mRNA | M | ⋯ | i506 | i701 | 6 | 6 | 2.08 | 2.40 | 319 | 276 | 10 | 10.0 |\n", "\n" ], "text/plain": [ " Label sample_year group enrich_rep RNA_sample_num genotype condition\n", "1 1_2019_P_M1 2019 P 1 1 WT pH4 \n", "2 2_2019_P_M1 2019 P 1 2 WT pH4 \n", "3 3_2019_P_M1 2019 P 1 3 WT pH4 \n", "4 4_2019_P_M1 2019 P 1 4 WT pH4 \n", "5 5_2019_P_M1 2019 P 1 5 WT pH4 \n", "6 6_2019_P_M1 2019 P 1 6 WT pH4 \n", " libprep_person enrichment_method enrichment_short ⋯ i5_primer i7_primer\n", "1 C mRNA M ⋯ i501 i701 \n", "2 C mRNA M ⋯ i502 i701 \n", "3 C mRNA M ⋯ i503 i701 \n", "4 P mRNA M ⋯ i504 i701 \n", "5 P mRNA M ⋯ i505 i701 \n", "6 P mRNA M ⋯ i506 i701 \n", " library_num bio_replicate Nanodrop_260_280 Nanodrop_260_230\n", "1 1 1 2.14 1.52 \n", "2 2 2 2.12 1.79 \n", "3 3 3 2.11 2.49 \n", "4 4 4 2.13 1.15 \n", "5 5 5 2.09 2.42 \n", "6 6 6 2.08 2.40 \n", " Nanodrop_concentration_ng_ul Bioanalyzer_concentration_ng_ul\n", "1 293 197 \n", "2 290 225 \n", "3 302 241 \n", "4 296 189 \n", "5 337 268 \n", "6 319 276 \n", " RIN_normal_threshold RIN_lowered_threshold\n", "1 N/A 9.8 \n", "2 N/A 9.9 \n", "3 N/A 9.9 \n", "4 N/A 9.7 \n", "5 10 10.0 \n", "6 10 10.0 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mtdf2019 %>% head" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A tibble: 24 × 5
LabelCNAG_00001CNAG_00002CNAG_00003CNAG_00004
<chr><int><int><int><int>
1_2019_P_M1 0158201904
10_2019_P_M10119131513
11_2019_P_M10 90121573
12_2019_P_M10 81151533
13_2019_P_M10188215474
14_2019_P_M10177154440
15_2019_P_M10216197425
16_2019_P_M10224195548
17_2019_P_M10234211517
18_2019_P_M10338201464
19_2019_P_M10191118458
2_2019_P_M1 0204156902
20_2019_P_M10201133405
21_2019_P_M10192109339
22_2019_P_M10166113406
23_2019_P_M10202154442
24_2019_P_M10235169523
3_2019_P_M1 0149161941
4_2019_P_M1 0176171795
5_2019_P_M1 0161162849
6_2019_P_M1 0148103688
7_2019_P_M1 0172172768
8_2019_P_M1 0169170744
9_2019_P_M1 0124175659
\n" ], "text/latex": [ "A tibble: 24 × 5\n", "\\begin{tabular}{r|lllll}\n", " Label & CNAG\\_00001 & CNAG\\_00002 & CNAG\\_00003 & CNAG\\_00004\\\\\n", " & & & & \\\\\n", "\\hline\n", "\t 1\\_2019\\_P\\_M1 & 0 & 158 & 201 & 904\\\\\n", "\t 10\\_2019\\_P\\_M1 & 0 & 119 & 131 & 513\\\\\n", "\t 11\\_2019\\_P\\_M1 & 0 & 90 & 121 & 573\\\\\n", "\t 12\\_2019\\_P\\_M1 & 0 & 81 & 151 & 533\\\\\n", "\t 13\\_2019\\_P\\_M1 & 0 & 188 & 215 & 474\\\\\n", "\t 14\\_2019\\_P\\_M1 & 0 & 177 & 154 & 440\\\\\n", "\t 15\\_2019\\_P\\_M1 & 0 & 216 & 197 & 425\\\\\n", "\t 16\\_2019\\_P\\_M1 & 0 & 224 & 195 & 548\\\\\n", "\t 17\\_2019\\_P\\_M1 & 0 & 234 & 211 & 517\\\\\n", "\t 18\\_2019\\_P\\_M1 & 0 & 338 & 201 & 464\\\\\n", "\t 19\\_2019\\_P\\_M1 & 0 & 191 & 118 & 458\\\\\n", "\t 2\\_2019\\_P\\_M1 & 0 & 204 & 156 & 902\\\\\n", "\t 20\\_2019\\_P\\_M1 & 0 & 201 & 133 & 405\\\\\n", "\t 21\\_2019\\_P\\_M1 & 0 & 192 & 109 & 339\\\\\n", "\t 22\\_2019\\_P\\_M1 & 0 & 166 & 113 & 406\\\\\n", "\t 23\\_2019\\_P\\_M1 & 0 & 202 & 154 & 442\\\\\n", "\t 24\\_2019\\_P\\_M1 & 0 & 235 & 169 & 523\\\\\n", "\t 3\\_2019\\_P\\_M1 & 0 & 149 & 161 & 941\\\\\n", "\t 4\\_2019\\_P\\_M1 & 0 & 176 & 171 & 795\\\\\n", "\t 5\\_2019\\_P\\_M1 & 0 & 161 & 162 & 849\\\\\n", "\t 6\\_2019\\_P\\_M1 & 0 & 148 & 103 & 688\\\\\n", "\t 7\\_2019\\_P\\_M1 & 0 & 172 & 172 & 768\\\\\n", "\t 8\\_2019\\_P\\_M1 & 0 & 169 & 170 & 744\\\\\n", "\t 9\\_2019\\_P\\_M1 & 0 & 124 & 175 & 659\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A tibble: 24 × 5\n", "\n", "| Label <chr> | CNAG_00001 <int> | CNAG_00002 <int> | CNAG_00003 <int> | CNAG_00004 <int> |\n", "|---|---|---|---|---|\n", "| 1_2019_P_M1 | 0 | 158 | 201 | 904 |\n", "| 10_2019_P_M1 | 0 | 119 | 131 | 513 |\n", "| 11_2019_P_M1 | 0 | 90 | 121 | 573 |\n", "| 12_2019_P_M1 | 0 | 81 | 151 | 533 |\n", "| 13_2019_P_M1 | 0 | 188 | 215 | 474 |\n", "| 14_2019_P_M1 | 0 | 177 | 154 | 440 |\n", "| 15_2019_P_M1 | 0 | 216 | 197 | 425 |\n", "| 16_2019_P_M1 | 0 | 224 | 195 | 548 |\n", "| 17_2019_P_M1 | 0 | 234 | 211 | 517 |\n", "| 18_2019_P_M1 | 0 | 338 | 201 | 464 |\n", "| 19_2019_P_M1 | 0 | 191 | 118 | 458 |\n", "| 2_2019_P_M1 | 0 | 204 | 156 | 902 |\n", "| 20_2019_P_M1 | 0 | 201 | 133 | 405 |\n", "| 21_2019_P_M1 | 0 | 192 | 109 | 339 |\n", "| 22_2019_P_M1 | 0 | 166 | 113 | 406 |\n", "| 23_2019_P_M1 | 0 | 202 | 154 | 442 |\n", "| 24_2019_P_M1 | 0 | 235 | 169 | 523 |\n", "| 3_2019_P_M1 | 0 | 149 | 161 | 941 |\n", "| 4_2019_P_M1 | 0 | 176 | 171 | 795 |\n", "| 5_2019_P_M1 | 0 | 161 | 162 | 849 |\n", "| 6_2019_P_M1 | 0 | 148 | 103 | 688 |\n", "| 7_2019_P_M1 | 0 | 172 | 172 | 768 |\n", "| 8_2019_P_M1 | 0 | 169 | 170 | 744 |\n", "| 9_2019_P_M1 | 0 | 124 | 175 | 659 |\n", "\n" ], "text/plain": [ " Label CNAG_00001 CNAG_00002 CNAG_00003 CNAG_00004\n", "1 1_2019_P_M1 0 158 201 904 \n", "2 10_2019_P_M1 0 119 131 513 \n", "3 11_2019_P_M1 0 90 121 573 \n", "4 12_2019_P_M1 0 81 151 533 \n", "5 13_2019_P_M1 0 188 215 474 \n", "6 14_2019_P_M1 0 177 154 440 \n", "7 15_2019_P_M1 0 216 197 425 \n", "8 16_2019_P_M1 0 224 195 548 \n", "9 17_2019_P_M1 0 234 211 517 \n", "10 18_2019_P_M1 0 338 201 464 \n", "11 19_2019_P_M1 0 191 118 458 \n", "12 2_2019_P_M1 0 204 156 902 \n", "13 20_2019_P_M1 0 201 133 405 \n", "14 21_2019_P_M1 0 192 109 339 \n", "15 22_2019_P_M1 0 166 113 406 \n", "16 23_2019_P_M1 0 202 154 442 \n", "17 24_2019_P_M1 0 235 169 523 \n", "18 3_2019_P_M1 0 149 161 941 \n", "19 4_2019_P_M1 0 176 171 795 \n", "20 5_2019_P_M1 0 161 162 849 \n", "21 6_2019_P_M1 0 148 103 688 \n", "22 7_2019_P_M1 0 172 172 768 \n", "23 8_2019_P_M1 0 169 170 744 \n", "24 9_2019_P_M1 0 124 175 659 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cnt2019[,1:5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create columnData object" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DataFrame with 6 rows and 3 columns\n", " Label genotype condition\n", " \n", "1_2019_P_M1 1_2019_P_M1 WT pH4\n", "2_2019_P_M1 2_2019_P_M1 WT pH4\n", "3_2019_P_M1 3_2019_P_M1 WT pH4\n", "4_2019_P_M1 4_2019_P_M1 WT pH4\n", "5_2019_P_M1 5_2019_P_M1 WT pH4\n", "6_2019_P_M1 6_2019_P_M1 WT pH4" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# columnData --- metadata\n", "mtdf2019 %>%\n", " DataFrame ->\n", " columnData2019\n", "\n", "### Add the labels as rownames\n", "rownames(columnData2019) <- columnData2019[[\"Label\"]]\n", "\n", "columnData2019[, c(\"Label\", \"genotype\", \"condition\")] %>% head" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A tibble: 4 × 5
LabelCNAG_00001CNAG_00002CNAG_00003CNAG_00004
<chr><int><int><int><int>
1_2019_P_M1 0158201904
10_2019_P_M10119131513
11_2019_P_M10 90121573
12_2019_P_M10 81151533
\n" ], "text/latex": [ "A tibble: 4 × 5\n", "\\begin{tabular}{r|lllll}\n", " Label & CNAG\\_00001 & CNAG\\_00002 & CNAG\\_00003 & CNAG\\_00004\\\\\n", " & & & & \\\\\n", "\\hline\n", "\t 1\\_2019\\_P\\_M1 & 0 & 158 & 201 & 904\\\\\n", "\t 10\\_2019\\_P\\_M1 & 0 & 119 & 131 & 513\\\\\n", "\t 11\\_2019\\_P\\_M1 & 0 & 90 & 121 & 573\\\\\n", "\t 12\\_2019\\_P\\_M1 & 0 & 81 & 151 & 533\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A tibble: 4 × 5\n", "\n", "| Label <chr> | CNAG_00001 <int> | CNAG_00002 <int> | CNAG_00003 <int> | CNAG_00004 <int> |\n", "|---|---|---|---|---|\n", "| 1_2019_P_M1 | 0 | 158 | 201 | 904 |\n", "| 10_2019_P_M1 | 0 | 119 | 131 | 513 |\n", "| 11_2019_P_M1 | 0 | 90 | 121 | 573 |\n", "| 12_2019_P_M1 | 0 | 81 | 151 | 533 |\n", "\n" ], "text/plain": [ " Label CNAG_00001 CNAG_00002 CNAG_00003 CNAG_00004\n", "1 1_2019_P_M1 0 158 201 904 \n", "2 10_2019_P_M1 0 119 131 513 \n", "3 11_2019_P_M1 0 90 121 573 \n", "4 12_2019_P_M1 0 81 151 533 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "### Note that libraries are across rows and libraries across columns\n", "### DESeq2 requires that the matrix is transposed as that the gene names become row names\n", "cnt2019[1:4,1:5]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 5 × 6 of type int
1_2019_P_M110_2019_P_M111_2019_P_M112_2019_P_M113_2019_P_M114_2019_P_M1
CNAG_00001 0 0 0 0 0 0
CNAG_00002158119 90 81188177
CNAG_00003201131121151215154
CNAG_00004904513573533474440
CNAG_00005 22 24 18 20 25 13
\n" ], "text/latex": [ "A matrix: 5 × 6 of type int\n", "\\begin{tabular}{r|llllll}\n", " & 1\\_2019\\_P\\_M1 & 10\\_2019\\_P\\_M1 & 11\\_2019\\_P\\_M1 & 12\\_2019\\_P\\_M1 & 13\\_2019\\_P\\_M1 & 14\\_2019\\_P\\_M1\\\\\n", "\\hline\n", "\tCNAG\\_00001 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", "\tCNAG\\_00002 & 158 & 119 & 90 & 81 & 188 & 177\\\\\n", "\tCNAG\\_00003 & 201 & 131 & 121 & 151 & 215 & 154\\\\\n", "\tCNAG\\_00004 & 904 & 513 & 573 & 533 & 474 & 440\\\\\n", "\tCNAG\\_00005 & 22 & 24 & 18 & 20 & 25 & 13\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 5 × 6 of type int\n", "\n", "| | 1_2019_P_M1 | 10_2019_P_M1 | 11_2019_P_M1 | 12_2019_P_M1 | 13_2019_P_M1 | 14_2019_P_M1 |\n", "|---|---|---|---|---|---|---|\n", "| CNAG_00001 | 0 | 0 | 0 | 0 | 0 | 0 |\n", "| CNAG_00002 | 158 | 119 | 90 | 81 | 188 | 177 |\n", "| CNAG_00003 | 201 | 131 | 121 | 151 | 215 | 154 |\n", "| CNAG_00004 | 904 | 513 | 573 | 533 | 474 | 440 |\n", "| CNAG_00005 | 22 | 24 | 18 | 20 | 25 | 13 |\n", "\n" ], "text/plain": [ " 1_2019_P_M1 10_2019_P_M1 11_2019_P_M1 12_2019_P_M1 13_2019_P_M1\n", "CNAG_00001 0 0 0 0 0 \n", "CNAG_00002 158 119 90 81 188 \n", "CNAG_00003 201 131 121 151 215 \n", "CNAG_00004 904 513 573 533 474 \n", "CNAG_00005 22 24 18 20 25 \n", " 14_2019_P_M1\n", "CNAG_00001 0 \n", "CNAG_00002 177 \n", "CNAG_00003 154 \n", "CNAG_00004 440 \n", "CNAG_00005 13 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "### Transpose the count matrix (so that libraries are across the columns and genes across rows) \n", "### Note that as.matrix() converts the tibble to a matrix object\n", "cnt2019 %>%\n", " gather(key = gene, value = value, 2:ncol(cnt2019)) %>% \n", " spread_(key = names(cnt2019)[1],value = 'value') %>%\n", " column_to_rownames(\"gene\") %>%\n", " as.matrix ->\n", " countData2019\n", "\n", "countData2019[1:5, 1:6]\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reorder the columns of the count matrix according to the order of Label in columnData" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "### The two sets coincide\n", "setequal(columnData2019[[\"Label\"]], colnames(countData2019))\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "FALSE" ], "text/latex": [ "FALSE" ], "text/markdown": [ "FALSE" ], "text/plain": [ "[1] FALSE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "### but they are identical as they follow different orders\n", "identical(columnData2019[[\"Label\"]], colnames(countData2019))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reorder the columns of countData " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "countData2019 <- countData2019[,columnData2019[[\"Label\"]]]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 4 × 5 of type int
1_2019_P_M12_2019_P_M13_2019_P_M14_2019_P_M15_2019_P_M1
CNAG_00001 0 0 0 0 0
CNAG_00002158204149176161
CNAG_00003201156161171162
CNAG_00004904902941795849
\n" ], "text/latex": [ "A matrix: 4 × 5 of type int\n", "\\begin{tabular}{r|lllll}\n", " & 1\\_2019\\_P\\_M1 & 2\\_2019\\_P\\_M1 & 3\\_2019\\_P\\_M1 & 4\\_2019\\_P\\_M1 & 5\\_2019\\_P\\_M1\\\\\n", "\\hline\n", "\tCNAG\\_00001 & 0 & 0 & 0 & 0 & 0\\\\\n", "\tCNAG\\_00002 & 158 & 204 & 149 & 176 & 161\\\\\n", "\tCNAG\\_00003 & 201 & 156 & 161 & 171 & 162\\\\\n", "\tCNAG\\_00004 & 904 & 902 & 941 & 795 & 849\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 4 × 5 of type int\n", "\n", "| | 1_2019_P_M1 | 2_2019_P_M1 | 3_2019_P_M1 | 4_2019_P_M1 | 5_2019_P_M1 |\n", "|---|---|---|---|---|---|\n", "| CNAG_00001 | 0 | 0 | 0 | 0 | 0 |\n", "| CNAG_00002 | 158 | 204 | 149 | 176 | 161 |\n", "| CNAG_00003 | 201 | 156 | 161 | 171 | 162 |\n", "| CNAG_00004 | 904 | 902 | 941 | 795 | 849 |\n", "\n" ], "text/plain": [ " 1_2019_P_M1 2_2019_P_M1 3_2019_P_M1 4_2019_P_M1 5_2019_P_M1\n", "CNAG_00001 0 0 0 0 0 \n", "CNAG_00002 158 204 149 176 161 \n", "CNAG_00003 201 156 161 171 162 \n", "CNAG_00004 904 902 941 795 849 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "countData2019[1:4,1:5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### make sure that labels match" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "### The two variables coincide\n", "setequal(columnData2019[[\"Label\"]], colnames(countData2019))\n", "### but they are identical as they follow different orders\n", "identical(columnData2019[[\"Label\"]], colnames(countData2019))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Make DESeq object on the basis of the counts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The design option allows you to specify an additive or a multiplicitive model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Additive model" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning message in DESeqDataSet(se, design = design, ignoreRank):\n", "“some variables in design formula are characters, converting to factors”" ] } ], "source": [ "dds_add <- DESeqDataSetFromMatrix(\n", " countData2019, # Count matrix\n", " columnData2019, # metadata\n", " ~ condition + genotype) # design formula" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Inspect object" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "class: DESeqDataSet \n", "dim: 8499 24 \n", "metadata(1): version\n", "assays(1): counts\n", "rownames(8499): CNAG_00001 CNAG_00002 ... large_MTrRNA small_MTrRNA\n", "rowData names(0):\n", "colnames(24): 1_2019_P_M1 2_2019_P_M1 ... 23_2019_P_M1 24_2019_P_M1\n", "colData names(22): Label sample_year ... RIN_normal_threshold\n", " RIN_lowered_threshold" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dds_add" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. 'design'
  2. \n", "\t
  3. 'dispersionFunction'
  4. \n", "\t
  5. 'rowRanges'
  6. \n", "\t
  7. 'colData'
  8. \n", "\t
  9. 'assays'
  10. \n", "\t
  11. 'NAMES'
  12. \n", "\t
  13. 'elementMetadata'
  14. \n", "\t
  15. 'metadata'
  16. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 'design'\n", "\\item 'dispersionFunction'\n", "\\item 'rowRanges'\n", "\\item 'colData'\n", "\\item 'assays'\n", "\\item 'NAMES'\n", "\\item 'elementMetadata'\n", "\\item 'metadata'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 'design'\n", "2. 'dispersionFunction'\n", "3. 'rowRanges'\n", "4. 'colData'\n", "5. 'assays'\n", "6. 'NAMES'\n", "7. 'elementMetadata'\n", "8. 'metadata'\n", "\n", "\n" ], "text/plain": [ "[1] \"design\" \"dispersionFunction\" \"rowRanges\" \n", "[4] \"colData\" \"assays\" \"NAMES\" \n", "[7] \"elementMetadata\" \"metadata\" " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "slotNames(dds_add)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check design" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "~condition + genotype" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dds_add@design" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check column data" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DataFrame with 24 rows and 22 columns\n", " Label sample_year group enrich_rep RNA_sample_num\n", " \n", "1_2019_P_M1 1_2019_P_M1 2019 P 1 1\n", "2_2019_P_M1 2_2019_P_M1 2019 P 1 2\n", "3_2019_P_M1 3_2019_P_M1 2019 P 1 3\n", "4_2019_P_M1 4_2019_P_M1 2019 P 1 4\n", "5_2019_P_M1 5_2019_P_M1 2019 P 1 5\n", "... ... ... ... ... ...\n", "20_2019_P_M1 20_2019_P_M1 2019 P 1 20\n", "21_2019_P_M1 21_2019_P_M1 2019 P 1 21\n", "22_2019_P_M1 22_2019_P_M1 2019 P 1 22\n", "23_2019_P_M1 23_2019_P_M1 2019 P 1 23\n", "24_2019_P_M1 24_2019_P_M1 2019 P 1 24\n", " genotype condition libprep_person enrichment_method\n", " \n", "1_2019_P_M1 WT pH4 C mRNA\n", "2_2019_P_M1 WT pH4 C mRNA\n", "3_2019_P_M1 WT pH4 C mRNA\n", "4_2019_P_M1 WT pH4 P mRNA\n", "5_2019_P_M1 WT pH4 P mRNA\n", "... ... ... ... ...\n", "20_2019_P_M1 sre1d pH8 C mRNA\n", "21_2019_P_M1 sre1d pH8 C mRNA\n", "22_2019_P_M1 sre1d pH8 P mRNA\n", "23_2019_P_M1 sre1d pH8 P mRNA\n", "24_2019_P_M1 sre1d pH8 P mRNA\n", " enrichment_short i7_index i5_index i5_primer i7_primer\n", " \n", "1_2019_P_M1 M ATTACTCG AGGCTATA i501 i701\n", "2_2019_P_M1 M ATTACTCG GCCTCTAT i502 i701\n", "3_2019_P_M1 M ATTACTCG AGGATAGG i503 i701\n", "4_2019_P_M1 M ATTACTCG TCAGAGCC i504 i701\n", "5_2019_P_M1 M ATTACTCG CTTCGCCT i505 i701\n", "... ... ... ... ... ...\n", "20_2019_P_M1 M CGCTCATT TCAGAGCC i504 i703\n", "21_2019_P_M1 M CGCTCATT CTTCGCCT i505 i703\n", "22_2019_P_M1 M CGCTCATT TAAGATTA i506 i703\n", "23_2019_P_M1 M CGCTCATT ACGTCCTG i507 i703\n", "24_2019_P_M1 M CGCTCATT GTCAGTAC i508 i703\n", " library_num bio_replicate Nanodrop_260_280 Nanodrop_260_230\n", " \n", "1_2019_P_M1 1 1 2.14 1.52\n", "2_2019_P_M1 2 2 2.12 1.79\n", "3_2019_P_M1 3 3 2.11 2.49\n", "4_2019_P_M1 4 4 2.13 1.15\n", "5_2019_P_M1 5 5 2.09 2.42\n", "... ... ... ... ...\n", "20_2019_P_M1 20 2 2.14 2.39\n", "21_2019_P_M1 21 3 2.01 2.22\n", "22_2019_P_M1 22 4 2.22 2.33\n", "23_2019_P_M1 23 5 2.13 2.56\n", "24_2019_P_M1 24 6 2.11 2.16\n", " Nanodrop_concentration_ng_ul Bioanalyzer_concentration_ng_ul\n", " \n", "1_2019_P_M1 293 197\n", "2_2019_P_M1 290 225\n", "3_2019_P_M1 302 241\n", "4_2019_P_M1 296 189\n", "5_2019_P_M1 337 268\n", "... ... ...\n", "20_2019_P_M1 172 131\n", "21_2019_P_M1 397 295\n", "22_2019_P_M1 567 499\n", "23_2019_P_M1 254 206\n", "24_2019_P_M1 215 336\n", " RIN_normal_threshold RIN_lowered_threshold\n", " \n", "1_2019_P_M1 N/A 9.8\n", "2_2019_P_M1 N/A 9.9\n", "3_2019_P_M1 N/A 9.9\n", "4_2019_P_M1 N/A 9.7\n", "5_2019_P_M1 10 10\n", "... ... ...\n", "20_2019_P_M1 N/A 10\n", "21_2019_P_M1 N/A 10\n", "22_2019_P_M1 10 10\n", "23_2019_P_M1 N/A 10\n", "24_2019_P_M1 10 10" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dds_add@colData" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get count matrix" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 10 × 10 of type int
1_2019_P_M12_2019_P_M13_2019_P_M14_2019_P_M15_2019_P_M16_2019_P_M17_2019_P_M18_2019_P_M19_2019_P_M110_2019_P_M1
CNAG_00001 0 0 0 0 0 0 0 0 0 0
CNAG_00002 158 204 149 176 161 148 172 169 124 119
CNAG_00003 201 156 161 171 162 103 172 170 175 131
CNAG_00004 904 902 941 795 849 688 768 744 659 513
CNAG_00005 22 33 12 15 26 13 29 33 21 24
CNAG_000065964485443624489436841714859426742393712
CNAG_000073119349626282437249825942505238320862021
CNAG_0000814811744160213911433118313131389 981 934
CNAG_00009 494 750 541 436 502 522 490 470 404 433
CNAG_00010152716131564131912861020 9491227 757 682
\n" ], "text/latex": [ "A matrix: 10 × 10 of type int\n", "\\begin{tabular}{r|llllllllll}\n", " & 1\\_2019\\_P\\_M1 & 2\\_2019\\_P\\_M1 & 3\\_2019\\_P\\_M1 & 4\\_2019\\_P\\_M1 & 5\\_2019\\_P\\_M1 & 6\\_2019\\_P\\_M1 & 7\\_2019\\_P\\_M1 & 8\\_2019\\_P\\_M1 & 9\\_2019\\_P\\_M1 & 10\\_2019\\_P\\_M1\\\\\n", "\\hline\n", "\tCNAG\\_00001 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", "\tCNAG\\_00002 & 158 & 204 & 149 & 176 & 161 & 148 & 172 & 169 & 124 & 119\\\\\n", "\tCNAG\\_00003 & 201 & 156 & 161 & 171 & 162 & 103 & 172 & 170 & 175 & 131\\\\\n", "\tCNAG\\_00004 & 904 & 902 & 941 & 795 & 849 & 688 & 768 & 744 & 659 & 513\\\\\n", "\tCNAG\\_00005 & 22 & 33 & 12 & 15 & 26 & 13 & 29 & 33 & 21 & 24\\\\\n", "\tCNAG\\_00006 & 5964 & 4854 & 4362 & 4489 & 4368 & 4171 & 4859 & 4267 & 4239 & 3712\\\\\n", "\tCNAG\\_00007 & 3119 & 3496 & 2628 & 2437 & 2498 & 2594 & 2505 & 2383 & 2086 & 2021\\\\\n", "\tCNAG\\_00008 & 1481 & 1744 & 1602 & 1391 & 1433 & 1183 & 1313 & 1389 & 981 & 934\\\\\n", "\tCNAG\\_00009 & 494 & 750 & 541 & 436 & 502 & 522 & 490 & 470 & 404 & 433\\\\\n", "\tCNAG\\_00010 & 1527 & 1613 & 1564 & 1319 & 1286 & 1020 & 949 & 1227 & 757 & 682\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 10 × 10 of type int\n", "\n", "| | 1_2019_P_M1 | 2_2019_P_M1 | 3_2019_P_M1 | 4_2019_P_M1 | 5_2019_P_M1 | 6_2019_P_M1 | 7_2019_P_M1 | 8_2019_P_M1 | 9_2019_P_M1 | 10_2019_P_M1 |\n", "|---|---|---|---|---|---|---|---|---|---|---|\n", "| CNAG_00001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |\n", "| CNAG_00002 | 158 | 204 | 149 | 176 | 161 | 148 | 172 | 169 | 124 | 119 |\n", "| CNAG_00003 | 201 | 156 | 161 | 171 | 162 | 103 | 172 | 170 | 175 | 131 |\n", "| CNAG_00004 | 904 | 902 | 941 | 795 | 849 | 688 | 768 | 744 | 659 | 513 |\n", "| CNAG_00005 | 22 | 33 | 12 | 15 | 26 | 13 | 29 | 33 | 21 | 24 |\n", "| CNAG_00006 | 5964 | 4854 | 4362 | 4489 | 4368 | 4171 | 4859 | 4267 | 4239 | 3712 |\n", "| CNAG_00007 | 3119 | 3496 | 2628 | 2437 | 2498 | 2594 | 2505 | 2383 | 2086 | 2021 |\n", "| CNAG_00008 | 1481 | 1744 | 1602 | 1391 | 1433 | 1183 | 1313 | 1389 | 981 | 934 |\n", "| CNAG_00009 | 494 | 750 | 541 | 436 | 502 | 522 | 490 | 470 | 404 | 433 |\n", "| CNAG_00010 | 1527 | 1613 | 1564 | 1319 | 1286 | 1020 | 949 | 1227 | 757 | 682 |\n", "\n" ], "text/plain": [ " 1_2019_P_M1 2_2019_P_M1 3_2019_P_M1 4_2019_P_M1 5_2019_P_M1\n", "CNAG_00001 0 0 0 0 0 \n", "CNAG_00002 158 204 149 176 161 \n", "CNAG_00003 201 156 161 171 162 \n", "CNAG_00004 904 902 941 795 849 \n", "CNAG_00005 22 33 12 15 26 \n", "CNAG_00006 5964 4854 4362 4489 4368 \n", "CNAG_00007 3119 3496 2628 2437 2498 \n", "CNAG_00008 1481 1744 1602 1391 1433 \n", "CNAG_00009 494 750 541 436 502 \n", "CNAG_00010 1527 1613 1564 1319 1286 \n", " 6_2019_P_M1 7_2019_P_M1 8_2019_P_M1 9_2019_P_M1 10_2019_P_M1\n", "CNAG_00001 0 0 0 0 0 \n", "CNAG_00002 148 172 169 124 119 \n", "CNAG_00003 103 172 170 175 131 \n", "CNAG_00004 688 768 744 659 513 \n", "CNAG_00005 13 29 33 21 24 \n", "CNAG_00006 4171 4859 4267 4239 3712 \n", "CNAG_00007 2594 2505 2383 2086 2021 \n", "CNAG_00008 1183 1313 1389 981 934 \n", "CNAG_00009 522 490 470 404 433 \n", "CNAG_00010 1020 949 1227 757 682 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "counts(dds_add)[1:10,1:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Change design: multiplicative model" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning message in DESeqDataSet(se, design = design, ignoreRank):\n", "“some variables in design formula are characters, converting to factors”" ] } ], "source": [ "dds_mult <- DESeqDataSetFromMatrix(\n", " countData2019, # Count matrix\n", " columnData2019, # metadata\n", " ~ condition + genotype + condition:genotype) # design formula" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following demonstration, we will use the additive model. The multiplicitive model will be illustrated in the appendix below." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "dds2019 <- dds_add" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "'/home/jovyan/work/scratch/analysis_output/img/pilotdds2019.RData'" ], "text/latex": [ "'/home/jovyan/work/scratch/analysis\\_output/img/pilotdds2019.RData'" ], "text/markdown": [ "'/home/jovyan/work/scratch/analysis_output/img/pilotdds2019.RData'" ], "text/plain": [ "[1] \"/home/jovyan/work/scratch/analysis_output/img/pilotdds2019.RData\"" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "curdir <- \"/home/jovyan/work/scratch/analysis_output\"\n", "imgdir <- file.path(curdir, \"img\")\n", "\n", "imgfile <- file.path(imgdir, \"pilotdds2019.RData\")\n", "\n", "imgfile" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "/home/jovyan/work/scratch/analysis_output/img/pilotdds2019.RData: '6632de5c8a2eed06d8c40c958e6f5d03'" ], "text/latex": [ "\\textbf{/home/jovyan/work/scratch/analysis\\textbackslash{}\\_output/img/pilotdds2019.RData:} '6632de5c8a2eed06d8c40c958e6f5d03'" ], "text/markdown": [ "**/home/jovyan/work/scratch/analysis_output/img/pilotdds2019.RData:** '6632de5c8a2eed06d8c40c958e6f5d03'" ], "text/plain": [ "/home/jovyan/work/scratch/analysis_output/img/pilotdds2019.RData \n", " \"6632de5c8a2eed06d8c40c958e6f5d03\" " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "save(dds2019, file = imgfile)\n", "tools::md5sum(imgfile)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "R version 3.6.0 (2019-04-26)\n", "Platform: x86_64-pc-linux-gnu (64-bit)\n", "Running under: Debian GNU/Linux 9 (stretch)\n", "\n", "Matrix products: default\n", "BLAS: /usr/lib/openblas-base/libblas.so.3\n", "LAPACK: /usr/lib/libopenblasp-r0.2.19.so\n", "\n", "locale:\n", " [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C \n", " [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 \n", " [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 \n", " [7] LC_PAPER=en_US.UTF-8 LC_NAME=C \n", " [9] LC_ADDRESS=C LC_TELEPHONE=C \n", "[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C \n", "\n", "attached base packages:\n", "[1] parallel stats4 stats graphics grDevices utils datasets \n", "[8] methods base \n", "\n", "other attached packages:\n", " [1] DESeq2_1.24.0 SummarizedExperiment_1.14.0\n", " [3] DelayedArray_0.10.0 BiocParallel_1.18.0 \n", " [5] matrixStats_0.54.0 Biobase_2.44.0 \n", " [7] GenomicRanges_1.36.0 GenomeInfoDb_1.20.0 \n", " [9] IRanges_2.18.1 S4Vectors_0.22.0 \n", "[11] BiocGenerics_0.30.0 forcats_0.4.0 \n", "[13] stringr_1.4.0 dplyr_0.8.1 \n", "[15] purrr_0.3.2 readr_1.3.1 \n", "[17] tidyr_0.8.3 tibble_2.1.2 \n", "[19] ggplot2_3.1.1 tidyverse_1.2.1 \n", "\n", "loaded via a namespace (and not attached):\n", " [1] nlme_3.1-139 bitops_1.0-6 bit64_0.9-7 \n", " [4] lubridate_1.7.4 RColorBrewer_1.1-2 httr_1.4.0 \n", " [7] repr_1.0.1 tools_3.6.0 backports_1.1.4 \n", "[10] R6_2.4.0 rpart_4.1-15 DBI_1.0.0 \n", "[13] Hmisc_4.2-0 lazyeval_0.2.2 colorspace_1.4-1 \n", "[16] nnet_7.3-12 withr_2.1.2 tidyselect_0.2.5 \n", "[19] gridExtra_2.3 bit_1.1-14 compiler_3.6.0 \n", "[22] cli_1.1.0 rvest_0.3.4 htmlTable_1.13.1 \n", "[25] xml2_1.2.0 scales_1.0.0 checkmate_1.9.3 \n", "[28] genefilter_1.66.0 pbdZMQ_0.3-3 digest_0.6.19 \n", "[31] foreign_0.8-71 XVector_0.24.0 base64enc_0.1-3 \n", "[34] pkgconfig_2.0.2 htmltools_0.3.6 htmlwidgets_1.3 \n", "[37] rlang_0.3.4 readxl_1.3.1 RSQLite_2.1.1 \n", "[40] rstudioapi_0.10 generics_0.0.2 jsonlite_1.6 \n", "[43] acepack_1.4.1 RCurl_1.95-4.12 magrittr_1.5 \n", "[46] GenomeInfoDbData_1.2.1 Formula_1.2-3 Matrix_1.2-17 \n", "[49] Rcpp_1.0.1 IRkernel_1.0.1 munsell_0.5.0 \n", "[52] stringi_1.4.3 zlibbioc_1.30.0 plyr_1.8.4 \n", "[55] blob_1.1.1 grid_3.6.0 crayon_1.3.4 \n", "[58] lattice_0.20-38 IRdisplay_0.7.0 haven_2.1.0 \n", "[61] splines_3.6.0 annotate_1.62.0 hms_0.4.2 \n", "[64] locfit_1.5-9.1 zeallot_0.1.0 knitr_1.23 \n", "[67] pillar_1.4.1 uuid_0.1-2 geneplotter_1.62.0 \n", "[70] XML_3.98-1.19 glue_1.3.1 evaluate_0.14 \n", "[73] latticeExtra_0.6-28 data.table_1.12.2 modelr_0.1.4 \n", "[76] vctrs_0.1.0 cellranger_1.1.0 gtable_0.3.0 \n", "[79] assertthat_0.2.1 xfun_0.7 xtable_1.8-4 \n", "[82] broom_0.5.2 survival_2.44-1.1 memoise_1.1.0 \n", "[85] AnnotationDbi_1.46.0 cluster_2.0.8 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sessionInfo()" ] } ], "metadata": { "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }