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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE147nnn/GSE147081/suppl/GSE147081_RAW.tar" -O "GSE147081_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 "SRR11318011"
gz1="$(_compress_if_exists 'SRR11318011_1' || true)"
gz2="$(_compress_if_exists 'SRR11318011_2' || true)"
gzs="$(_compress_if_exists 'SRR11318011' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen1_S10_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen1_S10_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318012"
gz1="$(_compress_if_exists 'SRR11318012_1' || true)"
gz2="$(_compress_if_exists 'SRR11318012_2' || true)"
gzs="$(_compress_if_exists 'SRR11318012' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen1_S11_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen1_S11_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318013"
gz1="$(_compress_if_exists 'SRR11318013_1' || true)"
gz2="$(_compress_if_exists 'SRR11318013_2' || true)"
gzs="$(_compress_if_exists 'SRR11318013' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen1_S12_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen1_S12_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318014"
gz1="$(_compress_if_exists 'SRR11318014_1' || true)"
gz2="$(_compress_if_exists 'SRR11318014_2' || true)"
gzs="$(_compress_if_exists 'SRR11318014' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen1_S9_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen1_S9_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318015"
gz1="$(_compress_if_exists 'SRR11318015_1' || true)"
gz2="$(_compress_if_exists 'SRR11318015_2' || true)"
gzs="$(_compress_if_exists 'SRR11318015' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen2_S13_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen2_S13_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318016"
gz1="$(_compress_if_exists 'SRR11318016_1' || true)"
gz2="$(_compress_if_exists 'SRR11318016_2' || true)"
gzs="$(_compress_if_exists 'SRR11318016' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen2_S14_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen2_S14_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318017"
gz1="$(_compress_if_exists 'SRR11318017_1' || true)"
gz2="$(_compress_if_exists 'SRR11318017_2' || true)"
gzs="$(_compress_if_exists 'SRR11318017' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen2_S15_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen2_S15_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318018"
gz1="$(_compress_if_exists 'SRR11318018_1' || true)"
gz2="$(_compress_if_exists 'SRR11318018_2' || true)"
gzs="$(_compress_if_exists 'SRR11318018' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3Spleen2_S16_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3Spleen2_S16_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318019"
gz1="$(_compress_if_exists 'SRR11318019_1' || true)"
gz2="$(_compress_if_exists 'SRR11318019_2' || true)"
gzs="$(_compress_if_exists 'SRR11318019' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL1_S1_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL1_S1_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318020"
gz1="$(_compress_if_exists 'SRR11318020_1' || true)"
gz2="$(_compress_if_exists 'SRR11318020_2' || true)"
gzs="$(_compress_if_exists 'SRR11318020' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL1_S2_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL1_S2_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318021"
gz1="$(_compress_if_exists 'SRR11318021_1' || true)"
gz2="$(_compress_if_exists 'SRR11318021_2' || true)"
gzs="$(_compress_if_exists 'SRR11318021' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL1_S3_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL1_S3_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318022"
gz1="$(_compress_if_exists 'SRR11318022_1' || true)"
gz2="$(_compress_if_exists 'SRR11318022_2' || true)"
gzs="$(_compress_if_exists 'SRR11318022' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL1_S4_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL1_S4_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318023"
gz1="$(_compress_if_exists 'SRR11318023_1' || true)"
gz2="$(_compress_if_exists 'SRR11318023_2' || true)"
gzs="$(_compress_if_exists 'SRR11318023' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL2_S5_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL2_S5_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318024"
gz1="$(_compress_if_exists 'SRR11318024_1' || true)"
gz2="$(_compress_if_exists 'SRR11318024_2' || true)"
gzs="$(_compress_if_exists 'SRR11318024' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL2_S6_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL2_S6_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318025"
gz1="$(_compress_if_exists 'SRR11318025_1' || true)"
gz2="$(_compress_if_exists 'SRR11318025_2' || true)"
gzs="$(_compress_if_exists 'SRR11318025' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL2_S7_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL2_S7_L005_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11318026"
gz1="$(_compress_if_exists 'SRR11318026_1' || true)"
gz2="$(_compress_if_exists 'SRR11318026_2' || true)"
gzs="$(_compress_if_exists 'SRR11318026' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "TIL-Try3TIL2_S8_L005_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "TIL-Try3TIL2_S8_L005_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/SRR11318011/SRR11318011"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318012/SRR11318012"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318013/SRR11318013"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318014/SRR11318014"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318015/SRR11318015"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318016/SRR11318016"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318017/SRR11318017"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318018/SRR11318018"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318019/SRR11318019"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318020/SRR11318020"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318021/SRR11318021"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318022/SRR11318022"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318023/SRR11318023"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318024/SRR11318024"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318025/SRR11318025"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318026/SRR11318026"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318011/SRR11318011"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318012/SRR11318012"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318013/SRR11318013"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318014/SRR11318014"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318015/SRR11318015"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318016/SRR11318016"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318017/SRR11318017"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318018/SRR11318018"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318019/SRR11318019"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318020/SRR11318020"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318021/SRR11318021"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318022/SRR11318022"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318023/SRR11318023"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318024/SRR11318024"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318025/SRR11318025"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11318026/SRR11318026"

echo "Download complete. Files saved to $OUTDIR"