4
|
1 #!/bin/bash
|
|
2
|
|
3 # This tool creates a UCSC track line given a bigWig or bedGraph input file, a track name and genome assembly.
|
|
4
|
|
5 ## Define URL prefix
|
|
6
|
|
7 URL="http://data.bric.dk/galaxy/UCSC"
|
|
8
|
|
9 #parse input
|
|
10 while getopts hi:t:n:o: myarg
|
|
11 do case "$myarg" in
|
|
12 h) echo "Usage: create UCSC track line -i <INPUT_FILE> -t <FILE_TYPE> -n <TRACK_NAME> -o <ASSEMBLY>"
|
|
13 exit ;;
|
|
14 i) input_file="$OPTARG" ;;
|
|
15 t) file_type="$OPTARG" ;;
|
|
16 n) track_name="$OPTARG" ;;
|
|
17 o) org_assembly="$OPTARG" ;;
|
|
18 [?]) echo "Usage: create UCSC track line -i <INPUT_FILE> -t <FILE_TYPE> -n <TRACK_NAME> -o <ASSEMBLY>"
|
|
19
|
|
20 exit 1 ;;
|
|
21 esac
|
|
22 done
|
|
23
|
|
24 ####################################################################
|
|
25 # Check if a link to that file exists in the UCSC webfolder
|
|
26 flag=0
|
|
27
|
|
28 for link in `ls -1 $UCSCPATH`
|
|
29 do
|
|
30 if [ `readlink -f $input_file` == `readlink -f $UCSCPATH/$link` ] ; then
|
|
31 link_path=/$link # use already existing link
|
|
32 flag=1
|
|
33 fi
|
|
34 done
|
|
35
|
|
36 # If link to input file doesn't exist, create anonymous soft-link for input file in a folder accessible from the web.
|
|
37
|
|
38 if [ $flag == 0 ]; then
|
|
39
|
|
40 link_path=`mktemp -u --tmpdir=/`
|
|
41 ln -s $input_file $UCSCPATH$link_path
|
|
42 fi
|
|
43
|
|
44 ####################################################################
|
|
45 ##Convert 4th character of file_type to uppercase (e.g. bigwig -> bigWig). UCSC browser doesn't recognize the file type otherwise.
|
|
46
|
|
47 ##Split file_type string to prefix (big) and suffix (wig, bed) and uppercase the first character of the latter.
|
|
48 prefix=`echo ${file_type:0:3}`
|
|
49 suffix=`echo ${file_type:3} | sed -e "s/\b\(.\)/\u\1/g"`
|
|
50
|
|
51 file_type=`echo ${prefix}${suffix}`
|
|
52
|
|
53 ####################################################################
|
|
54 #Contruct URL
|
|
55 bigURL=`echo ${URL}${link_path}`
|
|
56
|
|
57 ####################################################################
|
|
58 ## Print track line
|
|
59 echo "track name='$track_name' db=$org_assembly type=$file_type visibility=full alwaysZero=ON bigDataUrl=$bigURL"
|