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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE78nnn/GSE78507/suppl/GSE78507_RAW.tar" -O "GSE78507_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 "SRR3187400"
gz1="$(_compress_if_exists 'SRR3187400_1' || true)"
gz2="$(_compress_if_exists 'SRR3187400_2' || true)"
gzs="$(_compress_if_exists 'SRR3187400' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan-1to25-Imp1_S16_R1.A01_Stefan_1to25_Imp1_IGF2BP1.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan-1to25-Imp1_S16_R2.A01_Stefan_1to25_Imp1_IGF2BP1.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187401"
gz1="$(_compress_if_exists 'SRR3187401_1' || true)"
gz2="$(_compress_if_exists 'SRR3187401_2' || true)"
gzs="$(_compress_if_exists 'SRR3187401' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan-1to25-Imp1_S16_R1.B06_Stefan_1to25_Imp1_IGF2BP1.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan-1to25-Imp1_S16_R2.B06_Stefan_1to25_Imp1_IGF2BP1.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187402"
gz1="$(_compress_if_exists 'SRR3187402_1' || true)"
gz2="$(_compress_if_exists 'SRR3187402_2' || true)"
gzs="$(_compress_if_exists 'SRR3187402' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan-1to25-Imp2_S17_R1.C01_Stefan_1to25_Imp2_IGF2BP2.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan-1to25-Imp2_S17_R2.C01_Stefan_1to25_Imp2_IGF2BP2.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187403"
gz1="$(_compress_if_exists 'SRR3187403_1' || true)"
gz2="$(_compress_if_exists 'SRR3187403_2' || true)"
gzs="$(_compress_if_exists 'SRR3187403' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan-1to25-Imp2_S17_R1.D08fixed_Stefan_1to25_Imp2_IGF2BP2.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan-1to25-Imp2_S17_R2.D08fixed_Stefan_1to25_Imp2_IGF2BP2.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187404"
gz1="$(_compress_if_exists 'SRR3187404_1' || true)"
gz2="$(_compress_if_exists 'SRR3187404_2' || true)"
gzs="$(_compress_if_exists 'SRR3187404' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan-1to25-Input_S15_R1.unassigned.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan-1to25-Input_S15_R2.unassigned.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187405"
gz1="$(_compress_if_exists 'SRR3187405_1' || true)"
gz2="$(_compress_if_exists 'SRR3187405_2' || true)"
gzs="$(_compress_if_exists 'SRR3187405' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IGF2BP1_040915_TCCGGAGA-ATAGAGGC_R1.A01_Stefan_IGF2BP1_040915_IGF2BP1.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IGF2BP1_040915_TCCGGAGA-ATAGAGGC_R2.A01_Stefan_IGF2BP1_040915_IGF2BP1.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187406"
gz1="$(_compress_if_exists 'SRR3187406_1' || true)"
gz2="$(_compress_if_exists 'SRR3187406_2' || true)"
gzs="$(_compress_if_exists 'SRR3187406' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IGF2BP1_040915_TCCGGAGA-ATAGAGGC_R1.B06_Stefan_IGF2BP1_040915_IGF2BP1.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IGF2BP1_040915_TCCGGAGA-ATAGAGGC_R2.B06_Stefan_IGF2BP1_040915_IGF2BP1.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187407"
gz1="$(_compress_if_exists 'SRR3187407_1' || true)"
gz2="$(_compress_if_exists 'SRR3187407_2' || true)"
gzs="$(_compress_if_exists 'SRR3187407' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IGF2BP2_040915_GAGATTCC-CCTATCCT_R1.C01_Stefan_IGF2BP2_040915_IGF2BP2.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IGF2BP2_040915_GAGATTCC-CCTATCCT_R2.C01_Stefan_IGF2BP2_040915_IGF2BP2.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187408"
gz1="$(_compress_if_exists 'SRR3187408_1' || true)"
gz2="$(_compress_if_exists 'SRR3187408_2' || true)"
gzs="$(_compress_if_exists 'SRR3187408' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IGF2BP2_040915_GAGATTCC-CCTATCCT_R1.D08fixed_Stefan_IGF2BP2_040915_IGF2BP2.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IGF2BP2_040915_GAGATTCC-CCTATCCT_R2.D08fixed_Stefan_IGF2BP2_040915_IGF2BP2.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187409"
gz1="$(_compress_if_exists 'SRR3187409_1' || true)"
gz2="$(_compress_if_exists 'SRR3187409_2' || true)"
gzs="$(_compress_if_exists 'SRR3187409' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IGF2BP3_040915_TCCGGAGA-TATAGCCT_R1.C01_Stefan_IGF2BP3_040915_IGF2BP3.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IGF2BP3_040915_TCCGGAGA-TATAGCCT_R2.C01_Stefan_IGF2BP3_040915_IGF2BP3.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187410"
gz1="$(_compress_if_exists 'SRR3187410_1' || true)"
gz2="$(_compress_if_exists 'SRR3187410_2' || true)"
gzs="$(_compress_if_exists 'SRR3187410' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IGF2BP3_040915_TCCGGAGA-TATAGCCT_R1.D08fixed_Stefan_IGF2BP3_040915_IGF2BP3.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IGF2BP3_040915_TCCGGAGA-TATAGCCT_R2.D08fixed_Stefan_IGF2BP3_040915_IGF2BP3.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187411"
gz1="$(_compress_if_exists 'SRR3187411_1' || true)"
gz2="$(_compress_if_exists 'SRR3187411_2' || true)"
gzs="$(_compress_if_exists 'SRR3187411' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IgG_040915_ATTACTCG-TATAGCCT_R1.A01_Stefan_IgG_040915_IgG.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IgG_040915_ATTACTCG-TATAGCCT_R2.A01_Stefan_IgG_040915_IgG.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187412"
gz1="$(_compress_if_exists 'SRR3187412_1' || true)"
gz2="$(_compress_if_exists 'SRR3187412_2' || true)"
gzs="$(_compress_if_exists 'SRR3187412' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_IgG_040915_ATTACTCG-TATAGCCT_R1.B06_Stefan_IgG_040915_IgG.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_IgG_040915_ATTACTCG-TATAGCCT_R2.B06_Stefan_IgG_040915_IgG.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187413"
gz1="$(_compress_if_exists 'SRR3187413_1' || true)"
gz2="$(_compress_if_exists 'SRR3187413_2' || true)"
gzs="$(_compress_if_exists 'SRR3187413' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Stefan_Input_040915_GAGATTCC-ATAGAGGC_R1.unassigned.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Stefan_Input_040915_GAGATTCC-ATAGAGGC_R2.unassigned.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187414"
gz1="$(_compress_if_exists 'SRR3187414_1' || true)"
gz2="$(_compress_if_exists 'SRR3187414_2' || true)"
gzs="$(_compress_if_exists 'SRR3187414' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "FOX2-H1ES_S9_R1.A01_RBFOX2_H1ES_1to25_RBFOX2.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "FOX2-H1ES_S9_R2.A01_RBFOX2_H1ES_1to25_RBFOX2.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187415"
gz1="$(_compress_if_exists 'SRR3187415_1' || true)"
gz2="$(_compress_if_exists 'SRR3187415_2' || true)"
gzs="$(_compress_if_exists 'SRR3187415' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "FOX2-H1ES_S9_R1.B06_RBFOX2_H1ES_1to25_RBFOX2.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "FOX2-H1ES_S9_R2.B06_RBFOX2_H1ES_1to25_RBFOX2.randomer.fastq.gz"
fi

