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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE224nnn/GSE224998/suppl/GSE224998_RAW.tar" -O "GSE224998_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 "SRR23391944"
gz1="$(_compress_if_exists 'SRR23391944_1' || true)"
gz2="$(_compress_if_exists 'SRR23391944_2' || true)"
gzs="$(_compress_if_exists 'SRR23391944' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-WT-3_S6_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391945"
gz1="$(_compress_if_exists 'SRR23391945_1' || true)"
gz2="$(_compress_if_exists 'SRR23391945_2' || true)"
gzs="$(_compress_if_exists 'SRR23391945' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-WT-3_S6_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391946"
gz1="$(_compress_if_exists 'SRR23391946_1' || true)"
gz2="$(_compress_if_exists 'SRR23391946_2' || true)"
gzs="$(_compress_if_exists 'SRR23391946' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-WT-2_S5_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391947"
gz1="$(_compress_if_exists 'SRR23391947_1' || true)"
gz2="$(_compress_if_exists 'SRR23391947_2' || true)"
gzs="$(_compress_if_exists 'SRR23391947' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-WT-2_S5_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391948"
gz1="$(_compress_if_exists 'SRR23391948_1' || true)"
gz2="$(_compress_if_exists 'SRR23391948_2' || true)"
gzs="$(_compress_if_exists 'SRR23391948' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-WT-1_S4_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391949"
gz1="$(_compress_if_exists 'SRR23391949_1' || true)"
gz2="$(_compress_if_exists 'SRR23391949_2' || true)"
gzs="$(_compress_if_exists 'SRR23391949' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-WT-1_S4_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391950"
gz1="$(_compress_if_exists 'SRR23391950_1' || true)"
gz2="$(_compress_if_exists 'SRR23391950_2' || true)"
gzs="$(_compress_if_exists 'SRR23391950' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-62m-3_S9_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391951"
gz1="$(_compress_if_exists 'SRR23391951_1' || true)"
gz2="$(_compress_if_exists 'SRR23391951_2' || true)"
gzs="$(_compress_if_exists 'SRR23391951' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-62m-3_S9_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391952"
gz1="$(_compress_if_exists 'SRR23391952_1' || true)"
gz2="$(_compress_if_exists 'SRR23391952_2' || true)"
gzs="$(_compress_if_exists 'SRR23391952' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-62m-2_S8_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391953"
gz1="$(_compress_if_exists 'SRR23391953_1' || true)"
gz2="$(_compress_if_exists 'SRR23391953_2' || true)"
gzs="$(_compress_if_exists 'SRR23391953' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-62m-2_S8_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391954"
gz1="$(_compress_if_exists 'SRR23391954_1' || true)"
gz2="$(_compress_if_exists 'SRR23391954_2' || true)"
gzs="$(_compress_if_exists 'SRR23391954' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-62m-1_S7_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391955"
gz1="$(_compress_if_exists 'SRR23391955_1' || true)"
gz2="$(_compress_if_exists 'SRR23391955_2' || true)"
gzs="$(_compress_if_exists 'SRR23391955' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-62m-1_S7_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391956"
gz1="$(_compress_if_exists 'SRR23391956_1' || true)"
gz2="$(_compress_if_exists 'SRR23391956_2' || true)"
gzs="$(_compress_if_exists 'SRR23391956' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-101m-3_S12_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391957"
gz1="$(_compress_if_exists 'SRR23391957_1' || true)"
gz2="$(_compress_if_exists 'SRR23391957_2' || true)"
gzs="$(_compress_if_exists 'SRR23391957' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-101m-3_S12_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391958"
gz1="$(_compress_if_exists 'SRR23391958_1' || true)"
gz2="$(_compress_if_exists 'SRR23391958_2' || true)"
gzs="$(_compress_if_exists 'SRR23391958' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-101m-2_S11_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391959"
gz1="$(_compress_if_exists 'SRR23391959_1' || true)"
gz2="$(_compress_if_exists 'SRR23391959_2' || true)"
gzs="$(_compress_if_exists 'SRR23391959' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-101m-2_S11_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391960"
gz1="$(_compress_if_exists 'SRR23391960_1' || true)"
gz2="$(_compress_if_exists 'SRR23391960_2' || true)"
gzs="$(_compress_if_exists 'SRR23391960' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-IN-3_S3_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391961"
gz1="$(_compress_if_exists 'SRR23391961_1' || true)"
gz2="$(_compress_if_exists 'SRR23391961_2' || true)"
gzs="$(_compress_if_exists 'SRR23391961' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-IN-3_S3_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391962"
gz1="$(_compress_if_exists 'SRR23391962_1' || true)"
gz2="$(_compress_if_exists 'SRR23391962_2' || true)"
gzs="$(_compress_if_exists 'SRR23391962' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-IN-2_S2_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391963"
gz1="$(_compress_if_exists 'SRR23391963_1' || true)"
gz2="$(_compress_if_exists 'SRR23391963_2' || true)"
gzs="$(_compress_if_exists 'SRR23391963' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-IN-2_S2_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391964"
gz1="$(_compress_if_exists 'SRR23391964_1' || true)"
gz2="$(_compress_if_exists 'SRR23391964_2' || true)"
gzs="$(_compress_if_exists 'SRR23391964' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-IN-1_S1_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR23391965"
gz1="$(_compress_if_exists 'SRR23391965_1' || true)"
gz2="$(_compress_if_exists 'SRR23391965_2' || true)"
gzs="$(_compress_if_exists 'SRR23391965' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "RPS19-IN-1_S1_L002_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/SRR23391944/SRR23391944"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391945/SRR23391945"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391946/SRR23391946"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391947/SRR23391947"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391948/SRR23391948"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391949/SRR23391949"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391950/SRR23391950"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391951/SRR23391951"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391952/SRR23391952"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391953/SRR23391953"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391954/SRR23391954"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391955/SRR23391955"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391956/SRR23391956"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391957/SRR23391957"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391958/SRR23391958"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391959/SRR23391959"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391960/SRR23391960"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391961/SRR23391961"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391962/SRR23391962"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391963/SRR23391963"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391964/SRR23391964"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391965/SRR23391965"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391958/SRR23391958"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391959/SRR23391959"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391956/SRR23391956"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391957/SRR23391957"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391954/SRR23391954"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391955/SRR23391955"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391952/SRR23391952"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391953/SRR23391953"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391950/SRR23391950"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391951/SRR23391951"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391964/SRR23391964"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391965/SRR23391965"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391962/SRR23391962"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391963/SRR23391963"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391960/SRR23391960"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391961/SRR23391961"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391948/SRR23391948"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391949/SRR23391949"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391946/SRR23391946"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391947/SRR23391947"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391944/SRR23391944"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR23391945/SRR23391945"

echo "Download complete. Files saved to $OUTDIR"