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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE95nnn/GSE95156/suppl/GSE95156_Alpha_Beta.txt.gz" -O "GSE95156_Alpha_Beta.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 "SRR5277343"
gz1="$(_compress_if_exists 'SRR5277343_1' || true)"
gz2="$(_compress_if_exists 'SRR5277343_2' || true)"
gzs="$(_compress_if_exists 'SRR5277343' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT8b_2_GCCAAT_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT8b_2_GCCAAT_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277344"
gz1="$(_compress_if_exists 'SRR5277344_1' || true)"
gz2="$(_compress_if_exists 'SRR5277344_2' || true)"
gzs="$(_compress_if_exists 'SRR5277344' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT8b_1_ACAGTG_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT8b_1_ACAGTG_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277345"
gz1="$(_compress_if_exists 'SRR5277345_1' || true)"
gz2="$(_compress_if_exists 'SRR5277345_2' || true)"
gzs="$(_compress_if_exists 'SRR5277345' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT8a_2_ACTTGA_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT8a_2_ACTTGA_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277346"
gz1="$(_compress_if_exists 'SRR5277346_1' || true)"
gz2="$(_compress_if_exists 'SRR5277346_2' || true)"
gzs="$(_compress_if_exists 'SRR5277346' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT8a_1_ATCACG_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT8a_1_ATCACG_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277347"
gz1="$(_compress_if_exists 'SRR5277347_1' || true)"
gz2="$(_compress_if_exists 'SRR5277347_2' || true)"
gzs="$(_compress_if_exists 'SRR5277347' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT4b_2_ATTCCT_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT4b_2_ATTCCT_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277348"
gz1="$(_compress_if_exists 'SRR5277348_1' || true)"
gz2="$(_compress_if_exists 'SRR5277348_2' || true)"
gzs="$(_compress_if_exists 'SRR5277348' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT4b_1_CGTACG_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT4b_1_CGTACG_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277349"
gz1="$(_compress_if_exists 'SRR5277349_1' || true)"
gz2="$(_compress_if_exists 'SRR5277349_2' || true)"
gzs="$(_compress_if_exists 'SRR5277349' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT4a_2_GTGAAA_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT4a_2_GTGAAA_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277350"
gz1="$(_compress_if_exists 'SRR5277350_1' || true)"
gz2="$(_compress_if_exists 'SRR5277350_2' || true)"
gzs="$(_compress_if_exists 'SRR5277350' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT4a_1_CTTGTA_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT4a_1_CTTGTA_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277351"
gz1="$(_compress_if_exists 'SRR5277351_1' || true)"
gz2="$(_compress_if_exists 'SRR5277351_2' || true)"
gzs="$(_compress_if_exists 'SRR5277351' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT20b_2_GGCTAC_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT20b_2_GGCTAC_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277352"
gz1="$(_compress_if_exists 'SRR5277352_1' || true)"
gz2="$(_compress_if_exists 'SRR5277352_2' || true)"
gzs="$(_compress_if_exists 'SRR5277352' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT20b_1_TAGCTT_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT20b_1_TAGCTT_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277353"
gz1="$(_compress_if_exists 'SRR5277353_1' || true)"
gz2="$(_compress_if_exists 'SRR5277353_2' || true)"
gzs="$(_compress_if_exists 'SRR5277353' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT20a_2_CCGTCC_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT20a_2_CCGTCC_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277354"
gz1="$(_compress_if_exists 'SRR5277354_1' || true)"
gz2="$(_compress_if_exists 'SRR5277354_2' || true)"
gzs="$(_compress_if_exists 'SRR5277354' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT20a_1_CAGATC_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT20a_1_CAGATC_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277355"
gz1="$(_compress_if_exists 'SRR5277355_1' || true)"
gz2="$(_compress_if_exists 'SRR5277355_2' || true)"
gzs="$(_compress_if_exists 'SRR5277355' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT16b_2_ACTTGA_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT16b_2_ACTTGA_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277356"
gz1="$(_compress_if_exists 'SRR5277356_1' || true)"
gz2="$(_compress_if_exists 'SRR5277356_2' || true)"
gzs="$(_compress_if_exists 'SRR5277356' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT16b_1_ATCACG_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT16b_1_ATCACG_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277357"
gz1="$(_compress_if_exists 'SRR5277357_1' || true)"
gz2="$(_compress_if_exists 'SRR5277357_2' || true)"
gzs="$(_compress_if_exists 'SRR5277357' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT16a_2_TGACCA_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT16a_2_TGACCA_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277358"
gz1="$(_compress_if_exists 'SRR5277358_1' || true)"
gz2="$(_compress_if_exists 'SRR5277358_2' || true)"
gzs="$(_compress_if_exists 'SRR5277358' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT16a_1_CGATGT_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT16a_1_CGATGT_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277359"
gz1="$(_compress_if_exists 'SRR5277359_1' || true)"
gz2="$(_compress_if_exists 'SRR5277359_2' || true)"
gzs="$(_compress_if_exists 'SRR5277359' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT12b_2_GTGAAA_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT12b_2_GTGAAA_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277360"
gz1="$(_compress_if_exists 'SRR5277360_1' || true)"
gz2="$(_compress_if_exists 'SRR5277360_2' || true)"
gzs="$(_compress_if_exists 'SRR5277360' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT12b_1_CTTGTA_L003_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT12b_1_CTTGTA_L003_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277361"
gz1="$(_compress_if_exists 'SRR5277361_1' || true)"
gz2="$(_compress_if_exists 'SRR5277361_2' || true)"
gzs="$(_compress_if_exists 'SRR5277361' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT12a_2_GGCTAC_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT12a_2_GGCTAC_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277362"
gz1="$(_compress_if_exists 'SRR5277362_1' || true)"
gz2="$(_compress_if_exists 'SRR5277362_2' || true)"
gzs="$(_compress_if_exists 'SRR5277362' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT12a_1_TAGCTT_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT12a_1_TAGCTT_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277363"
gz1="$(_compress_if_exists 'SRR5277363_1' || true)"
gz2="$(_compress_if_exists 'SRR5277363_2' || true)"
gzs="$(_compress_if_exists 'SRR5277363' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT0b_2_GATCAG_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT0b_2_GATCAG_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277364"
gz1="$(_compress_if_exists 'SRR5277364_1' || true)"
gz2="$(_compress_if_exists 'SRR5277364_2' || true)"
gzs="$(_compress_if_exists 'SRR5277364' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT0b_1_TTAGGC_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT0b_1_TTAGGC_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277365"
gz1="$(_compress_if_exists 'SRR5277365_1' || true)"
gz2="$(_compress_if_exists 'SRR5277365_2' || true)"
gzs="$(_compress_if_exists 'SRR5277365' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT0a_2_GCCAAT_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT0a_2_GCCAAT_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR5277366"
gz1="$(_compress_if_exists 'SRR5277366_1' || true)"
gz2="$(_compress_if_exists 'SRR5277366_2' || true)"
gzs="$(_compress_if_exists 'SRR5277366' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "ZT0a_1_ACAGTG_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "ZT0a_1_ACAGTG_L001_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/SRR5277343/SRR5277343"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277344/SRR5277344"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277345/SRR5277345"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277346/SRR5277346"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277347/SRR5277347"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277348/SRR5277348"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277349/SRR5277349"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277350/SRR5277350"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277351/SRR5277351"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277352/SRR5277352"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277353/SRR5277353"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277354/SRR5277354"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277355/SRR5277355"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277356/SRR5277356"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277357/SRR5277357"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277358/SRR5277358"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277359/SRR5277359"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277360/SRR5277360"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277361/SRR5277361"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277362/SRR5277362"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR005/277/SRR5277363.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277364/SRR5277364"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277365/SRR5277365"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR005/277/SRR5277366.sralite.1"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277347/SRR5277347"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277352/SRR5277352"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277354/SRR5277354"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277359/SRR5277359"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR005/277/SRR5277363.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277365/SRR5277365"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR005/277/SRR5277366.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277364/SRR5277364"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277362/SRR5277362"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277361/SRR5277361"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277360/SRR5277360"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277358/SRR5277358"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277357/SRR5277357"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277356/SRR5277356"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277355/SRR5277355"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277353/SRR5277353"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277351/SRR5277351"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277350/SRR5277350"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277349/SRR5277349"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277348/SRR5277348"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277346/SRR5277346"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277345/SRR5277345"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277344/SRR5277344"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR5277343/SRR5277343"

echo "Download complete. Files saved to $OUTDIR"