annotate NGSrich_0.5.5/thirdparty/fetchChromSizes @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 #!/bin/sh
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 # fetchChromSizes - script to grab chrom.sizes from UCSC via either of:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 # mysql, wget or ftp
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 # "$Id: fetchChromSizes,v 1.2 2009/03/26 18:40:09 hiram Exp $"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 usage() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 echo "usage: fetchChromSizes <db> > <db>.chrom.sizes"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 echo " used to fetch chrom.sizes information from UCSC for the given <db>"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 echo "<db> - name of UCSC database, e.g.: hg18, mm9, etc ..."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 echo ""
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 echo "This script expects to find one of the following commands:"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 echo " wget, mysql, or ftp in order to fetch information from UCSC."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 echo "Route the output to the file <db>.chrom.sizes as indicated above."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 echo ""
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 echo "Example: fetchChromSizes hg18 > hg18.chrom.sizes"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 exit 255
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 DB=$1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 export DB
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 if [ -z "${DB}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 usage
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 WGET=`type wget 2> /dev/null | sed -e "s/.* is //"`
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 MYSQL=`type mysql 2> /dev/null | sed -e "s/.* is //"`
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 FTP=`type ftp 2> /dev/null | sed -e "s/.* is //"`
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 if [ -z "${WGET}" -a -z "${MYSQL}" -a -z "${FTP}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 echo "ERROR: can not find any of the commands: wget mysql or ftp"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 usage
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 DONE=0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 export DONE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 if [ -n "${MYSQL}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 echo "INFO: trying MySQL ${MYSQL} for database ${DB}" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 ${MYSQL} -N --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 "SELECT chrom,size FROM chromInfo ORDER BY size DESC;" ${DB}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 if [ $? -ne 0 ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 echo "WARNING: mysql command failed" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 DONE=1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 if [ "${DONE}" -eq 1 ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 exit 0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 if [ -n "${WGET}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 echo "INFO: trying WGET ${WGET} for database ${DB}" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 tmpResult=chromInfoTemp.$$.gz
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 ${WGET} \
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 "ftp://hgdownload.cse.ucsc.edu/goldenPath/${DB}/database/chromInfo.txt.gz" \
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 -O ${tmpResult} 2> /dev/null
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 if [ $? -ne 0 -o ! -s "${tmpResult}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 echo "WARNING: wget command failed" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 rm -f "${tmpResult}"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 zcat ${tmpResult} 2> /dev/null | cut -f1,2 | sort -k2nr
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 rm -f "${tmpResult}"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 DONE=1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 if [ "${DONE}" -eq 1 ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 exit 0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 if [ -n "${FTP}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 echo "INFO: trying FTP ${FTP} for database ${DB}" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 tmpFtpRsp=fetchTemp.$$
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 echo "user anonymous fetchChromSizes@" > ${tmpFtpRsp}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 echo "cd goldenPath/${DB}/database" >> ${tmpFtpRsp}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 echo "get chromInfo.txt.gz ${tmpResult}" >> ${tmpFtpRsp}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 echo "bye" >> ${tmpFtpRsp}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 ${FTP} -u -n -i hgdownload.cse.ucsc.edu < ${tmpFtpRsp} > /dev/null 2>&1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 if [ $? -ne 0 -o ! -s "${tmpResult}" ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 echo "ERROR: ftp command failed" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 rm -f "${tmpFtpRsp}" "${tmpResult}"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 zcat ${tmpResult} | cut -f1,2 | sort -k2nr
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 rm -f "${tmpFtpRsp}" "${tmpResult}"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 DONE=1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 fi
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 if [ "${DONE}" -eq 0 ]; then
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 echo "ERROR: sorry, attempt to fetch chrom.sizes has failed ?" 1>&2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 exit 255
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 fi