Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleIf it's simpler and faster, would one ever want to align a miRNA dataset to hg19 rather than mirbase? If so, why?
  1. Due to natural variation, sequencing errors, and processing issues, variation between reference sequence and sample sequence is always possible. Alignment to the human genome allows a putative "microRNA" read the opportunity to find a better alignment in a region of the genome that is not an annotated microRNA. If this occurs, we might think that a read represents a microRNA (since it aligned in the mirbase alignment), when it is actually more likely to have come from a non-miRNA area of the genome.
  2. If we suspect our library contained other RNA species, we may want to quantify the level of "contamination". Aligning to the human genome will allow rRNA, tRNA, snoRNA, etc to align. We can then use programs such as bedtools, coupled with appropriate genome annotation files, to quantify these "off-target" hits.

...

ReferenceSpeciesBase LengthContig NumberSourceDownload
Hg19hg19Human3.1 Gbp25 (really 93)UCSCUCSC GoldenPath
SacCer3sacCer3Yeast12.2 Mbp17UCSCUCSC GoldenPath
MirbaseV20mirbase V20Human160 Kbp1908MirbaseMirbase Downloads

Searching genomes , however, is hard work and takes a long time if done on an un-indexed, linear genomic sequence.  So , most aligners require that references first be indexed for quick access  The aligners we are using each require a different index, but use the same method (the Burrows-Wheeler Transform) to get the job done.  This This requires taking a FASTA file as input, with each chromosome (or contig) as a separate entry, and producing some aligner-specific set of files as output.  Then, those output Those index files are then used by the aligner when executing a given alignment command. Hg19 performing the sequence alignment. 

hg19 is way too big for us to index here, so we're not going to do it, and it's not included in the core_ngs_tools directory at Corral that we've been copying from.  Instead. Instead, all hg19 index files are located at:

Code Block
languagebash
titleBWA hg19 index location
/scratch/01063/abattenh/ref_genome/bwa/bwtsw/hg19

Now, we're going to We will grab the other FASTA files for the other two references , and we will build each index right before we use it in each set of exercise below.  These . These two references are located at:

Code Block
languagebash
titleYeast and mirbase FASTA locations
/corral-repl/utexas/BioITeam/core_ngs_tools/references/sacCer3.fa
/corral-repl/utexas/BioITeam/core_ngs_tools/references/hairpin_cDNA_hsa.fa

Now, First stage the yeast and mirbase reference fasta FASTA files in your scratch work archive area in a directory called 'called references'.

 

