Mapping

Overview
Creative Commons License: CC-BY Questions:
  • What is mapping?

  • What two things are crucial for a correct mapping?

  • What is BAM?

Objectives:
  • Run a tool to map reads to a reference genome

  • Explain what is a BAM file and what it contains

  • Use genome browser to understand your data

Requirements:
Time estimation: 1 hour
Level: Introductory Introductory
Supporting Materials:
Published: Oct 4, 2016
Last modification: Dec 4, 2024
License: Tutorial Content is licensed under Creative Commons Attribution 4.0 International License. The GTN Framework is licensed under MIT
purl PURL: https://gxy.io/GTN:T00237
rating Rating: 4.3 (16 recent ratings, 105 all time)
version Revision: 42

Sequencing produces a collection of sequences without genomic context. We do not know to which part of the genome the sequences correspond to. Mapping the reads of an experiment to a reference genome is a key step in modern genomic data analysis. With the mapping the reads are assigned to a specific location in the genome and insights like the expression level of genes can be gained.

The reads do not come with position information, so we do not know what part of the genome they came from. We need to use the sequence of the read itself to find the corresponding region in the reference sequence. But the reference sequence can be quite long (~3 billion bases for human), making it a daunting task to find a matching region. Since our reads are short, there may be several, equally likely places in the reference sequence from which they could have been read. This is especially true for repetitive regions.

In principle, we could do a BLAST analysis to figure out where the sequenced pieces fit best in the known genome. We would need to do that for each of the millions of reads in our sequencing data. Aligning millions of short sequences this way may, however, take a couple of weeks. And we do not care about the exact base to base correspondence (alignment). What we are interested in is “where these reads came from”. This approach is called mapping.

In the following, we will process a dataset with the mapper Bowtie2 and we will visualize the data with the program IGV.

Agenda

In this tutorial, we will deal with:

  1. Prepare the data
  2. Map reads on a reference genome
  3. Inspection of a BAM file
  4. Visualization using a Genome Browser
    1. IGV
    2. JBrowse
  5. Conclusion

Prepare the data

Hands-on: Data upload
  1. Create a new history for this tutorial and give it a proper name

    To create a new history simply click the new-history icon at the top of the history panel:

    UI for creating new history

    1. Click on galaxy-pencil (Edit) next to the history name (which by default is “Unnamed history”)
    2. Type the new name
    3. Click on Save
    4. To cancel renaming, click the galaxy-undo “Cancel” button

    If you do not have the galaxy-pencil (Edit) next to the history name (which can be the case if you are using an older version of Galaxy) do the following:

    1. Click on Unnamed history (or the current name of the history) (Click to rename history) at the top of your history panel
    2. Type the new name
    3. Press Enter

  2. Import wt_H3K4me3_read1.fastq.gz and wt_H3K4me3_read2.fastq.gz from Zenodo or from the data library (ask your instructor)

    https://zenodo.org/record/1324070/files/wt_H3K4me3_read1.fastq.gz
    https://zenodo.org/record/1324070/files/wt_H3K4me3_read2.fastq.gz
    
    • Copy the link location
    • Click galaxy-upload Upload Data at the top of the tool panel

    • Select galaxy-wf-edit Paste/Fetch Data
    • Paste the link(s) into the text field

    • Press Start

    • Close the window

    As an alternative to uploading the data from a URL or your computer, the files may also have been made available from a shared data library:

    1. Go into Data (top panel) then Data libraries
    2. Navigate to the correct folder as indicated by your instructor.
      • On most Galaxies tutorial data will be provided in a folder named GTN - Material –> Topic Name -> Tutorial Name.
    3. Select the desired files
    4. Click on Add to History galaxy-dropdown near the top and select as Datasets from the dropdown menu
    5. In the pop-up window, choose

      • “Select history”: the history you want to import the data to (or create a new one)
    6. Click on Import

    As default, Galaxy takes the link as name, so rename them.

  3. Rename the files to reads_1 and reads_2

    • Click on the galaxy-pencil pencil icon for the dataset to edit its attributes
    • In the central panel, change the Name field
    • Click the Save button

