-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_bed_batch.sh
46 lines (34 loc) · 1.07 KB
/
merge_bed_batch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# The purpose of this script is to perform the merge command using bedtools on multiple files
# This command attempts to merge features based on a defined distance between one feature to another
# Setting
folder=$1 # the first ARGV is the path of the folder on which to act
base='.bed' # the suffix of the bed files
gap=500000 # gap in bp for the merge command
output_path=$folder/"merged"/ # where to put the output
###
## Varify input variables
if [ $# -eq 0 ]
then
echo "No arguments supplied :( please specify input folder"
echo "e.g. sh ./merge_bed_batch.sh ./input_beds/"
else
echo "Run initiated"
## Create the ouput folder
mkdir $output_path
## Parse input folder and invoke the merge command
N=$(ls $folder | wc -l)
ii=1;
while [ $ii -le $N ]; do
file=$(ls $folder | head -n $ii | tail -n 1)
sample=$(basename $file $base)
# act only on the definded file types
if [ ${file: -4} == $base ]; then
echo $extension
echo "Merging bed: "$sample
bedtools merge -i $folder$file -d 500000 > $output_path$file
fi
ii=$((ii + 1))
done
echo "Done!"
fi