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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE63nnn/GSE63816/suppl/GSE63816_RAW.tar" -O "GSE63816_RAW.tar"

# --- 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 "SRR1691633"
gz1="$(_compress_if_exists 'SRR1691633_1' || true)"
gz2="$(_compress_if_exists 'SRR1691633_2' || true)"
gzs="$(_compress_if_exists 'SRR1691633' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_1_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_1_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691634"
gz1="$(_compress_if_exists 'SRR1691634_1' || true)"
gz2="$(_compress_if_exists 'SRR1691634_2' || true)"
gzs="$(_compress_if_exists 'SRR1691634' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_2_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_2_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691635"
gz1="$(_compress_if_exists 'SRR1691635_1' || true)"
gz2="$(_compress_if_exists 'SRR1691635_2' || true)"
gzs="$(_compress_if_exists 'SRR1691635' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_3_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_3_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691636"
gz1="$(_compress_if_exists 'SRR1691636_1' || true)"
gz2="$(_compress_if_exists 'SRR1691636_2' || true)"
gzs="$(_compress_if_exists 'SRR1691636' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_4_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_4_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691637"
gz1="$(_compress_if_exists 'SRR1691637_1' || true)"
gz2="$(_compress_if_exists 'SRR1691637_2' || true)"
gzs="$(_compress_if_exists 'SRR1691637' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_5_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_5_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691638"
gz1="$(_compress_if_exists 'SRR1691638_1' || true)"
gz2="$(_compress_if_exists 'SRR1691638_2' || true)"
gzs="$(_compress_if_exists 'SRR1691638' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_6_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_6_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691639"
gz1="$(_compress_if_exists 'SRR1691639_1' || true)"
gz2="$(_compress_if_exists 'SRR1691639_2' || true)"
gzs="$(_compress_if_exists 'SRR1691639' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_7_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_7_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691640"
gz1="$(_compress_if_exists 'SRR1691640_1' || true)"
gz2="$(_compress_if_exists 'SRR1691640_2' || true)"
gzs="$(_compress_if_exists 'SRR1691640' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_mut_MDS_8_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_mut_MDS_8_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691641"
gz1="$(_compress_if_exists 'SRR1691641_1' || true)"
gz2="$(_compress_if_exists 'SRR1691641_2' || true)"
gzs="$(_compress_if_exists 'SRR1691641' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_WT_MDS_1_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_WT_MDS_1_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691642"
gz1="$(_compress_if_exists 'SRR1691642_1' || true)"
gz2="$(_compress_if_exists 'SRR1691642_2' || true)"
gzs="$(_compress_if_exists 'SRR1691642' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_WT_MDS_2_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_WT_MDS_2_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691643"
gz1="$(_compress_if_exists 'SRR1691643_1' || true)"
gz2="$(_compress_if_exists 'SRR1691643_2' || true)"
gzs="$(_compress_if_exists 'SRR1691643' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_WT_MDS_3_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_WT_MDS_3_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691644"
gz1="$(_compress_if_exists 'SRR1691644_1' || true)"
gz2="$(_compress_if_exists 'SRR1691644_2' || true)"
gzs="$(_compress_if_exists 'SRR1691644' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZRSR2_WT_MDS_4_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZRSR2_WT_MDS_4_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691645"
gz1="$(_compress_if_exists 'SRR1691645_1' || true)"
gz2="$(_compress_if_exists 'SRR1691645_2' || true)"
gzs="$(_compress_if_exists 'SRR1691645' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Normal_BM_1_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Normal_BM_1_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691646"
gz1="$(_compress_if_exists 'SRR1691646_1' || true)"
gz2="$(_compress_if_exists 'SRR1691646_2' || true)"
gzs="$(_compress_if_exists 'SRR1691646' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Normal_BM_2_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Normal_BM_2_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691647"
gz1="$(_compress_if_exists 'SRR1691647_1' || true)"
gz2="$(_compress_if_exists 'SRR1691647_2' || true)"
gzs="$(_compress_if_exists 'SRR1691647' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Normal_BM_3_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Normal_BM_3_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691648"
gz1="$(_compress_if_exists 'SRR1691648_1' || true)"
gz2="$(_compress_if_exists 'SRR1691648_2' || true)"
gzs="$(_compress_if_exists 'SRR1691648' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Normal_BM_4_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Normal_BM_4_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691649"
gz1="$(_compress_if_exists 'SRR1691649_1' || true)"
gz2="$(_compress_if_exists 'SRR1691649_2' || true)"
gzs="$(_compress_if_exists 'SRR1691649' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TF1_con_sh_1_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TF1_con_sh_1_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691650"
gz1="$(_compress_if_exists 'SRR1691650_1' || true)"
gz2="$(_compress_if_exists 'SRR1691650_2' || true)"
gzs="$(_compress_if_exists 'SRR1691650' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TF1_ZRSR2_sh1_1_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TF1_ZRSR2_sh1_1_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691651"
gz1="$(_compress_if_exists 'SRR1691651_1' || true)"
gz2="$(_compress_if_exists 'SRR1691651_2' || true)"
gzs="$(_compress_if_exists 'SRR1691651' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TF1_ZRSR2_sh2_1_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TF1_ZRSR2_sh2_1_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691652"
gz1="$(_compress_if_exists 'SRR1691652_1' || true)"
gz2="$(_compress_if_exists 'SRR1691652_2' || true)"
gzs="$(_compress_if_exists 'SRR1691652' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TF1_con_sh_2_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TF1_con_sh_2_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691653"
gz1="$(_compress_if_exists 'SRR1691653_1' || true)"
gz2="$(_compress_if_exists 'SRR1691653_2' || true)"
gzs="$(_compress_if_exists 'SRR1691653' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TF1_ZRSR2_sh1_2_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TF1_ZRSR2_sh1_2_R2.fastq.bz2.gz"
fi

fasterq-dump --split-files "SRR1691654"
gz1="$(_compress_if_exists 'SRR1691654_1' || true)"
gz2="$(_compress_if_exists 'SRR1691654_2' || true)"
gzs="$(_compress_if_exists 'SRR1691654' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TF1_ZRSR2_sh2_2_R1.fastq.bz2.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TF1_ZRSR2_sh2_2_R2.fastq.bz2.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691633/SRR1691633.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691634/SRR1691634"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691635/SRR1691635"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691636/SRR1691636"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691637/SRR1691637"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691638/SRR1691638.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691639/SRR1691639"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691640/SRR1691640"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691641/SRR1691641"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691642/SRR1691642"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691643/SRR1691643"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691644/SRR1691644.sralite.1"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691645/SRR1691645.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691646/SRR1691646"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691647/SRR1691647"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691648/SRR1691648"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691649/SRR1691649"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691650/SRR1691650"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691651/SRR1691651"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691652/SRR1691652"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691653/SRR1691653"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691654/SRR1691654"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691648/SRR1691648"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691634/SRR1691634"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691637/SRR1691637"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691643/SRR1691643"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691644/SRR1691644.sralite.1"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691645/SRR1691645.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691646/SRR1691646"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691647/SRR1691647"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691649/SRR1691649"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691652/SRR1691652"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691650/SRR1691650"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691653/SRR1691653"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691651/SRR1691651"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691654/SRR1691654"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691633/SRR1691633.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691635/SRR1691635"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691636/SRR1691636"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/691/SRR1691638/SRR1691638.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691639/SRR1691639"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691640/SRR1691640"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691641/SRR1691641"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1691642/SRR1691642"

echo "Download complete. Files saved to $OUTDIR"