Debian Codegraph @

docs/content/tools/summary.rst

raw
1 .. _summary:
2
3 ###############
4 *summary*
5 ###############
6
7 |
8
9 Genomics experiments have numerous sources of both technical and biological variation
10 that can confound analysis and interpretation. Therefore, one of the most important steps
11 in genomics data analysis is generating high-level summary stats of one's data to ask if the
12 basic observations align with the expectation. Doing such quality control as early
13 as possible in the analysis workflow helps to head off unnecessary time spent chasing
14 technical artifacts that masquerade as biological signals. **This quality control
15 is the motivation behind the** ``bedtools summary`` **command.**
16
17 Given an input interval file in standard formats, as well as a genome file defining
18 the chromosome names and lengths relevant to your data, ``bedtools summary`` will compute
19 several summary statistics detailing, for each chromosome, the number of intervals,
20 the total number of base pairs, and the fraction of intervals and base pairs observed
21 in your input file. From these summary measures, one can get a quick sense of questions like:
22
23 - Are all chromosomes represented in my data or annotation file?
24 - Do all chromosomes have the expected number of intervals or fraction of base pairs represented?
25 - Which chromosomes are outliers?
26
27 For example, the following plot was generated directly from the output of ``bedtools summary``.
28 It depicts, for each chromosome, the fraction of all intervals in the RepeatMasker track from UCSC
29 **observed** on each chromosome versus the fraction of RepeatMasker intervals that are **expected**
30 for each chromosome, based on the fraction of the genome that each chromosome represents.
31
32 This plot highlights that ``chr19``, ``chrM``, and ``chrMT`` (the different mitochondrial reference genomes) are outliers.
33 Chromosome 19 has more than 1.5 times the intervals that are expected based upon the length of
34 the chromosome. ChrM has no intervals, making the observed-to-expected ratio be 0.
35 This former is because the repeat content of chromosome 19 "is approximately 55%, more than 10% higher
36 than the genome-wide average" (``Grimwood J, et al. Nature. 2004;428:529–35``). The latter is because
37 are indeed no repeat annotations provided by UCSC for the mitochondrial genome.
38
39 In this case, the extremes in observed versus expected ratios make sense. However,
40 **this tool allows one to detect cases that do not and are either artifacts or
41 biological signals**.
42
43 .. image:: ../images/tool-glyphs/summary.png
44 :width: 600pt
45
46 ==========================================================================
47 Usage and option summary
48 ==========================================================================
49 **Usage**:
50 ::
51
52 bedtools summary -i <BED/GFF/VCF> -g <GENOME>
53
54
55 ===============================
56 Default behavior
57 ===============================
58 ``bedtools summary`` scans the input interval file and the chromosome lengths provided in
59 the "genome" file and reports the following columns for each chromosome.
60
61 #. **chrom** (chromosome name)
62 #. **chrom_length** (the length of the chromosome in bp)
63 #. **num_ivls** (the total number of intervals observed for the chromosome)
64 #. **total_ivl_bp** (the total number of bp observed in the intervals for the chromosome)
65 #. **chrom_frac_genome** (the fraction of the genome represented by the chromosome)
66 #. **frac_all_ivls** (the fraction of all intervals observed the chromosome)
67 #. **frac_all_bp** (the fraction of all bp observed the chromosome)
68 #. **min** (the smallest interval observed on that chromosome)
69 #. **max** (the largest interval observed on that chromosome)
70 #. **mean** (the mean interval length observed on that chromosome)
71
72 In addition, ``bedtools summary`` reports a final line with the chromosome name "all", which
73 depicts the metrics above but tabulated across all chromosomes in the input file.
74
75 As an example, let's recreate the figure above by running ``bedtools summary`` on the
76 simple repeats track from UCSC. We'll begin by downloading the data in track the
77 track table and converting it to BED format.
78
79 .. code-block:: bash
80
81 curl -s http://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/simpleRepeat.txt.gz \
82 | gzcat \
83 | cut -f 2-5 \
84 | grep -v -E 'Un|fix|random|alt|hap' \
85 > simrep.grch38.bed
86
87 head simrep.grch38.bed
88 chr1 10000 10468 trf
89 chr1 10627 10800 trf
90 chr1 10757 10997 trf
91 chr1 11225 11447 trf
92 chr1 11271 11448 trf
93 chr1 11283 11448 trf
94 chr1 19305 19443 trf
95 chr1 20828 20863 trf
96 chr1 30862 30959 trf
97 chr1 44835 44876 trf
98
99 Now, let's make a "genome" file for GRCh38 from the `chromInfo` table at UCSC
100
101 .. code-block:: bash
102
103 curl -s http://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/chromInfo.txt.gz \
104 | gzcat \
105 | cut -f 1-2 \
106 | grep -v -E 'Un|fix|random|alt|hap' \
107 > grch38.genome.txt
108
109 head grch38.genome.txt
110 chr1 248956422
111 chr2 242193529
112 chr3 198295559
113 chr4 190214555
114 chr5 181538259
115 chr6 170805979
116 chr7 159345973
117 chrX 156040895
118 chr8 145138636
119 chr9 138394717
120
121 Now, let's run ``bedtools summary``.
122
123 .. code-block:: bash
124
125 bedtools summary -i simrep.grch38.bed -g grch38.genome.txt | column -t
126 chrom chrom_length num_ivls total_ivl_bp chrom_frac_genome frac_all_ivls frac_all_bp min max mean
127 chr1 248956422 74548 15557884 0.080613126 0.077210928 0.048725518 25 124438 208.696195740
128 chr2 242193529 74474 14493548 0.078423273 0.077134284 0.045392139 25 336509 194.612186803
129 chr3 198295559 56894 13946854 0.064208928 0.058926309 0.043679955 25 500000 245.137518895
130 chr4 190214555 56685 10160257 0.061592265 0.058709844 0.031820766 25 136950 179.240663315
131 chr5 181538259 53887 16801740 0.058782844 0.055811896 0.052621133 25 500000 311.795794904
132 chr6 170805979 51802 11222841 0.055307687 0.053652418 0.035148658 25 500000 216.648797344
133 chr7 159345973 55972 20054618 0.051596890 0.057971375 0.062808775 25 150228 358.297327235
134 chrX 156040895 50432 27398336 0.050526692 0.052233481 0.085808462 25 500000 543.272842640
135 chr8 145138636 45937 15650021 0.046996495 0.047577915 0.049014080 25 500000 340.684437382
136 chr9 138394717 39329 10932158 0.044812786 0.040733870 0.034238272 25 159861 277.966843805
137 chr11 135086622 41279 14127024 0.043741611 0.042753526 0.044244227 25 500000 342.232709126
138 chr10 133797422 45074 11407694 0.043324163 0.046684087 0.035727596 25 110000 253.088121755
139 chr12 133275309 44151 13878240 0.043155100 0.045728117 0.043465064 25 356015 314.335802134
140 chr13 114364328 29907 9423815 0.037031646 0.030975307 0.029514313 25 110000 315.103989033
141 chr14 107043718 27973 9245970 0.034661202 0.028972223 0.028957323 25 173523 330.531941515
142 chr15 101991189 25557 9565023 0.033025172 0.026469921 0.029956561 25 110000 374.262354736
143 chr16 90338345 35288 11959674 0.029251932 0.036548522 0.037456334 25 138208 338.916175470
144 chr17 83257441 32093 16264416 0.026959106 0.033239393 0.050938295 25 132210 506.790141152
145 chr18 80373285 23966 18684937 0.026025204 0.024822089 0.058519091 25 500000 779.643536677
146 chr20 64444167 22608 12620160 0.020867290 0.023415580 0.039524901 25 500000 558.216560510
147 chr19 58617616 30854 11391752 0.018980628 0.031956135 0.035677667 25 396802 369.214753355
148 chrY 57227415 15130 4564760 0.018530475 0.015670458 0.014296307 25 227093 301.702577660
149 chr22 50818468 16760 10691540 0.016455232 0.017358684 0.033484683 25 498537 637.920047733
150 chr21 46709983 14911 9253172 0.015124887 0.015443636 0.028979879 25 499939 620.560123399
151 chrM 16569 0 0 0.000005365 0.000000000 0.000000000 -1 -1 -1
152 all 3088286401 965511 319296434 1.0 1.0 1.0 25 500000 330.702015824
153
154
155 Notice the following:
156
157 1. There are 0 intervals reported for `chrM` or `chrMT`; therefore, the min, max, and mean are all "-1".
158 2. The last line in the output is has an "genome" chromosome, meaning it is a summary of all of the chromosomes.
159
160 Using this report, there are many high-level sanity checks one can explore. For example, we can
161 create the plot described above by saving the output to a file.
162
163 .. code-block:: bash
164
165 bedtools summary -i simrep.grch38.bed -g grch38.genome.txt > ~/simrep.summary.tsv
166
167
168 Now run following R code. (Sorry, I am not an R expert)
169
170 .. code-block:: R
171
172 if (!require("dplyr")) install.packages("dplyr")
173 if (!require("ggplot2")) install.packages("ggplot2")
174 library(dplyr)
175 library(ggplot2)
176
177 x = read_tsv('~/simrep.summary.tsv')
178 x = x %>% mutate(obs_v_exp = frac_all_ivls/chrom_frac_genome)
179
180 p = ggplot(x) +
181 ylim(0,3) +
182 ylab("Observed vs. Expected fraction") +
183 xlab("Chromosome") +
184 geom_point(aes(x=factor(chrom, level=chrom),
185 y=obs_v_exp,
186 color=ifelse(obs_v_exp>1.5 | obs_v_exp<0.5, 'red', 'black'))) +
187 scale_color_identity() +
188 theme_bw()
189 p + theme(axis.text.x = element_text(size = 12, angle = 90))
190
191 .. image:: ../images/tool-glyphs/summary.png
192 :width: 600pt
193
194
195
196