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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE185nnn/GSE185373/suppl/GSE185373_RAW.tar" -O "GSE185373_RAW.tar"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE185nnn/GSE185373/suppl/GSE185373_RNAseq_counts_raw.csv.gz" -O "GSE185373_RNAseq_counts_raw.csv.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 "SRR16207034"
gz1="$(_compress_if_exists 'SRR16207034_1' || true)"
gz2="$(_compress_if_exists 'SRR16207034_2' || true)"
gzs="$(_compress_if_exists 'SRR16207034' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "DMSO-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "DMSO-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207035"
gz1="$(_compress_if_exists 'SRR16207035_1' || true)"
gz2="$(_compress_if_exists 'SRR16207035_2' || true)"
gzs="$(_compress_if_exists 'SRR16207035' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "DMSO-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "DMSO-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207036"
gz1="$(_compress_if_exists 'SRR16207036_1' || true)"
gz2="$(_compress_if_exists 'SRR16207036_2' || true)"
gzs="$(_compress_if_exists 'SRR16207036' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "DMSO-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "DMSO-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207037"
gz1="$(_compress_if_exists 'SRR16207037_1' || true)"
gz2="$(_compress_if_exists 'SRR16207037_2' || true)"
gzs="$(_compress_if_exists 'SRR16207037' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PB-10nM-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PB-10nM-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207038"
gz1="$(_compress_if_exists 'SRR16207038_1' || true)"
gz2="$(_compress_if_exists 'SRR16207038_2' || true)"
gzs="$(_compress_if_exists 'SRR16207038' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PB-10nM-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PB-10nM-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207039"
gz1="$(_compress_if_exists 'SRR16207039_1' || true)"
gz2="$(_compress_if_exists 'SRR16207039_2' || true)"
gzs="$(_compress_if_exists 'SRR16207039' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PB-10nM-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PB-10nM-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207040"
gz1="$(_compress_if_exists 'SRR16207040_1' || true)"
gz2="$(_compress_if_exists 'SRR16207040_2' || true)"
gzs="$(_compress_if_exists 'SRR16207040' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-23-1uM-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-23-1uM-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207041"
gz1="$(_compress_if_exists 'SRR16207041_1' || true)"
gz2="$(_compress_if_exists 'SRR16207041_2' || true)"
gzs="$(_compress_if_exists 'SRR16207041' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-23-1uM-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-23-1uM-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207042"
gz1="$(_compress_if_exists 'SRR16207042_1' || true)"
gz2="$(_compress_if_exists 'SRR16207042_2' || true)"
gzs="$(_compress_if_exists 'SRR16207042' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-23-1uM-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-23-1uM-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207043"
gz1="$(_compress_if_exists 'SRR16207043_1' || true)"
gz2="$(_compress_if_exists 'SRR16207043_2' || true)"
gzs="$(_compress_if_exists 'SRR16207043' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-23-5uM-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-23-5uM-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207044"
gz1="$(_compress_if_exists 'SRR16207044_1' || true)"
gz2="$(_compress_if_exists 'SRR16207044_2' || true)"
gzs="$(_compress_if_exists 'SRR16207044' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-23-5uM-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-23-5uM-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207045"
gz1="$(_compress_if_exists 'SRR16207045_1' || true)"
gz2="$(_compress_if_exists 'SRR16207045_2' || true)"
gzs="$(_compress_if_exists 'SRR16207045' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-23-5uM-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-23-5uM-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207046"
gz1="$(_compress_if_exists 'SRR16207046_1' || true)"
gz2="$(_compress_if_exists 'SRR16207046_2' || true)"
gzs="$(_compress_if_exists 'SRR16207046' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-43-5uM-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-43-5uM-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207047"
gz1="$(_compress_if_exists 'SRR16207047_1' || true)"
gz2="$(_compress_if_exists 'SRR16207047_2' || true)"
gzs="$(_compress_if_exists 'SRR16207047' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-43-5uM-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-43-5uM-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16207048"
gz1="$(_compress_if_exists 'SRR16207048_1' || true)"
gz2="$(_compress_if_exists 'SRR16207048_2' || true)"
gzs="$(_compress_if_exists 'SRR16207048' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WX-02-43-5uM-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WX-02-43-5uM-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919523"
gz1="$(_compress_if_exists 'SRR16919523_1' || true)"
gz2="$(_compress_if_exists 'SRR16919523_2' || true)"
gzs="$(_compress_if_exists 'SRR16919523' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "DMSO-2h-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "DMSO-2h-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919524"
gz1="$(_compress_if_exists 'SRR16919524_1' || true)"
gz2="$(_compress_if_exists 'SRR16919524_2' || true)"
gzs="$(_compress_if_exists 'SRR16919524' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "DMSO-2h-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "DMSO-2h-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919525"
gz1="$(_compress_if_exists 'SRR16919525_1' || true)"
gz2="$(_compress_if_exists 'SRR16919525_2' || true)"
gzs="$(_compress_if_exists 'SRR16919525' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "DMSO-2h-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "DMSO-2h-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919526"
gz1="$(_compress_if_exists 'SRR16919526_1' || true)"
gz2="$(_compress_if_exists 'SRR16919526_2' || true)"
gzs="$(_compress_if_exists 'SRR16919526' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KB02-2h-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KB02-2h-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919527"
gz1="$(_compress_if_exists 'SRR16919527_1' || true)"
gz2="$(_compress_if_exists 'SRR16919527_2' || true)"
gzs="$(_compress_if_exists 'SRR16919527' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KB02-2h-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KB02-2h-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919528"
gz1="$(_compress_if_exists 'SRR16919528_1' || true)"
gz2="$(_compress_if_exists 'SRR16919528_2' || true)"
gzs="$(_compress_if_exists 'SRR16919528' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KB02-2h-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KB02-2h-3_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919529"
gz1="$(_compress_if_exists 'SRR16919529_1' || true)"
gz2="$(_compress_if_exists 'SRR16919529_2' || true)"
gzs="$(_compress_if_exists 'SRR16919529' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KB05-2h-1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KB05-2h-1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919530"
gz1="$(_compress_if_exists 'SRR16919530_1' || true)"
gz2="$(_compress_if_exists 'SRR16919530_2' || true)"
gzs="$(_compress_if_exists 'SRR16919530' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KB05-2h-2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KB05-2h-2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR16919531"
gz1="$(_compress_if_exists 'SRR16919531_1' || true)"
gz2="$(_compress_if_exists 'SRR16919531_2' || true)"
gzs="$(_compress_if_exists 'SRR16919531' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KB05-2h-3_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KB05-2h-3_R2_001.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207034/SRR16207034"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207035/SRR16207035"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207036/SRR16207036"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207037/SRR16207037"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207038/SRR16207038"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207039/SRR16207039"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207040/SRR16207040"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207041/SRR16207041"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207042/SRR16207042"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207043/SRR16207043"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207044/SRR16207044"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207045/SRR16207045"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207046/SRR16207046"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207047/SRR16207047"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207048/SRR16207048"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919523/SRR16919523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919524/SRR16919524"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919525/SRR16919525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919526/SRR16919526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919527/SRR16919527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919528/SRR16919528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919529/SRR16919529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919530/SRR16919530"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919531/SRR16919531"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207034/SRR16207034"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919523/SRR16919523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919524/SRR16919524"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919525/SRR16919525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207035/SRR16207035"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207036/SRR16207036"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919526/SRR16919526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919527/SRR16919527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919528/SRR16919528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919529/SRR16919529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919530/SRR16919530"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16919531/SRR16919531"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207037/SRR16207037"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207038/SRR16207038"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207039/SRR16207039"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207040/SRR16207040"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207041/SRR16207041"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207042/SRR16207042"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207043/SRR16207043"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207044/SRR16207044"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207045/SRR16207045"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207046/SRR16207046"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207047/SRR16207047"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR16207048/SRR16207048"

echo "Download complete. Files saved to $OUTDIR"