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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_100pg_Buffer_only_confident_peaks.bed.gz" -O "GSE248461_100pg_Buffer_only_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_100pg_RBFOX2_cleaned_confident_peaks.bed.gz" -O "GSE248461_100pg_RBFOX2_cleaned_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_100pg_RBFOX2_confident_peaks.bed.gz" -O "GSE248461_100pg_RBFOX2_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_1ng_Buffer_only_confident_peaks.bed.gz" -O "GSE248461_1ng_Buffer_only_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_1ng_RBFOX2_cleaned_confident_peaks.bed.gz" -O "GSE248461_1ng_RBFOX2_cleaned_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_1ng_RBFOX2_confident_peaks.bed.gz" -O "GSE248461_1ng_RBFOX2_confident_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE248nnn/GSE248461/suppl/GSE248461_RAW.tar" -O "GSE248461_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 "SRR26918582"
gz1="$(_compress_if_exists 'SRR26918582_1' || true)"
gz2="$(_compress_if_exists 'SRR26918582_2' || true)"
gzs="$(_compress_if_exists 'SRR26918582' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "1ng_36_S7_L001_R1_001.fastq.gz"
fi

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

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

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

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

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

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

fasterq-dump --split-files "SRR26918589"
gz1="$(_compress_if_exists 'SRR26918589_1' || true)"
gz2="$(_compress_if_exists 'SRR26918589_2' || true)"
gzs="$(_compress_if_exists 'SRR26918589' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_36_S14_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR26918590"
gz1="$(_compress_if_exists 'SRR26918590_1' || true)"
gz2="$(_compress_if_exists 'SRR26918590_2' || true)"
gzs="$(_compress_if_exists 'SRR26918590' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_35_S13_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR26918591"
gz1="$(_compress_if_exists 'SRR26918591_1' || true)"
gz2="$(_compress_if_exists 'SRR26918591_2' || true)"
gzs="$(_compress_if_exists 'SRR26918591' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_34_S12_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR26918592"
gz1="$(_compress_if_exists 'SRR26918592_1' || true)"
gz2="$(_compress_if_exists 'SRR26918592_2' || true)"
gzs="$(_compress_if_exists 'SRR26918592' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_33_S11_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR26918593"
gz1="$(_compress_if_exists 'SRR26918593_1' || true)"
gz2="$(_compress_if_exists 'SRR26918593_2' || true)"
gzs="$(_compress_if_exists 'SRR26918593' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_21_S10_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR26918594"
gz1="$(_compress_if_exists 'SRR26918594_1' || true)"
gz2="$(_compress_if_exists 'SRR26918594_2' || true)"
gzs="$(_compress_if_exists 'SRR26918594' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_20_S9_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR26918595"
gz1="$(_compress_if_exists 'SRR26918595_1' || true)"
gz2="$(_compress_if_exists 'SRR26918595_2' || true)"
gzs="$(_compress_if_exists 'SRR26918595' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "100pg_19_S8_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/SRR26918582/SRR26918582"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918583/SRR26918583"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918584/SRR26918584"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918585/SRR26918585"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos6/sra-pub-zq-40/SRR026/26918/SRR26918586/SRR26918586.lite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918587/SRR26918587"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918588/SRR26918588"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918589/SRR26918589"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918590/SRR26918590"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918591/SRR26918591"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918592/SRR26918592"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918593/SRR26918593"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918594/SRR26918594"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918595/SRR26918595"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918595/SRR26918595"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918594/SRR26918594"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918593/SRR26918593"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918592/SRR26918592"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918591/SRR26918591"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918590/SRR26918590"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918589/SRR26918589"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918588/SRR26918588"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918587/SRR26918587"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918586/SRR26918586"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918585/SRR26918585"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918584/SRR26918584"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918583/SRR26918583"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR26918582/SRR26918582"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos6/sra-pub-zq-40/SRR026/26918/SRR26918586/SRR26918586.lite.1"

echo "Download complete. Files saved to $OUTDIR"