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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232518/suppl/GSE232518_epr_cds_3_fusion_joined.tsv.gz" -O "GSE232518_epr_cds_3_fusion_joined.tsv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE232nnn/GSE232518/suppl/GSE232518_epr_volcano_plot_values.tsv.gz" -O "GSE232518_epr_volcano_plot_values.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 "SRR24557488"
gz1="$(_compress_if_exists 'SRR24557488_1' || true)"
gz2="$(_compress_if_exists 'SRR24557488_2' || true)"
gzs="$(_compress_if_exists 'SRR24557488' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_06_S6_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_06_S6_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557489"
gz1="$(_compress_if_exists 'SRR24557489_1' || true)"
gz2="$(_compress_if_exists 'SRR24557489_2' || true)"
gzs="$(_compress_if_exists 'SRR24557489' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_05_S5_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_05_S5_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557490"
gz1="$(_compress_if_exists 'SRR24557490_1' || true)"
gz2="$(_compress_if_exists 'SRR24557490_2' || true)"
gzs="$(_compress_if_exists 'SRR24557490' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_04_S4_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_04_S4_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557491"
gz1="$(_compress_if_exists 'SRR24557491_1' || true)"
gz2="$(_compress_if_exists 'SRR24557491_2' || true)"
gzs="$(_compress_if_exists 'SRR24557491' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_12_S12_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_12_S12_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557492"
gz1="$(_compress_if_exists 'SRR24557492_1' || true)"
gz2="$(_compress_if_exists 'SRR24557492_2' || true)"
gzs="$(_compress_if_exists 'SRR24557492' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_11_S11_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_11_S11_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557493"
gz1="$(_compress_if_exists 'SRR24557493_1' || true)"
gz2="$(_compress_if_exists 'SRR24557493_2' || true)"
gzs="$(_compress_if_exists 'SRR24557493' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_10_S10_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_10_S10_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557494"
gz1="$(_compress_if_exists 'SRR24557494_1' || true)"
gz2="$(_compress_if_exists 'SRR24557494_2' || true)"
gzs="$(_compress_if_exists 'SRR24557494' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_03_S3_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_03_S3_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557495"
gz1="$(_compress_if_exists 'SRR24557495_1' || true)"
gz2="$(_compress_if_exists 'SRR24557495_2' || true)"
gzs="$(_compress_if_exists 'SRR24557495' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_02_S2_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_02_S2_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557496"
gz1="$(_compress_if_exists 'SRR24557496_1' || true)"
gz2="$(_compress_if_exists 'SRR24557496_2' || true)"
gzs="$(_compress_if_exists 'SRR24557496' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_01_S1_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_01_S1_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557497"
gz1="$(_compress_if_exists 'SRR24557497_1' || true)"
gz2="$(_compress_if_exists 'SRR24557497_2' || true)"
gzs="$(_compress_if_exists 'SRR24557497' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_09_S9_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_09_S9_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557498"
gz1="$(_compress_if_exists 'SRR24557498_1' || true)"
gz2="$(_compress_if_exists 'SRR24557498_2' || true)"
gzs="$(_compress_if_exists 'SRR24557498' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_08_S8_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_08_S8_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557499"
gz1="$(_compress_if_exists 'SRR24557499_1' || true)"
gz2="$(_compress_if_exists 'SRR24557499_2' || true)"
gzs="$(_compress_if_exists 'SRR24557499' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_07_S7_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_07_S7_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557500"
gz1="$(_compress_if_exists 'SRR24557500_1' || true)"
gz2="$(_compress_if_exists 'SRR24557500_2' || true)"
gzs="$(_compress_if_exists 'SRR24557500' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_18_S18_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_18_S18_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557501"
gz1="$(_compress_if_exists 'SRR24557501_1' || true)"
gz2="$(_compress_if_exists 'SRR24557501_2' || true)"
gzs="$(_compress_if_exists 'SRR24557501' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_17_S17_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_17_S17_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557502"
gz1="$(_compress_if_exists 'SRR24557502_1' || true)"
gz2="$(_compress_if_exists 'SRR24557502_2' || true)"
gzs="$(_compress_if_exists 'SRR24557502' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_16_S16_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_16_S16_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557503"
gz1="$(_compress_if_exists 'SRR24557503_1' || true)"
gz2="$(_compress_if_exists 'SRR24557503_2' || true)"
gzs="$(_compress_if_exists 'SRR24557503' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_24_S24_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_24_S24_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557504"
gz1="$(_compress_if_exists 'SRR24557504_1' || true)"
gz2="$(_compress_if_exists 'SRR24557504_2' || true)"
gzs="$(_compress_if_exists 'SRR24557504' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_23_S23_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_23_S23_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557505"
gz1="$(_compress_if_exists 'SRR24557505_1' || true)"
gz2="$(_compress_if_exists 'SRR24557505_2' || true)"
gzs="$(_compress_if_exists 'SRR24557505' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_22_S22_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_22_S22_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557506"
gz1="$(_compress_if_exists 'SRR24557506_1' || true)"
gz2="$(_compress_if_exists 'SRR24557506_2' || true)"
gzs="$(_compress_if_exists 'SRR24557506' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_15_S15_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_15_S15_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557507"
gz1="$(_compress_if_exists 'SRR24557507_1' || true)"
gz2="$(_compress_if_exists 'SRR24557507_2' || true)"
gzs="$(_compress_if_exists 'SRR24557507' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_14_S14_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_14_S14_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557508"
gz1="$(_compress_if_exists 'SRR24557508_1' || true)"
gz2="$(_compress_if_exists 'SRR24557508_2' || true)"
gzs="$(_compress_if_exists 'SRR24557508' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_13_S13_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_13_S13_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557509"
gz1="$(_compress_if_exists 'SRR24557509_1' || true)"
gz2="$(_compress_if_exists 'SRR24557509_2' || true)"
gzs="$(_compress_if_exists 'SRR24557509' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_21_S21_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_21_S21_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557510"
gz1="$(_compress_if_exists 'SRR24557510_1' || true)"
gz2="$(_compress_if_exists 'SRR24557510_2' || true)"
gzs="$(_compress_if_exists 'SRR24557510' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_20_S20_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_20_S20_L004_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR24557511"
gz1="$(_compress_if_exists 'SRR24557511_1' || true)"
gz2="$(_compress_if_exists 'SRR24557511_2' || true)"
gzs="$(_compress_if_exists 'SRR24557511' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Torin_RS_19_S19_L004_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Torin_RS_19_S19_L004_R2_001.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557488/SRR24557488"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557489/SRR24557489"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557490/SRR24557490"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557491/SRR24557491"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557492/SRR24557492"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557493/SRR24557493"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557494/SRR24557494"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557495/SRR24557495"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557496/SRR24557496"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557497/SRR24557497"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557498/SRR24557498"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557499/SRR24557499"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557500/SRR24557500"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557501/SRR24557501"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557502/SRR24557502"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557503/SRR24557503"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557504/SRR24557504"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557505/SRR24557505"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557506/SRR24557506"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557507/SRR24557507"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557508/SRR24557508"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557509/SRR24557509"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557510/SRR24557510"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557511/SRR24557511"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557496/SRR24557496"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557495/SRR24557495"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557494/SRR24557494"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557490/SRR24557490"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557489/SRR24557489"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557488/SRR24557488"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557499/SRR24557499"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557498/SRR24557498"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557497/SRR24557497"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557493/SRR24557493"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557492/SRR24557492"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557491/SRR24557491"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557508/SRR24557508"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557507/SRR24557507"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557506/SRR24557506"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557502/SRR24557502"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557501/SRR24557501"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557500/SRR24557500"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557511/SRR24557511"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557510/SRR24557510"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557509/SRR24557509"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557505/SRR24557505"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557504/SRR24557504"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR24557503/SRR24557503"

echo "Download complete. Files saved to $OUTDIR"