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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE230nnn/GSE230717/suppl/GSE230717_CAPRIN.reproducible_enriched_windows.tsv.gz.bed.gz" -O "GSE230717_CAPRIN.reproducible_enriched_windows.tsv.gz.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE230nnn/GSE230717/suppl/GSE230717_KR_G3BP1_HEK.reproducible_enriched_windows.tsv.gz.bed.gz" -O "GSE230717_KR_G3BP1_HEK.reproducible_enriched_windows.tsv.gz.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE230nnn/GSE230717/suppl/GSE230717_SNRNP200_HEK.reproducible_enriched_windows.tsv.gz.bed.gz" -O "GSE230717_SNRNP200_HEK.reproducible_enriched_windows.tsv.gz.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE230nnn/GSE230717/suppl/GSE230717_SNRNP200_HEKstress.reproducible_enriched_windows.tsv.gz.bed.gz" -O "GSE230717_SNRNP200_HEKstress.reproducible_enriched_windows.tsv.gz.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE230nnn/GSE230717/suppl/GSE230717_SNRNP200_cyto.reproducible_enriched_windows.tsv.gz.bed.gz" -O "GSE230717_SNRNP200_cyto.reproducible_enriched_windows.tsv.gz.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE230nnn/GSE230717/suppl/GSE230717_SNRNP200_stress.reproducible_enriched_windows.tsv.gz.bed.gz" -O "GSE230717_SNRNP200_stress.reproducible_enriched_windows.tsv.gz.bed.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 "SRR24321506"
gz1="$(_compress_if_exists 'SRR24321506_1' || true)"
gz2="$(_compress_if_exists 'SRR24321506_2' || true)"
gzs="$(_compress_if_exists 'SRR24321506' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "SNRNP200_cytoplasmic_arsenite_ip2_S159_L001_R1_001.fastq.gz"
fi

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

fasterq-dump --split-files "SRR24321508"
gz1="$(_compress_if_exists 'SRR24321508_1' || true)"
gz2="$(_compress_if_exists 'SRR24321508_2' || true)"
gzs="$(_compress_if_exists 'SRR24321508' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-stress-SNRNP200-IP_S27_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321509"
gz1="$(_compress_if_exists 'SRR24321509_1' || true)"
gz2="$(_compress_if_exists 'SRR24321509_2' || true)"
gzs="$(_compress_if_exists 'SRR24321509' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-Stress-IP-SNRNP200_S4_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321510"
gz1="$(_compress_if_exists 'SRR24321510_1' || true)"
gz2="$(_compress_if_exists 'SRR24321510_2' || true)"
gzs="$(_compress_if_exists 'SRR24321510' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KR-B-IP_S51_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321511"
gz1="$(_compress_if_exists 'SRR24321511_1' || true)"
gz2="$(_compress_if_exists 'SRR24321511_2' || true)"
gzs="$(_compress_if_exists 'SRR24321511' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KR-A-IP_S49_L002_R1_001.fastq.gz"
fi

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

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

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

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

fasterq-dump --split-files "SRR24321516"
gz1="$(_compress_if_exists 'SRR24321516_1' || true)"
gz2="$(_compress_if_exists 'SRR24321516_2' || true)"
gzs="$(_compress_if_exists 'SRR24321516' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-baseline-SNRNP200-IP_S23_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321517"
gz1="$(_compress_if_exists 'SRR24321517_1' || true)"
gz2="$(_compress_if_exists 'SRR24321517_2' || true)"
gzs="$(_compress_if_exists 'SRR24321517' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-IP-SNRNP200_S16_L001_R1_001.fastq.gz"
fi

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

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

fasterq-dump --split-files "SRR24321520"
gz1="$(_compress_if_exists 'SRR24321520_1' || true)"
gz2="$(_compress_if_exists 'SRR24321520_2' || true)"
gzs="$(_compress_if_exists 'SRR24321520' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-stress-SNRNP200-Input_S26_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321521"
gz1="$(_compress_if_exists 'SRR24321521_1' || true)"
gz2="$(_compress_if_exists 'SRR24321521_2' || true)"
gzs="$(_compress_if_exists 'SRR24321521' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-Stress-Input-SNRNP200_S3_L001_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321522"
gz1="$(_compress_if_exists 'SRR24321522_1' || true)"
gz2="$(_compress_if_exists 'SRR24321522_2' || true)"
gzs="$(_compress_if_exists 'SRR24321522' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KR-B-IN_S52_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321523"
gz1="$(_compress_if_exists 'SRR24321523_1' || true)"
gz2="$(_compress_if_exists 'SRR24321523_2' || true)"
gzs="$(_compress_if_exists 'SRR24321523' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KR-A-IN_S50_L002_R1_001.fastq.gz"
fi

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

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

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

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

fasterq-dump --split-files "SRR24321528"
gz1="$(_compress_if_exists 'SRR24321528_1' || true)"
gz2="$(_compress_if_exists 'SRR24321528_2' || true)"
gzs="$(_compress_if_exists 'SRR24321528' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-baseline-SNRNP200-Input_S22_L002_R1_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24321529"
gz1="$(_compress_if_exists 'SRR24321529_1' || true)"
gz2="$(_compress_if_exists 'SRR24321529_2' || true)"
gzs="$(_compress_if_exists 'SRR24321529' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "HEK-Input-SNRNP200_S15_L001_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/SRR24321506/SRR24321506"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321507/SRR24321507"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321508/SRR24321508"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321509/SRR24321509"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321510/SRR24321510"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321511/SRR24321511"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321512/SRR24321512"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321513/SRR24321513"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321514/SRR24321514"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321515/SRR24321515"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321516/SRR24321516"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321517/SRR24321517"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321518/SRR24321518"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321519/SRR24321519"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321520/SRR24321520"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321521/SRR24321521"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321522/SRR24321522"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321523/SRR24321523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321524/SRR24321524"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321525/SRR24321525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321526/SRR24321526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321527/SRR24321527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321528/SRR24321528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321529/SRR24321529"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321525/SRR24321525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321524/SRR24321524"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321513/SRR24321513"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321512/SRR24321512"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321528/SRR24321528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321516/SRR24321516"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321529/SRR24321529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321517/SRR24321517"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321521/SRR24321521"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321509/SRR24321509"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321520/SRR24321520"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321508/SRR24321508"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321523/SRR24321523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321511/SRR24321511"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321522/SRR24321522"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321510/SRR24321510"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321519/SRR24321519"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321518/SRR24321518"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321507/SRR24321507"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321506/SRR24321506"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321527/SRR24321527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321526/SRR24321526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321515/SRR24321515"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24321514/SRR24321514"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR024/24321/SRR24321506/SRR24321506.lite.1"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR024/24321/SRR24321507/SRR24321507.lite.1"

echo "Download complete. Files saved to $OUTDIR"