Difference between revisions of "BamUtil: stats"

From Genome Analysis Wiki
Jump to: navigation, search
(BaseQC)
(BaseQC: Add average mapping quality stats)
Line 75: Line 75:
 
# regardless of duplicate/qc failure/unmapped/mapping quality
 
# regardless of duplicate/qc failure/unmapped/mapping quality
 
# regardless of the CIGAR for this position (other than clips at the beginning/end which are not counted, but deletions and skips are counted)
 
# regardless of the CIGAR for this position (other than clips at the beginning/end which are not counted, but deletions and skips are counted)
*TotalReads(e6) - # of reads that span this position.  
+
*TotalReads - # of reads that span this position.  
 
*DupRate(%) - # of reads marked duplicate in the flag / TotalReads
 
*DupRate(%) - # of reads marked duplicate in the flag / TotalReads
 
*QCFailRate(%) - # of reads marked QC failure in the flag / TotalReads
 
*QCFailRate(%) - # of reads marked QC failure in the flag / TotalReads
 
*PairedReads(%) - # of reads marked paired in the flag / TotalReads
 
*PairedReads(%) - # of reads marked paired in the flag / TotalReads
 
*ProperPaired(%) - # of reads marked paired AND proper paired in the flag / TotalReads
 
*ProperPaired(%) - # of reads marked paired AND proper paired in the flag / TotalReads
*MappedBases(e9) - # of reads marked mapped in the flag
+
*MappedBases - # of reads marked mapped in the flag
 
*MappingRate(%) - # of reads marked mapped in the flag / TotalReads
 
*MappingRate(%) - # of reads marked mapped in the flag / TotalReads
 
*ZeroMapQual(%) - # of reads marked mapped in the flag AND have a Mapping Quality of 0 / TotalReads
 
*ZeroMapQual(%) - # of reads marked mapped in the flag AND have a Mapping Quality of 0 / TotalReads
Line 87: Line 87:
  
  
For each position, the following counts are incremented if:
+
For each position, the following counts exclude:
# a read spans the reference position (starts before or at this reference position and ends at or after this position)
+
# unmapped reads
# the read is NOT a duplicate, qc failure, unmapped, or mapped with a mapping quality less than the min
+
# duplicates
# the CIGAR for this position is a M/=/X (match/mismatch)
+
# failed QC
 +
# deletions/skips (only CIGAR M/X/= are included)
 +
# MapQ below the min
 
*Depth - # of reads.   
 
*Depth - # of reads.   
*Q20Bases(e9) - # of bases at this position with a base quality (from the read) of Q20 or higher.
+
*Q20Bases - # of bases at this position with a base quality (from the read) of Q20 or higher.
 
*Q20BasesPct(%) - Q20Bases / Depth
 
*Q20BasesPct(%) - Q20Bases / Depth
 +
 +
 +
For each position, the following counts exclude:
 +
# unmapped reads
 +
# duplicates
 +
# failed QC
 +
# deletions/skips (only CIGAR M/X/= are included)
 +
# MapQ of 255
 +
*AverageMapQuality - average calculated by summing all mapping qualities that are not excluded (as defined above) and dividing by the number of mapping qualities added.
 +
*AverageMapQualCount - # of mapping qualities used to calculate AverageMapQuality.
 +
  
  
Line 99: Line 112:
  
 
Currently there is no special logic to exclude reads from the counts when the base is 'N'.
 
Currently there is no special logic to exclude reads from the counts when the base is 'N'.
 +
 +
=== Sample Output ===
 +
 +
<pre>
 +
chrom chromStart chromEnd Depth Q20Bases Q20BasesPct(%) TotalReads MappedBases MappingRate(%) MapRate_MQPass(%) ZeroMapQual(%) MapQual<10(%) PairedReads(%) ProperPaired(%) DupRate(%) QCFailRate(%) AverageMapQuality AverageMapQualCount
 +
