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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE112nnn/GSE112383/suppl/GSE112383_Samples_DDX_TEs_complete_RPKM_table.txt.gz" -O "GSE112383_Samples_DDX_TEs_complete_RPKM_table.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE112nnn/GSE112383/suppl/GSE112383_Samples_naive_complete_RPKM_table.txt.gz" -O "GSE112383_Samples_naive_complete_RPKM_table.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE112nnn/GSE112383/suppl/GSE112383_Samples_sgDDX6_complete_RPKM_table.txt.gz" -O "GSE112383_Samples_sgDDX6_complete_RPKM_table.txt.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 "SRR6903969"
gz1="$(_compress_if_exists 'SRR6903969_1' || true)"
gz2="$(_compress_if_exists 'SRR6903969_2' || true)"
gzs="$(_compress_if_exists 'SRR6903969' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "WIBR3_shCTRL_rep1.fastq.gz"
fi

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903969/SRR6903969"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903970/SRR6903970"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903971/SRR6903971"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903972/SRR6903972"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903974/SRR6903974"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903976/SRR6903976"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903977/SRR6903977"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903978/SRR6903978"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903979/SRR6903979"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903980/SRR6903980"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903981/SRR6903981"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903982/SRR6903982"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903983/SRR6903983"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903984/SRR6903984"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903985/SRR6903985"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903986/SRR6903986"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903987/SRR6903987"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903988/SRR6903988"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903974/SRR6903974"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903976/SRR6903976"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903983/SRR6903983"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903984/SRR6903984"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903977/SRR6903977"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903978/SRR6903978"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903985/SRR6903985"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903986/SRR6903986"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903987/SRR6903987"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903988/SRR6903988"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903969/SRR6903969"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903970/SRR6903970"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903979/SRR6903979"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903980/SRR6903980"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903971/SRR6903971"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903972/SRR6903972"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903981/SRR6903981"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR6903982/SRR6903982"

echo "Download complete. Files saved to $OUTDIR"