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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE153nnn/GSE153264/suppl/GSE153264_0hr_v_24hr_gene_exp.diff.gz" -O "GSE153264_0hr_v_24hr_gene_exp.diff.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE153nnn/GSE153264/suppl/GSE153264_0hr_v_2hr_gene_exp.diff.gz" -O "GSE153264_0hr_v_2hr_gene_exp.diff.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE153nnn/GSE153264/suppl/GSE153264_0hr_v_4hr_gene_exp.diff.gz" -O "GSE153264_0hr_v_4hr_gene_exp.diff.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE153nnn/GSE153264/suppl/GSE153264_0hr_v_8hr_gene_exp.diff.gz" -O "GSE153264_0hr_v_8hr_gene_exp.diff.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE153nnn/GSE153264/suppl/GSE153264_CD34_DMSO_v_dTAG-4hr_gene_exp.diff.gz" -O "GSE153264_CD34_DMSO_v_dTAG-4hr_gene_exp.diff.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE153nnn/GSE153264/suppl/GSE153264_parental_v_0hr_gene_exp.diff.gz" -O "GSE153264_parental_v_0hr_gene_exp.diff.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 "SRR12091803"
gz1="$(_compress_if_exists 'SRR12091803_1' || true)"
gz2="$(_compress_if_exists 'SRR12091803_2' || true)"
gzs="$(_compress_if_exists 'SRR12091803' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-1-ATTACTCG-TAAGATTA_S1_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091804"
gz1="$(_compress_if_exists 'SRR12091804_1' || true)"
gz2="$(_compress_if_exists 'SRR12091804_2' || true)"
gzs="$(_compress_if_exists 'SRR12091804' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-2-TCCGGAGA-TAAGATTA_S2_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091805"
gz1="$(_compress_if_exists 'SRR12091805_1' || true)"
gz2="$(_compress_if_exists 'SRR12091805_2' || true)"
gzs="$(_compress_if_exists 'SRR12091805' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-3-CGCTCATT-TAAGATTA_S3_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091806"
gz1="$(_compress_if_exists 'SRR12091806_1' || true)"
gz2="$(_compress_if_exists 'SRR12091806_2' || true)"
gzs="$(_compress_if_exists 'SRR12091806' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-4-GAGATTCC-TAAGATTA_S4_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091807"
gz1="$(_compress_if_exists 'SRR12091807_1' || true)"
gz2="$(_compress_if_exists 'SRR12091807_2' || true)"
gzs="$(_compress_if_exists 'SRR12091807' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-5-ATTCAGAA-TAAGATTA_S5_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091808"
gz1="$(_compress_if_exists 'SRR12091808_1' || true)"
gz2="$(_compress_if_exists 'SRR12091808_2' || true)"
gzs="$(_compress_if_exists 'SRR12091808' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-6-GAATTCGT-TAAGATTA_S6_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091809"
gz1="$(_compress_if_exists 'SRR12091809_1' || true)"
gz2="$(_compress_if_exists 'SRR12091809_2' || true)"
gzs="$(_compress_if_exists 'SRR12091809' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-7-CTGAAGCT-TAAGATTA_S7_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091810"
gz1="$(_compress_if_exists 'SRR12091810_1' || true)"
gz2="$(_compress_if_exists 'SRR12091810_2' || true)"
gzs="$(_compress_if_exists 'SRR12091810' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-8-TAATGCGC-TAAGATTA_S8_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091811"
gz1="$(_compress_if_exists 'SRR12091811_1' || true)"
gz2="$(_compress_if_exists 'SRR12091811_2' || true)"
gzs="$(_compress_if_exists 'SRR12091811' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-9-CGGCTATG-TAAGATTA_S9_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091812"
gz1="$(_compress_if_exists 'SRR12091812_1' || true)"
gz2="$(_compress_if_exists 'SRR12091812_2' || true)"
gzs="$(_compress_if_exists 'SRR12091812' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-10-TCCGCGAA-TAAGATTA_S10_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091813"
gz1="$(_compress_if_exists 'SRR12091813_1' || true)"
gz2="$(_compress_if_exists 'SRR12091813_2' || true)"
gzs="$(_compress_if_exists 'SRR12091813' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-11-TCTCGCGC-TAAGATTA_S11_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091814"
gz1="$(_compress_if_exists 'SRR12091814_1' || true)"
gz2="$(_compress_if_exists 'SRR12091814_2' || true)"
gzs="$(_compress_if_exists 'SRR12091814' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2023-KS-12-AGCGATAG-TAAGATTA_S12_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091815"
gz1="$(_compress_if_exists 'SRR12091815_1' || true)"
gz2="$(_compress_if_exists 'SRR12091815_2' || true)"
gzs="$(_compress_if_exists 'SRR12091815' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "4582-KS-1_S9_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "4582-KS-1_S9_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091816"
gz1="$(_compress_if_exists 'SRR12091816_1' || true)"
gz2="$(_compress_if_exists 'SRR12091816_2' || true)"
gzs="$(_compress_if_exists 'SRR12091816' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "4582-KS-2_S10_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "4582-KS-2_S10_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091817"
gz1="$(_compress_if_exists 'SRR12091817_1' || true)"
gz2="$(_compress_if_exists 'SRR12091817_2' || true)"
gzs="$(_compress_if_exists 'SRR12091817' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "4582-KS-3_S11_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "4582-KS-3_S11_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12091818"
gz1="$(_compress_if_exists 'SRR12091818_1' || true)"
gz2="$(_compress_if_exists 'SRR12091818_2' || true)"
gzs="$(_compress_if_exists 'SRR12091818' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "4582-KS-4_S12_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "4582-KS-4_S12_L005_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/SRR12091803/SRR12091803"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091804/SRR12091804"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091805/SRR12091805"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091806/SRR12091806"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091807/SRR12091807"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091808/SRR12091808"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091809/SRR12091809"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091810/SRR12091810"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091811/SRR12091811"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091812/SRR12091812"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091813/SRR12091813"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091814/SRR12091814"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091815/SRR12091815"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091816/SRR12091816"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091817/SRR12091817"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091818/SRR12091818"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091812/SRR12091812"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091813/SRR12091813"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091814/SRR12091814"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091803/SRR12091803"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091804/SRR12091804"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091805/SRR12091805"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091806/SRR12091806"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091807/SRR12091807"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091808/SRR12091808"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091809/SRR12091809"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091810/SRR12091810"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091811/SRR12091811"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091815/SRR12091815"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091816/SRR12091816"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091817/SRR12091817"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12091818/SRR12091818"

echo "Download complete. Files saved to $OUTDIR"