fasterq-dump --split-files "SRR3187416"
gz1="$(_compress_if_exists 'SRR3187416_1' || true)"
gz2="$(_compress_if_exists 'SRR3187416_2' || true)"
gzs="$(_compress_if_exists 'SRR3187416' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "SF3B4_H1_INPUT_ATTACTCG-CCTATCCT_L005_R1.unassigned.randomer.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "SF3B4_H1_INPUT_ATTACTCG-CCTATCCT_L005_R2.unassigned.randomer.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187400/SRR3187400"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187401/SRR3187401"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187402/SRR3187402"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187403/SRR3187403"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187404/SRR3187404"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187405/SRR3187405"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187406/SRR3187406"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187407/SRR3187407"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187408/SRR3187408"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187409/SRR3187409"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187410/SRR3187410"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187411/SRR3187411"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187412/SRR3187412"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187413/SRR3187413"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187414/SRR3187414"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187415/SRR3187415"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187416/SRR3187416"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187414/SRR3187414"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187415/SRR3187415"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187416/SRR3187416"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187400/SRR3187400"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187401/SRR3187401"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187402/SRR3187402"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187403/SRR3187403"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187404/SRR3187404"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187405/SRR3187405"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187406/SRR3187406"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187407/SRR3187407"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187408/SRR3187408"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187409/SRR3187409"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187410/SRR3187410"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187411/SRR3187411"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187412/SRR3187412"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3187413/SRR3187413"

echo "Download complete. Files saved to $OUTDIR"