#!/usr/bin/env bash
# Bulk download script for GSE232597
# Generated from Yeo Lab Publications Database
# Total files: 55

OUTDIR="GSE232597"
mkdir -p "$OUTDIR"
cd "$OUTDIR"

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_FLAG_IP1_enriched_windows.tsv.gz" -O "GSE232597_FLAG_IP1_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_FLAG_IP2_enriched_windows.tsv.gz" -O "GSE232597_FLAG_IP2_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_FLAG_reproducible_enriched_windows.tsv.gz" -O "GSE232597_FLAG_reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_RTCA_IP1_enriched_windows.tsv.gz" -O "GSE232597_RTCA_IP1_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_RTCA_IP2_enriched_windows.tsv.gz" -O "GSE232597_RTCA_IP2_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_RTCA_reproducible_enriched_windows.tsv.gz" -O "GSE232597_RTCA_reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_SCAF8_IP1_enriched_windows.tsv.gz" -O "GSE232597_SCAF8_IP1_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_SCAF8_IP2_enriched_windows.tsv.gz" -O "GSE232597_SCAF8_IP2_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_SCAF8_reproducible_enriched_windows.tsv.gz" -O "GSE232597_SCAF8_reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_STAU2_IP1_enriched_windows.tsv.gz" -O "GSE232597_STAU2_IP1_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_STAU2_IP2_enriched_windows.tsv.gz" -O "GSE232597_STAU2_IP2_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_STAU2_reproducible_enriched_windows.tsv.gz" -O "GSE232597_STAU2_reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_TRNAU1AP_IP1_enriched_windows.tsv.gz" -O "GSE232597_TRNAU1AP_IP1_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_TRNAU1AP_IP2_enriched_windows.tsv.gz" -O "GSE232597_TRNAU1AP_IP2_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232597/suppl/GSE232597_TRNAU1AP_reproducible_enriched_windows.tsv.gz" -O "GSE232597_TRNAU1AP_reproducible_enriched_windows.tsv.gz"

# --- SRA run files ---
# Tip: use 'fasterq-dump' from SRA Toolkit for FASTQ conversion
#      with optional renaming to original submitted FASTQ names.
# Set to 1 to rename SRR outputs (e.g. SRR_1.fastq.gz -> sample_R1.fastq.gz)
RENAME_SRA_TO_ORIGINAL=1

_compress_if_exists() {
  local stem="$1"
  if [ -f "${stem}.fastq" ]; then
    gzip -f "${stem}.fastq"
    echo "${stem}.fastq.gz"
    return 0
  fi
  if [ -f "${stem}.fq" ]; then
    gzip -f "${stem}.fq"
    echo "${stem}.fq.gz"
    return 0
  fi
  return 1
}