1 100 101 2 2 100.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 11.000 3
 +
1 101 102 2 0 0.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 11.000 3
 +
1 102 103 0 0 0.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 0.000 0
 +
1 103 104 0 0 0.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 0.000 0
 +
1 104 105 2 0 0.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 11.000 3
 +
1 105 106 2 2 100.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 11.000 3
 +
1 110 111 0 0 0.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 0.000 0
 +
1 111 112 2 2 100.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 11.000 3
 +
1 112 113 2 2 100.000 3 3 100.000 66.667 33.333 66.667 100.000 0.000 0.000 0.000 11.000 3
 +
1 10012 10013 14 0 0.000 42 33 78.571 52.381 26.190 52.381 85.714 35.714 14.286 14.286 11.000 21
 +
1 10013 10014 14 10 71.429 39 30 76.923 51.282 25.641 51.282 84.615 38.462 15.385 15.385 11.000 21
 +
1 10023 10024 0 0 0.000 39 30 76.923 51.282 25.641 51.282 84.615 38.462 15.385 15.385 0.000 0
 +
1 10024 10025 14 12 85.714 39 30 76.923 51.282 25.641 51.282 84.615 38.462 15.385 15.385 11.000 21
 +
</pre>

Revision as of 16:06, 22 September 2011


Overview of the stats function of bamUtil

The stats option on the bamUtil executable generates the specified statistics on a SAM/BAM file.

Parameters

	Required Parameters:
		--in : the SAM/BAM file to calculate stats for
	Types of Statistics that can be generated:
		--basic       : Turn on basic statistic generation
		--qual        : Generate a count for each quality (displayed as non-phred quality)
		--phred       : Generate a count for each quality (displayed as phred quality)
		--baseQC      : Write per base statistics to the specified file.
	Optional Parameters:
		--maxNumReads : Maximum number of reads to process
		                Defaults to -1 to indicate all reads.
		--unmapped    : Only process unmapped reads (requires a bamIndex file)
		--bamIndex    : The path/name of the bam index file
		                (if required and not specified, uses the --in value + ".bai")
		--regionList  : File containing the region list chr<tab>start_pos<tab>end<pos>.
		                Positions are 0 based and the end_pos is not included in the region.
		                Uses bamIndex.
		--minMapQual  : The minimum mapping quality for filtering reads in the baseQC stats.
		--dbsnp       : The dbSnp file of positions to exclude from baseQC analysis.
		--noeof       : Do not expect an EOF block on a bam file.
		--params      : Print the parameter settings

For all types of statistics, the bam file used is specified by --in.

The optional parameters are also used for all types of statistics.

Usage:

	./bam stats --in <inputFile> [--basic] [--qual] [--phred] [--baseQC <outputFileName>] [--maxNumReads <maxNum>] [--unmapped] [--bamIndex <bamIndexFile>] [--regionList <regFileName>] [--minMapQual <minMapQ>] [--dbsnp <dbsnpFile>] [--noeof] [--params]


Types of Statistics

Basic

Prints summary statistics for the file:

  • TotalReads - # of reads that are in the file
  • MappedReads - # of reads marked mapped in the flag
  • PairedReads - # of reads marked paired in the flag
  • ProperPair - # of reads marked paired AND proper paired in the flag
  • DuplicateReads - # of reads marked duplicate in the flag
  • QCFailureReads - # of reads marked QC failure in the flag
  • MappingRate(%) - # of reads marked mapped in the flag / TotalReads
  • PairedReads(%) - # of reads marked paired in the flag / TotalReads
  • ProperPair(%) - # of reads marked paired AND proper paired in the flag / TotalReads
  • DupRate(%) - # of reads marked duplicate in the flag / TotalReads
  • QCFailRate(%) - # of reads marked QC failure in the flag / TotalReads
  • TotalBases - # of bases in all reads
  • BasesInMappedReads - # of bases in reads marked mapped in the flag


