annotate bigwig_to_wig.sh @ 4:aa6e6ef8c7cc draft

Deleted selected files
author nikos
date Tue, 02 Sep 2014 07:52:21 -0400
parents 99dc4bdb1d35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
1 #!/bin/bash
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
2 #$Id: bigwig2wig 23 2014-01-28 12:09:22Z jens $
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
3
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
4 #SCRIPT CONVERTS BIGWIG FILE TO FIXED-STEP WIGGLE FORMAT FILE
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
5 #RESOLUTION IS CONTROLLED THROUGH THE BIN SIZE
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
6
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
7 #default bin_size
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
8 bin_size=500
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
9 mylab="wiggle file"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
10
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
11 #parse input
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
12 while getopts hf:b:l: myarg
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
13 do case "$myarg" in
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
14 h) echo "Usage: bigwig_correlation -f <bigwig_file> -b <bin_size>"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
15 echo "Ex: bigwig_correlation -f <MYFILE.bw> -b 600"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
16 exit ;;
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
17 f) bigwig_file="$OPTARG" ;; #required
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
18 l) mylab="$OPTARG" ;; #optional
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
19 b) bin_size="$OPTARG" ;; #optional
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
20 [?]) echo "Usage: bigwig_correlation -f <MYFILE.bw> -b <bin_size>"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
21 exit 1 ;;
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
22 esac
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
23 done
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
24
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
25 ###################################################
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
26 ###VALIDATE INPUT
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
27 ###################################################
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
28
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
29 #make tmp-filename to hold chromosome info
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
30 org_assembly_file=`mktemp -u`
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
31 bigWigInfo -chroms $bigwig_file | perl -ne "/^\tchr/ && print" | perl -pe "s/ +/\t/g" | cut -f2,4 > $org_assembly_file
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
32
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
33 #check bin_size & define step_size
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
34 bin_size_mod=`expr $bin_size % 2` #determine modulus
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
35 if [ $bin_size_mod -ne 0 ]; then
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
36 echo "Chosen bin_size must be an even positive number, added +1 to bin_size"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
37 bin_size=$(($bin_size + 1))
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
38 fi
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
39
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
40 if [ $bin_size -lt 100 ]; then
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
41 echo "ERROR: Chosen bin_size must be a positive number >=100"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
42 exit 1
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
43 fi
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
44 #set stetp size equal to bin size i.e. non-overlapping intervals
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
45 step_size=$bin_size
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
46
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
47 ###################################################
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
48 ###EXTRACT DENSITIES FROM NORMALIZED BIGWIG FILES
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
49 ###################################################
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
50
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
51
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
52 #make track definition line
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
53 echo "track type=wiggle_0 name=$mylab description=\"fixedStep format\""
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
54
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
55 #for each chromsome
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
56 cat $org_assembly_file | while read line; do
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
57
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
58 cur_chr=`echo $line | cut --delimiter=" " -f1`
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
59 cur_length=`echo $line | cut --delimiter=" " -f2`
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
60
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
61 n_bins=`echo "scale=0; (${cur_length}-${step_size})/${bin_size}" | bc`
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
62
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
63 start=1
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
64 stop=`echo "$n_bins * $bin_size" | bc`
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
65
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
66 #write header line for each chromosome
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
67 echo "fixedStep chrom=$cur_chr start=$start step=$step_size span=$step_size"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
68
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
69 #get densities along chr in n_bins with chosen bin_size and step_size (giving overlap in bins)
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
70 nice bigWigSummary $bigwig_file $cur_chr $start $stop $n_bins | perl -pe 's/\t/\n/g' | perl -pe "s/n\/a/0/"
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
71 #gives warning if no data in/for current chromosome
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
72
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
73 done
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
74
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
75 #rm tmp
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
76 rm $org_assembly_file
99dc4bdb1d35 Uploaded
nikos
parents:
diff changeset
77