expandmkdir $SCRATCH/references cp /corral-repl/utexas/BioITeam/core_ngs_tools
/references/*.fa 
$SCRATCH
$WORK/archive/references/fasta/
Code Block
languagebash
titleHint:Stage FASTA references
mkdir -p $WORK/archive/references/fasta
cp $CLASSDIR
Code Block

 With that, we're ready to get started on the first exercise.

Exercise #1: BWA

...

Yeast ChIP-seq

Like other tools you've worked with so far, you first need to load bwa using the module system.  So, go ahead and do that now, and then enter 'bwa' with no arguments to view the help page.

Expand
titleHint:
Code Block
module load bwa
bwa

As you can see, there are several commands one can use with bwa to do different things.  To test out one of them, we're going to index the genome with the 'index' command.  If you enter 'bwa index' with no arguments, you will see a list of the required arguments.  Here, we only need to specify two things: whether to use 'bwtsw' or 'is' indexing, and the name of the fasta file.  We will specify 'bwtsw' as the indexing option, and the name of the FASTA file is, obviously, sacCer3.fa.  The output of this command, importantly, is a group of files that are all required together as the index.  So, within the references directory, we will create another directory called "yeast", move the yeast FASTA file into that directory, and run the index commands from there:

Code Block
cd $SCRATCH/references/
mkdir yeast
mv sacCer3.fa yeast
cd yeast
bwa index -a bwtsw sacCer3.fa

This command should produce a set of output files that look like this:

...

Overview ChIP-seq alignment workflow with BWA

We will perform a global alignment of the paired-end Yeast ChIP-seq sequences using bwa. This workflow generally has the following steps:

  1. Trim the FASTQ sequences down to 50 with fastx_clipper
    • this removes most of any 5' adapter contamination without the fuss of specific adapter trimming w/cutadapt
  2. Prepare the sacCer3 reference index for bwa (one time) using bwa index
  3. Perform a global bwa alignment on the R1 reads (bwa aln) producing a BWA-specific binary .sai intermediate file
  4. Perform a global bwa alignment on the R2 reads (bwa aln) producing a BWA-specific binary .sai intermediate file
  5. Perform pairing of the separately aligned reads and report the alignments in SAM format using bwa sampe
  6. Convert the SAM file to a BAM file (samtools view)
  7. Sort the BAM file by genomic location (samtools sort)
  8. Index the BAM file (samtools index)
  9. Gather simple alignment statistics (samtools flagstat and samtools idxstat)

We're going to skip the trimming step for now and see how it goes. We'll perform steps 2 - 5 now and leave samtools for the next course section, since those steps (6 - 10) are common to nearly all post-alignment workflows.

Building the BWA sacCer3 index

Like other tools you've worked with so far, you first need to load bwa using the module system.  Go ahead and do that now, and then enter bwa with no arguments to view the top-level help page (many NGS tools will provide some help when called with no arguments).

Code Block
module load bwa
bwa
Expand
titleTop-level BWA help

Program: bwa (alignment via Burrows-Wheeler transformation)
Version: 0.7.7-r441
Contact: Heng Li <lh3@sanger.ac.uk>

Usage:   bwa <command> [options]

Command: index         index sequences in the FASTA format
         mem           BWA-MEM algorithm
         fastmap       identify super-maximal exact matches
         pemerge       merge overlapping paired ends (EXPERIMENTAL)
         aln           gapped/ungapped alignment
         samse         generate alignment (single ended)
         sampe         generate alignment (paired ended)
         bwasw         BWA-SW for long queries

         fa2pac        convert FASTA to PAC format
         pac2bwt       generate BWT from PAC
         pac2bwtgen    alternative algorithm for generating BWT
         bwtupdate     update .bwt to the new format
         bwt2sa        generate SA from BWT and Occ

Note: To use BWA, you need to first index the genome with `bwa index'.
      There are three alignment algorithms in BWA: `mem', `bwasw', and
      `aln/samse/sampe'. If you are not sure which to use, try `bwa mem'
      first. Please `man ./bwa.1' for the manual. 

As you can see, bwa offers a number of sub-commands one can use with to do different things. We're going to index the genome with the index command. To learn what this sub-command needs in the way of options and arguments, enter bwa index with no arguments.

Code Block
Usage:   bwa index [-a bwtsw|is] [-c] <in.fasta>
Options: -a STR    BWT construction algorithm: bwtsw or is [auto]
         -p STR    prefix of the index [same as fasta name]
         -6        index files named as <in.fasta>.64.* instead of <in.fasta>.*
Warning: `-a bwtsw' does not work for short genomes, while `-a is' and
         `-a div' do not work not for long genomes. Please choose `-a'
         according to the length of the genome.

Here, we only need to specify two things:

  • the name of the FASTA file  
  • whether to use the  bwtsw or is algorithm for indexing

Since sacCer3 is relative large (~12 Mbp) we will specify bwtsw as the indexing option, and the name of the FASTA file is sacCer3.fa.

Importantly, the output of this command is a group of files that are all required together as the index. So, within the references directory, we will create another directory called bwa/sacCer3, make a symbolic link to the yeast FASTA there, and run the index command in that directory.

Code Block
languagebash
titlePrepare BWA reference directory for sacCer3
mkdir -p $WORK/archive/references/bwa/sacCer3
cd $WORK/archive/references/bwa/sacCer3
ln -s ../../fasta/sacCer3.fa
ls -la

Now execute the bwa index command.

Code Block
languagebash
titleBuild BWA index for sacCer3
bwa index -a bwtsw sacCer3.fa

Since the yeast genome is not large when compared to human, this should not take long to execute (otherwise we would do it as a batch job). When it is comple you should see a set of index files like this:

Code Block
titleBWA index files for sacCer3
sacCer3.fa
sacCer3.fa.amb
sacCer3.fa.ann
sacCer3.fa.bwt
sacCer3.fa.pac
sacCer3.fa.sa

Exploring the FASTA with grep

A common question is what contigs are in a given FASTA file. You'll usually want to know this before you start the alignment so that you're familiar with the contig naming convention – and to verify that it's the one you expect.

We saw that a FASTA consists of a number of contig entries, each one starting with a name line of the form below, followed by many lines of bases.

Code Block
>contigName

How do we dig out just the lines that have the contig names and ignore all the sequences? Well, the contig name lines all follow the pattern above, and since the > character is not a valid base, it will never appear on a sequence line.

We've discovered a pattern (also known as a regular expression) to use in searching, and the command line tool that does regular expression matching is grep.

Regular expressions are so powerful that nearly every modern computer language includes a "regex" module of some sort. There are many online tutorials for regular expressions (and a few different flavors of them). But the most common is the Perl style (http://perldoc.perl.org/perlretut.html). We're only going to use the most simple of regular expressions here, but learning more about them will pay handsome dividends for you in the future.

Here's how to execute grep to list contig names in a FASTA file.

Code Block
languagebash
titlegrep to match contig names in a FASTA file
grep -P '^>' sacCer3.fa | more

Notes:

  • The -P option tells grep to use Perl-style regular expression patterns.
    • This makes including special characters like Tab ( \t ), Carriage Return ( \r ) or Linefeed ( \n ) much easier that the default Posix paterns.
    • While it is not really required here, it generally never hurts to include this option.
  • '^>' is the regular expression describing the pattern we're looking for (described more below)

  • sacCer3.fa is the file to search. Lines with text that match our pattern will be written to standard output; non matching lines will be omitted.
  • We pipe to more just in case there are a lot of contig names.

Now down to the nuts and bolts of our pattern, '^>'

First, the single quotes around the pattern – they are only a signal for the bash shell. As part of its friendly command line parsing and evaluation, the shell will often look for special characters on the command line that mean something to it (for example, the $ in front of an environment variable name, like in $SCRATCH). Well, regular expressions treat the $ specially too – but in a completely different way! Those single quotes tell the shell "don't look inside here for special characters – treat this as a literal string and pass it to the program". So the shell will obey, will strip the single quotes off the string, and pass the actual pattern, ^>, to the grep program. (Aside: We've see that the shell does look inside double quotes ( " ) for certain special signals, such as looking for environment variable names to evaluate.)

So what does ^> mean to grep? Well, from our contig name format description above we see that contig name lines always start with a > character, so > is a literal for grep to use in its pattern match.

We might be able to get away with just using this literal alone as our regex, specifying '>' as the command line argument. But for grep, the more specific the pattern, the better. So we constrain where the > can appear on the line. The special carat ( ^ ) character represents "beginning of line". o means

Performing the alignment

Now, we're ready to execute the actual alignment, with the goal of producing a SAM/BAM file from the input FASTQ files and reference.  We will first generate SAI files from each of the FASTQ files with the reference individually using the 'aln' command, then combine them (with the reference) into one SAM/BAM output file using the 'sampe' command.   We need a directory to put the alignments when they are finished, as well as any intermediate files, so create a directory called 'alignments'.  The command flow, all together, is as follows. Notice how each file is in its proper directory, which requires us to specify the whole file path in the alignment commands.

...

The rest of the options control the details of how much a mismatch or gap is penalized, limits on the number of acceptable hits per read, and so on.  Much more information can be accessed at the BWA manual page.

Exercise #2: Bowtie2 and Local Alignment - Human microRNA-seq

Now we're going to switch over to a different aligner that was originally designed for very short reads, and is frequently used for RNA-seq data.  Accordingly, we have prepared a test microRNA-seq dataset for you to experiment with.  This data is derived from a human H1 embryonic stem cell (H1-hESC) small RNA dataset generated by the ENCODE Consortium (its about a half million reads).  However, there is a problem!  We don't know (or, well, you don't know) what the adapter structure or sequences were.  So, you have a bunch of 36 base pair reads, but many of those reads will include extra sequence that will impede alignment!  We need an aligner that can find subsections of the read that align, and discard (or "soft-clip") the rest away.  Bowtie2 is just such an aligner.  Go ahead and load it up so we can examine some help pages and options.  To do that, you must first load the "perl" module, and then the bowtie2 module designated "bowtie/2.2.0". 

...