# Option A: Download via SRA Toolkit (recommended)
fasterq-dump --split-files "SRR24579324"
gz1="$(_compress_if_exists 'SRR24579324_1' || true)"
gz2="$(_compress_if_exists 'SRR24579324_2' || true)"
gzs="$(_compress_if_exists 'SRR24579324' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "FLAG_IP2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579325"
gz1="$(_compress_if_exists 'SRR24579325_1' || true)"
gz2="$(_compress_if_exists 'SRR24579325_2' || true)"
gzs="$(_compress_if_exists 'SRR24579325' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "FLAG_IP1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579326"
gz1="$(_compress_if_exists 'SRR24579326_1' || true)"
gz2="$(_compress_if_exists 'SRR24579326_2' || true)"
gzs="$(_compress_if_exists 'SRR24579326' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "FLAG_IN2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579327"
gz1="$(_compress_if_exists 'SRR24579327_1' || true)"
gz2="$(_compress_if_exists 'SRR24579327_2' || true)"
gzs="$(_compress_if_exists 'SRR24579327' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "FLAG_IN1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579332"
gz1="$(_compress_if_exists 'SRR24579332_1' || true)"
gz2="$(_compress_if_exists 'SRR24579332_2' || true)"
gzs="$(_compress_if_exists 'SRR24579332' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "STAU2_IP2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579333"
gz1="$(_compress_if_exists 'SRR24579333_1' || true)"
gz2="$(_compress_if_exists 'SRR24579333_2' || true)"
gzs="$(_compress_if_exists 'SRR24579333' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "STAU2_IP1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579334"
gz1="$(_compress_if_exists 'SRR24579334_1' || true)"
gz2="$(_compress_if_exists 'SRR24579334_2' || true)"
gzs="$(_compress_if_exists 'SRR24579334' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "STAU2_IN2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579335"
gz1="$(_compress_if_exists 'SRR24579335_1' || true)"
gz2="$(_compress_if_exists 'SRR24579335_2' || true)"
gzs="$(_compress_if_exists 'SRR24579335' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "STAU2_IN1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579336"
gz1="$(_compress_if_exists 'SRR24579336_1' || true)"
gz2="$(_compress_if_exists 'SRR24579336_2' || true)"
gzs="$(_compress_if_exists 'SRR24579336' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "SCAF8_IP2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579337"
gz1="$(_compress_if_exists 'SRR24579337_1' || true)"
gz2="$(_compress_if_exists 'SRR24579337_2' || true)"
gzs="$(_compress_if_exists 'SRR24579337' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "SCAF8_IP1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579338"
gz1="$(_compress_if_exists 'SRR24579338_1' || true)"
gz2="$(_compress_if_exists 'SRR24579338_2' || true)"
gzs="$(_compress_if_exists 'SRR24579338' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "SCAF8_IN2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579339"
gz1="$(_compress_if_exists 'SRR24579339_1' || true)"
gz2="$(_compress_if_exists 'SRR24579339_2' || true)"
gzs="$(_compress_if_exists 'SRR24579339' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "SCAF8_IN1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579340"
gz1="$(_compress_if_exists 'SRR24579340_1' || true)"
gz2="$(_compress_if_exists 'SRR24579340_2' || true)"
gzs="$(_compress_if_exists 'SRR24579340' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "RTCA_IP2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579341"
gz1="$(_compress_if_exists 'SRR24579341_1' || true)"
gz2="$(_compress_if_exists 'SRR24579341_2' || true)"
gzs="$(_compress_if_exists 'SRR24579341' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "RTCA_IP1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579342"
gz1="$(_compress_if_exists 'SRR24579342_1' || true)"
gz2="$(_compress_if_exists 'SRR24579342_2' || true)"
gzs="$(_compress_if_exists 'SRR24579342' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "RTCA_IN2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579343"
gz1="$(_compress_if_exists 'SRR24579343_1' || true)"
gz2="$(_compress_if_exists 'SRR24579343_2' || true)"
gzs="$(_compress_if_exists 'SRR24579343' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "RTCA_IN1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579344"
gz1="$(_compress_if_exists 'SRR24579344_1' || true)"
gz2="$(_compress_if_exists 'SRR24579344_2' || true)"
gzs="$(_compress_if_exists 'SRR24579344' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "TRNAU1AP_IP2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579345"
gz1="$(_compress_if_exists 'SRR24579345_1' || true)"
gz2="$(_compress_if_exists 'SRR24579345_2' || true)"
gzs="$(_compress_if_exists 'SRR24579345' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "TRNAU1AP_IP1.fastq.gz"
fi

fasterq-dump --split-files "SRR24579346"
gz1="$(_compress_if_exists 'SRR24579346_1' || true)"
gz2="$(_compress_if_exists 'SRR24579346_2' || true)"
gzs="$(_compress_if_exists 'SRR24579346' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "TRNAU1AP_IN2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579347"
gz1="$(_compress_if_exists 'SRR24579347_1' || true)"
gz2="$(_compress_if_exists 'SRR24579347_2' || true)"
gzs="$(_compress_if_exists 'SRR24579347' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "TRNAU1AP_IN1.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579324/SRR24579324"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579325/SRR24579325"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579326/SRR24579326"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579327/SRR24579327"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579332/SRR24579332"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579333/SRR24579333"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579334/SRR24579334"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579335/SRR24579335"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579336/SRR24579336"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579337/SRR24579337"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579338/SRR24579338"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos4/sra-pub-run-30/SRR024/24579/SRR24579339/SRR24579339.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579340/SRR24579340"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579341/SRR24579341"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579342/SRR24579342"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579343/SRR24579343"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579344/SRR24579344"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579345/SRR24579345"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579346/SRR24579346"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579347/SRR24579347"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579327/SRR24579327"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579326/SRR24579326"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579325/SRR24579325"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579324/SRR24579324"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579343/SRR24579343"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579342/SRR24579342"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579341/SRR24579341"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579340/SRR24579340"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos4/sra-pub-run-30/SRR024/24579/SRR24579339/SRR24579339.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579338/SRR24579338"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579337/SRR24579337"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579336/SRR24579336"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579335/SRR24579335"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579334/SRR24579334"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579333/SRR24579333"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579332/SRR24579332"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579347/SRR24579347"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579346/SRR24579346"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579345/SRR24579345"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579344/SRR24579344"

echo "Download complete. Files saved to $OUTDIR"