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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232514/suppl/GSE232514_RAW.tar" -O "GSE232514_RAW.tar"

# --- 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 "SRR24557412"
gz1="$(_compress_if_exists 'SRR24557412_1' || true)"
gz2="$(_compress_if_exists 'SRR24557412_2' || true)"
gzs="$(_compress_if_exists 'SRR24557412' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-14_S14_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557413"
gz1="$(_compress_if_exists 'SRR24557413_1' || true)"
gz2="$(_compress_if_exists 'SRR24557413_2' || true)"
gzs="$(_compress_if_exists 'SRR24557413' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-13_S13_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557414"
gz1="$(_compress_if_exists 'SRR24557414_1' || true)"
gz2="$(_compress_if_exists 'SRR24557414_2' || true)"
gzs="$(_compress_if_exists 'SRR24557414' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-12_S12_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557415"
gz1="$(_compress_if_exists 'SRR24557415_1' || true)"
gz2="$(_compress_if_exists 'SRR24557415_2' || true)"
gzs="$(_compress_if_exists 'SRR24557415' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-11_S11_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557416"
gz1="$(_compress_if_exists 'SRR24557416_1' || true)"
gz2="$(_compress_if_exists 'SRR24557416_2' || true)"
gzs="$(_compress_if_exists 'SRR24557416' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-10_S10_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557417"
gz1="$(_compress_if_exists 'SRR24557417_1' || true)"
gz2="$(_compress_if_exists 'SRR24557417_2' || true)"
gzs="$(_compress_if_exists 'SRR24557417' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-9_S9_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557418"
gz1="$(_compress_if_exists 'SRR24557418_1' || true)"
gz2="$(_compress_if_exists 'SRR24557418_2' || true)"
gzs="$(_compress_if_exists 'SRR24557418' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-8_S8_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557419"
gz1="$(_compress_if_exists 'SRR24557419_1' || true)"
gz2="$(_compress_if_exists 'SRR24557419_2' || true)"
gzs="$(_compress_if_exists 'SRR24557419' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-7_S7_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557420"
gz1="$(_compress_if_exists 'SRR24557420_1' || true)"
gz2="$(_compress_if_exists 'SRR24557420_2' || true)"
gzs="$(_compress_if_exists 'SRR24557420' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-6_S6_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557421"
gz1="$(_compress_if_exists 'SRR24557421_1' || true)"
gz2="$(_compress_if_exists 'SRR24557421_2' || true)"
gzs="$(_compress_if_exists 'SRR24557421' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-5_S5_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557422"
gz1="$(_compress_if_exists 'SRR24557422_1' || true)"
gz2="$(_compress_if_exists 'SRR24557422_2' || true)"
gzs="$(_compress_if_exists 'SRR24557422' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-4_S4_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557423"
gz1="$(_compress_if_exists 'SRR24557423_1' || true)"
gz2="$(_compress_if_exists 'SRR24557423_2' || true)"
gzs="$(_compress_if_exists 'SRR24557423' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-3_S3_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557424"
gz1="$(_compress_if_exists 'SRR24557424_1' || true)"
gz2="$(_compress_if_exists 'SRR24557424_2' || true)"
gzs="$(_compress_if_exists 'SRR24557424' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-2_S2_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557425"
gz1="$(_compress_if_exists 'SRR24557425_1' || true)"
gz2="$(_compress_if_exists 'SRR24557425_2' || true)"
gzs="$(_compress_if_exists 'SRR24557425' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HM-OT-1_S1_L001_R1_001.fastq.gz"
fi

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557412/SRR24557412"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557413/SRR24557413"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557414/SRR24557414"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557415/SRR24557415"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557416/SRR24557416"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557417/SRR24557417"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557418/SRR24557418"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557419/SRR24557419"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557420/SRR24557420"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557421/SRR24557421"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557422/SRR24557422"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557423/SRR24557423"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557424/SRR24557424"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557425/SRR24557425"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557426/SRR24557426"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557427/SRR24557427"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557428/SRR24557428"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557429/SRR24557429"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557430/SRR24557430"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557431/SRR24557431"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557432/SRR24557432"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557433/SRR24557433"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557434/SRR24557434"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557435/SRR24557435"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557436/SRR24557436"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557437/SRR24557437"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557438/SRR24557438"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557439/SRR24557439"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557440/SRR24557440"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557441/SRR24557441"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557441/SRR24557441"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557440/SRR24557440"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557439/SRR24557439"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557438/SRR24557438"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557437/SRR24557437"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557436/SRR24557436"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557435/SRR24557435"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557434/SRR24557434"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557433/SRR24557433"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557432/SRR24557432"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557431/SRR24557431"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557430/SRR24557430"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557429/SRR24557429"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557428/SRR24557428"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557427/SRR24557427"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557426/SRR24557426"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557416/SRR24557416"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557415/SRR24557415"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557414/SRR24557414"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557413/SRR24557413"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557412/SRR24557412"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557425/SRR24557425"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557424/SRR24557424"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557423/SRR24557423"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557422/SRR24557422"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557421/SRR24557421"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557420/SRR24557420"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557419/SRR24557419"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557418/SRR24557418"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557417/SRR24557417"

echo "Download complete. Files saved to $OUTDIR"