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