Commit patch to not break on spaces.
[bowtie.git] / scripts / make_mm8.sh
1 #!/bin/sh
2
3 #
4 # Downloads sequence for the mm8 version of M. musculus (mouse) from
5 # UCSC.
6 #
7 # Note that UCSC's mm8 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 5_random \
46 7_random \
47 8_random \
48 9_random \
49 10_random \
50 13_random \
51 15_random \
52 17_random \
53 X_random \
54 Y_random \
55 Un_random"
56
57 CHRS_TO_INDEX=$BASE_CHRS
58
59 UCSC_MM8_BASE=ftp://hgdownload.cse.ucsc.edu/goldenPath/mm8/chromosomes
60
61 get() {
62         file=$1
63         if ! wget --version >/dev/null 2>/dev/null ; then
64                 if ! curl --version >/dev/null 2>/dev/null ; then
65                         echo "Please install wget or curl somewhere in your PATH"
66                         exit 1
67                 fi
68                 curl -o `basename $1` $1
69                 return $?
70         else
71                 wget $1
72                 return $?
73         fi
74 }
75
76 BOWTIE_BUILD_EXE=./bowtie-build
77 if [ ! -x "$BOWTIE_BUILD_EXE" ] ; then
78         if ! which bowtie-build ; then
79                 echo "Could not find bowtie-build in current directory or in PATH"
80                 exit 1
81         else
82                 BOWTIE_BUILD_EXE=`which bowtie-build`
83         fi
84 fi
85
86 INPUTS=
87 for c in $CHRS_TO_INDEX ; do
88         if [ ! -f ${c}.fa ] ; then
89                 F=${c}.fa.gz
90                 get ${UCSC_MM8_BASE}/$F || (echo "Error getting $F" && exit 1)
91                 gunzip $F || (echo "Error unzipping $F" && exit 1)
92         fi
93         [ -n "$INPUTS" ] && INPUTS=$INPUTS,${c}.fa
94         [ -z "$INPUTS" ] && INPUTS=${c}.fa
95 done
96
97 CMD="${BOWTIE_BUILD_EXE} $* ${INPUTS} mm8"
98 echo Running $CMD
99 if $CMD ; then
100         echo "mm8 index built; you may remove fasta files"
101 else
102         echo "Index building failed; see error message"
103 fi