-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTAR_index.sh
More file actions
executable file
·133 lines (120 loc) · 3.03 KB
/
STAR_index.sh
File metadata and controls
executable file
·133 lines (120 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# This script start the pipeline from .fastq.gz files assuming
# all single-end.fastq.gz files are located in fastqs/ relative to $WORKDIR and
# all paired-end.fastq.gz files are located in paired_fastqs/ relative to $WORKDIR.
########## Step 0: check command line args and make sure files exist ##########
## Initialize variables with default values:
WORKDIR=""
GENOME=""
STAR=""
fastqc=""
skip_qc=false
Genomeversion=""
n_cpus=8
## Parse command line args
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-S|--STAR)
STAR="$2"
shift #pass argument
;;
-f|--fasqc)
fastqc="$2"
shift #pass argument
;;
-g|--genome)
GENOME="$2"
shift # past argument
;;
-w|--workdir)
WORKDIR="$2"
shift # past argument
;;
--hg)
Genomeversion="$2"
shift # past argument
;;
-t|--cpus)
n_cpus="$2"
shift # past argument
;;
--skip-qc)
skip_qc=true
shift # past argument
;;
-h|--help)
echo "Usage: ./STAR_INDEX.sh -g <GENOME> -w <WORKDIR>"
echo "Options:"
echo " -S|--STAR: Path for STAR executable"
echo " -h|--hg: genome version (19/38)"
echo " -t, --cpus: Number of CPUs to use, default to 8"
exit
;;
*)
# unknown option
echo "Unknown option: $key, exiting."
echo "Usage: ./STAR_INDEX -g <GENOME> -w <WORKDIR>"
echo "Options:"
echo " --skip-qc: Skip fastQC steps for the fastq files"
echo " -h|--hg: genome version (19/38)"
echo " -t, --cpus: Number of CPUs to use, default to 8"
exit
;;
esac
shift # past argument or value
done
## Detect number of CPUs and use min(N_CPUS, n_cpus) for jobs
N_CPUS=$(nproc)
N_CPUS=$(($N_CPUS>n_cpus?n_cpus:$N_CPUS))
echo "Number of CPUs to be used: $N_CPUS"
## Check genome versiom
if [ "$Genomeversion" != 19 ] && [ "$Genomeversion" != 38 ] ; then
echo "invalid genome version $hg. Please enter 19 or 38"
exit 1
else
echo "hg=hg$Genomeversion"
fi
## Check $WORKDIR
if [[ ! -d $WORKDIR ]]; then
echo "Could not find working directory: $WORKDIR, exiting. Please make sure the working directory exists"
exit 1
else
## Convert to absolute paths
GENOME=$(readlink -e $GENOME)
WORKDIR=$(readlink -e $WORKDIR)
echo "GENOME=$GENOME"
echo "WORKDIR=$WORKDIR"
fi
if [[ ! -d $STAR ]]; then
echo "Could not find STAR executalbe: $STAR, exiting. Please make sure the working directory exists"
exit 1
## Check $GENOME
if [[ ! -d $GENOME ]]; then
echo "Could not find reference genome: $GENOME, exiting. Please make sure the working directory exists"
exit 1
else
GENOME_GTF="$GENOME/hg$Genomeversion.gtf"
GENOME_FA="$GENOME/hg$Genomeversion.fa"
if [[ ! -f $GENOME_GTF ]]; then
echo "$GENOME_GTF not found, exiting"
exit 1
fi
if [[ ! -f $GENOME_FA ]]; then
echo "$GENOME_FA not found, exiting"
exit 1
fi
STAR_INDEX="$GENOME/"
fi
## Make STAR index if not exists
echo $STAR_INDEX
if [ ! -d $STAR_INDEX ]; then
echo "STAR index does not exist, building STAR index"
$STAR\
--runThreadN $N_CPUS \
--runMode genomeGenerate \
--genomeDir $STAR_INDEX \
--genomeFastaFiles $GENOME_FA \
--sjdbGTFfile $GENOME_GTF \
--sjdbOverhang 100
fi