#!/bin/bash # Load Bowtie2 module for alignment module load Bowtie2 # Read project name from a file and set up output log path project=$(cat ../project.txt) output=~/ngs/$project/summary/bowtie2.log # Log the start time and Bowtie2 version echo "Processing fastq files on" $(date) > $output printf "\n" >> $output bowtie2 --version >> $output printf "\n" >> $output # Define paths to reference genomes for alignment cerevisiae=/shared/biodata/ngs/Reference/iGenomes/Saccharomyces_cerevisiae/UCSC/sacCer3/Sequence/Bowtie2Index/genome drosophila=/shared/biodata/ngs/Reference/iGenomes/Drosophila_melanogaster/UCSC/dm6/Sequence/Bowtie2Index/genome # Define input and output directories fastq_dir=/home/ngs/fast/fastq/$project/ sam_dir=/home/ngs/fast/sam/$project/ # Loop through each sample name listed in the sample_names.txt file for i in $(cat ../sample_names.txt); do echo "Results for sample:" $i >> $output # Create a list of all R1 fastq files for the current sample ls ${fastq_dir}*${i}*R1*fastq > ${i}_fastq_R1.list count=0 # Loop through each R1 fastq file and perform paired-end alignment for j in $(cat ${i}_fastq_R1.list); do # Identify corresponding R2 fastq file by replacing '_R1' with '_R2' k=$(echo $j | sed 's/_R1/_R2/') # Run Bowtie2 alignment for the first read pair, including headers if [ $count -lt 1 ]; then # Align against Saccharomyces cerevisiae genome bowtie2 --local --very-sensitive-local --no-unal --no-mixed --no-discordant -q --phred33 -I 10 -X 700 --threads 12 -x $cerevisiae -1 $j -2 $k > ${sam_dir}/${i}.sam 2>> $output # Align against Drosophila melanogaster genome bowtie2 --local --very-sensitive-local --no-unal --no-mixed --no-discordant -q --phred33 -I 10 -X 700 --threads 12 -x $drosophila -1 $j -2 $k > ${sam_dir}/${i}_dm.sam 2>> $output else # Subsequent alignments for the same sample (without headers) bowtie2 --no-head --local --very-sensitive-local --no-unal --no-mixed --no-discordant -q --phred33 -I 10 -X 700 --threads 12 -x $cerevisiae -1 $j -2 $k >> ${sam_dir}/${i}.sam 2>> $output # Subsequent alignments against Drosophila genome bowtie2 --no-head --local --very-sensitive-local --no-unal --no-mixed --no-discordant -q --phred33 -I 10 -X 700 --threads 12 -x $drosophila -1 $j -2 $k >> ${sam_dir}/${i}_dm.sam 2>> $output fi # Increment count for managing header inclusion count=$(echo "print($count + 1)" | python3) done # Add spacing in the output log after processing each sample printf "\n" >> $output # Clean up temporary file listing R1 fastq files rm ${i}_fastq_R1.list done