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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE203nnn/GSE203086/suppl/GSE203086_RAW.tar" -O "GSE203086_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 "SRR19217837"
gz1="$(_compress_if_exists 'SRR19217837_1' || true)"
gz2="$(_compress_if_exists 'SRR19217837_2' || true)"
gzs="$(_compress_if_exists 'SRR19217837' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_2_S25_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_2_S25_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217838"
gz1="$(_compress_if_exists 'SRR19217838_1' || true)"
gz2="$(_compress_if_exists 'SRR19217838_2' || true)"
gzs="$(_compress_if_exists 'SRR19217838' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_2_S26_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_2_S26_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217839"
gz1="$(_compress_if_exists 'SRR19217839_1' || true)"
gz2="$(_compress_if_exists 'SRR19217839_2' || true)"
gzs="$(_compress_if_exists 'SRR19217839' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_2_S27_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_2_S27_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217840"
gz1="$(_compress_if_exists 'SRR19217840_1' || true)"
gz2="$(_compress_if_exists 'SRR19217840_2' || true)"
gzs="$(_compress_if_exists 'SRR19217840' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_2_S28_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_2_S28_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217841"
gz1="$(_compress_if_exists 'SRR19217841_1' || true)"
gz2="$(_compress_if_exists 'SRR19217841_2' || true)"
gzs="$(_compress_if_exists 'SRR19217841' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_1_S17_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_1_S17_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217842"
gz1="$(_compress_if_exists 'SRR19217842_1' || true)"
gz2="$(_compress_if_exists 'SRR19217842_2' || true)"
gzs="$(_compress_if_exists 'SRR19217842' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_1_S18_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_1_S18_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217843"
gz1="$(_compress_if_exists 'SRR19217843_1' || true)"
gz2="$(_compress_if_exists 'SRR19217843_2' || true)"
gzs="$(_compress_if_exists 'SRR19217843' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_1_S19_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_1_S19_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217844"
gz1="$(_compress_if_exists 'SRR19217844_1' || true)"
gz2="$(_compress_if_exists 'SRR19217844_2' || true)"
gzs="$(_compress_if_exists 'SRR19217844' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_Control_1_S20_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_Control_1_S20_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217845"
gz1="$(_compress_if_exists 'SRR19217845_1' || true)"
gz2="$(_compress_if_exists 'SRR19217845_2' || true)"
gzs="$(_compress_if_exists 'SRR19217845' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_2_S29_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_2_S29_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217846"
gz1="$(_compress_if_exists 'SRR19217846_1' || true)"
gz2="$(_compress_if_exists 'SRR19217846_2' || true)"
gzs="$(_compress_if_exists 'SRR19217846' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_2_S30_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_2_S30_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217847"
gz1="$(_compress_if_exists 'SRR19217847_1' || true)"
gz2="$(_compress_if_exists 'SRR19217847_2' || true)"
gzs="$(_compress_if_exists 'SRR19217847' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_2_S31_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_2_S31_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217848"
gz1="$(_compress_if_exists 'SRR19217848_1' || true)"
gz2="$(_compress_if_exists 'SRR19217848_2' || true)"
gzs="$(_compress_if_exists 'SRR19217848' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_2_S32_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_2_S32_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217849"
gz1="$(_compress_if_exists 'SRR19217849_1' || true)"
gz2="$(_compress_if_exists 'SRR19217849_2' || true)"
gzs="$(_compress_if_exists 'SRR19217849' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_1_S21_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_1_S21_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217850"
gz1="$(_compress_if_exists 'SRR19217850_1' || true)"
gz2="$(_compress_if_exists 'SRR19217850_2' || true)"
gzs="$(_compress_if_exists 'SRR19217850' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_1_S22_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_1_S22_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217851"
gz1="$(_compress_if_exists 'SRR19217851_1' || true)"
gz2="$(_compress_if_exists 'SRR19217851_2' || true)"
gzs="$(_compress_if_exists 'SRR19217851' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_1_S23_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_1_S23_L008_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR19217852"
gz1="$(_compress_if_exists 'SRR19217852_1' || true)"
gz2="$(_compress_if_exists 'SRR19217852_2' || true)"
gzs="$(_compress_if_exists 'SRR19217852' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Day_7_MALAT1_1_S24_L008_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Day_7_MALAT1_1_S24_L008_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/SRR19217837/SRR19217837"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217838/SRR19217838"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217839/SRR19217839"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217840/SRR19217840"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217841/SRR19217841"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217842/SRR19217842"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217843/SRR19217843"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217844/SRR19217844"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217845/SRR19217845"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217846/SRR19217846"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217847/SRR19217847"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217848/SRR19217848"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217849/SRR19217849"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217850/SRR19217850"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217851/SRR19217851"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217852/SRR19217852"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217841/SRR19217841"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217842/SRR19217842"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217843/SRR19217843"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217844/SRR19217844"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217837/SRR19217837"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217838/SRR19217838"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217839/SRR19217839"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217840/SRR19217840"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217849/SRR19217849"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217850/SRR19217850"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217851/SRR19217851"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217852/SRR19217852"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217845/SRR19217845"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217846/SRR19217846"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217847/SRR19217847"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR19217848/SRR19217848"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos9/sra-pub-zq-924/SRR019/19217/SRR19217848/SRR19217848.lite.1"

echo "Download complete. Files saved to $OUTDIR"