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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE78nnn/GSE78959/suppl/GSE78959_TSC2-cellModel_RNA.txt.gz" -O "GSE78959_TSC2-cellModel_RNA.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE78nnn/GSE78959/suppl/GSE78959_TSC2-cellModel_RPF.txt.gz" -O "GSE78959_TSC2-cellModel_RPF.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 "SRR3208852"
gz1="$(_compress_if_exists 'SRR3208852_1' || true)"
gz2="$(_compress_if_exists 'SRR3208852_2' || true)"
gzs="$(_compress_if_exists 'SRR3208852' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2T15_ATCACG_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208853"
gz1="$(_compress_if_exists 'SRR3208853_1' || true)"
gz2="$(_compress_if_exists 'SRR3208853_2' || true)"
gzs="$(_compress_if_exists 'SRR3208853' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2T16_CGATGT_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208854"
gz1="$(_compress_if_exists 'SRR3208854_1' || true)"
gz2="$(_compress_if_exists 'SRR3208854_2' || true)"
gzs="$(_compress_if_exists 'SRR3208854' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2T17_TTAGGC_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208855"
gz1="$(_compress_if_exists 'SRR3208855_1' || true)"
gz2="$(_compress_if_exists 'SRR3208855_2' || true)"
gzs="$(_compress_if_exists 'SRR3208855' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2T18_TGACCA_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208856"
gz1="$(_compress_if_exists 'SRR3208856_1' || true)"
gz2="$(_compress_if_exists 'SRR3208856_2' || true)"
gzs="$(_compress_if_exists 'SRR3208856' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2T19_GCCAAT_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208857"
gz1="$(_compress_if_exists 'SRR3208857_1' || true)"
gz2="$(_compress_if_exists 'SRR3208857_2' || true)"
gzs="$(_compress_if_exists 'SRR3208857' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2T20_CTTGTA_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208858"
gz1="$(_compress_if_exists 'SRR3208858_1' || true)"
gz2="$(_compress_if_exists 'SRR3208858_2' || true)"
gzs="$(_compress_if_exists 'SRR3208858' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3T15_ATCACG_L003_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208859"
gz1="$(_compress_if_exists 'SRR3208859_1' || true)"
gz2="$(_compress_if_exists 'SRR3208859_2' || true)"
gzs="$(_compress_if_exists 'SRR3208859' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3T16_CGATGT_L003_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208860"
gz1="$(_compress_if_exists 'SRR3208860_1' || true)"
gz2="$(_compress_if_exists 'SRR3208860_2' || true)"
gzs="$(_compress_if_exists 'SRR3208860' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3T17_TTAGGC_L003_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208861"
gz1="$(_compress_if_exists 'SRR3208861_1' || true)"
gz2="$(_compress_if_exists 'SRR3208861_2' || true)"
gzs="$(_compress_if_exists 'SRR3208861' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3T18_TGACCA_L003_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208862"
gz1="$(_compress_if_exists 'SRR3208862_1' || true)"
gz2="$(_compress_if_exists 'SRR3208862_2' || true)"
gzs="$(_compress_if_exists 'SRR3208862' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3T19_GCCAAT_L003_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208863"
gz1="$(_compress_if_exists 'SRR3208863_1' || true)"
gz2="$(_compress_if_exists 'SRR3208863_2' || true)"
gzs="$(_compress_if_exists 'SRR3208863' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3T20_CTTGTA_L003_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208864"
gz1="$(_compress_if_exists 'SRR3208864_1' || true)"
gz2="$(_compress_if_exists 'SRR3208864_2' || true)"
gzs="$(_compress_if_exists 'SRR3208864' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2R15_CAGATC_L005_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208865"
gz1="$(_compress_if_exists 'SRR3208865_1' || true)"
gz2="$(_compress_if_exists 'SRR3208865_2' || true)"
gzs="$(_compress_if_exists 'SRR3208865' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2R16_CTTGTA_L005_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208866"
gz1="$(_compress_if_exists 'SRR3208866_1' || true)"
gz2="$(_compress_if_exists 'SRR3208866_2' || true)"
gzs="$(_compress_if_exists 'SRR3208866' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2R17_ACAGTG_L006_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208867"
gz1="$(_compress_if_exists 'SRR3208867_1' || true)"
gz2="$(_compress_if_exists 'SRR3208867_2' || true)"
gzs="$(_compress_if_exists 'SRR3208867' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2R18_GCCAAT_L006_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208868"
gz1="$(_compress_if_exists 'SRR3208868_1' || true)"
gz2="$(_compress_if_exists 'SRR3208868_2' || true)"
gzs="$(_compress_if_exists 'SRR3208868' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2R19_CAGATC_L006_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208869"
gz1="$(_compress_if_exists 'SRR3208869_1' || true)"
gz2="$(_compress_if_exists 'SRR3208869_2' || true)"
gzs="$(_compress_if_exists 'SRR3208869' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "2R20_CTTGTA_L006_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208870"
gz1="$(_compress_if_exists 'SRR3208870_1' || true)"
gz2="$(_compress_if_exists 'SRR3208870_2' || true)"
gzs="$(_compress_if_exists 'SRR3208870' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3R15_ACAGTG_L007_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208871"
gz1="$(_compress_if_exists 'SRR3208871_1' || true)"
gz2="$(_compress_if_exists 'SRR3208871_2' || true)"
gzs="$(_compress_if_exists 'SRR3208871' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3R16_GCCAAT_L007_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208872"
gz1="$(_compress_if_exists 'SRR3208872_1' || true)"
gz2="$(_compress_if_exists 'SRR3208872_2' || true)"
gzs="$(_compress_if_exists 'SRR3208872' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3R17_CAGATC_L007_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208873"
gz1="$(_compress_if_exists 'SRR3208873_1' || true)"
gz2="$(_compress_if_exists 'SRR3208873_2' || true)"
gzs="$(_compress_if_exists 'SRR3208873' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3R18_CTTGTA_L007_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208874"
gz1="$(_compress_if_exists 'SRR3208874_1' || true)"
gz2="$(_compress_if_exists 'SRR3208874_2' || true)"
gzs="$(_compress_if_exists 'SRR3208874' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3R19_ACAGTG_L008_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR3208875"
gz1="$(_compress_if_exists 'SRR3208875_1' || true)"
gz2="$(_compress_if_exists 'SRR3208875_2' || true)"
gzs="$(_compress_if_exists 'SRR3208875' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "3R20_GCCAAT_L008_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/SRR3208852/SRR3208852"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208853/SRR3208853"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208854/SRR3208854"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208855/SRR3208855"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208856/SRR3208856"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208857/SRR3208857"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208858/SRR3208858"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208859/SRR3208859"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208860/SRR3208860"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208861/SRR3208861"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208862/SRR3208862"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208863/SRR3208863"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208864/SRR3208864"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208865/SRR3208865"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208866/SRR3208866"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208867/SRR3208867"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208868/SRR3208868"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208869/SRR3208869"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208870/SRR3208870"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208871/SRR3208871"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208872/SRR3208872"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208873/SRR3208873"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208874/SRR3208874"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208875/SRR3208875"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208864/SRR3208864"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208865/SRR3208865"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208866/SRR3208866"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208867/SRR3208867"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208868/SRR3208868"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208869/SRR3208869"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208852/SRR3208852"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208853/SRR3208853"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208854/SRR3208854"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR003/208/SRR3208854/SRR3208854.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208855/SRR3208855"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208856/SRR3208856"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208857/SRR3208857"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208870/SRR3208870"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208871/SRR3208871"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208872/SRR3208872"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208873/SRR3208873"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208874/SRR3208874"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208875/SRR3208875"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208858/SRR3208858"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208859/SRR3208859"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208860/SRR3208860"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208861/SRR3208861"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208862/SRR3208862"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR3208863/SRR3208863"

echo "Download complete. Files saved to $OUTDIR"