Qual/Phred

Prints a count of the number of times each quality value appears in the file.

  • phred Displays Quality as phred integers [0-93]
  • qual Displays Quality as non-phred integers (phred + 33) [33-126]


BaseQC

The baseQC option generates the following statistics:

For each position, the following counts are incremented if:

  1. a read spans the reference position (starts before or at this reference position and ends at or after this position)
  2. regardless of duplicate/qc failure/unmapped/mapping quality
  3. regardless of the CIGAR for this position (other than clips at the beginning/end which are not counted, but deletions and skips are counted)
  • TotalReads - # of reads that span this position.
  • DupRate(%) - # of reads marked duplicate in the flag / TotalReads
  • QCFailRate(%) - # of reads marked QC failure in the flag / TotalReads
  • PairedReads(%) - # of reads marked paired in the flag / TotalReads
  • ProperPaired(%) - # of reads marked paired AND proper paired in the flag / TotalReads
  • MappedBases - # of reads marked mapped in the flag
  • MappingRate(%) - # of reads marked mapped in the flag / TotalReads
  • ZeroMapQual(%) - # of reads marked mapped in the flag AND have a Mapping Quality of 0 / TotalReads
  • MapQual<10(%) - # of reads marked mapped in the flag AND have a Mapping Quality < 10 / TotalReads
  • MapRate_MQpass(%) - # of reads marked mapped in the flag AND have a Mapping Quality >= a minimum Mapping Quality / TotalReads


For each position, the following counts exclude:

  1. unmapped reads
  2. duplicates
  3. failed QC
  4. deletions/skips (only CIGAR M/X/= are included)
  5. MapQ below the min
  • Depth - # of reads.
  • Q20Bases - # of bases at this position with a base quality (from the read) of Q20 or higher.
  • Q20BasesPct(%) - Q20Bases / Depth


For each position, the following counts exclude:

  1. unmapped reads
  2. duplicates
  3. failed QC
  4. deletions/skips (only CIGAR M/X/= are included)
  5. MapQ of 255
  • AverageMapQuality - average calculated by summing all mapping qualities that are not excluded (as defined above) and dividing by the number of mapping qualities added.
  • AverageMapQualCount - # of mapping qualities used to calculate AverageMapQuality.


Currently there is no special logic to exclude positions where the refernce is 'N'.

Currently there is no special logic to exclude reads from the counts when the base is 'N'.

Sample Output

chrom	chromStart	chromEnd	Depth	Q20Bases	Q20BasesPct(%)	TotalReads	MappedBases	MappingRate(%)	MapRate_MQPass(%)	ZeroMapQual(%)	MapQual<10(%)	PairedReads(%)	ProperPaired(%)	DupRate(%)	QCFailRate(%)	AverageMapQuality	AverageMapQualCount
1	100	101	2	2	100.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	11.000	3
1	101	102	2	0	0.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	11.000	3
1	102	103	0	0	0.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	0.000	0
1	103	104	0	0	0.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	0.000	0
1	104	105	2	0	0.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	11.000	3
1	105	106	2	2	100.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	11.000	3
1	110	111	0	0	0.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	0.000	0
1	111	112	2	2	100.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	11.000	3
1	112	113	2	2	100.000	3	3	100.000	66.667	33.333	66.667	100.000	0.000	0.000	0.000	11.000	3
1	10012	10013	14	0	0.000	42	33	78.571	52.381	26.190	52.381	85.714	35.714	14.286	14.286	11.000	21
1	10013	10014	14	10	71.429	39	30	76.923	51.282	25.641	51.282	84.615	38.462	15.385	15.385	11.000	21
1	10023	10024	0	0	0.000	39	30	76.923	51.282	25.641	51.282	84.615	38.462	15.385	15.385	0.000	0
1	10024	10025	14	12	85.714	39	30	76.923	51.282	25.641	51.282	84.615	38.462	15.385	15.385	11.000	21