Skip to content

Instantly share code, notes, and snippets.

@arq5x
Last active November 23, 2021 02:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arq5x/830da3b4e7eb930ef028ffc3e1ccfd84 to your computer and use it in GitHub Desktop.
Save arq5x/830da3b4e7eb930ef028ffc3e1ccfd84 to your computer and use it in GitHub Desktop.
compute average scores for share intervals
cat a.bed
chr1 10 50 10
cat b.bed
chr1 20 40 20
cat c.bed
chr1 30 33 30
# Find the sub-intervals shared and unique to each file.
bedtools multiinter -i a.bed b.bed c.bed | column -t
chr1 10 20 1 1 1 0 0
chr1 20 30 2 1,2 1 1 0
chr1 30 33 3 1,2,3 1 1 1
chr1 33 40 2 1,2 1 1 0
chr1 40 50 1 1 1 0 0
# Intersect the sub-intervals with the original intervals to collect the scores
bedtools multiinter -i a.bed b.bed c.bed \
| bedtools intersect -a - -b a.bed b.bed c.bed -wa -wb \
| column -t
chr1 10 20 1 1 1 0 0 1 chr1 10 50 10
chr1 20 30 2 1,2 1 1 0 1 chr1 10 50 10
chr1 20 30 2 1,2 1 1 0 2 chr1 20 40 20
chr1 30 33 3 1,2,3 1 1 1 1 chr1 10 50 10
chr1 30 33 3 1,2,3 1 1 1 2 chr1 20 40 20
chr1 30 33 3 1,2,3 1 1 1 3 chr1 30 33 30
chr1 33 40 2 1,2 1 1 0 1 chr1 10 50 10
chr1 33 40 2 1,2 1 1 0 2 chr1 20 40 20
chr1 40 50 1 1 1 0 0 1 chr1 10 50 10
# Grooupby the sub-intervals with the mean score from each of the original files.
bedtools multiinter -i a.bed b.bed c.bed \
| bedtools intersect -a - -b a.bed b.bed c.bed -wa -wb \
| bedtools groupby -g 1-5 -c 13 -o mean \
| column -t
chr1 10 20 1 1 10
chr1 20 30 2 1,2 15
chr1 30 33 3 1,2,3 20
chr1 33 40 2 1,2 15
chr1 40 50 1 1 10
@arq5x
Copy link
Author

arq5x commented Jul 10, 2018

foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment