| | 1 | = SAM/BAM quality control = |
| | 2 | |
| | 3 | \\ |
| | 4 | |
| | 5 | = Analyzing short read quality (after mapping) = |
| | 6 | |
| | 7 | == Remove Duplicates == |
| | 8 | * Remove duplicates, for eg. from PCR |
| | 9 | |
| | 10 | {{{ |
| | 11 | #samtools command |
| | 12 | samtools rmdup [-sS] <input.srt.bam> <output.bam> |
| | 13 | -s or -S depending on PE data or not |
| | 14 | }}} |
| | 15 | |
| | 16 | == Determining the paired-end insert size for DNA samples == |
| | 17 | |
| | 18 | If paired-end insert size or distance is unknown or need to be verified, it can be extracted from a BAM/SAM file after running Bowtie. |
| | 19 | |
| | 20 | When mapping with bowtie (or another mapper), the insert size can often be included as an input parameter (example for bowtie: -X 500), which can help with mapping. See the [[http://barcwiki.wi.mit.edu/wiki/SOPs/mapping|mapping SOP]] for mapping details. |
| | 21 | |
| | 22 | |
| | 23 | Method 1: Get insert sizes from BAM file |
| | 24 | {{{ |
| | 25 | # Using a SAM file (at Unix command prompt) |
| | 26 | awk -F "\t" '$9 > 0 {print $9}' s_1_bowtie.sam > s_1_insert_sizes.txt |
| | 27 | # Using a BAM file (at Unix command prompt) |
| | 28 | samtools view s_1_bowtie.bam | awk -F"\t" '$9 > 0 {print $9}' > s_1_insert_sizes.txt |
| | 29 | |
| | 30 | # and then process column of numbers with R (or Excel) |
| | 31 | # In R Session |
| | 32 | sizeFile = "s_1_insert_sizes.txt" |
| | 33 | sample.name = "My paired reads" |
| | 34 | distance = read.delim(sizeFile, h=F)[,1] |
| | 35 | pdf(paste(sample.name, "insert.size.histogram.pdf", sep="."), w=11, h=8.5) |
| | 36 | hist(distance, breaks=200, col="wheat", main=paste("Insert sizes for", sample.name), xlab="length (nt)") |
| | 37 | dev.off() |
| | 38 | }}} |
| | 39 | |
| | 40 | Method 2: Calculate insert sizes with CollectInsertSizeMetrics function from picard (http://picard.sourceforge.net). This is also a good approximation for RNA samples. |
| | 41 | {{{ |
| | 42 | # |
| | 43 | # I=File Input SAM or BAM file. (Required) |
| | 44 | # O=File File to write the output to. (Required) |
| | 45 | # H=File File to write insert size histogram chart to. (Required) |
| | 46 | # output: CollectInsertSizeMetrics.txt: values for -r and --mate-std-dev can be found in this text file |
| | 47 | # CollectInsertSizeMetrics_hist.pdf: insert size histogram (graphic representation) |
| | 48 | bsub java -jar /usr/local/share/picard-tools/CollectInsertSizeMetrics.jar I=foo.bam O=CollectInsertSizeMetrics.txt H=CollectInsertSizeMetrics_hist.pdf |
| | 49 | }}} |
| | 50 | |
| | 51 | |
| | 52 | == Quality control after mapping== |
| | 53 | == QC to get a (visual) summary of mapping statistics. For eg. coverage/distribution of mapped reads across the genome or transcriptome == |
| | 54 | |
| | 55 | See [[https://sequencing.qcfail.com/|QC Fail Sequencing]] from the Babraham Institute |
| | 56 | |
| | 57 | |
| | 58 | |
| | 59 | |
| | 60 | ==== [http://broadinstitute.github.io/picard/ | Picard]: CollectRnaSeqMetrics.jar to find coverage across gene body for 5' or 3' bias ==== |
| | 61 | ==== [RNA-seq only] Get global coverage profile across transcripts ==== |
| | 62 | |
| | 63 | Do reads come from across the length of a typical transcript, or is there 3' or 5' bias (where most reads come from one end of a typical transcript)? |
| | 64 | |
| | 65 | One way to look at this is with Picard's CollectRnaSeqMetrics tool |
| | 66 | {{{ |
| | 67 | # Usage: |
| | 68 | java -jar /usr/local/share/picard-tools/CollectRnaSeqMetrics.jar INPUT=bamFile REF_FLAT=refFlatFile STRAND_SPECIFICITY=NONE OUTPUT=outputFile REFERENCE_SEQUENCE=/path/to/genome.fa CHART_OUTPUT=output.pdf VALIDATION_STRINGENCY=SILENT |
| | 69 | # Example command |
| | 70 | java -jar /usr/local/share/picard-tools/CollectRnaSeqMetrics.jar INPUT=WT.bam REF_FLAT=/nfs/genomes/mouse_mm10_dec_11_no_random/anno/refFlat.txt STRAND_SPECIFICITY=NONE OUTPUT=QC_metrics/WT.RnaSeqMetrics.txt REFERENCE_SEQUENCE=/nfs/genomes/mouse_mm10_dec_11_no_random/fasta_whole_genome/mm10.fa CHART_OUTPUT=QC_metrics/WT.RnaSeqMetrics.pdf VALIDATION_STRINGENCY=SILENT |
| | 71 | |
| | 72 | }}} |
| | 73 | The VALIDATION_STRINGENCY=SILENT option will keep the program from crashing if it finds something unexpected. The default: VALIDATION_STRINGENCY=STRICT |
| | 74 | |
| | 75 | |
| | 76 | |
| | 77 | |
| | 78 | |
| | 79 | ==== [http://qualimap.bioinfo.cipf.es/ | QualiMap]: can be used on DNA or RNA-Seq to get summary of mapping and coverage/distribution ==== |
| | 80 | {{{ |
| | 81 | # Graphical interface: enter 'qualimap' on the command line |
| | 82 | # Command line: |
| | 83 | unset DISPLAY #needed for submitting to cluster |
| | 84 | bsub "qualimap bamqc -bam myFile.bam -outdir output_qualimap" |
| | 85 | # For huge data, you can increase memory with --java-mem-size="4800M" to avoid OutOfMemoryError: Java heap space |
| | 86 | |
| | 87 | |
| | 88 | #rnaseq qc |
| | 89 | bsub "qualimap rnaseq -bam myFile.bam -gtf Homo_sapiens.GRCh37.72.canonical.gtf -outdir output_qualimap_rnaseq -p non-strand-specific" |
| | 90 | |
| | 91 | #counts qc (after using htseq-count or similar program to generate a matrix of counts) |
| | 92 | qualimap counts -d countsqc_input.txt -c -s HUMAN -outdir counts_qc |
| | 93 | #Format of countsqc_input.txt (below), totalCounts.txt is a matrix of counts; header lines must be commented "#" and species is human or mouse only. |
| | 94 | #Sample Condition Path Column |
| | 95 | HMLE1 HMLE totalCounts.txt 2 |
| | 96 | HMLE2 HMLE totalCounts.txt 3 |
| | 97 | HMLE3 HMLE totalCounts.txt 4 |
| | 98 | N81 N8 totalCounts.txt 5 |
| | 99 | N82 N8 totalCounts.txt 6 |
| | 100 | N83 N8 totalCounts.txt 7 |
| | 101 | |
| | 102 | }}} |
| | 103 | |
| | 104 | |
| | 105 | |
| | 106 | ==== [http://rseqc.sourceforge.net/ | RSeQC]: RNA-Seq quality control package for getting mapping statistics (eg. unique/multi-mapped reads) ==== |
| | 107 | {{{ |
| | 108 | bam_stat.py -i myFile.bam |
| | 109 | }}} |
| | 110 | ==== infer_experiment.py from RseQC package: can be used to check if the RNA-seq reads are stranded. ==== |
| | 111 | {{{ |
| | 112 | |
| | 113 | # Command line: |
| | 114 | |
| | 115 | bsub infer_experiment.py -i accepted_hits.bam -r hs.bed |
| | 116 | |
| | 117 | -i INPUT_FILE in SAM or BAM format |
| | 118 | -r Reference gene model in bed fomat. |
| | 119 | |
| | 120 | # sample output on strand-specific PE reads: |
| | 121 | This is PairEnd Data |
| | 122 | Fraction of reads explained by "1++,1--,2+-,2-+": 0.0193 |
| | 123 | Fraction of reads explained by "1+-,1-+,2++,2--": 0.9807 |
| | 124 | Fraction of reads explained by other combinations: 0.0000 |
| | 125 | |
| | 126 | # sample output on non-stranded PE reads: |
| | 127 | This is PairEnd Data |
| | 128 | Fraction of reads explained by "1++,1--,2+-,2-+": 0.5103 |
| | 129 | Fraction of reads explained by "1+-,1-+,2++,2--": 0.4897 |
| | 130 | Fraction of reads explained by other combinations: 0.0000 |
| | 131 | |
| | 132 | For pair-end RNA-seq, there are two different ways to strand reads: |
| | 133 | i) 1++,1--,2+-,2-+ |
| | 134 | read1 mapped to '+' strand indicates parental gene on '+' strand |
| | 135 | read1 mapped to '-' strand indicates parental gene on '-' strand |
| | 136 | read2 mapped to '+' strand indicates parental gene on '-' strand |
| | 137 | read2 mapped to '-' strand indicates parental gene on '+' strand |
| | 138 | ii) 1+-,1-+,2++,2-- |
| | 139 | read1 mapped to '+' strand indicates parental gene on '-' strand |
| | 140 | read1 mapped to '-' strand indicates parental gene on '+' strand |
| | 141 | read2 mapped to '+' strand indicates parental gene on '+' strand |
| | 142 | read2 mapped to '-' strand indicates parental gene on '-' strand |
| | 143 | |
| | 144 | For single-end RNA-seq, there are two different ways to strand reads: |
| | 145 | i) ++,-- |
| | 146 | read mapped to '+' strand indicates parental gene on '+' strand |
| | 147 | read mapped to '-' strand indicates parental gene on '-' strand |
| | 148 | ii) +-,-+ |
| | 149 | read mapped to '+' strand indicates parental gene on '-' strand |
| | 150 | read mapped to '-' strand indicates parental gene on '+' strand |
| | 151 | |
| | 152 | |
| | 153 | }}} |
| | 154 | |
| | 155 | |
| | 156 | \\ |
| | 157 | |