We just imported in Galaxy FASTQ files corresponding to paired-end data as we could get directly from a sequencing facility.

During sequencing, errors are introduced, such as incorrect nucleotides being called. Sequencing errors might bias the analysis and can lead to a misinterpretation of the data. The first step for any type of sequencing data is always to check their quality.

There is a dedicated tutorial for quality control of sequencing data. We will not repeat the steps there. You should follow the tutorial and apply it to your data before going further.

Map reads on a reference genome

Read mapping is the process to align the reads on a reference genomes. A mapper takes as input a reference genome and a set of reads. Its aim is to align each read in the set of reads on the reference genome, allowing mismatches, indels and clipping of some short fragments on the two ends of the reads:

Explanation of mapping. Open image in new tab

Figure 1: Illustration of the mapping process. The input consists of a set of reads and a reference genome. In the middle, it gives the results of mapping: the locations of the reads on the reference genome. The first read is aligned at position 100 and the alignment has two mismatches. The second read is aligned at position 114. It is a local alignment with clippings on the left and right. The third read is aligned at position 123. It consists of a 2-base insertion and a 1-base deletion.

We need a reference genome to map the reads on.

Question
  1. What is a reference genome?
  2. For each model organism, several possible reference genomes may be available (e.g. hg19 and hg38 for human). What do they correspond to?
  3. Which reference genome should we use?
  1. A reference genome (or reference assembly) is a set of nucleic acid sequences assembled as a representative example of a species’ genetic material. As they are often assembled from the sequencing of different individuals, they do not accurately represent the set of genes of any single organism, but a mosaic of different nucleic acid sequences from each individual.
  2. As the cost of DNA sequencing falls, and new full genome sequencing technologies emerge, more genome sequences continue to be generated. Using these new sequences, new alignments are built and the reference genomes improved (fewer gaps, fixed misrepresentations in the sequence, etc). The different reference genomes correspond to the different released versions (called “builds”).
  3. This data comes from the ChIP-seq of mice, so we will use mm10 (Mus musculus).

Currently, there are over 60 different mappers, and their number is growing. In this tutorial, we will use Bowtie2, a fast and memory-efficient open-source tool particularly good at aligning sequencing reads of about 50 up to 1,000s of bases to relatively long genomes.

Hands-on: Mapping with Bowtie2
  1. Bowtie2 ( Galaxy version 2.4.2+galaxy0) with the following parameters
    • “Is this single or paired library”: Paired-end
      • param-file “FASTA/Q file #1”: reads_1
      • param-file “FASTA/Q file #2”: reads_2
      • “Do you want to set paired-end options?”: No

        You should have a look at the parameters there, specially the mate orientation if you know it. They can improve the quality of the paired-end mapping.

    • “Will you select a reference genome from your history or use a built-in index?”: Use a built-in genome index
      • “Select reference genome”: Mouse (Mus musculus): mm10
    • “Select analysis mode”: Default setting only

      You should have a look at the non default parameters and try to understand them. They can have an impact on the mapping and improving it.

    • “Save the bowtie2 mapping statistics to the history”: Yes
  2. Inspect the mapping stats file by clicking on the galaxy-eye (eye) icon
Question
  1. What information is provided here?
  2. How many reads have been mapped exactly 1 time?
  3. How many reads have been mapped more than 1 time? How is it possible? What should we do with them?
  4. How many pair of reads have not been mapped? What are the causes?
  1. The information given here is a quantity one. We can see how many sequences are aligned. It does not tell us something about the quality.
  2. ~90% reads have been aligned exactly 1 time
  3. ~7% reads have been aligned concordantly >1 times. These are called multi-mapped reads. It can happen because of repetitions in the reference genome (multiple copies of a gene for example), particularly when the reads are small. It is difficult to decide where these sequences come from and therefore most of the pipelines ignore them. Always check the statistics there to be sure of not discarding too much information in any downstream analyses.
  4. ~3% pair of reads have not been mapped because
    • both reads in the pair aligned but their positions do not concord with pair of reads (aligned discordantly 1 time)
    • reads of these pairs are multi-mapped (aligned >1 times in pairs aligned 0 times concordantly or discordantly)
    • one read of these pairs are mapped but not the paired read (aligned exactly 1 time in pairs aligned 0 times concordantly or discordantly)
    • the rest are not mapped at all

