2016-12-21 23:07:22 +00:00
|
|
|
# bedtools
|
|
|
|
|
|
|
|
> A swiss-army knife of tools for genomic-analysis tasks.
|
2019-02-24 15:47:41 +00:00
|
|
|
> Used to intersect, group, convert and count data in BAM, BED, GFF/GTF, VCF format.
|
2021-09-29 19:56:15 +01:00
|
|
|
> More information: <https://bedtools.readthedocs.io>.
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2021-08-15 18:59:09 +01:00
|
|
|
- Intersect two files regarding the sequences' strand and save the result to the specified file:
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
`bedtools intersect -a {{path/to/file1}} -b {{path/to/file2}} -s > {{path/to/output_file}}`
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
- Intersect two files with a left outer join, i.e. report each feature from `file1` and NULL if no overlap with `file2`:
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
`bedtools intersect -a {{path/to/file1}} -b {{path/to/file2}} -lof > {{path/to/output_file}}`
|
2016-12-21 23:07:22 +00:00
|
|
|
|
|
|
|
- Using more efficient algorithm to intersect two pre-sorted files:
|
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
`bedtools intersect -a {{path/to/file1}} -b {{path/to/file2}} -sorted > {{path/to/output_file}}`
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
- Group file `path/to/file` based on the first three and the fifth column and summarize the sixth column by summing it up:
|
2016-12-21 23:07:22 +00:00
|
|
|
|
|
|
|
`bedtools groupby -i {{path/to/file}} -c 1-3,5 -g 6 -o sum`
|
|
|
|
|
2020-10-24 13:58:11 +01:00
|
|
|
- Convert bam-formatted file to a bed-formatted one:
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
`bedtools bamtobed -i {{path/to/file.bam}} > {{path/to/file.bed}}`
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
- Find for all features in `file1.bed` the closest one in `file2.bed` and write their distance in an extra column (input files must be sorted):
|
2016-12-21 23:07:22 +00:00
|
|
|
|
2023-11-12 03:08:58 +00:00
|
|
|
`bedtools closest -a {{path/to/file1.bed}} -b {{path/to/file2.bed}} -d`
|