-
Notifications
You must be signed in to change notification settings - Fork 1
/
03.02-sequence_preprocessing.Rmd
72 lines (57 loc) · 3.61 KB
/
03.02-sequence_preprocessing.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
# Sequencing data preprocessing {#sequencing-data-preprocessing}
The first step of the bioinformatic pipeline is to pre-process the raw sequencing data to prepare them for downstream analyses.
### Preprocess the reads using fastp {-}
Raw sequencing data require an initial preprocessing to get rid off low-quality nucleotides and reads, as well as any remains of sequencing adaptors that can mess around in the downstream analyses. An efficient way to do so is to use the software **fastp**, which can perform all above-mentioned operations in a single go and directly on compressed files.
:::: {.tipbox}
**fastP** documentation [can be found here](https://github.com/OpenGene/fastp).
:::
\small
```{sh eval=FALSE}
fastp \
--in1 {input.r1i} --in2 {input.r2i} \
--out1 {output.r1o} --out2 {output.r2o} \
--trim_poly_g \
--trim_poly_x \
--low_complexity_filter \
--n_base_limit 5 \
--qualified_quality_phred 20 \
--length_required 60 \
--thread {threads} \
--html {output.fastp_html} \
--json {output.fastp_json} \
--adapter_sequence {params.adapter1} \
--adapter_sequence_r2 {params.adapter2}
```
\normalsize
### Splitting host and non-host data {-}
Depending on the sample type employed for data generation, sequencing data might contain only host reads, only microbial reads, or a mixture of both. For example, blood sampled from an animal is expected to only contain host DNA/RNA reads (unless an infection is ongoing), while DNA extracted from a microbial culture is only expected to contain microbial DNA/RNA reads (unless human contamination has happened). In contrast, intestinal content samples, faecal samples, leave samples or root samples can contain both host and microbial nucleic acids.
#### Index host genome {-}
In order to map metagenomic reads to a reference host genome, it is necessary to index the genome. An index is a data structure that allows for efficient searching of the reference genome by breaking it down into smaller, more manageable pieces. Without an index, aligning reads to a reference genome would be prohibitively slow, especially for large genomes. Bowtie2 is a popular software tool for aligning reads to a reference genome, and it requires an index of the reference genome before alignment can be performed. Bowtie2 uses an index based on the Burrows-Wheeler transform (BWT) algorithm, which enables it to efficiently align reads to the reference genome. Here are the basic command to create a Bowtie2 index for a reference genome:
\small
```{sh eval=FALSE}
bowtie2-build \
--large-index \
--threads {threads} \
{input.genome} {output.index}
```
\normalsize
#### Map samples to host genomes {-}
The next step is to map the reads against the reference genome, followed by a split between reads that have been mapped (in the example below are retained in a BAM/SAM file) and the reads that were not mapped (in the example below outputed to fastq files). The mapped reads can be used for performing population genomic analyses, while the unmapped reads can be used for metagenomic analyses.
\small
```{sh eval=FALSE}
# Map reads to the reference genome using Bowtie2
bowtie2 \
--time \
--threads {threads} \
-x {indexed.genome} \
-1 {input.r1i} \
-2 {input.r2i} \
| samtools view -b -@ {threads} - | samtools sort -@ {threads} -o {output.all_bam} -
# Extract non-host reads
samtools view -b -f12 -@ {threads} {output.all_bam} \
| samtools fastq -@ {threads} -1 {output.non_host_r1} -2 {output.non_host_r2} -
# Send host reads to BAM
samtools view -b -F12 -@ {threads} {output.all_bam} \
| samtools sort -@ {threads} -o {output.host_bam} -
```
\normalsize