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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE152nnn/GSE152033/suppl/GSE152033_Supplementary_Table_1.xlsx" -O "GSE152033_Supplementary_Table_1.xlsx"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE152nnn/GSE152033/suppl/GSE152033_Supplementary_Table_2.xlsx" -O "GSE152033_Supplementary_Table_2.xlsx"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE152nnn/GSE152033/suppl/GSE152033_Supplementary_Table_4.xlsx" -O "GSE152033_Supplementary_Table_4.xlsx"

# --- 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 "SRR11955144"
gz1="$(_compress_if_exists 'SRR11955144_1' || true)"
gz2="$(_compress_if_exists 'SRR11955144_2' || true)"
gzs="$(_compress_if_exists 'SRR11955144' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NT-11_S3_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NT-11_S3_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955145"
gz1="$(_compress_if_exists 'SRR11955145_1' || true)"
gz2="$(_compress_if_exists 'SRR11955145_2' || true)"
gzs="$(_compress_if_exists 'SRR11955145' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NT-11_S3_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NT-11_S3_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955146"
gz1="$(_compress_if_exists 'SRR11955146_1' || true)"
gz2="$(_compress_if_exists 'SRR11955146_2' || true)"
gzs="$(_compress_if_exists 'SRR11955146' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NT-F_S1_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NT-F_S1_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955147"
gz1="$(_compress_if_exists 'SRR11955147_1' || true)"
gz2="$(_compress_if_exists 'SRR11955147_2' || true)"
gzs="$(_compress_if_exists 'SRR11955147' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "NT-F_S1_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "NT-F_S1_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955148"
gz1="$(_compress_if_exists 'SRR11955148_1' || true)"
gz2="$(_compress_if_exists 'SRR11955148_2' || true)"
gzs="$(_compress_if_exists 'SRR11955148' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Rcas9-PIN_S2_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Rcas9-PIN_S2_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955149"
gz1="$(_compress_if_exists 'SRR11955149_1' || true)"
gz2="$(_compress_if_exists 'SRR11955149_2' || true)"
gzs="$(_compress_if_exists 'SRR11955149' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Rcas9-PIN_S2_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Rcas9-PIN_S2_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955150"
gz1="$(_compress_if_exists 'SRR11955150_1' || true)"
gz2="$(_compress_if_exists 'SRR11955150_2' || true)"
gzs="$(_compress_if_exists 'SRR11955150' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PIN2-10_S4_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PIN2-10_S4_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955151"
gz1="$(_compress_if_exists 'SRR11955151_1' || true)"
gz2="$(_compress_if_exists 'SRR11955151_2' || true)"
gzs="$(_compress_if_exists 'SRR11955151' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PIN2-10_S4_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PIN2-10_S4_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955152"
gz1="$(_compress_if_exists 'SRR11955152_1' || true)"
gz2="$(_compress_if_exists 'SRR11955152_2' || true)"
gzs="$(_compress_if_exists 'SRR11955152' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PIN3-12_S6_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PIN3-12_S6_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955153"
gz1="$(_compress_if_exists 'SRR11955153_1' || true)"
gz2="$(_compress_if_exists 'SRR11955153_2' || true)"
gzs="$(_compress_if_exists 'SRR11955153' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "PIN3-12_S6_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "PIN3-12_S6_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955154"
gz1="$(_compress_if_exists 'SRR11955154_1' || true)"
gz2="$(_compress_if_exists 'SRR11955154_2' || true)"
gzs="$(_compress_if_exists 'SRR11955154' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "MBNL-10_S7_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "MBNL-10_S7_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955155"
gz1="$(_compress_if_exists 'SRR11955155_1' || true)"
gz2="$(_compress_if_exists 'SRR11955155_2' || true)"
gzs="$(_compress_if_exists 'SRR11955155' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "MBNL-10_S7_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "MBNL-10_S7_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955156"
gz1="$(_compress_if_exists 'SRR11955156_1' || true)"
gz2="$(_compress_if_exists 'SRR11955156_2' || true)"
gzs="$(_compress_if_exists 'SRR11955156' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G1-2-12w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G1-2-12w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955157"
gz1="$(_compress_if_exists 'SRR11955157_1' || true)"
gz2="$(_compress_if_exists 'SRR11955157_2' || true)"
gzs="$(_compress_if_exists 'SRR11955157' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G1-6-12w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G1-6-12w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955158"
gz1="$(_compress_if_exists 'SRR11955158_1' || true)"
gz2="$(_compress_if_exists 'SRR11955158_2' || true)"
gzs="$(_compress_if_exists 'SRR11955158' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G1F1-6w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G1F1-6w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955159"
gz1="$(_compress_if_exists 'SRR11955159_1' || true)"
gz2="$(_compress_if_exists 'SRR11955159_2' || true)"
gzs="$(_compress_if_exists 'SRR11955159' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G1F2-1w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G1F2-1w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955160"
gz1="$(_compress_if_exists 'SRR11955160_1' || true)"
gz2="$(_compress_if_exists 'SRR11955160_2' || true)"
gzs="$(_compress_if_exists 'SRR11955160' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G2F1-6w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G2F1-6w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955161"
gz1="$(_compress_if_exists 'SRR11955161_1' || true)"
gz2="$(_compress_if_exists 'SRR11955161_2' || true)"
gzs="$(_compress_if_exists 'SRR11955161' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G2F2-1w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G2F2-1w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955162"
gz1="$(_compress_if_exists 'SRR11955162_1' || true)"
gz2="$(_compress_if_exists 'SRR11955162_2' || true)"
gzs="$(_compress_if_exists 'SRR11955162' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G5-18-12w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G5-18-12w_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11955163"
gz1="$(_compress_if_exists 'SRR11955163_1' || true)"
gz2="$(_compress_if_exists 'SRR11955163_2' || true)"
gzs="$(_compress_if_exists 'SRR11955163' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "G5F2-6w_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "G5F2-6w_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/SRR11955144/SRR11955144"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955145/SRR11955145"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955146/SRR11955146"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955147/SRR11955147"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955148/SRR11955148"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955149/SRR11955149"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955150/SRR11955150"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955151/SRR11955151"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955152/SRR11955152"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955153/SRR11955153"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955154/SRR11955154"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955155/SRR11955155"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955156/SRR11955156"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955157/SRR11955157"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955158/SRR11955158"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955159/SRR11955159"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955160/SRR11955160"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955161/SRR11955161"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955162/SRR11955162"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955163/SRR11955163"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955156/SRR11955156"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955157/SRR11955157"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955158/SRR11955158"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955159/SRR11955159"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955160/SRR11955160"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955161/SRR11955161"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955162/SRR11955162"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955163/SRR11955163"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955154/SRR11955154"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955155/SRR11955155"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955144/SRR11955144"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955145/SRR11955145"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955146/SRR11955146"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955147/SRR11955147"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955150/SRR11955150"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955151/SRR11955151"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955152/SRR11955152"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955153/SRR11955153"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955148/SRR11955148"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11955149/SRR11955149"

echo "Download complete. Files saved to $OUTDIR"