Commit patch to not break on spaces.
[bowtie.git] / scripts / make_mm9.sh
1 #!/bin/sh
2
3 #
4 # Downloads sequence for the mm9 version of M. musculus (mouse) from
5 # UCSC.
6 #
7 # Note that UCSC's mm9 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 BASE_CHRS="\
20 chr1 \
21 chr2 \
22 chr3 \
23 chr4 \
24 chr5 \
25 chr6 \
26 chr7 \
27 chr8 \
28 chr9 \
29 chr10 \
30 chr11 \
31 chr12 \
32 chr13 \
33 chr14 \
34 chr15 \
35 chr16 \
36 chr17 \
37 chr18 \
38 chr19 \
39 chrX \
40 chrY \
41 chrM"
42
43 RANDOM_CHRS="\
44 1_random \
45 3_random \
46 4_random \
47 5_random \
48 7_random \
49 8_random \
50 9_random \
51 13_random \
52 16_random \
53 17_random \
54 X_random \
55 Y_random \
56 Un_random"
57
58 CHRS_TO_INDEX=$BASE_CHRS
59
60 UCSC_MM9_BASE=ftp://hgdownload.cse.ucsc.edu/goldenPath/mm9/chromosomes
61
62 get() {
63         file=$1
64         if ! wget --version >/dev/null 2>/dev/null ; then
65                 if ! curl --version >/dev/null 2>/dev/null ; then
66                         echo "Please install wget or curl somewhere in your PATH"
67                         exit 1
68                 fi
69                 curl -o `basename $1` $1
70                 return $?
71         else
72                 wget $1
73                 return $?
74         fi
75 }
76
77 BOWTIE_BUILD_EXE=./bowtie-build
78 if [ ! -x "$BOWTIE_BUILD_EXE" ] ; then
79         if ! which bowtie-build ; then
80                 echo "Could not find bowtie-build in current directory or in PATH"
81                 exit 1
82         else
83                 BOWTIE_BUILD_EXE=`which bowtie-build`
84         fi
85 fi
86
87 INPUTS=
88 for c in $CHRS_TO_INDEX ; do
89         if [ ! -f ${c}.fa ] ; then
90                 F=${c}.fa.gz
91                 get ${UCSC_MM9_BASE}/$F || (echo "Error getting $F" && exit 1)
92                 gunzip $F || (echo "Error unzipping $F" && exit 1)
93         fi
94         [ -n "$INPUTS" ] && INPUTS=$INPUTS,${c}.fa
95         [ -z "$INPUTS" ] && INPUTS=${c}.fa
96 done
97
98 CMD="${BOWTIE_BUILD_EXE} $* ${INPUTS} mm9"
99 echo Running $CMD
100 if $CMD ; then
101         echo "mm9 index built; you may remove fasta files"
102 else
103         echo "Index building failed; see error message"
104 fi