-
Notifications
You must be signed in to change notification settings - Fork 13
/
CaRpools-MANUAL.Rmd
executable file
·2893 lines (2135 loc) · 118 KB
/
CaRpools-MANUAL.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "caRpools - End-To-End Analysis of Pooled CRISPR/Cas9 Screens"
output:
pdf_document:
keep_tex: yes
number_sections: yes
toc: yes
toc_depth: 4
html_document:
fig_height: 6
fig_width: 11
theme: readable
toc: yes
toc_depth: 4
---
\newpage
\begin{center}
\includegraphics{./pictures/CaRpools.png}
\end{center}
\newpage
```{r loadlibs, echo=FALSE, error=FALSE, warning=FALSE, message=FALSE, include=FALSE}
if("caRpools" %in% rownames(installed.packages()) == FALSE) {install.packages("caRpools")}
library(caRpools,warn.conflicts = FALSE, quietly = TRUE,verbose =FALSE)
load.packages()
data(caRpools)
```
# Introduction
The **CaRpools** (**C**RISPR **A**nalyze**R** for **Pool**ed **S**creens) package allows users to analyze raw NGS read count data from pooled CRISPR Screens in an end-to-end fashion and serves as a basis for creating customized reports for more advanced users.
These pooled screens must contain lentivirus-based libraries as they can be obtained via [Addgene](https://www.addgene.org/CRISPR/libraries/) e.g. .
It provides functions to create different quality control plots, normalize the data, compare the data and perform hit identification via three different methods.
Furthermore it can be used to completely analyze the date in a streamlined workflow with the provided analysis template.
![](./pictures/workflow.png)
With **CaRpools**, the user can analyze pooled CRISPR/Cas9 screens end-to-end in a standardized fashion allowing for reproducible data analysis.
This includes:
* FASTQ data extraction (optional)
* Mapping against a reference library FASTA file using bowtie2 (optional)
* Extract Mapping data and convert it into read count files (optional)
* Generate quality control plot
* Generate data set statistics
* Perform hit analysis using three different methods
* Visualize hit candidates
* Compare hit analysis for most robust hit identification
* Retrieve information about single sgRNAs for hit candidates
* Generate standardized reports, which can be customized (for advanced users)
\newpage
## Download caRpools
CaRpools is available as an R package **caRpools** without the scripts and template files.
The complete package with the PERL scripts and all template files can be obtained from [Github](https://github.com/boutroslab/carpools) (https://github.com/boutroslab/carpools) and our website [CRISPR-AnalyzeR.de](http://www.crispr-analyzer.de).
We recommend to download the template files and Scripts from Github and install caRpools in R using the package installer `install.packages("caRpools").
## Quality Control
Available Quality Control plots include (for sgRNAs or summarized for genes):
* Read-count Distribution `carpools.read.distribution`
* Read Depth `carpools.read.depth`
* sgRNAs present per Gene Target `carpools.reads.genedesigns`
* Read-count Overview per sgRNA / Gene `carpools.read.ballmap`
* Read-count comparison of different samples `carpools.read.count.vs`
* Read-count / Fold-change of sgRNAs for single genes `carpools.raw.genes`
## Annotation
Since several gene identifiers are used for generating CRISPR pooled KO libraries, e.g. EnsemblID,
loaded data-sets can automatically be annotated with further gene annotation like official gene symbol or descriptions
using the `biomaRt` interface.
More details can be found below in the section of `get.gene.info` or via `?get.gene.info` / `?biomaRt`.
## Gene Read Count Data or Removing Gene Data
Furthermore, sgRNA read-count data can be aggregated (summed up) to corresponding genes `aggregatetogenes` or gene data can be excluded for the analysis using `gene.remove`.
## Hit Analysis
Moreover, this package can be used to identify screening hits using either
* DESeq2 `stat.DESeq`
* Wilcox-based hit calling `stat.wilcox`
* MAGeCK `stat.mageck`
and hit calling / data analysis can be compared between all the methods with `compare.analysis` or `carpools.hit.overview`.
Finally evaluated data analysis can be visualized in different ways with `carpools.hitident` for all methods listed above.
## sgRNA Information
Moreover, you will also be provided with in-depth information about the sgRNAs of your genes.
These can be derived from `carpools.raw.genes` for any gene or `carpools.hit.sgrna` for your hit candidates in an automated way.
## Report
All this data can be used to automatically generate a standardized report using the provided R Markdown template file including all plots and tables for you data analysis.
Two different templates are provides:
* A standard report for generating short, brief data analysis
* An extended report with additional plots and tables
The R Markdown templates provide the user with the ability to generate HTML output as well as PDF output (LATEX installation necessary) including high-quality plots.
__Provided PDF templates:__
* CaRpools-PDF.rmd
* CaRpools-extended-PDF.rmd
__Provided HTML templates:__
* CaRpools-HTML.rmd
* CaRpools-extended-HTML.rmd
\newpage
# Requirements and Installation
## Virtual Box Image
We also included a Virtual Box Image that already includes all necessary software and package files.
You just need to install Virtual Box 5 from the [Website](https://www.virtualbox.org).
You can download the caRpools virtual box image from our website [crispr-analyzer.de](http://www.crispr-analyzer.de) or [Github](https://github.com/boutroslab/carpools) (https://github.com/boutroslab/carpools).
### How to use the Virtual Box caRpools
Please see the [VirtualBox tutorial](https://github.com/boutroslab/caRpools/blob/master/docs/CaRpools-SHORTGUIDE-VirtualBox.Rmd) for instructions.
## Download caRpools
CaRpools is available as an R package **caRpools** without the scripts and template files.
The complete package with the PERL scripts and all template files can be obtained from [Github](https://github.com/boutroslab/carpools) (https://github.com/boutroslab/carpools) and our website.
We recommend to download the template files and Scripts from Github and install caRpools in R using the package installer `install.packages("caRpools").
## Hardware Requirements
For CRISPR-Libraries of 12 K size (12K sgRNAs), caRpools will work on any laptop/PC with at least 4GB of RAM and a modern dual-core CPU.
CRISPR-Libraries with a size of more than 100 K (100 K sgRNAs) run best with at least 8 GB of RAM.
## Software Requirements
CaRpools was tested on MacOSX Yosemite and Ubuntu 14.04 LTS.
However, it should work on any operating system that fulfills the software requirements.
The following software needs to be installed:
* PERL 5
* Bowtie2 2.2.0 or higher [Website](http://bowtie-bio.sourceforge.net/bowtie2/index.shtml)
* MAGeCK 0.51 (password protected download) [Website](http://sourceforge.net/p/mageck/wiki/Home/)
* TexLive [Website](https://www.tug.org/texlive/)
+ pdflatex
+ xelatex
* R 3.2.0 or higher [Website](https://www.r-project.org/)
* Pandoc 1.15.0.6 [Website](http://www.pandoc.org/)
* R-Studio [Website](http://www.rstudio.com) (GUI)
The following **R packages** need be installed (can be done via `load.packages()`):
* Bioconductor Basics
+ BiocInstaller >= 1.18.3
+ BiocGenerics >= 0.14.0
* __biomaRt >=2.24.0__
* seqinr >= 3.1-3
* xlsx >= 0.5.7
+ rJava >= 0.9.6
+ xlsxjars >= 0.6.1
* stringi >= 0.5
* scatterplot3d >= 0.3
* MESS >= 0.3
* DESeq2 >= 1.8.1
* rmarkdown >= 0.7
* knitr >= 1.10.5
* VennDiagram >= 1.6.9
* sm >= 2.2
## BiomaRt and Annotation Requirements
__Please note that for any annotation, biomaRt needs full access to the internet.__
In case of incorrect proxy settings, the report generation will fail with a biomaRt error.
This means that if any proxy server is used, this has to be configured before using caRpools as described in the following articles:
* [BiomaRt vignette](http://www.bioconductor.org/packages/release/bioc/vignettes/biomaRt/inst/doc/biomaRt.pdf)
* [Setting up proxy in R-Studio](https://support.rstudio.com/hc/en-us/articles/200488488-Configuring-R-to-Use-an-HTTP-Proxy)
* [Setting up proxy in R, Stackoverflow](http://stackoverflow.com/questions/6467277/proxy-setting-for-r)
* [Setting up Proxy for R/R-Studio in Ubuntu](http://askubuntu.com/questions/572722/setting-up-the-proxy-for-rstudio)
* [Configuration of Proxy for R](https://bhoom.wordpress.com/2013/05/27/configuring-r-to-use-an-http-proxy-faq-knowledge-base-rstudio-support/)
## Installation Procedure
Install all software listed above according to the installation information stated on the software website.
All necessary R packages can be installed automatically by `load.packages()`.
## Dataset / Screening Requirements
Since CaRpools fosters reproducibility of CRISPR/Cas9 screens, the following requirements for pooled screening data __must be fullfilled to analyze data__:
* Two biological replicates of _untreated_ sample data
* Two biological replicates of _treated_ sample data
**By default, _TWO_ replicates per condition are used by the templates provided. If you want to analyse more than two replicates per group, please have a look at _Providing more than two replicates_ . **
## Files that can be loaded
The following files are required for data analysis:
__Either__
* NGS FASTQ file for each sample
* Library reference in FASTA format
__or__
* Final read count file for each sample
* Library reference in FASTA format
CaRpools accepts either FASTQ files or read count files for each sample.
FASTQ file are then extracted and mapped using Bowtie2 against the library reference. Finally, read count files for each sample are generated.
As an alternative, these final read count files can be provided as well, so that no extraction or mapping is necessary.
In addition, a library reference file in FASTA format is necessary, usually this is the file that was used for ordering custom oligo libraries.
File structures are shown below.
### Structure of NGS Readcount Data
General information about the FASTQ file format can be obtained in an easy-to-understand article from [Wikipedia](https://en.wikipedia.org/wiki/FASTQ_format).
![](./pictures/fastq-format.png)
__maschine.pattern__
The machine pattern used for extracting the sequences is a regular expression to identify the read ID including your sequencing machine.
in the case of the above sample, the PERL regular expression used must be __M01100__.
![](./pictures/fastq-format-example.png)
### Extraction Pattern
CaRpools extracts the integrated DNA sequence of your target sequence as a DNA barcode.
In order to extract this sequence, a __PERL regular expression__ pattern is used to identify the desired nucleotide sequence, which is called __seq.pattern__.
As an example, part of a U6 promoter-driven sgRNA cassette is given as follows:
![](./pictures/extraction.png)
Since we want to extract the target sequence, the regular expression will use a part of the U6 promoter and a part of the sgRNA backbone to identify the target sequence.
CACC __(.{20})__ GTTTTAGAGC
The parenthesis are necessary to extract the target sequence, for more information please see [RegExR](http://www.regexr.com/).
### Structure of FASTA Library Reference File
The library reference file must be in FASTA format and include ALL sgRNAs present in the data-set with exactly the same naming.
e.g.
![](./pictures/library-fasta.png)
### Read-Count Data Files
CaRpools also takes read count files. If FASTQ files are provided and extracted/mapped with CaRpools, read count files will be created for each sample.
Data for each sample must be formatted in a **tab-separated** way as follows:
![](./pictures/readcount.png)
As shown in the above file, __Gene1__ is the Gene identifier, **_3423** is a unique part for identification of this sgRNA for the given gene and *Gene1_3423* is the whole identifier which uniquely identifies this sgRNA within the data-set.
The name of each complete sgRNA **must** contain the gene it refers to either as gene symbol or any other identifier which shares the same separator in addition to a part of identifier that is unique for each sgRNA for that gene.
The name can therefore be anything, as long as the *identifier is the same for each gene* and the *separator is the same for all data*.
In principle a sgRNA identifier must consist of a **gene identifier**, followed by a **seperator** (e.g. _ or -) as well as a *secondary* **sgRNA identifier**.
**Please note:**
* Read counts MUST be numeric only.
* Within the sgRNA/Gene identifer, no special characters *except for _ and -* are allowed!
### File Loading
Files can be loaded via `load.file(filename, header, sep)` with the following arguments
* filename: the filename as character
* header: TRUE / FALSE , whether a header is used (as it is for the above sample)
* sep: the separator, default is `\t` for tab-separated files.
**Please see `?read.table` for a detailed description of the arguments.**
## Files and Folder Structure to use CaRpools
__Please note: the MAIN FOLDER must be the R working directory!__
Data and Script paths can be adjusted in the MIACCS file.
The following files are necessary to use CaRpools for report generation:
**MIACCS.xls**
Minimum Information About CRISPR/Cas Screens. This file needs to be filled out to provide all necessary information about the screen.
**R Markdown Template files**
Either CaRpools-extended-PDF.rmd, CaRpools-PDF.rmd or CaRpools-extended-HTML.rmd or CaRpools-HTML.rmd. Is the template for report generation.
**Data Files**
Two replicates (or more) per Control and Treated. Can be FASTQ files OR already mapped, not normalized read count files.
**CRISPR-mapping.pl**
PERL script to map your extracted FASTQ files, if desired (as indicated in the MIACCS.xls)
**CRISPR-extract.pl**
PERL script to extract 20 nt target sequence from FAST files, if desired (as indicated in the MIACCS.xls)
**CaRpools.png**
The logo file
The following files are necessary to use _single_ CaRpools functions:
**Data Files**
Either raw read count files or FASTQ files (that need to be extracted and mapped using CaRpools)
Please note that CaRpools always starts with loading data files. For raw-read-count files, use `load.file`. For FASTQ files, please see the sections below.
\newpage
__CaRpools folder structure for Report Generation using raw Read Count files:__
![](./pictures/folder-structure-before.png)
\newpage
__CaRpools folder structure for Report Generation using raw Read Count files AFTER REPORT GENERATION:__
![](./pictures/folder-structure-FINAL.png)
\newpage
__CaRpools folder structrue for Report Generation using FASTQ files:__
![](./pictures/folder-structure-FASTQ-before.png)
\newpage
__CaRpools folder structure for Report Generation using FASTQ files AFTER REPORT GENERATION:__
![](./pictures/folder-structure-FASTQ-FINAL.png)
\newpage
# Using CaRpools with Provided R Markdown Templates
By default, CaRpools is meant to be used to generate standardized reports of CRISPR/Cas9 pooled screenings using the provided R markdown templates.
However, these templates can also serve as a basic frame for advanced users to modify them and create customized reports to their needs.
In the following sections, the use of CaRpools with the provided template files is explained in more detail. Please see the above instructions of how to install all necessary tools, packages and components for CaRpools.
For the modification of the templates, please see the manuals for R Markdown and knitr.
Single parameters and detailed instructions of the single function within CaRpools are given in the section **Using CaRpools as a stand-alone R Package**.
## Setup Files and R-Studio
All packages and software tools need be installed correctly as shown before.
1. Copy all files in the designated folders as shown above.
* __Please note: the MAIN FOLDER must be R working directory!__
* The MIACCS.xls as well the R markdown template and CaRpools.png must be in the same folder as the R working dir.
2. Adjust the path to the data and scripts folder if necessary in the MIACCS.xls . Use the absolute path. If the folder structure is as shown above, you do not need to make any adjustments.
3. Adjust and fill out the **MIACCS.xls** file.
4. You can use `CarPools(type="check")` to check for the correct folder structure and data file presence as it is indicated in the MIACCS.xls file.
5. You can check for your R working directory by `getwd()` and set it to any directory you want by `setwd("/PATH")`.
### Check Setup
You can verify that the MIACCS.xls file as well as the used template file and all necessary scripts are found by calling `check.caRpools()`.
See below for more information about the arguments.
By default, it **requires a correct MIACCS file + the script files + all packages installed + MAGeCK + Bowtie2 + Pandoc.**
## The MIACCS.xls file
The MIACCS (**M**inimum **I**nformation **A**bout **C**RISPR/**C**as **S**creens) file, provided as Excel sheet, combines all information which is necessary to reproduce the screens. This includes a description of the screen, hypothesis, all materials used as well as the experimental workflow.
Moreover, the MIACCS file is used to setup the analysis using caRpools, thus allowing a reproducible and standardized way of performing and analyzing pooled CRISPR/Cas screens.
The following parameters are found within the MIACCS.xls file:
### Using FASTQ Files
Instead of providing already mapped read count files, caRpools provides the functionality to use the generated RAW FASTQ files as they are supplied by the sequencing machine, e.g. Illumina MiSeq/NextSeq/HiSeq systems.
If desired, caRpools can extract your 20 nt target sequence (without filtering for quality) from these files and map it against your library reference using bowtie2.
In this case, you need to provide the following files that must be within the datapath set in the MIACCS file:
* Two replicate FASTQ files for the untreated sample
* Two replicate FASTQ files for the treated sample
* Your ordered library reference as FASTA file
* optional bowtie2 index files of your library fasta files (generated via bowtie2-build)
Moreover, the wrapper files CRISPR-mapping.pl and CRISPR-extract.pl need to be in the scriptpath as set in the MIACCS file.
caRpools will then generate the following files during the extraction and mapping:
**filename_extracted.fastq** FASTQ file with the extracted 20 nt target sequence
**multiple library-filename.bt2** bowtie2 index files (if create index files set as TRUE in the MIACCS file)
**filename_extracted.sam** SAM alignment file of the extracted 20 nt target sequence against the library reference
**filename_extracted-designs.txt** Read Count files for each sgRNA
**filename_extracted-genes.txt** Read Count files SUMMED up for each gene (not used during analysis)
The following parameters must be set in the MIACCS.xls file under **Data Extraction and Bowtie2 Mapping/Alignment** to extract file from FASTQ data:
**Do you want to extract the sgRNA target sequence from FASTQ?** *TRUE or FALSE*
This indicates whether you would like to extract the 20 nt target sequence from the provided FASTQ file (TRUE).
**Regular expression to extract target sequence from FASTQ file** *PERL regular expression pattern*
This must be a PERL regular expression pattern that is used to identify the 20 nt target sequence. By default, this is *ACC(.{20})GT{2,4}AGAGC* and can be used for the GeckoV2 library or other libraries that are based on U6-driven sgRNA expression . Can be ANY PERL expression pattern. The only importance is, that the part which identifies the 20 nt target sequence is in parenthesis only.
**Regular Expression to extract maschine ID from Reads**
This must be the unique sequencing machine ID/serial number as indicated in the FASTQ files.
**Is the data within the FASTQ file in Reverse Complement?** *TRUE or FALSE*
Did you sequence your data in reverse complement order? By default, this is set to FALSE.
**Do you want to map the reads to the reference file?** *TRUE or FALSE*
If set to TRUE, bowtie2 will be called to map the extracted or not-extracted FASTQ files to your bowtie2 reference library index. For further information about bowtie2 mapping, please see the [Bowtie2 Manual](http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml).
**Do you want to create the Bowtie2 index files?** *TRUE or FALSE*
If set to TRUE, bowtie2 indexes will be created for your library-reference.fasta file. If you do not have created this indexes before, set this to TRUE so that they are created before the mapping to your library reference is performed. More information about bowtie2 index files can be found [here](http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml#the-bowtie2-build-indexer).
**How many threads shall bowtie2 use?** *integer*
In the case bowtie2 mapping is set to TRUE, please give the number of cores or threads to use. For most dual-core CPU, the default value 4 is fine. More information about threading can be found [here](http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml#performance-tuning).
**Bowtie2 Sensitivity?** *default: very-sensitive-local*
*Other options: very-fast, fast, sensitive, very-fast-local, fast-local, sensitive-local*
You can adjust the sensitivity of bowtie2 using this parameter. By default, bowtie2 is used in a very-sensitive-local setting. More information about different sensitivity parameters can be found at the [bowtie2 options](http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml#options).
**Additional Bowtie2 parameters?**
You can pass additional parameters to bowtie2 as they are indicated in the [bowtie2 manual](http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml). Please leave empty if not used.
**Alignment Quality**
After bowtie2 mapping, the alignment is converted into read count files *filename_extracted-design.txt* and *filename_extracted-genes.txt*.
You can indicate how well the alignment must be in order to be used for generating the read count for each sgRNA.
By default, this is set to *perfect*, which only employs a mapped read if the full 20 nt from the sequencing match perfectly to the sgRNA found in your library reference. The following options can be used:
* __perfect__ - Read is used of all 20 nt from the sequencing are matching the target sequence given in the library reference
* __high__ - Read is used if at least 18 nt (starting from the PAM) are matching the target sequence in the reference
* __seed__ - Read is used if at least 14 nt (starting from the PAM) are a perfect match against the target sequence in the reference
![](./pictures/alignment-match.png)
#### Example of a MIACCS File entry for FASTQ files
![](./pictures/miaccs-fastq.png)
### Using Read Count Files
Instead of using raw NGS Fastq files, caRpools can also be used to directly analysis read-count files without fastq data extraction and mapping.
In this case, already finalized read-count files are provided that must be in the same format as described in **Read Count Data Files**.
If you provide read-count files, please make sure you fill out the MIACCS file accordingly.
An example of a MIACCS file for read-count files is shown below.
#### Example of a MIACCS File entry for Read-Count files
![](./pictures/miaccs-readcount.png)
### Data Analysis Options
CaRpools is not only meant as a tool for standardized and fully reproducible data analysis of CRISPR-Cas screens, but also fosters exploratory data analysis.
Therefore caRpools offers the user different options for data analysis as illustrated below. All options can be set within the MIACCS file or directly passed on to the individual functions of caRpools (advanced users).
![](./pictures/miaccs-analysis.png)
## Providing more than two replicates per Group
CaRpools allows the usage of more than two replicates for both the untreated and treated groups. However, the standard templates we provide accept two biological replicates only.
There are two ways of using the caRpools report generation function with more replicates:
* use the provided templates stating __4-replicates__
* modify the templates
If you like to modify the template of caRpools, you just need to add certain statements for the additional replicates. This will change with the next larger update.
#### Load more files
When loading files (e.g. read-count files or fastq files for extraction), you can just put additional code of the following scheme:
```{r, eval=FALSE, echo=TRUE}
## for data extraction of a third replicate or more
# First edit the MIACCS file loading
fileCONTROL3 = as.character(miaccs["carpools.untreated3",3])
d.CONTROL3 = as.character(miaccs["carpools.untreated3.desc",3])
fileTREAT3 = as.character(miaccs["carpools.treated3",3])
d.TREAT3 = as.character(miaccs["carpools.treated3.desc",3])
# Additional CONTROL replicate
fileCONTROL3 = data.extract(scriptpath, datapath, fastqfile=fileCONTROL3,
extract, seq.pattern, maschine.pattern, createindex, referencefile,
mapping, reversecomplement, threads, bowtieparams, sensitivity, match)
# Additional Treatment replicate
fileTREAT3 = data.extract(scriptpath, datapath, fastqfile=fileTREAT3,
extract, seq.pattern, maschine.pattern, createindex, referencefile,
mapping, reversecomplement, threads, bowtieparams, sensitivity, match)
## If you do not want to extract FASTQ files, but just load a read-count file this is the way to go
CONTROL3 = load.file(paste(datapath, fileCONTROL3, sep="/"))
TREAT3 = load.file(paste(datapath, fileTREAT3, sep="/"))
```
#### QC plots and Gene Annotation using several replicates
In principal you can use as many replicates per treatment group as you want, the minimum however is two replicates.
Some of the QC plots and other functions require single replicates, others can be used with as many replicates as you want directly within the function call.
This means you need to call the function for each replicate separately for the following functions:
* load.file
* data.extract
* get.gene.info
* aggregatetogenes
* stats.data
* unmapped.genes
* carpools.read.distribution
* carpools.reads.genedesigns
These function accept several replicates directly as a list:
* carpools.read.depth
* carpools.readcount.vs
* stat.wilcox
* stat.deseq
* stat.mageck
All other functions do not depend on read-count data directly so that you do not think about replicates for those, as all handling is done automatically.
#### Provide more replicates to statistical analysis
```{r, eval=FALSE, echo=TRUE}
## WILCOX
# Provide more replicates as list
data.wilcox = stat.wilcox(untreated.list = list(CONTROL1, CONTROL2, CONTROL3, CONTROL4),
treated.list = list(TREAT1,TREAT2, TREAT3, TREAT4), namecolumn=namecolumn,
fullmatchcolumn=fullmatchcolumn, normalize=normalize, norm.fun=norm.function,
sorting=FALSE, controls=controls.nontarget, control.picks=control.picks)
## DESEQ2
data.deseq = stat.DESeq(untreated.list = list(CONTROL1, CONTROL2, CONTROL3, CONTROL4),
treated.list = list(TREAT1,TREAT2, TREAT3, TREAT4), namecolumn=namecolumn,
fullmatchcolumn=fullmatchcolumn, extractpattern=g.extractpattern, sorting=FALSE,
filename.deseq = paste(analysis.name, "-ANALYSIS-DESeq2-sgRNA.tab", sep=""), sgRNA.pval = sig.pval.deseq, fitType="mean")
## MAGECK
data.mageck = stat.mageck(untreated.list = list(CONTROL1, CONTROL2, CONTROL3, CONTROL4),
treated.list = list(TREAT1,TREAT2, TREAT3, TREAT4), namecolumn=namecolumn,
fullmatchcolumn=fullmatchcolumn, norm.fun="median", extractpattern=g.extractpattern,
mageckfolder=NULL, sort.criteria="neg", adjust.method="fdr",
filename = paste(analysis.name, "-ANALYSIS-MAGeCK-RAW", sep=""), fdr.pval=sig.pval.mageck)
```
# Start CaRpools Report Generation
You can start caRpools Report Generation after you did the following steps:
* Installed all required software and R packages (use _check.caRpools(files=FALSE)_ to verify)
* Put every file in the correct folder (MIACCS, data files, script files, Rmd templates)
* Put everything in the R working directory or set the working directory to the folder of your files
* Filled out the MIACCS file with all information, e.g. correct filenames, reference, data analysis options
You can check for all requirements by calling `check.caRpools`.
## Start CaRpools using R-Studio
In the case you use R-Studio, you can start caRpools by just opening the corresponding Rmd template file.
At the top, you will find the **Knit PDF** or **Knit HTML** button, so you just need to press that and caRpools will generate the report.
![](./pictures/rstudio-knit.png)
As an alternative, you can start caRpools via `use.caRpools` and provide additional parameters (see below).
## Start CaRpools using R console
Moreover, caRpools report generation can also be initiated without R-studio installation, so that this can be done via R command line even on remote computers.
In this case, caRpools report generation can be started via `use.caRpools` with additional parameters, which are described below.
#### use.caRpools()
**Usage:**
`use.caRpools(type=NULL, file="CaRpools-extended-PDF.Rmd", miaccs="MIACCS.xls", check=TRUE, work.dir=NULL)`
**type**
*Description* If you provide a custom Rmd template that can generate both, PDF and HTML reports you can indicate which version you want to generate.
*Default* NULL
*Values* "PDF", "HTML"
**file**
*Description* The file name of your custom Rmd template file (with extension).
*Default* "CaRpools-extended-PDF.Rmd"
*Values* filename as character
**miaccs**
*Description* The filename of your MIACCS file.
*Default* "MIACCS.xls"
*Values* filename as character
**check**
*Description* Indicates whether caRpools will check for correct installation and file access.
*Default* TRUE
*Values* TRUE or FALSE (boolean)
**work.dir**
*Description* You can provide the absolute path to the working directory in which all files are placed (e.g. the MIACCS.xls and Rmd template).
*Default* NULL
*Values* absolute path (character) or NULL if standard R working directory is used
\newpage
# Using CaRpools as a stand-alone R Package
**CaRpools can be used without the provided R markdown templates to generate own reports or individualized analysis of CRISPR/Cas9 screens.**
The following sections will explain every function included in CaRpools and provide hints, tips and a documentation of how to use CaRpools for data analysis. This will help you in customizing the generated reports to you needs, create new reports or just use single functions of CaRpools within your data analysis workflow.
## Loading Data
CaRpools offers two ways of providing CRISPR/Cas9 screening data.
Either raw **read-count files** are directly used as described before, or read-count files are generated from NGS FASTQ files by extracting the 20 nt target sequence, mapping it against a reference library and extracting the read-count information for each sgRNA identifier.
```{r load-file, echo=TRUE, eval=FALSE}
CONTROL1 = load.file("./data/untreated1.txt", header= TRUE, sep="\t")
```
**Usage**
`load.file(filename, header = TRUE, sep="\t", comment.char="", type = NULL)`
**filename**
Filename to be loaded. If read-count files are loaded, please include the extension.
For FASTQ files, please pass on the output of `data.extract` as this is the filename of the extracted file.
*Default* empty
*Values* filename (character) or output from `data.extract`
**header**
Is the first line just a header?
*Default* TRUE
*Values* TRUE, FALSE (boolean)
**sep**
Separator of data, usually tab-separated.
*Default* "\t" for TAB-separated data
*Values* Any separator
**comment.char**
Are character files within any quote etc?
*Default* ""
*Values* Any character
**type**
Indicates which files are being loaded. Three file-types are possible. Either NULL for tab-separated files, fastalib for library reference files or xlsx for loading the MIACCS file.
*Default* NULL
*Values* NULL, "fastalib", "xlsx"
### Loading Read-Count files Directly
Read-Count files (normalized or not normalized) can be loaded with `load.file` into a data frame that is used for further usage.
For each untreated and treated sample two replicates are used:
```{r load-files-read-count, echo=TRUE, eval=FALSE}
CONTROL1 = load.file("./data/untreated1.txt", header= TRUE, sep="\t")
CONTROL = load.file("./data/untreated2.txt", header= TRUE, sep="\t")
TREAT1 = load.file("./data/treated1.txt", header= TRUE, sep="\t")
TREAT2 = load.file("./data/treated2.txt", header= TRUE, sep="\t")
# Don't forget the library reference
libFILE = load.file(
paste(datapath, paste(referencefile,".fasta",sep=""), sep="/"),header = FALSE,
type="fastalib")
```
### Loading FASTQ Files to Generate Read-Count Files
In a first step, NGS FASTQ data is extracted and mapped against a reference library file using bowtie2.
```{r load-files-fastq, echo=TRUE, eval=FALSE}
fileCONTROL1 = data.extract(
scriptpath="path.to.scripts", datapath="path.to.FASTQ",fastqfile="filename1",
extract=TRUE, seq.pattern, maschine.pattern, createindex=TRUE,
bowtie2file=filename.lib.reference, referencefile="filename.lib.reference",
mapping=TRUE, reversecomplement=FALSE, threads, bowtieparams,
sensitivity="very-sensitive-local",match="perfect")
# Now we can load the generated Read-Count file directly!
CONTROL1 = load.file(paste(datapath, fileCONTROL1, sep="/")) # Untreated sample 1 loaded
# Don't forget the library reference
libFILE = load.file(
paste(datapath, paste(referencefile,".fasta",sep=""), sep="/"),header = FALSE,
type="fastalib")
```
A closer look to the data frame we just loaded:
`r knitr::kable(CONTROL1[40:50,])`
#### data.extract()
**Usage:**
`data.extract(scriptpath=NULL, datapath=NULL, fastqfile=NULL, extract = FALSE, pattern = "default", maschinepattern = "default", createindex = FALSE, bowtie2file = NULL, referencefile= NULL, mapping = FALSE, reversecomplement = FALSE, threads = 1, bowtieparams = "", sensitivity = "very-sensitive-local", match = "perfect")`
**scriptpath**
Absolute path of the folder that contains `CRISPR-extract.pl` and `CRISPR-mapping.pl`
*Default* NULL
*Values* absolute path (character)
**datapath**
Absolute path of the folder that contains the data files (e.g. file.FASTQ)
*Default* NULL
*Values* absolute path (character)
**fastqfile**
Filename of FASTQ file WITHOUT .fastq extension
*Default* NULL
*Values* filename (character)
**extract**
Whether CRISPR-extract.pl is used to extract the 20 nt target sequence from the NGS reads using `pattern`
*Default* FALSE
*Values* TRUE, FALSE (boolean)
**pattern**
PERL regular Expression to extract 20 nt target sequence from NGS reads. Please see *extract pattern* in this manual for more information.
*Default* Regular Expression (character)
**maschinepattern**
Machine ID of your Sequencing machine. Used to identify the read id.
**createindex**
Do you want caRpools to generate a bowtie2 index? Only necessary if `mapping=TRUE`.
*Default* FALSE
*Values* TRUE, FALSE
**bowtie2file**
Filename of bowtie2 index file, without extension. Is the same as reference file, if `createindex=TRUE`.
**referencefile**
Filename of the library reference FASTA file, without extension. Is the same as bowtie2 file, if `createindex=TRUE`.
**mapping**
Indicates whether FASTQ files need to be mapped against `referencefile`/`bowtie2file`. FALSE by default.
*Default* FALSE
*Values* TRUE, FALSE
**reversecomplement**
Is the NGS sequence in reverse complement order?
*Default* FALSE
*Values* TRUE, FALSE
**threads**
How many threads can bowtie2 use for mapping? Only used if `mapping=TRUE`. Usually cores of CPU.
*Default* 2
*Values* any integer
**bowtieparams**
If you want to pass additional parameters to bowtie2.
**sensitivity**
You can adjust the sensitivity of bowtie2 using this parameter. By default, bowtie2 is used in a very-sensitive-local setting. More information about different sensitivity parameters can be found at the [bowtie2 options](http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml#options).
*Default* "very-sensitive-local"
*Other options: very-fast, fast, sensitive, very-fast-local, fast-local, sensitive-local*
**match**
After bowtie2 mapping, the alignment is converted into read count files *filename_extracted-design.txt* and *filename_extracted-genes.txt*.
You can indicate how well the alignment must be in order to be used for generating the read count for each sgRNA.
By default, this is set to *perfect*, which only employs a mapped read if the full 20 nt from the sequencing match perfectly to the sgRNA found in your library reference. The following options can be used:
* __perfect__ - Read is used of all 20 nt from the sequencing are matching the target sequence given in the library reference
* __high__ - Read is used if at least 18 nt (starting from the PAM) are matching the target sequence in the reference
* __seed__ - Read is used if at least 14 nt (starting from the PAM) are a perfect match against the target sequence in the reference
### Aggregating sgRNA read-count to Gene read-count
CaRpools allows you to aggregate sgRNA read-counts to gene read-counts using `aggregatetogenes()`.
```{r aggregate1, echo=TRUE, eval=FALSE}
CONTROL1.g=aggregatetogenes(data.frame = CONTROL1, agg.function=sum,
extractpattern = expression("^(.+?)(_.+)"),type = "aggregate")
```
#### aggregatetogenes()
**Usage**
`aggregatetogenes(data.frame, namecolumn=1, countcolumn=2, agg.function=sum, extractpattern=expression("^(.+?)_.+"), type="aggregate")`
**data.frame**
A data-frame of sgRNA read-count data as done by `load.file`
*Default* empty
*Values* data-frame
**namecolumn**
In which column are the sgRNA identifiers?
*Default* 1
*Values* column number (numeric)
**countcolumn**
In which column are the read counts?
*Default* 2
*Values* column number (numeric)
**extractpattern**
PERL regular expression that is used to retrieve the gene identifier from the overall sgRNA identifier.
e.g. in **AAK1_107_0** it will extract **AAK1**, since this is the gene identifier belonging to this sgRNA identifier. **Please see: Read-Count Data Files**
*Default* expression("^(.+?)(_.+)"), will work for most available libraries.
*Values* PERL regular expression with parenthesis indicating the gene identifier (expression)
**type**
CaRpools can either aggregate the data frame (`type = "annotate"`) or annotate the gene identifiers only as an additional column (`type = "annotate"`).
*Default* "aggregate"
*Values* "aggregate", "annotate"
##### Example for data aggregation
```{r aggregate-example1, echo=TRUE, eval=FALSE}
CONTROL1.g=aggregatetogenes(data.frame = CONTROL1, agg.function=sum,
extractpattern = expression("^(.+?)(_.+)"), type="aggregate")
knitr::kable(CONTROL1.g[1:10,])
```
`r knitr::kable(CONTROL1.g[1:10,])`
##### Example for data annotation
```{r aggregate-example2, echo=TRUE, eval=TRUE}
CONTROL1.g.annotate=aggregatetogenes(data.frame = CONTROL1, agg.function=sum,
extractpattern = expression("^(.+?)(_.+)"), type="annotate")
knitr::kable(CONTROL1.g.annotate[1:10,])
```
### Convert Gene Identifier or Annotate Gene Information
It is also possible to either enrich the screening data-set file with additional information provided by the biomaRt interface.
For example, gene identifiers can be changed from EnsemblIDs to official gene symbols are Gene Ontology terms can be added to the data-set.
This can be done using `get.gene.info`, which serves as a wrapper for the **biomaRt** package with its load of options and possibilities (more information see `?biomaRt`).
You can convert any gene identifier which is included in your sgRNA identifier to e.g. EnsemblID or HGNC Gene Symbol using caRpools.
**Please note that Internet Access is required for biomaRt.**
For further information about biomaRt conversion, please see the [biomaRt Manual](www.bioconductor.org/packages/release/bioc/vignettes/biomaRt/inst/doc/biomaRt.pdf).
```{r get.gene.info, echo=TRUE,eval=FALSE}
# Convert HGNC gene symbol to EnsemblID
CONTROL1 = get.gene.info(
CONTROL1, namecolumn=1, extractpattern=expression("^(.+?)(_.+)"),
host="www.ensembl.org",
database="ENSEMBL_MART_ENSEMBL", dataset="hsapiens_gene_ensembl", filters="hgnc_symbol",
attributes = "ensembl_gene_id", return.val = "dataset")
# Also convert the library reference
libFILE = get.gene.info(
libFILE, namecolumn=1, extractpattern=expression("^(.+?)(_.+)"),
host="www.ensembl.org",
database="ENSEMBL_MART_ENSEMBL", dataset="hsapiens_gene_ensembl", filters="hgnc_symbol",
attributes = "ensembl_gene_id", return.val = "dataset")
```
This will convert a gene identifier, which is extracted by a PERL Regular Expression **(.+?)(_.+)** and of type hgnc_symbol (gene symbol), to an Ensembl Gene ID.
#### get.gene.info()
**Usage**
`get.gene.info = function(data, namecolumn=1, extractpattern=expression("^(.+?)(_.+)"), host="www.ensembl.org", database="ensembl", dataset="hsapiens_gene_ensembl", filters="ensembl_gene_id", attributes = c("hgnc_symbol"), return.val = "dataset", controls=FALSE)`
**data**
Data frame that contains read-count data.
*Default* none
*Values* data.frame containing read-count data (data.frame)
**namecolumn**
In which column are the sgRNA identifiers?
*Default* 1
*Values* column number (numeric)
**extractpattern**
PERL regular expression that is used to retrieve the gene identifier from the overall sgRNA identifier.
e.g. in **AAK1_107_0** it will extract **AAK1**, since this is the gene identifier belonging to this sgRNA identifier. **Please see: Read-Count Data Files**
*Default* expression("^(.+?)(_.+)"), will work for most available libraries.
*Values* PERL regular expression with parenthesis indicating the gene identifier (expression)
**host**
The host which is used to retrieve biomaRt information.
*Default* "www.ensembl.org"
*Values* See biomaRt website for further information.
**database**
BiomaRt database to be used. See `?listMarts()` or biomaRt documentation.
*Default* "ENSEMBL_MART_ENSEMBL", is using the ensembl database
*Values* Any biomaRt database (character)
**dataset**
The biomaRt data-set to be used. For *homo sapiens*, *hsapiens_gene_ensembl* is recommended. See `?listDatasets` or biomaRt documentation.
*Default* "hsapiens_gene_ensembl"
*Values* Any biomaRt dataset (character)
**filters**
The input filter information to retrieve biomaRt annotation, usually is the type of gene identifier used in the read-count files, e.g. "ensemble_gene_id". see `?listFilters`
*Default* "ensembl_gene_id"
*Values* Any biomaRt filter (character)
**attributes**
The output attribute to retrieve from biomaRt, usually the annotations that need to be fetched, e.g. "hgnc_symbol". see `?listAttributes`
*Default* "hgnc_symbol"
*Values* Any biomaRt attribute (character)
**return.val**
The type of object that is returned. For whole data-set, e.g. conversion of gene identifiers, use "dataset".
*Default* "dataset"
*Values* "dataset" (will give back the same data frame, but with exchanged gene identifiers), "info" (will return a data frame with all attributes fetched for genes, is used to annotate gene with additional information)
**controls**
Is set to TRUE if `data` is not a data frame, but a vector.
*Default* FALSE
*Values* TRUE, FALSE (boolean)
##### Example: Replace Gene Identifier (EnsemblID) by Official Gene Symbol
```{r geneinfo-replace, echo=TRUE, eval=TRUE}
CONTROL1.replaced = get.gene.info(CONTROL1, namecolumn=1, host="www.ensembl.org",
extractpattern=expression("^(.+?)(_.+)"), database="ENSEMBL_MART_ENSEMBL", dataset="hsapiens_gene_ensembl",
filters="hgnc_symbol", attributes =c("ensembl_gene_id"), return.val = "dataset")
knitr::kable(CONTROL1.replaced[1:10,])
```
##### Example: Enrich Dataset by Gene Description
```{r geneinfo-replace2, echo=TRUE, eval=TRUE}
CONTROL1.replaced.info = get.gene.info(CONTROL1, namecolumn=1, host="www.ensembl.org",
extractpattern=expression("^(.+?)(_.+)"), database="ENSEMBL_MART_ENSEMBL", dataset="hsapiens_gene_ensembl",
filters="hgnc_symbol", attributes = c("ensembl_gene_id","description"), return.val = "info")
knitr::kable(CONTROL1.replaced.info[1:10,])
```
\newpage
## Quality Control of pooled CRISPR Screening data
There are several different functions available to determine the quality of your data:
* General Data-set Statistics
* Specific Statistics of Included Controls
* Read-count Distribution `plot.read.distribution`
* Read Depth `plot.read.depth`
* sgRNAs present per Gene Target `plot.reads.genedesigns`
* Read-count comparison of different samples `plot.read.count.vs`
* Information about the phenotype of sgRNAs `plot.raw.genes`
### Dataset Statistics
```{r stats-general-pre, echo=FALSE, eval=TRUE}
# General
U1.stats = stats.data(dataset=CONTROL1, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")
U2.stats = stats.data(dataset=CONTROL2, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")
T1.stats =stats.data(dataset=TREAT1, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")
T2.stats =stats.data(dataset=TREAT2, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")
# Combine Stats
combined.stats = cbind.data.frame(U1.stats[,1:2], U2.stats[,2], T1.stats[,2], T2.stats[,2])
colnames(combined.stats) = c("Readcount", d.CONTROL1, d.CONTROL2, d.TREAT1, d.TREAT2)
```
General statistics for a given data-set can be obtained by `stats.data`.
For further information about the possibilities, see `?stats.data`.
A typical table would look like this (shorted):
`r knitr::kable(combined.stats)`
```{r stats-general, echo=TRUE, eval=FALSE}
# General
U1.stats = stats.data(dataset=CONTROL1, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")
U2.stats = stats.data(dataset=CONTROL2, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")
T1.stats =stats.data(dataset=TREAT1, namecolumn = 1, fullmatchcolumn = 2,
extractpattern=expression("^(.+?)_.+"), type="stats")