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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_100pg_Enzyme_only_cleaned_confident_peaks.bed.gz" -O "GSE263371_100pg_Enzyme_only_cleaned_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_100pg_Enzyme_only_confident_peaks.bed.gz" -O "GSE263371_100pg_Enzyme_only_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_1ng_Enzyme_only_cleaned_confident_peaks.bed.gz" -O "GSE263371_1ng_Enzyme_only_cleaned_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_1ng_Enzyme_only_confident_peaks.bed.gz" -O "GSE263371_1ng_Enzyme_only_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_Buffer_only_PFA_confident_peaks.bed.gz" -O "GSE263371_Buffer_only_PFA_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_Enzyme_only_PFA_cleaned_confident_peaks.bed.gz" -O "GSE263371_Enzyme_only_PFA_cleaned_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_Enzyme_only_PFA_confident_peaks.bed.gz" -O "GSE263371_Enzyme_only_PFA_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_RAW.tar" -O "GSE263371_RAW.tar"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_RBFOX2_INSCRIBE_PFA_cleaned_confident_peaks.bed.gz" -O "GSE263371_RBFOX2_INSCRIBE_PFA_cleaned_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE263nnn/GSE263371/suppl/GSE263371_RBFOX2_INSCRIBE_PFA_confident_peaks.bed.gz" -O "GSE263371_RBFOX2_INSCRIBE_PFA_confident_peaks.bed.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 "SRR28574783"
gz1="$(_compress_if_exists 'SRR28574783_1' || true)"
gz2="$(_compress_if_exists 'SRR28574783_2' || true)"
gzs="$(_compress_if_exists 'SRR28574783' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "isSTAMP15_09_S9_L001_R1_001.fastq.gz"
fi

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

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

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

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

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

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

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

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

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

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

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

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

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

fasterq-dump --split-files "SRR28574797"
gz1="$(_compress_if_exists 'SRR28574797_1' || true)"
gz2="$(_compress_if_exists 'SRR28574797_2' || true)"
gzs="$(_compress_if_exists 'SRR28574797' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "isSTAMP08_sd_01_S10_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/SRR28574783/SRR28574783"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574784/SRR28574784"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574785/SRR28574785"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574786/SRR28574786"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574787/SRR28574787"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574788/SRR28574788"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574789/SRR28574789"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574790/SRR28574790"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574791/SRR28574791"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574792/SRR28574792"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574793/SRR28574793"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574794/SRR28574794"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574795/SRR28574795"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574796/SRR28574796"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574797/SRR28574797"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574797/SRR28574797"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574796/SRR28574796"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574795/SRR28574795"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574794/SRR28574794"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574793/SRR28574793"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574792/SRR28574792"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574791/SRR28574791"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574790/SRR28574790"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574789/SRR28574789"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574788/SRR28574788"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574787/SRR28574787"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574786/SRR28574786"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574785/SRR28574785"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574784/SRR28574784"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28574783/SRR28574783"

echo "Download complete. Files saved to $OUTDIR"