-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbowtie2_alignment.sh
63 lines (52 loc) · 2.18 KB
/
bowtie2_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
55
56
57
58
59
60
61
62
63
#!/bin/bash
#SBATCH --job-name=bowtie2_alignment
#SBATCH --output=bowtie2_alignment.out
#SBATCH --error=bowtie2_alignment.err
#SBATCH --time=48:00:00
#SBATCH --nodes=4
#SBATCH --ntasks-per-node=8
#SBATCH --mem-per-cpu=8G
# Load necessary modules
module load StdEnv/2020
module load bowtie2/2.5.1
module load samtools/1.17
# Base directory for SRA data
SRA_DIR="/scratch/a252chan"
# Loop through each SRA ID directory
for SRA_ID_DIR in $SRA_DIR/*/; do
# Extract the SRA ID from the directory name
SRA_ID=$(basename $SRA_ID_DIR)
# Specify the path to the trimmed FASTQ files
FASTQ_PATH="${SRA_ID_DIR}fastq"
# Define BAM file path
BAM_FILE="${SRA_ID_DIR}aligned_${SRA_ID}_reads.bam"
# Check if trimmed FASTQ files exist
if [[ -f "${FASTQ_PATH}/trimmed_${SRA_ID}_1.fastq" && -f "${FASTQ_PATH}/trimmed_${SRA_ID}_2.fastq" ]]; then
# Check if the BAM file exists (from previous runs)
if [[ -f "$BAM_FILE" ]]; then
# Check for EOF marker in BAM file
if samtools quickcheck "$BAM_FILE"; then
echo "BAM file for $SRA_ID is complete, skipping."
continue
else
echo "BAM file for $SRA_ID is corrupted or incomplete, rerunning alignment."
# Align reads using Bowtie2
bowtie2 -x /scratch/a252chan/closDifficile/FN545816 \
-1 "${FASTQ_PATH}/trimmed_${SRA_ID}_1.fastq" \
-2 "${FASTQ_PATH}/trimmed_${SRA_ID}_2.fastq" \
| samtools view -bS - > "${SRA_ID_DIR}aligned_${SRA_ID}_reads.bam"
fi
else
echo "BAM file for $SRA_ID not found, starting alignment."
# Align reads using Bowtie2
bowtie2 -x /scratch/a252chan/closDifficile/FN545816 \
-1 "${FASTQ_PATH}/trimmed_${SRA_ID}_1.fastq" \
-2 "${FASTQ_PATH}/trimmed_${SRA_ID}_2.fastq" \
| samtools view -bS - > "${SRA_ID_DIR}aligned_${SRA_ID}_reads.bam"
fi
# Remove untrimmed FASTQ files
find "${FASTQ_PATH}" -type f -name '*.fastq' ! -name '*trimmed*' -exec rm {} +
else
echo "Trimmed FASTQ files for $SRA_ID not found."
fi
done