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