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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shRTCA_SE.MATS.JC.txt.gz" -O "GSE232598_shRTCA_SE.MATS.JC.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shRTCA_TPM.csv.gz" -O "GSE232598_shRTCA_TPM.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shSCAF8_SE.MATS.JC.txt.gz" -O "GSE232598_shSCAF8_SE.MATS.JC.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shSCAF8_TPM.csv.gz" -O "GSE232598_shSCAF8_TPM.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shSTAU2_SE.MATS.JC.txt.gz" -O "GSE232598_shSTAU2_SE.MATS.JC.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shSTAU2_TPM.csv.gz" -O "GSE232598_shSTAU2_TPM.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shTRNAU1AP_SE.MATS.JC.txt.gz" -O "GSE232598_shTRNAU1AP_SE.MATS.JC.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232598/suppl/GSE232598_shTRNAU1AP_TPM.csv.gz" -O "GSE232598_shTRNAU1AP_TPM.csv.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 "SRR24579591"
gz1="$(_compress_if_exists 'SRR24579591_1' || true)"
gz2="$(_compress_if_exists 'SRR24579591_2' || true)"
gzs="$(_compress_if_exists 'SRR24579591' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shNT_3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shNT_3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579592"
gz1="$(_compress_if_exists 'SRR24579592_1' || true)"
gz2="$(_compress_if_exists 'SRR24579592_2' || true)"
gzs="$(_compress_if_exists 'SRR24579592' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shNT_2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shNT_2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579593"
gz1="$(_compress_if_exists 'SRR24579593_1' || true)"
gz2="$(_compress_if_exists 'SRR24579593_2' || true)"
gzs="$(_compress_if_exists 'SRR24579593' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shNT_1_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shNT_1_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579597"
gz1="$(_compress_if_exists 'SRR24579597_1' || true)"
gz2="$(_compress_if_exists 'SRR24579597_2' || true)"
gzs="$(_compress_if_exists 'SRR24579597' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shSTAU2_3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shSTAU2_3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579598"
gz1="$(_compress_if_exists 'SRR24579598_1' || true)"
gz2="$(_compress_if_exists 'SRR24579598_2' || true)"
gzs="$(_compress_if_exists 'SRR24579598' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shSTAU2_2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shSTAU2_2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579599"
gz1="$(_compress_if_exists 'SRR24579599_1' || true)"
gz2="$(_compress_if_exists 'SRR24579599_2' || true)"
gzs="$(_compress_if_exists 'SRR24579599' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shSTAU2_1_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shSTAU2_1_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579600"
gz1="$(_compress_if_exists 'SRR24579600_1' || true)"
gz2="$(_compress_if_exists 'SRR24579600_2' || true)"
gzs="$(_compress_if_exists 'SRR24579600' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shSCAF8_3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shSCAF8_3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579601"
gz1="$(_compress_if_exists 'SRR24579601_1' || true)"
gz2="$(_compress_if_exists 'SRR24579601_2' || true)"
gzs="$(_compress_if_exists 'SRR24579601' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shSCAF8_2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shSCAF8_2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579602"
gz1="$(_compress_if_exists 'SRR24579602_1' || true)"
gz2="$(_compress_if_exists 'SRR24579602_2' || true)"
gzs="$(_compress_if_exists 'SRR24579602' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shSCAF8_1_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shSCAF8_1_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579603"
gz1="$(_compress_if_exists 'SRR24579603_1' || true)"
gz2="$(_compress_if_exists 'SRR24579603_2' || true)"
gzs="$(_compress_if_exists 'SRR24579603' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shRTCA_3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shRTCA_3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579604"
gz1="$(_compress_if_exists 'SRR24579604_1' || true)"
gz2="$(_compress_if_exists 'SRR24579604_2' || true)"
gzs="$(_compress_if_exists 'SRR24579604' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shRTCA_2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shRTCA_2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579605"
gz1="$(_compress_if_exists 'SRR24579605_1' || true)"
gz2="$(_compress_if_exists 'SRR24579605_2' || true)"
gzs="$(_compress_if_exists 'SRR24579605' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shRTCA_1_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shRTCA_1_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579606"
gz1="$(_compress_if_exists 'SRR24579606_1' || true)"
gz2="$(_compress_if_exists 'SRR24579606_2' || true)"
gzs="$(_compress_if_exists 'SRR24579606' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shTRNAU1AP_3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shTRNAU1AP_3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579607"
gz1="$(_compress_if_exists 'SRR24579607_1' || true)"
gz2="$(_compress_if_exists 'SRR24579607_2' || true)"
gzs="$(_compress_if_exists 'SRR24579607' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shTRNAU1AP_2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shTRNAU1AP_2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR24579608"
gz1="$(_compress_if_exists 'SRR24579608_1' || true)"
gz2="$(_compress_if_exists 'SRR24579608_2' || true)"
gzs="$(_compress_if_exists 'SRR24579608' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "shTRNAU1AP_1_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "shTRNAU1AP_1_R2.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579591/SRR24579591"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579592/SRR24579592"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579593/SRR24579593"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579597/SRR24579597"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579598/SRR24579598"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579599/SRR24579599"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579600/SRR24579600"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579601/SRR24579601"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579602/SRR24579602"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579603/SRR24579603"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579604/SRR24579604"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579605/SRR24579605"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579606/SRR24579606"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579607/SRR24579607"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579608/SRR24579608"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579593/SRR24579593"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579592/SRR24579592"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579591/SRR24579591"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579605/SRR24579605"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579604/SRR24579604"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579603/SRR24579603"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579602/SRR24579602"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579601/SRR24579601"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579600/SRR24579600"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579599/SRR24579599"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579598/SRR24579598"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579597/SRR24579597"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579608/SRR24579608"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579607/SRR24579607"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24579606/SRR24579606"

echo "Download complete. Files saved to $OUTDIR"