Commit patch to not break on spaces.
[bowtie.git] / scripts / make_galGal3.sh
1 #!/bin/sh
2
3 #
4 # Downloads sequence for the galGal3 version of G. gallus (chicken)
5 # from UCSC.
6 #
7
8 BASE_CHRS=chr1
9 # Add autosomes 2-24
10 i=2
11 while [ $i -lt 25 ] ; do
12         BASE_CHRS="$BASE_CHRS chr$i"
13         i=`expr $i + 1`
14 done
15 # Add autosomes 26-28
16 BASE_CHRS="$BASE_CHRS chr26 chr27 chr28 chr32"
17 # Add sex chromosomes
18 BASE_CHRS="$BASE_CHRS chrW chrZ"
19 # Add mitochondrial
20 BASE_CHRS="$BASE_CHRS chrM"
21 # Add other unplaced, but autosome-associated
22 BASE_CHRS="$BASE_CHRS chr1_random chr2_random chr4_random chr5_random chr6_random chr7_random chr8_random chr10_random chr11_random chr12_random chr13_random chr16_random chr17_random chr18_random chr20_random chr22_random chr25_random chr28_random"
23 # Add other unplaced, but sex-chromosome-associated
24 BASE_CHRS="$BASE_CHRS chrW_random chrZ_random"
25 # Add totally unplaced
26 BASE_CHRS="$BASE_CHRS chrUn_random"
27
28 CHRS_TO_INDEX=$BASE_CHRS
29
30 FTP_BASE=ftp://hgdownload.cse.ucsc.edu/goldenPath/galGal3/chromosomes
31
32 get() {
33         file=$1
34         if ! wget --version >/dev/null 2>/dev/null ; then
35                 if ! curl --version >/dev/null 2>/dev/null ; then
36                         echo "Please install wget or curl somewhere in your PATH"
37                         exit 1
38                 fi
39                 curl -o `basename $1` $1
40                 return $?
41         else
42                 wget $1
43                 return $?
44         fi
45 }
46
47 BOWTIE_BUILD_EXE=./bowtie-build
48 if [ ! -x "$BOWTIE_BUILD_EXE" ] ; then
49         if ! which bowtie-build ; then
50                 echo "Could not find bowtie-build in current directory or in PATH"
51                 exit 1
52         else
53                 BOWTIE_BUILD_EXE=`which bowtie-build`
54         fi
55 fi
56
57 INPUTS=
58 for c in $CHRS_TO_INDEX ; do
59         if [ ! -f ${c}.fa ] ; then
60                 F=${c}.fa.gz
61                 get ${FTP_BASE}/$F || (echo "Error getting $F" && exit 1)
62                 gunzip $F || (echo "Error unzipping $F" && exit 1)
63         fi
64         [ -n "$INPUTS" ] && INPUTS=$INPUTS,${c}.fa
65         [ -z "$INPUTS" ] && INPUTS=${c}.fa
66 done
67
68 CMD="${BOWTIE_BUILD_EXE} $* ${INPUTS} galGal3"
69 echo Running $CMD
70 if $CMD ; then
71         echo "galGal3 index built; you may remove fasta files"
72 else
73         echo "Index building failed; see error message"
74 fi