Evaluating and processing raw sequencing data GVA2016
Overview
Before you start the alignment and analysis processes, it can be useful to perform some initial quality checks on your raw data. If you don't do this (or even if you do), you may notice later that something looks fishy in the the output: for example, many of your reads are not mapping or the ends of many of your reads do not align. Both can give you clues about whether you need to process the reads to improve the quality of data that you are putting into your analysis. Each year this tutorial is discussed at some length for if it should be included as a main tutorial, if it should be included as an optional tutorial, or if it should be ignored all together as the quality of data increases. Recently a colleague of ours spent several days working with and trying to understand some data he got back before reaching out for help, after a few hours of running into a wall, fastqc was used to determine that the library was not constructed correctly in less than 30 minutes. So here we present the tutorial as quick thing to check which may save you significant amounts of time later on.
Learning Objectives
This tutorial covers the commands necessary to use several common programs for evaluating read files in FASTQ format and for processing them (if necessary).
- Diagnose common issues in FASTQ read files that will negatively impact analysis.
- Trim adaptor sequences and low quality regions from the ends of reads to improve analysis.
Table of Contents
As we discussed yesterday, we do not want to run things on the head node, so we should start a new idev session. The reservation name has changed from CCBB_Bio_Summer_School_2016_Day1 to CCBB_Bio_Summer_School_2016_Day2. See if you can figure out how to start your own idev session.
Illumina sequence data format (FASTQ)
GSAF gives you paired end sequencing data in two matching FASTQ format files, containing reads for each end sequenced: for example, Sample_ABC_L005_R1.cat.fastq
and Sample_ABC_L005_R2.cat.fastq
. Each read end sequenced is representd by a 4-line entry in the FASTQ file.
A 4-line FASTQ file entry looks like this:
@HWI-ST1097:104:D13TNACXX:4:1101:1715:2142 1:N:0:CGATGT GCGTTGGTGGCATAGTGGTGAGCATAGCTGCCTTCCAAGCAGTTATGGGAG + =<@BDDD=A;+2C9F<CB?;CGGA<<ACEE*1?C:D>DE=FC*0BAG?DB6
- Line 1 is the read identifier, which describes the machine, flowcell, cluster, grid coordinate, end and barcode for the read. Except for the barcode information, read identifiers will be identical for corresponding entries in the R1 and R2 fastq files.
- Line 2 is the sequence reported by the machine.
- Line 3 is always '+' from GSAF (it can optionally include a sequence description but rarely or never actually does)
- Line 4 is a string of Ascii-encoded base quality scores, one character per base in the sequence. For each base, an integer quality score = -10 log(probabilty base is wrong) is calculated, then added to 33 to make a number in the ASCII printable character range.
See the Wikipedia FASTQ format page for more information.
Now that you know the basics, see if you can complete the following exercises on your own.
Exercise: Examine the 2nd sequence in a FASTQ file
What the 2nd sequence in the file $BI/gva_course/mapping/data/SRR030257_1.fastq
is?
Counting sequences
If you get an error from running a program, one of the first thing to check is that the length of your FASTQ files is evenly divisible by four and — if the program expects paired reads — that the R1 and R2 files have the same number of reads. The wc
command (word count) using the -l
switch to tell it to count lines, not words, is perfect for this:
Exercise: Counting FASTQ file lines
How many sequences are in the FASTQ file above?
As mentioned many programs have problems if R1 and R2 do not have the same number of reads. While you can obviously change the wc -l command to check R2 rather than R1, fastq files are often stored in a compressed state to save disk space. By using pipes to link commands, you can still count the lines, and you don't have to uncompress the file to do it! Specifically, you can use gunzip -c
to write decompressed data to standard output (-c
means "to console", and leaves the original *.gz
file untouched). You then pipe that output to wc -l
to get the line count.
How many lines/sequences does the compressed file contain? Does this agree with what you found for R1?
While checking the number of reads a file has can solve some of the most basic problems, it doesn't really provide any direct evidence as to the quality of the sequencing data. To get this type of information before starting meaningful analysis other programs must be used. Place your sticky note on your computer when you have made it this far and start looking over the fastqc links below. Once everyone has caught up we will go over this together.
FASTQ Evaluation Tools
The first order of business after receiving sequencing data should be to check your data quality. This often-overlooked step helps guide the manner in which you process the data, and can prevent many headaches that could require you to redo an entire analysis after they rear their ugly heads.
FastQC
FastQC is a tool that produces a quality analysis report on FASTQ files. Online documentation for FastQC
First and foremost, the FastQC "Summary" on the left should generally be ignored. Its "grading scale" (green - good, yellow - warning, red - failed) incorporates assumptions for a particular kind of experiment, and is not applicable to most real-world data. Instead, look through the individual reports and evaluate them according to your experiment type.
The FastQC reports I find most useful are:
- The Per base sequence quality report, which can help you decide if sequence trimming is needed before alignment.
- The Sequence Duplication Levels report, which helps you evaluate library enrichment / complexity. But note that different experiment types are expected to have vastly different duplication profiles.
- The Overrepresented Sequences report, which helps evaluate adapter contamination.
Running FastQC
FastQC is available from the TACC module system on lonestar. Interactive GUI versions are also available for Windows and Macintosh and can be downloaded from the Babraham Bioinformatics web site. We don't want to clutter up our work space so copy the SRR030257_1.fastq file to a new directory named BDIB_fastqc_tutorial on scratch, use the module system to load fastqc, use fastqc's help option after the module is loaded to figure out how to run the program. Once the program is completed use scp to copy the important file back to your local machine (The bold words are key words that may give you a hint of what steps to take next)
Exercise: FastQC results
What did FastQC create?
Looking at FastQC output
You can't run a web browser directly from your command line environment. You should copy the results back to your local machine (via scp
) to open them in a web browser.
Exercise: Should we trim this data?
Based on this FastQC output, should we trim (1) adaptor sequences from the ends of the reads AND/OR (2) low quality regions from the ends of the reads?
FASTQ Processing Tools
FASTX Toolkit
The FASTX-Toolkit provides a set of command line tools for manipulating fasta and fastq files. The available modules are described on their website. They include a fast fastx_trimmer utility for trimming fastq sequences (and quality score strings) before alignment and fastx_clipper for trimming specific sequences (such as adapters).
FASTX-Toolkit is available via the TACC module system.
module spider fastx_toolkit module load fastx_toolkit
Trimming low quality bases
Low quality base reads from the sequencer can cause an otherwise mappable sequence not to align. There are a number of open source tools that can trim off 3' bases and produce a FASTQ file of the trimmed reads to use as input to the alignment program, but fastx_trimmer has the advantage of being a module on TACC and therefore the easiest to use. By default the program reads its input data from standard input and writes trimmed sequences to standard output, use what you know about piping and printing text to the screen to trip the fastq file to 34 bases.
- The cat command prints the contents of the SRR030257_1.fastq file to the screen
- The | redirects that output to the fastx_trimmer command
- The -l 34 option says that base 34 should be the last base (i.e., trim down to 34 bases)
- The > redirects that output to the new file on the right side, in this case SRR030257_1.trimmed.fastq
Exercise: compressing the fastx_trimmer output
Compressed files are smaller, easier to transfer, and many programs allow for their use directly. How would you tell fastx_trimmer to compress (gzip) its output file?
Both of the above solutions give the same final product, but are clearly achieved in different ways. This is done to show you that data analysis is a results driven process, if the result is correct, and you know how you got the result it is correct as long as it is reproducable.
Adapter trimming
As mentioned above, fastx_clipper can be used to trim specific sequences, and based on our fastqc analysis, the sequence AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA is significantly overrepresented in our data. How would you use fastx_clipper to remove those sequences from the fastq file?
Command portion | purpose |
---|---|
-i SRR030257_1.trimmed.fastq | use this file as input |
-o SRR030257_1.trimmed.depleted.fastq | create this new output file |
-a AAAAAAAAAAAAAAAAA | remove bases containing this sequence |
-l 34 | discard any read shorter than 34 bases after sequence removed |
-n | keep reads containing "N" bases in them. Consider how they are treated in downstream applications |
Other fastx toolkit programs
What other fastx and fastq manipulation programs are part of the fastx toolkit? The available modules are described on their website, but we can also learn some things from the command prompt using module spider fastx_toolkit.
Consider how you might use fastq_quality_filter and fastq_quality_trimmer to limit your data based on quality scores.
Optional Exercise: Improve the quality of R2 the same way you did for R1.
Unfortunately we don't have time during the class to do this, but as a potential exercise in your free time, you could improve R2 the same way you did R1 and use the improved fastq files in the subsequent read mapping and variant calling tutorials to see the difference it can make.
Welcome to the University Wiki Service! Please use your IID (yourEID@eid.utexas.edu) when prompted for your email address during login or click here to enter your EID. If you are experiencing any issues loading content on pages, please try these steps to clear your browser cache.