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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE279nnn/GSE279254/suppl/GSE279254_snRNAseq_Chang.h5ad" -O "GSE279254_snRNAseq_Chang.h5ad"

# --- 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 "SRR30950141"
gz1="$(_compress_if_exists 'SRR30950141_1' || true)"
gz2="$(_compress_if_exists 'SRR30950141_2' || true)"
gzs="$(_compress_if_exists 'SRR30950141' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_prox_M2_S6_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_prox_M2_S6_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950142"
gz1="$(_compress_if_exists 'SRR30950142_1' || true)"
gz2="$(_compress_if_exists 'SRR30950142_2' || true)"
gzs="$(_compress_if_exists 'SRR30950142' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_dist_M2_S6_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_dist_M2_S6_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950143"
gz1="$(_compress_if_exists 'SRR30950143_1' || true)"
gz2="$(_compress_if_exists 'SRR30950143_2' || true)"
gzs="$(_compress_if_exists 'SRR30950143' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_dist_M1_S9_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_dist_M1_S9_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950144"
gz1="$(_compress_if_exists 'SRR30950144_1' || true)"
gz2="$(_compress_if_exists 'SRR30950144_2' || true)"
gzs="$(_compress_if_exists 'SRR30950144' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_dist_M1_S5_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_dist_M1_S5_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950145"
gz1="$(_compress_if_exists 'SRR30950145_1' || true)"
gz2="$(_compress_if_exists 'SRR30950145_2' || true)"
gzs="$(_compress_if_exists 'SRR30950145' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_c_prox_M1_S11_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_c_prox_M1_S11_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950146"
gz1="$(_compress_if_exists 'SRR30950146_1' || true)"
gz2="$(_compress_if_exists 'SRR30950146_2' || true)"
gzs="$(_compress_if_exists 'SRR30950146' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_c_prox_M1_S7_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_c_prox_M1_S7_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950147"
gz1="$(_compress_if_exists 'SRR30950147_1' || true)"
gz2="$(_compress_if_exists 'SRR30950147_2' || true)"
gzs="$(_compress_if_exists 'SRR30950147' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_c_dist_M1_S12_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_c_dist_M1_S12_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950148"
gz1="$(_compress_if_exists 'SRR30950148_1' || true)"
gz2="$(_compress_if_exists 'SRR30950148_2' || true)"
gzs="$(_compress_if_exists 'SRR30950148' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_c_dist_M1_S8_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_c_dist_M1_S8_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950149"
gz1="$(_compress_if_exists 'SRR30950149_1' || true)"
gz2="$(_compress_if_exists 'SRR30950149_2' || true)"
gzs="$(_compress_if_exists 'SRR30950149' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_prox_M2_S2_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_prox_M2_S2_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950150"
gz1="$(_compress_if_exists 'SRR30950150_1' || true)"
gz2="$(_compress_if_exists 'SRR30950150_2' || true)"
gzs="$(_compress_if_exists 'SRR30950150' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_prox_M1_S5_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_prox_M1_S5_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950151"
gz1="$(_compress_if_exists 'SRR30950151_1' || true)"
gz2="$(_compress_if_exists 'SRR30950151_2' || true)"
gzs="$(_compress_if_exists 'SRR30950151' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_prox_M1_S1_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_prox_M1_S1_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950152"
gz1="$(_compress_if_exists 'SRR30950152_1' || true)"
gz2="$(_compress_if_exists 'SRR30950152_2' || true)"
gzs="$(_compress_if_exists 'SRR30950152' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_mid_M2_S8_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_mid_M2_S8_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950153"
gz1="$(_compress_if_exists 'SRR30950153_1' || true)"
gz2="$(_compress_if_exists 'SRR30950153_2' || true)"
gzs="$(_compress_if_exists 'SRR30950153' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_mid_M2_S4_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_mid_M2_S4_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950154"
gz1="$(_compress_if_exists 'SRR30950154_1' || true)"
gz2="$(_compress_if_exists 'SRR30950154_2' || true)"
gzs="$(_compress_if_exists 'SRR30950154' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_mid_M1_S7_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_mid_M1_S7_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950155"
gz1="$(_compress_if_exists 'SRR30950155_1' || true)"
gz2="$(_compress_if_exists 'SRR30950155_2' || true)"
gzs="$(_compress_if_exists 'SRR30950155' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_mid_M1_S3_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_mid_M1_S3_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR30950156"
gz1="$(_compress_if_exists 'SRR30950156_1' || true)"
gz2="$(_compress_if_exists 'SRR30950156_2' || true)"
gzs="$(_compress_if_exists 'SRR30950156' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JC_EL_10XNuclei_si_dist_M2_S10_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JC_EL_10XNuclei_si_dist_M2_S10_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/SRR30950141/SRR30950141"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950142/SRR30950142"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950143/SRR30950143"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950144/SRR30950144"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950145/SRR30950145"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950146/SRR30950146"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950147/SRR30950147"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950148/SRR30950148"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950149/SRR30950149"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950150/SRR30950150"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950151/SRR30950151"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950152/SRR30950152"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950153/SRR30950153"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950154/SRR30950154"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950155/SRR30950155"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950156/SRR30950156"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950147/SRR30950147"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950148/SRR30950148"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950145/SRR30950145"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950146/SRR30950146"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950144/SRR30950144"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950143/SRR30950143"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950156/SRR30950156"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950142/SRR30950142"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950155/SRR30950155"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950154/SRR30950154"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950153/SRR30950153"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950152/SRR30950152"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950151/SRR30950151"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950150/SRR30950150"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950149/SRR30950149"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR30950141/SRR30950141"

echo "Download complete. Files saved to $OUTDIR"