-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTAR_pair_reads_batch_alignment.sh
54 lines (37 loc) · 1.5 KB
/
STAR_pair_reads_batch_alignment.sh
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
#!/bin/bash
#### THIS SCRIPT WILL RUN STAR ALIGNMENT TOOL ###
### GENERATE BAM FILES FROM FASTQ FILES AFTER ALIGNED TO A GENOME ####
### GENOME NEED TO BE INDEX FIRST, FOR WATERHEMP AND PALMER INDEXES ARE AVAILABLE AT ~/genomes #####
### Test the ls command inside the for loop before running change the parameter number after cut -c according to
# your file names
# ARGUMENTS
## FIRST ARGUMENTS - FILE PATH
file_path=$1
## SECOND ARGUMENT - OUTPUT PATH
out_path=$2
## THIRD ARGUMENT - NUMBER OF THREADS
threads=$3
## FOURTH ARGUMENT - INDEX PATH
genome_index=$4
### RUN SCRIPT ####
cd ${file_path}
for file in $(ls *.fastq.gz | rev | cut -c 21- | rev | uniq); do \
echo "############ Mapping ${file} ################"; \
STAR --runThreadN $threads \
--genomeDir $genome_index \
--readFilesCommand zcat \
--readFilesIn "${file}"_R1_trimmed.fastq.gz "${file}"_R2_trimmed.fastq.gz\
--outSAMtype BAM SortedByCoordinate \
--alignIntronMax 50000 \
--outFileNamePrefix "${out_path}"/"${file}". \
--outTmpDir "${out_path}"/temp_dir \
--limitBAMsortRAM 6643038087
done
echo "######## Finished STAR mapping #############";
### CREATE INDEX FOR ALL BAM FILES ####
echo "############## Creating bam files indexes ###########";
parallel samtools index ::: "${out_path}"/*.bam
echo "################ Move bam files to folder ############";
mkdir "${out_path}"/bam_files
mv "${out_path}"/*.bam "${out_path}"/bam_files
mv "${out_path}"/*.bai "${out_path}"/bam_files