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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE273nnn/GSE273092/suppl/GSE273092_featureCounts_output.txt.gz" -O "GSE273092_featureCounts_output.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE273nnn/GSE273092/suppl/GSE273092_zfp697_mKO_control_vs_wt_control_deseq2.txt.gz" -O "GSE273092_zfp697_mKO_control_vs_wt_control_deseq2.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE273nnn/GSE273092/suppl/GSE273092_zfp697_mKO_reloading_vs_control_deseq2.txt.gz" -O "GSE273092_zfp697_mKO_reloading_vs_control_deseq2.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE273nnn/GSE273092/suppl/GSE273092_zfp697_mKO_reloading_vs_unloading_deseq2.txt.gz" -O "GSE273092_zfp697_mKO_reloading_vs_unloading_deseq2.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE273nnn/GSE273092/suppl/GSE273092_zfp697_mKO_unloading_vs_control_deseq2.txt.gz" -O "GSE273092_zfp697_mKO_unloading_vs_control_deseq2.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 "SRR29988463"
gz1="$(_compress_if_exists 'SRR29988463_1' || true)"
gz2="$(_compress_if_exists 'SRR29988463_2' || true)"
gzs="$(_compress_if_exists 'SRR29988463' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-18_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-18_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988464"
gz1="$(_compress_if_exists 'SRR29988464_1' || true)"
gz2="$(_compress_if_exists 'SRR29988464_2' || true)"
gzs="$(_compress_if_exists 'SRR29988464' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-17_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-17_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988465"
gz1="$(_compress_if_exists 'SRR29988465_1' || true)"
gz2="$(_compress_if_exists 'SRR29988465_2' || true)"
gzs="$(_compress_if_exists 'SRR29988465' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-16_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-16_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988466"
gz1="$(_compress_if_exists 'SRR29988466_1' || true)"
gz2="$(_compress_if_exists 'SRR29988466_2' || true)"
gzs="$(_compress_if_exists 'SRR29988466' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-15_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-15_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988467"
gz1="$(_compress_if_exists 'SRR29988467_1' || true)"
gz2="$(_compress_if_exists 'SRR29988467_2' || true)"
gzs="$(_compress_if_exists 'SRR29988467' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-14_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-14_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988468"
gz1="$(_compress_if_exists 'SRR29988468_1' || true)"
gz2="$(_compress_if_exists 'SRR29988468_2' || true)"
gzs="$(_compress_if_exists 'SRR29988468' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-13_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-13_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988469"
gz1="$(_compress_if_exists 'SRR29988469_1' || true)"
gz2="$(_compress_if_exists 'SRR29988469_2' || true)"
gzs="$(_compress_if_exists 'SRR29988469' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-12_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-12_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988470"
gz1="$(_compress_if_exists 'SRR29988470_1' || true)"
gz2="$(_compress_if_exists 'SRR29988470_2' || true)"
gzs="$(_compress_if_exists 'SRR29988470' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-11_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-11_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988471"
gz1="$(_compress_if_exists 'SRR29988471_1' || true)"
gz2="$(_compress_if_exists 'SRR29988471_2' || true)"
gzs="$(_compress_if_exists 'SRR29988471' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-10_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-10_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988472"
gz1="$(_compress_if_exists 'SRR29988472_1' || true)"
gz2="$(_compress_if_exists 'SRR29988472_2' || true)"
gzs="$(_compress_if_exists 'SRR29988472' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-9_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-9_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988473"
gz1="$(_compress_if_exists 'SRR29988473_1' || true)"
gz2="$(_compress_if_exists 'SRR29988473_2' || true)"
gzs="$(_compress_if_exists 'SRR29988473' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-8_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-8_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988474"
gz1="$(_compress_if_exists 'SRR29988474_1' || true)"
gz2="$(_compress_if_exists 'SRR29988474_2' || true)"
gzs="$(_compress_if_exists 'SRR29988474' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-7_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-7_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988475"
gz1="$(_compress_if_exists 'SRR29988475_1' || true)"
gz2="$(_compress_if_exists 'SRR29988475_2' || true)"
gzs="$(_compress_if_exists 'SRR29988475' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-6_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-6_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988476"
gz1="$(_compress_if_exists 'SRR29988476_1' || true)"
gz2="$(_compress_if_exists 'SRR29988476_2' || true)"
gzs="$(_compress_if_exists 'SRR29988476' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-5_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-5_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988477"
gz1="$(_compress_if_exists 'SRR29988477_1' || true)"
gz2="$(_compress_if_exists 'SRR29988477_2' || true)"
gzs="$(_compress_if_exists 'SRR29988477' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-4_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-4_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988478"
gz1="$(_compress_if_exists 'SRR29988478_1' || true)"
gz2="$(_compress_if_exists 'SRR29988478_2' || true)"
gzs="$(_compress_if_exists 'SRR29988478' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-3_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-3_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988479"
gz1="$(_compress_if_exists 'SRR29988479_1' || true)"
gz2="$(_compress_if_exists 'SRR29988479_2' || true)"
gzs="$(_compress_if_exists 'SRR29988479' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-2_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-2_2.fastq.gz"
fi

fasterq-dump --split-files "SRR29988480"
gz1="$(_compress_if_exists 'SRR29988480_1' || true)"
gz2="$(_compress_if_exists 'SRR29988480_2' || true)"
gzs="$(_compress_if_exists 'SRR29988480' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "JR-JC-1_1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "JR-JC-1_2.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988463/SRR29988463"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988464/SRR29988464"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988465/SRR29988465"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988466/SRR29988466"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988467/SRR29988467"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988468/SRR29988468"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988469/SRR29988469"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988470/SRR29988470"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988471/SRR29988471"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos6/sra-pub-zq-40/SRR029/29988/SRR29988472/SRR29988472.lite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988473/SRR29988473"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988474/SRR29988474"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988475/SRR29988475"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988476/SRR29988476"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988477/SRR29988477"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988478/SRR29988478"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988479/SRR29988479"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988480/SRR29988480"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988471/SRR29988471"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988470/SRR29988470"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988480/SRR29988480"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988469/SRR29988469"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988468/SRR29988468"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988467/SRR29988467"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988466/SRR29988466"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988465/SRR29988465"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988464/SRR29988464"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988463/SRR29988463"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988479/SRR29988479"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988478/SRR29988478"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988477/SRR29988477"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988476/SRR29988476"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988475/SRR29988475"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988474/SRR29988474"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988473/SRR29988473"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29988472/SRR29988472"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos6/sra-pub-zq-40/SRR029/29988/SRR29988472/SRR29988472.lite.1"

echo "Download complete. Files saved to $OUTDIR"