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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE152nnn/GSE152684/suppl/GSE152684_Cas_CYFIP2_PE_TPM.txt.gz" -O "GSE152684_Cas_CYFIP2_PE_TPM.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE152nnn/GSE152684/suppl/GSE152684_Control_293T_SE_TPM.txt.gz" -O "GSE152684_Control_293T_SE_TPM.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE152nnn/GSE152684/suppl/GSE152684_RAW.tar" -O "GSE152684_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 "SRR12036520"
gz1="$(_compress_if_exists 'SRR12036520_1' || true)"
gz2="$(_compress_if_exists 'SRR12036520_2' || true)"
gzs="$(_compress_if_exists 'SRR12036520' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13b_CYFIP2_gRNA_1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13b_CYFIP2_gRNA_1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036521"
gz1="$(_compress_if_exists 'SRR12036521_1' || true)"
gz2="$(_compress_if_exists 'SRR12036521_2' || true)"
gzs="$(_compress_if_exists 'SRR12036521' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13b_CYFIP2_gRNA_2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13b_CYFIP2_gRNA_2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036522"
gz1="$(_compress_if_exists 'SRR12036522_1' || true)"
gz2="$(_compress_if_exists 'SRR12036522_2' || true)"
gzs="$(_compress_if_exists 'SRR12036522' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13b_NT_gRNA_1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13b_NT_gRNA_1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036523"
gz1="$(_compress_if_exists 'SRR12036523_1' || true)"
gz2="$(_compress_if_exists 'SRR12036523_2' || true)"
gzs="$(_compress_if_exists 'SRR12036523' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13b_NT_gRNA_2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13b_NT_gRNA_2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036524"
gz1="$(_compress_if_exists 'SRR12036524_1' || true)"
gz2="$(_compress_if_exists 'SRR12036524_2' || true)"
gzs="$(_compress_if_exists 'SRR12036524' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13d_CYFIP2_gRNA_1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13d_CYFIP2_gRNA_1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036525"
gz1="$(_compress_if_exists 'SRR12036525_1' || true)"
gz2="$(_compress_if_exists 'SRR12036525_2' || true)"
gzs="$(_compress_if_exists 'SRR12036525' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13d_CYFIP2_gRNA_2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13d_CYFIP2_gRNA_2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036526"
gz1="$(_compress_if_exists 'SRR12036526_1' || true)"
gz2="$(_compress_if_exists 'SRR12036526_2' || true)"
gzs="$(_compress_if_exists 'SRR12036526' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13d_NT_gRNA_1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13d_NT_gRNA_1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036527"
gz1="$(_compress_if_exists 'SRR12036527_1' || true)"
gz2="$(_compress_if_exists 'SRR12036527_2' || true)"
gzs="$(_compress_if_exists 'SRR12036527' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas13d_NT_gRNA_2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas13d_NT_gRNA_2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036528"
gz1="$(_compress_if_exists 'SRR12036528_1' || true)"
gz2="$(_compress_if_exists 'SRR12036528_2' || true)"
gzs="$(_compress_if_exists 'SRR12036528' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas9_CYFIP2_gRNA_1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas9_CYFIP2_gRNA_1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036529"
gz1="$(_compress_if_exists 'SRR12036529_1' || true)"
gz2="$(_compress_if_exists 'SRR12036529_2' || true)"
gzs="$(_compress_if_exists 'SRR12036529' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas9_CYFIP2_gRNA_2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas9_CYFIP2_gRNA_2_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036530"
gz1="$(_compress_if_exists 'SRR12036530_1' || true)"
gz2="$(_compress_if_exists 'SRR12036530_2' || true)"
gzs="$(_compress_if_exists 'SRR12036530' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas9_NT_gRNA_1_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas9_NT_gRNA_1_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR12036531"
gz1="$(_compress_if_exists 'SRR12036531_1' || true)"
gz2="$(_compress_if_exists 'SRR12036531_2' || true)"
gzs="$(_compress_if_exists 'SRR12036531' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cas9_NT_gRNA_2_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cas9_NT_gRNA_2_R2_001.fastq.gz"
fi

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

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

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


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036520/SRR12036520"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036521/SRR12036521"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036522/SRR12036522"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036523/SRR12036523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036524/SRR12036524"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036525/SRR12036525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036526/SRR12036526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036527/SRR12036527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036528/SRR12036528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036529/SRR12036529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036530/SRR12036530"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036531/SRR12036531"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036532/SRR12036532"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036533/SRR12036533"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036534/SRR12036534"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036520/SRR12036520"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036521/SRR12036521"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036522/SRR12036522"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036523/SRR12036523"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036524/SRR12036524"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036525/SRR12036525"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036526/SRR12036526"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036527/SRR12036527"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036528/SRR12036528"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036529/SRR12036529"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036530/SRR12036530"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036531/SRR12036531"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036532/SRR12036532"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036533/SRR12036533"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR12036534/SRR12036534"

echo "Download complete. Files saved to $OUTDIR"