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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE100nnn/GSE100943/suppl/GSE100943_RPKM_myo.txt.gz" -O "GSE100943_RPKM_myo.txt.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 "SRR5812278"
gz1="$(_compress_if_exists 'SRR5812278_1' || true)"
gz2="$(_compress_if_exists 'SRR5812278_2' || true)"
gzs="$(_compress_if_exists 'SRR5812278' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast1_S1_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast1_S1_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812279"
gz1="$(_compress_if_exists 'SRR5812279_1' || true)"
gz2="$(_compress_if_exists 'SRR5812279_2' || true)"
gzs="$(_compress_if_exists 'SRR5812279' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast1_S1_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast1_S1_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812280"
gz1="$(_compress_if_exists 'SRR5812280_1' || true)"
gz2="$(_compress_if_exists 'SRR5812280_2' || true)"
gzs="$(_compress_if_exists 'SRR5812280' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast2_S2_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast2_S2_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812281"
gz1="$(_compress_if_exists 'SRR5812281_1' || true)"
gz2="$(_compress_if_exists 'SRR5812281_2' || true)"
gzs="$(_compress_if_exists 'SRR5812281' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast2_S2_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast2_S2_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812282"
gz1="$(_compress_if_exists 'SRR5812282_1' || true)"
gz2="$(_compress_if_exists 'SRR5812282_2' || true)"
gzs="$(_compress_if_exists 'SRR5812282' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast3_S3_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast3_S3_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812283"
gz1="$(_compress_if_exists 'SRR5812283_1' || true)"
gz2="$(_compress_if_exists 'SRR5812283_2' || true)"
gzs="$(_compress_if_exists 'SRR5812283' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast3_S3_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast3_S3_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812284"
gz1="$(_compress_if_exists 'SRR5812284_1' || true)"
gz2="$(_compress_if_exists 'SRR5812284_2' || true)"
gzs="$(_compress_if_exists 'SRR5812284' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast4_S4_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast4_S4_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812285"
gz1="$(_compress_if_exists 'SRR5812285_1' || true)"
gz2="$(_compress_if_exists 'SRR5812285_2' || true)"
gzs="$(_compress_if_exists 'SRR5812285' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast4_S4_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast4_S4_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812286"
gz1="$(_compress_if_exists 'SRR5812286_1' || true)"
gz2="$(_compress_if_exists 'SRR5812286_2' || true)"
gzs="$(_compress_if_exists 'SRR5812286' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast5_S5_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast5_S5_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812287"
gz1="$(_compress_if_exists 'SRR5812287_1' || true)"
gz2="$(_compress_if_exists 'SRR5812287_2' || true)"
gzs="$(_compress_if_exists 'SRR5812287' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myoblast5_S5_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myoblast5_S5_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812288"
gz1="$(_compress_if_exists 'SRR5812288_1' || true)"
gz2="$(_compress_if_exists 'SRR5812288_2' || true)"
gzs="$(_compress_if_exists 'SRR5812288' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube1_S6_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube1_S6_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812289"
gz1="$(_compress_if_exists 'SRR5812289_1' || true)"
gz2="$(_compress_if_exists 'SRR5812289_2' || true)"
gzs="$(_compress_if_exists 'SRR5812289' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube1_S6_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube1_S6_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812290"
gz1="$(_compress_if_exists 'SRR5812290_1' || true)"
gz2="$(_compress_if_exists 'SRR5812290_2' || true)"
gzs="$(_compress_if_exists 'SRR5812290' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube2_S7_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube2_S7_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812291"
gz1="$(_compress_if_exists 'SRR5812291_1' || true)"
gz2="$(_compress_if_exists 'SRR5812291_2' || true)"
gzs="$(_compress_if_exists 'SRR5812291' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube2_S7_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube2_S7_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812292"
gz1="$(_compress_if_exists 'SRR5812292_1' || true)"
gz2="$(_compress_if_exists 'SRR5812292_2' || true)"
gzs="$(_compress_if_exists 'SRR5812292' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube3_S8_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube3_S8_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812293"
gz1="$(_compress_if_exists 'SRR5812293_1' || true)"
gz2="$(_compress_if_exists 'SRR5812293_2' || true)"
gzs="$(_compress_if_exists 'SRR5812293' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube3_S8_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube3_S8_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812294"
gz1="$(_compress_if_exists 'SRR5812294_1' || true)"
gz2="$(_compress_if_exists 'SRR5812294_2' || true)"
gzs="$(_compress_if_exists 'SRR5812294' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube4_S9_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube4_S9_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5812295"
gz1="$(_compress_if_exists 'SRR5812295_1' || true)"
gz2="$(_compress_if_exists 'SRR5812295_2' || true)"
gzs="$(_compress_if_exists 'SRR5812295' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Myotube4_S9_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Myotube4_S9_L002_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/SRR5812278/SRR5812278"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812279/SRR5812279"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812280/SRR5812280"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812281/SRR5812281"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812282/SRR5812282"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812283/SRR5812283"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812284/SRR5812284"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812285/SRR5812285"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812286/SRR5812286"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812287/SRR5812287"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812288/SRR5812288"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812289/SRR5812289"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812290/SRR5812290"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812291/SRR5812291"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812292/SRR5812292"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812293/SRR5812293"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812294/SRR5812294"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812295/SRR5812295"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812278/SRR5812278"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812279/SRR5812279"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812280/SRR5812280"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812281/SRR5812281"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812282/SRR5812282"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812283/SRR5812283"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812284/SRR5812284"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812285/SRR5812285"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812286/SRR5812286"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812287/SRR5812287"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812288/SRR5812288"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812289/SRR5812289"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812290/SRR5812290"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812291/SRR5812291"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812292/SRR5812292"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812293/SRR5812293"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812294/SRR5812294"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5812295/SRR5812295"

echo "Download complete. Files saved to $OUTDIR"