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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE262nnn/GSE262542/suppl/GSE262542_PRPF17_HeLa.tsv.gz" -O "GSE262542_PRPF17_HeLa.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE262nnn/GSE262542/suppl/GSE262542_PRPF17_Hek293T.tsv.gz" -O "GSE262542_PRPF17_Hek293T.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE262nnn/GSE262542/suppl/GSE262542_SND1_K562.tsv.gz" -O "GSE262542_SND1_K562.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE262nnn/GSE262542/suppl/GSE262542_hnRNPA2B1_HepG2.tsv.gz" -O "GSE262542_hnRNPA2B1_HepG2.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE262nnn/GSE262542/suppl/GSE262542_hnRNPC_K562.tsv.gz" -O "GSE262542_hnRNPC_K562.tsv.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 "SRR28464922"
gz1="$(_compress_if_exists 'SRR28464922_1' || true)"
gz2="$(_compress_if_exists 'SRR28464922_2' || true)"
gzs="$(_compress_if_exists 'SRR28464922' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gzs" ]; then
  mv -f "$gzs" "SND1_k562_IP2.fastq.gz"
fi

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464922/SRR28464922"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464923/SRR28464923"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464924/SRR28464924"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464925/SRR28464925"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464926/SRR28464926"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464927/SRR28464927"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464928/SRR28464928"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464929/SRR28464929"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464930/SRR28464930"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464931/SRR28464931"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464932/SRR28464932"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464933/SRR28464933"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464938/SRR28464938"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464939/SRR28464939"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464940/SRR28464940"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464941/SRR28464941"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612463/SRR32612463"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612464/SRR32612464"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612465/SRR32612465"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612466/SRR32612466"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464941/SRR28464941"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464940/SRR28464940"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464939/SRR28464939"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464938/SRR28464938"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612463/SRR32612463"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612464/SRR32612464"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612465/SRR32612465"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR32612466/SRR32612466"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464933/SRR28464933"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464932/SRR28464932"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464931/SRR28464931"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464930/SRR28464930"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464929/SRR28464929"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464928/SRR28464928"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464927/SRR28464927"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464926/SRR28464926"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464925/SRR28464925"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464924/SRR28464924"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464923/SRR28464923"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR28464922/SRR28464922"

echo "Download complete. Files saved to $OUTDIR"