Checking the mapping statistics is an important step to do before continuing any analyses. There are several potential sources for errors in mapping, including (but not limited to):

  • Polymerase Chain Reaction (PCR) artifacts: Many high-throughput sequencing (HTS) methods involve one or multiple PCR steps. PCR errors will show as mismatches in the alignment, and especially errors in early PCR rounds will show up in multiple reads, falsely suggesting genetic variation in the sample. A related error would be PCR duplicates, where the same read pair occurs multiple times, skewing coverage calculations in the alignment.
  • Sequencing errors: The sequencing machine can make an erroneous call either for physical reasons (e.g. oil on an Illumina slide) or due to properties of the sequenced DNA (e.g., homopolymers). As sequencing errors are often random, they can be filtered out as singleton reads during variant calling.
  • Mapping errors: The mapping algorithm can map a read to the wrong location in the reference. This often happens around repeats or other low-complexity regions.

So if the mapping statistics are not good, you should investigate the cause of these errors before going further in your analyses.

After that, you should have a look at the reads and inspect the BAM file where the read mappings are stored.

Inspection of a BAM file

A BAM (Binary Alignment Map) file is a compressed binary file storing the read sequences, whether they have been aligned to a reference sequence (e.g. a chromosome), and if so, the position on the reference sequence at which they have been aligned.

Hands-on: Inspect a BAM/SAM file
  1. Inspect the param-file output of Bowtie2 tool

A BAM file (or a SAM file, the non-compressed version) consists of:

  • A header section (the lines starting with @) containing metadata particularly the chromosome names and lengths (lines starting with the @SQ symbol)
  • An alignment section consisting of a table with 11 mandatory fields, as well as a variable number of optional fields:

    Col Field Type Brief Description
    1 QNAME String Query template NAME
    2 FLAG Integer Bitwise FLAG
    3 RNAME String References sequence NAME
    4 POS Integer 1- based leftmost mapping POSition
    5 MAPQ Integer MAPping Quality
    6 CIGAR String CIGAR String
    7 RNEXT String Ref. name of the mate/next read
    8 PNEXT Integer Position of the mate/next read
    9 TLEN Integer Observed Template LENgth
    10 SEQ String Segment SEQuence
    11 QUAL String ASCII of Phred-scaled base QUALity+33
Question
  1. Which information do you find in a SAM/BAM file?
  2. What is the additional information compared to a FASTQ file?
  1. Sequences and quality information, like a FASTQ
  2. Mapping information, Location of the read on the chromosome, Mapping quality, etc

The BAM file includes a lot of information about each read, particularly the quality of mapping.

Hands-on: Summary of mapping quality
  1. Samtools Stats ( Galaxy version 2.0.2+galaxy2) with the following parameters
    • param-file “BAM file”: aligned reads (output of Bowtie2 tool)
    • “Use reference sequence”: Locally cached/Use a built-in genome
      • “Using genome”: Mouse (Mus musculus): mm10 Full
  2. Inspect the param-file Stats file
Question
  1. What is the proportion of mismatches in the mapped reads when aligned to the reference genome?
  2. What does the error rate represent?
  3. What is the average quality? How is it represented?
  4. What is the insert size average?
  5. How many reads have a mapping quality score below 20?
  1. There are ~21,900 mismatches for ~4,753,900 bases mapped which on average produces ~0.005 mismatches per mapped bases.
  2. The error rate is the proportion of mismatches per mapped bases, so the ratio computed right before.
  3. The average quality is the mean quality score of the mapping. It is a Phred score like the one used in the FASTQ file for each nucleotide. But here the score is not per nucleotide, but per read and it represents the probability of mapping quality.
  4. The insert size is the distance between the two reads in the pairs.
  5. To get the info:
    1. Filter BAM ( Galaxy version 2.5.2+galaxy2) with a filter to keep only the reads with a mapping quality >= 20
    2. Samtools Stats ( Galaxy version 2.0.5) on the output of Filter

    Before filtering: 95,412 reads and after filtering: 89,664 reads.

