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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE276nnn/GSE276986/suppl/GSE276986_featurecounts_deepRNA-Seq.csv.gz" -O "GSE276986_featurecounts_deepRNA-Seq.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE276nnn/GSE276986/suppl/GSE276986_featurecounts_recoveryRNA-Seq.txt.gz" -O "GSE276986_featurecounts_recoveryRNA-Seq.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 "SRR30639513"
gz1="$(_compress_if_exists 'SRR30639513_1' || true)"
gz2="$(_compress_if_exists 'SRR30639513_2' || true)"
gzs="$(_compress_if_exists 'SRR30639513' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_U_C_S17_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_U_C_S17_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639514"
gz1="$(_compress_if_exists 'SRR30639514_1' || true)"
gz2="$(_compress_if_exists 'SRR30639514_2' || true)"
gzs="$(_compress_if_exists 'SRR30639514' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_U_B_S16_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_U_B_S16_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639515"
gz1="$(_compress_if_exists 'SRR30639515_1' || true)"
gz2="$(_compress_if_exists 'SRR30639515_2' || true)"
gzs="$(_compress_if_exists 'SRR30639515' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_U_A_S15_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_U_A_S15_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639516"
gz1="$(_compress_if_exists 'SRR30639516_1' || true)"
gz2="$(_compress_if_exists 'SRR30639516_2' || true)"
gzs="$(_compress_if_exists 'SRR30639516' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_24_C_S11_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_24_C_S11_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639517"
gz1="$(_compress_if_exists 'SRR30639517_1' || true)"
gz2="$(_compress_if_exists 'SRR30639517_2' || true)"
gzs="$(_compress_if_exists 'SRR30639517' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_24_B_S10_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_24_B_S10_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639518"
gz1="$(_compress_if_exists 'SRR30639518_1' || true)"
gz2="$(_compress_if_exists 'SRR30639518_2' || true)"
gzs="$(_compress_if_exists 'SRR30639518' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_24_A_S9_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_24_A_S9_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639519"
gz1="$(_compress_if_exists 'SRR30639519_1' || true)"
gz2="$(_compress_if_exists 'SRR30639519_2' || true)"
gzs="$(_compress_if_exists 'SRR30639519' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_0_C_S14_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_0_C_S14_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639520"
gz1="$(_compress_if_exists 'SRR30639520_1' || true)"
gz2="$(_compress_if_exists 'SRR30639520_2' || true)"
gzs="$(_compress_if_exists 'SRR30639520' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_0_B_S13_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_0_B_S13_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639521"
gz1="$(_compress_if_exists 'SRR30639521_1' || true)"
gz2="$(_compress_if_exists 'SRR30639521_2' || true)"
gzs="$(_compress_if_exists 'SRR30639521' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NK_0_A_S12_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NK_0_A_S12_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639522"
gz1="$(_compress_if_exists 'SRR30639522_1' || true)"
gz2="$(_compress_if_exists 'SRR30639522_2' || true)"
gzs="$(_compress_if_exists 'SRR30639522' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_U_C_S26_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_U_C_S26_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639523"
gz1="$(_compress_if_exists 'SRR30639523_1' || true)"
gz2="$(_compress_if_exists 'SRR30639523_2' || true)"
gzs="$(_compress_if_exists 'SRR30639523' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_U_B_S25_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_U_B_S25_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639524"
gz1="$(_compress_if_exists 'SRR30639524_1' || true)"
gz2="$(_compress_if_exists 'SRR30639524_2' || true)"
gzs="$(_compress_if_exists 'SRR30639524' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_U_A_S24_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_U_A_S24_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639525"
gz1="$(_compress_if_exists 'SRR30639525_1' || true)"
gz2="$(_compress_if_exists 'SRR30639525_2' || true)"
gzs="$(_compress_if_exists 'SRR30639525' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_24_C_S20_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_24_C_S20_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639526"
gz1="$(_compress_if_exists 'SRR30639526_1' || true)"
gz2="$(_compress_if_exists 'SRR30639526_2' || true)"
gzs="$(_compress_if_exists 'SRR30639526' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_24_B_S19_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_24_B_S19_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639527"
gz1="$(_compress_if_exists 'SRR30639527_1' || true)"
gz2="$(_compress_if_exists 'SRR30639527_2' || true)"
gzs="$(_compress_if_exists 'SRR30639527' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_24_A_S18_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_24_A_S18_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639528"
gz1="$(_compress_if_exists 'SRR30639528_1' || true)"
gz2="$(_compress_if_exists 'SRR30639528_2' || true)"
gzs="$(_compress_if_exists 'SRR30639528' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_0_C_S23_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_0_C_S23_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639529"
gz1="$(_compress_if_exists 'SRR30639529_1' || true)"
gz2="$(_compress_if_exists 'SRR30639529_2' || true)"
gzs="$(_compress_if_exists 'SRR30639529' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_0_B_S22_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_0_B_S22_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30639530"
gz1="$(_compress_if_exists 'SRR30639530_1' || true)"
gz2="$(_compress_if_exists 'SRR30639530_2' || true)"
gzs="$(_compress_if_exists 'SRR30639530' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NGN_0_A_S21_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NGN_0_A_S21_L001_R2_001.fastq.gz"
fi

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

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

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

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


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639513/SRR30639513"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639514/SRR30639514"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639515/SRR30639515"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639516/SRR30639516"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639517/SRR30639517"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639518/SRR30639518"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639519/SRR30639519"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639520/SRR30639520"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639521/SRR30639521"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639522/SRR30639522"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639523/SRR30639523"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos7/sra-pub-zq-41/SRR030/30639/SRR30639524/SRR30639524.lite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639525/SRR30639525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639526/SRR30639526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639527/SRR30639527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639528/SRR30639528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639529/SRR30639529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639530/SRR30639530"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639531/SRR30639531"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639532/SRR30639532"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639533/SRR30639533"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639534/SRR30639534"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639530/SRR30639530"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639529/SRR30639529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639528/SRR30639528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639527/SRR30639527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639526/SRR30639526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639525/SRR30639525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639534/SRR30639534"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639533/SRR30639533"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639523/SRR30639523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639522/SRR30639522"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639521/SRR30639521"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639520/SRR30639520"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639519/SRR30639519"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639518/SRR30639518"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639517/SRR30639517"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639516/SRR30639516"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639532/SRR30639532"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639531/SRR30639531"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639515/SRR30639515"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639514/SRR30639514"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30639513/SRR30639513"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos7/sra-pub-zq-41/SRR030/30639/SRR30639524/SRR30639524.lite.1"

echo "Download complete. Files saved to $OUTDIR"