Commit patch to not break on spaces.
[bowtie.git] / scripts / make_rn4.sh
1 #!/bin/sh
2
3 #
4 # Downloads sequence for the rn4 version of R. norvegicus (rat) from
5 # UCSC.
6 #
7 # Note that UCSC's rn4 build has two categories of compressed fasta
8 # files:
9 #
10 # 1. The base files, named chr??.fa.gz
11 # 2. The unplaced-sequence files, named chr??_random.fa.gz
12 #
13 # By default, this script builds and index for just the base files,
14 # since alignments to those sequences are the most useful.  To change
15 # which categories are built by this script, edit the CHRS_TO_INDEX
16 # variable below.
17 #
18
19 i=2
20 BASE_CHRS=chr1
21 while [ $i -lt 21 ] ; do
22         BASE_CHRS="$BASE_CHRS chr$i"
23         i=`expr $i + 1`
24 done
25 BASE_CHRS="$BASE_CHRS chrX chrM chrUn"
26
27 RANDOM_CHRS="\
28 chr1_random \
29 chr2_random \
30 chr3_random \
31 chr4_random \
32 chr5_random \
33 chr6_random \
34 chr7_random \
35 chr8_random \
36 chr9_random \
37 chr10_random \
38 chr11_random \
39 chr12_random \
40 chr13_random \
41 chr14_random \
42 chr15_random \
43 chr16_random \
44 chr17_random \
45 chr18_random \
46 chr19_random \
47 chr20_random \
48 chrX_random \
49 chrUn_random"
50
51 CHRS_TO_INDEX=$BASE_CHRS
52
53 RN4_BASE=ftp://hgdownload.cse.ucsc.edu/goldenPath/rn4/chromosomes
54
55 get() {
56         file=$1
57         if ! wget --version >/dev/null 2>/dev/null ; then
58                 if ! curl --version >/dev/null 2>/dev/null ; then
59                         echo "Please install wget or curl somewhere in your PATH"
60                         exit 1
61                 fi
62                 curl -o `basename $1` $1
63                 return $?
64         else
65                 wget $1
66                 return $?
67         fi
68 }
69
70 BOWTIE_BUILD_EXE=./bowtie-build
71 if [ ! -x "$BOWTIE_BUILD_EXE" ] ; then
72         if ! which bowtie-build ; then
73                 echo "Could not find bowtie-build in current directory or in PATH"
74                 exit 1
75         else
76                 BOWTIE_BUILD_EXE=`which bowtie-build`
77         fi
78 fi
79
80 INPUTS=
81 for c in $CHRS_TO_INDEX ; do
82         if [ ! -f ${c}.fa ] ; then
83                 F=${c}.fa.gz
84                 get ${RN4_BASE}/$F || (echo "Error getting $F" && exit 1)
85                 gunzip $F || (echo "Error unzipping $F" && exit 1)
86         fi
87         [ -n "$INPUTS" ] && INPUTS=$INPUTS,${c}.fa
88         [ -z "$INPUTS" ] && INPUTS=${c}.fa
89 done
90
91 CMD="${BOWTIE_BUILD_EXE} $* ${INPUTS} rn4"
92 echo Running $CMD
93 if $CMD ; then
94         echo "rn4 index built; you may remove fasta files"
95 else
96         echo "Index building failed; see error message"
97 fi