Visualization using a Genome Browser

IGV

The Integrative Genomics Viewer (IGV) is a high-performance visualization tool for interactive exploration of large, integrated genomic datasets. It supports a wide variety of data types, including array-based and next-generation sequence data, and genomic annotations. In the following, we will use it to visualize the mapped reads.

Hands-on: Visualization of the reads in IGV

There are two ways to run it:

  1. If you have IGV installed (or want to install it):
    1. Install IGV
    2. Launch IGV on your computer
    3. Expand the param-file output of Bowtie2 tool
    4. Click on the local in display with IGV to load the reads into the IGV browser
  2. If you do not have IGV
    1. Click on the Mouse mm10 (or correct organism) in display with IGV to load the reads into the IGV browser
  3. Zoom on the chr2:98,666,236-98,667,473

The reads have a direction: they are mapped to the forward or reverse strand, respectively. When hovering over a read, extra information is displayed

Question
  1. What could it mean if a bar in the coverage view is colored?
  2. What could be the reason why a read is white instead of grey?
  1. If a nucleotide differs from the reference sequence in more than 20% of quality weighted reads, IGV colors the bar in proportion to the read count of each base.
  2. They have a mapping quality equal to zero. Interpretation of this mapping quality depends on the mapping aligner as some commonly used aligners use this convention to mark a read with multiple alignments. In such a case, the read also maps to another location with equally good placement. It is also possible that the read could not be uniquely placed but the other placements do not necessarily give equally good quality hits.
Comment: Tips for IGV
  1. Because the number of reads over a region can be quite large, the IGV browser by default only displays the reads that fall into a small window. This behaviour can be changed in the IGV from view > Preferences > Alignments.
  2. If the genome of your interest is not there check if it is available via More…. If this is not the case, you can add it manually via the menu Genomes -> Load Genome from…

    Select genome in IGV

A general description of the user interface of the IGV browser is available here: IGV Browser description

JBrowse

JBrowse ( Galaxy version 1.16.11+galaxy0) is an alternative, web-based genome browser. Whereas IGV is a piece of software you must download and run, JBrowse instances are websites hosted online that provide an interface to browse genomics data. We’ll use it to visualise the mapped reads.

Hands-on: Visualization of the reads in JBrowse
  1. JBrowse ( Galaxy version 1.16.11+galaxy1) browser, with the following parameters:
    • “Reference genome to display”: Use a built-in genome
      • “Select a reference genome”: mm10
    • “JBrowse-in-Galaxy Action”: New JBrowse Instance
    • “Insert Track Group”:
      • “Insert Annotation Track”:
        • “Track Type”: BAM Pileups
        • “BAM Track Data”: aligned reads (output of Bowtie2 tool)
        • “Autogenerate SNP Track”: Yes
        • “Track Visibility”: On for new users
  2. Visualise the dataset galaxy-eye
  3. Zoom on the chr2:98,666,236-98,667,473
Comment: Slow

This can take about a minute or two to run, depending on your training instance’s resources. It takes time as the server builds up a small website for you, and pre-processes the reference genome into a more efficient format. If you wanted to share this with your colleagues, you could download this dataset and directly place it on your webserver.

The reads have a direction: they are mapped to the forward or reverse strand, respectively. When clicking on a read, extra information is displayed

Question
  1. What do the teardrop shape and line mean in the autogenerated SNP track?
  2. What do differently coloured reads mean?
  1. If enough reads have a different value, then it is marked with a teardrop icon. The coverage plot is marked in height with the percentage of reads with a different call at that position
  2. Colour Codes:

    Colour Meaning
          Original red Forward strand
          Original blue Reverse strand
          Hard red Forward strand, missing mate
          Hard Blue Reverse strand, missing mate
          Light red Forward strand not proper
          Light blue Reverse strand, not proper
          Black Forward, diff chr
          Grey Reverse, diff chr
          Grey No strand

Conclusion

After quality control, mapping is an important step of most analyses of sequencing data (RNA-Seq, ChIP-Seq, etc) to determine where in the genome our reads originated from and use this information for downstream analyses.