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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE220nnn/GSE220185/suppl/GSE220185_DDX42_DMSO.reproducible_enriched_windows.tsv.gz" -O "GSE220185_DDX42_DMSO.reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE220nnn/GSE220185/suppl/GSE220185_DDX42_PladB.reproducible_enriched_windows.tsv.gz" -O "GSE220185_DDX42_PladB.reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE220nnn/GSE220185/suppl/GSE220185_DDX42_WX-2-23.reproducible_enriched_windows.tsv.gz" -O "GSE220185_DDX42_WX-2-23.reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE220nnn/GSE220185/suppl/GSE220185_DDX42_WX-2-43.reproducible_enriched_windows.tsv.gz" -O "GSE220185_DDX42_WX-2-43.reproducible_enriched_windows.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE220nnn/GSE220185/suppl/GSE220185_RAW.tar" -O "GSE220185_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 "SRR22544216"
gz1="$(_compress_if_exists 'SRR22544216_1' || true)"
gz2="$(_compress_if_exists 'SRR22544216_2' || true)"
gzs="$(_compress_if_exists 'SRR22544216' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_PladB.CLIP2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544217"
gz1="$(_compress_if_exists 'SRR22544217_1' || true)"
gz2="$(_compress_if_exists 'SRR22544217_2' || true)"
gzs="$(_compress_if_exists 'SRR22544217' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_PladB.Input2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544218"
gz1="$(_compress_if_exists 'SRR22544218_1' || true)"
gz2="$(_compress_if_exists 'SRR22544218_2' || true)"
gzs="$(_compress_if_exists 'SRR22544218' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_PladB.CLIP1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544219"
gz1="$(_compress_if_exists 'SRR22544219_1' || true)"
gz2="$(_compress_if_exists 'SRR22544219_2' || true)"
gzs="$(_compress_if_exists 'SRR22544219' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_PladB.Input1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544220"
gz1="$(_compress_if_exists 'SRR22544220_1' || true)"
gz2="$(_compress_if_exists 'SRR22544220_2' || true)"
gzs="$(_compress_if_exists 'SRR22544220' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-43.CLIP2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544221"
gz1="$(_compress_if_exists 'SRR22544221_1' || true)"
gz2="$(_compress_if_exists 'SRR22544221_2' || true)"
gzs="$(_compress_if_exists 'SRR22544221' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-43.Input2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544222"
gz1="$(_compress_if_exists 'SRR22544222_1' || true)"
gz2="$(_compress_if_exists 'SRR22544222_2' || true)"
gzs="$(_compress_if_exists 'SRR22544222' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-43.CLIP1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544223"
gz1="$(_compress_if_exists 'SRR22544223_1' || true)"
gz2="$(_compress_if_exists 'SRR22544223_2' || true)"
gzs="$(_compress_if_exists 'SRR22544223' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-43.Input1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544224"
gz1="$(_compress_if_exists 'SRR22544224_1' || true)"
gz2="$(_compress_if_exists 'SRR22544224_2' || true)"
gzs="$(_compress_if_exists 'SRR22544224' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-23.CLIP2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544225"
gz1="$(_compress_if_exists 'SRR22544225_1' || true)"
gz2="$(_compress_if_exists 'SRR22544225_2' || true)"
gzs="$(_compress_if_exists 'SRR22544225' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-23.Input2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544226"
gz1="$(_compress_if_exists 'SRR22544226_1' || true)"
gz2="$(_compress_if_exists 'SRR22544226_2' || true)"
gzs="$(_compress_if_exists 'SRR22544226' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-23.CLIP1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544227"
gz1="$(_compress_if_exists 'SRR22544227_1' || true)"
gz2="$(_compress_if_exists 'SRR22544227_2' || true)"
gzs="$(_compress_if_exists 'SRR22544227' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_WX-2-23.Input1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544228"
gz1="$(_compress_if_exists 'SRR22544228_1' || true)"
gz2="$(_compress_if_exists 'SRR22544228_2' || true)"
gzs="$(_compress_if_exists 'SRR22544228' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_DMSO.CLIP2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544229"
gz1="$(_compress_if_exists 'SRR22544229_1' || true)"
gz2="$(_compress_if_exists 'SRR22544229_2' || true)"
gzs="$(_compress_if_exists 'SRR22544229' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_DMSO.Input2.fastq.gz"
fi

fasterq-dump --split-files "SRR22544230"
gz1="$(_compress_if_exists 'SRR22544230_1' || true)"
gz2="$(_compress_if_exists 'SRR22544230_2' || true)"
gzs="$(_compress_if_exists 'SRR22544230' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_DMSO.CLIP1.fastq.gz"
fi

fasterq-dump --split-files "SRR22544231"
gz1="$(_compress_if_exists 'SRR22544231_1' || true)"
gz2="$(_compress_if_exists 'SRR22544231_2' || true)"
gzs="$(_compress_if_exists 'SRR22544231' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "DDX42_DMSO.Input1.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544216/SRR22544216"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544217/SRR22544217"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544218/SRR22544218"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544219/SRR22544219"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544220/SRR22544220"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544221/SRR22544221"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544222/SRR22544222"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544223/SRR22544223"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544224/SRR22544224"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544225/SRR22544225"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544226/SRR22544226"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos10/sra-pub-zq-1002/SRR022/22544/SRR22544227/SRR22544227.lite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544228/SRR22544228"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544229/SRR22544229"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544230/SRR22544230"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544231/SRR22544231"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544230/SRR22544230"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544228/SRR22544228"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544231/SRR22544231"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544229/SRR22544229"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544218/SRR22544218"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544216/SRR22544216"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544219/SRR22544219"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544217/SRR22544217"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544226/SRR22544226"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544224/SRR22544224"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544225/SRR22544225"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544222/SRR22544222"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544220/SRR22544220"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544223/SRR22544223"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR22544221/SRR22544221"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos10/sra-pub-zq-1002/SRR022/22544/SRR22544227/SRR22544227.lite.1"

echo "Download complete. Files saved to $OUTDIR"