Skip to content

Commit 68b655b

Browse files
authored
Add files via upload
1 parent 150e8e2 commit 68b655b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

bdg_to_binarize.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
4+
usage() {
5+
echo "Usage: make binary file from the bedgraph file. "
6+
echo " Normalized value: bins per million mapped reads (BPM) , depth (nFrag or ReadsInTss) and cell_num (per 100 cells)."
7+
echo " bed_to_bdg.sh [-i bedgraph] [-o out_dir] [-f cutoff] [-m mark] [-t cell_type/cluster]"
8+
echo " [-s bin_size] [-c chrom_size]"
9+
echo "Description:"
10+
echo " -i bedgraph, the input bedgraph file path."
11+
echo " -o out_dir, the output dir name."
12+
echo " -f cutoff, used to binarye."
13+
echo " -m mark, the ChIPseq mark name, example H3K27me3."
14+
echo " -t cell_type / cluster name,"
15+
echo " -s bin_size, should the same with bedgraph file. Default:500."
16+
echo " -c chrom_size, the chroms size file."
17+
exit -1
18+
}
19+
20+
21+
22+
bin_size=500
23+
24+
while getopts 'h:i:o:f:m:t:s:c:' opts
25+
do
26+
case $opts in
27+
i) bdg="$OPTARG";;
28+
o) out_dir="$OPTARG";;
29+
f) cutoff="$OPTARG";;
30+
m) mark="$OPTARG";;
31+
t) cell_type="$OPTARG";;
32+
s) bin_size="$OPTARG";;
33+
c) chrom_size="$OPTARG";;
34+
h) usage;;
35+
?) usage;;
36+
esac
37+
done
38+
39+
40+
function binary_one_chr(){
41+
# $1 input_bdg, should the same with bin_size
42+
# $2 out, out file path
43+
# $3 mark
44+
# $4 cell type / cluster
45+
# $5 chr
46+
# $6 chrom_size file
47+
# $7 bin_size
48+
bdg=$1;out=$2;mark=$3;cell_type=$4;chr=$5;chrom_size=$6;bin_size=$7
49+
grep -w $chr $chrom_size|bedtools makewindows -g - -w $bin_size|\
50+
bedtools intersect -a - -b $bdg -wao|\
51+
awk -v cut=$cutoff '{if ($5 != -1 && $7 >cut){v=1}else{v=0};print v}'|\
52+
sed "1i$cell_type\t$chr\n$mark" > $out
53+
}
54+
55+
if [ ! -d "$out_dir" ]
56+
then
57+
mkdir -p $out_dir
58+
fi
59+
60+
chroms=(`cut -f 1 $chrom_size|grep -v random|grep -v chrUn|grep -v hap|grep -v chrM|grep -v chrY|tr '\n' ' '`)
61+
62+
for chr in ${chroms[@]}
63+
do
64+
o=${out_dir}/${cell_type}_${chr}"_binary.txt"
65+
binary_one_chr $bdg $o $mark $cell_type $chr $chrom_size $bin_size &
66+
done
67+
wait
68+

0 commit comments

Comments
 (0)