Skip to content

Instantly share code, notes, and snippets.

@icaoberg
Forked from arq5x/go.sh
Last active February 3, 2020 23:20
Show Gist options
  • Save icaoberg/0534d2de204cdcc321eab224a2ed4d3d to your computer and use it in GitHub Desktop.
Save icaoberg/0534d2de204cdcc321eab224a2ed4d3d to your computer and use it in GitHub Desktop.
[bedtools] Compute average scores for share intervals
# icaoberg - this example is fork that uses a bedtools in a Singularity container
CONTAINER=../../singularity-bedtools.simg
echo "chr1 10 50 10" > a.bed
echo "chr1 20 40 20" > b.bed
echo "chr1 30 33 30" > c.bed
# Find the sub-intervals shared and unique to each file.
if [ -f $CONTAINER ]; then
singularity run --app bedtools $CONTAINER multiinter -i a.bed b.bed c.bed | column -t
fi
# Intersect the sub-intervals with the original intervals to collect the scores
if [ -f $CONTAINER ]; then
singularity run --app bedtools $CONTAINER multiinter -i a.bed b.bed c.bed \
| singularity run --app bedtools $CONTAINER intersect -a - -b a.bed b.bed c.bed -wa -wb \
| column -t
fi
# Grooupby the sub-intervals with the mean score from each of the original files.
if [ -f $CONTAINER ]; then
singularity run --app bedtools $CONTAINER multiinter -i a.bed b.bed c.bed \
| singularity run --app bedtools $CONTAINER intersect -a - -b a.bed b.bed c.bed -wa -wb \
| singularity run --app bedtools $CONTAINER groupby -g 1-5 -c 13 -o mean \
| column -t
fi
rm -f *.bed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment