# This script is supposed to be run when having to download .fastq files from multiple SRA entries.
# To run this script, please copy it to the corresponding RAW folder from the service.

#module load SRA-Toolkit/3.0.5-gompi-2021a
mkdir logs

while IFS= read -r in || [ -n "$in" ]; do
    echo "srun --partition short_idx --mem 4G --cpus-per-task 2 --time 02:00:00 --job-name ${in}_SRA_DOWNLOAD --output logs/SRA_DOWNLOAD.${in}.%j.log fastq-dump --split-files --gzip ${in} &" >> _01_SRA_fastq_download.sh
done < ../ANALYSIS/samples_id.txt

echo 'for f in *_1.fastq.gz *_2.fastq.gz; do [ -e "$f" ] || continue; mv "$f" "$(echo "$f" | sed -E '\''s/_([12])\.fastq\.gz$/_R\1.fastq.gz/'\'')"; done' > _02_fix_filenames.sh