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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE55nnn/GSE55727/suppl/GSE55727_Human_ChIP_peaks.bed.gz" -O "GSE55727_Human_ChIP_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE55nnn/GSE55727/suppl/GSE55727_Human_RNA_Expression_Matrix.txt.gz" -O "GSE55727_Human_RNA_Expression_Matrix.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE55nnn/GSE55727/suppl/GSE55727_MEF_ChIP_peaks.bed.gz" -O "GSE55727_MEF_ChIP_peaks.bed.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE55nnn/GSE55727/suppl/GSE55727_MEF_KO_RNA_Expression_Matrix.txt.gz" -O "GSE55727_MEF_KO_RNA_Expression_Matrix.txt.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE55nnn/GSE55727/suppl/GSE55727_MEF_WT_RNA_Expression_Matrix.txt.gz" -O "GSE55727_MEF_WT_RNA_Expression_Matrix.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 "SRR1186241"
gz1="$(_compress_if_exists 'SRR1186241_1' || true)"
gz2="$(_compress_if_exists 'SRR1186241_2' || true)"
gzs="$(_compress_if_exists 'SRR1186241' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "70-dox-rep1-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "70-dox-rep1-reverse.fq.gz"
fi

fasterq-dump --split-files "SRR1186242"
gz1="$(_compress_if_exists 'SRR1186242_1' || true)"
gz2="$(_compress_if_exists 'SRR1186242_2' || true)"
gzs="$(_compress_if_exists 'SRR1186242' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "70-dox-rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "70-dox-rep2-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186243"
gz1="$(_compress_if_exists 'SRR1186243_1' || true)"
gz2="$(_compress_if_exists 'SRR1186243_2' || true)"
gzs="$(_compress_if_exists 'SRR1186243' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "70+dox-rep1-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "70+dox-rep1-reverse.fq.gz"
fi

fasterq-dump --split-files "SRR1186244"
gz1="$(_compress_if_exists 'SRR1186244_1' || true)"
gz2="$(_compress_if_exists 'SRR1186244_2' || true)"
gzs="$(_compress_if_exists 'SRR1186244' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "70+dox-rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "70+dox-rep2-forward.fq.gz"
fi

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

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

fasterq-dump --split-files "SRR1186247"
gz1="$(_compress_if_exists 'SRR1186247_1' || true)"
gz2="$(_compress_if_exists 'SRR1186247_2' || true)"
gzs="$(_compress_if_exists 'SRR1186247' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "11-dox-rep1-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "11-dox-rep1-reverse.fq.gz"
fi

fasterq-dump --split-files "SRR1186248"
gz1="$(_compress_if_exists 'SRR1186248_1' || true)"
gz2="$(_compress_if_exists 'SRR1186248_2' || true)"
gzs="$(_compress_if_exists 'SRR1186248' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "11-dox-rep2-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "11-dox-rep2-reverse.fq.gz"
fi

fasterq-dump --split-files "SRR1186249"
gz1="$(_compress_if_exists 'SRR1186249_1' || true)"
gz2="$(_compress_if_exists 'SRR1186249_2' || true)"
gzs="$(_compress_if_exists 'SRR1186249' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "11+dox-rep1-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "11+dox-rep1-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186250"
gz1="$(_compress_if_exists 'SRR1186250_1' || true)"
gz2="$(_compress_if_exists 'SRR1186250_2' || true)"
gzs="$(_compress_if_exists 'SRR1186250' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "11+dox-rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "11+dox-rep2-forward.fq.gz"
fi

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

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

fasterq-dump --split-files "SRR1186253"
gz1="$(_compress_if_exists 'SRR1186253_1' || true)"
gz2="$(_compress_if_exists 'SRR1186253_2' || true)"
gzs="$(_compress_if_exists 'SRR1186253' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WT_UNT_Rep1-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WT_UNT_Rep1-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186254"
gz1="$(_compress_if_exists 'SRR1186254_1' || true)"
gz2="$(_compress_if_exists 'SRR1186254_2' || true)"
gzs="$(_compress_if_exists 'SRR1186254' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WT_UNT_Rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WT_UNT_Rep2-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186255"
gz1="$(_compress_if_exists 'SRR1186255_1' || true)"
gz2="$(_compress_if_exists 'SRR1186255_2' || true)"
gzs="$(_compress_if_exists 'SRR1186255' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WT_UNT_Rep3-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WT_UNT_Rep3-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186256"
gz1="$(_compress_if_exists 'SRR1186256_1' || true)"
gz2="$(_compress_if_exists 'SRR1186256_2' || true)"
gzs="$(_compress_if_exists 'SRR1186256' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WT_DOX_Rep1-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WT_DOX_Rep1-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186257"
gz1="$(_compress_if_exists 'SRR1186257_1' || true)"
gz2="$(_compress_if_exists 'SRR1186257_2' || true)"
gzs="$(_compress_if_exists 'SRR1186257' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WT_DOX_Rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WT_DOX_Rep2-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1186258"
gz1="$(_compress_if_exists 'SRR1186258_1' || true)"
gz2="$(_compress_if_exists 'SRR1186258_2' || true)"
gzs="$(_compress_if_exists 'SRR1186258' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WT_DOX_Rep3-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WT_DOX_Rep3-reverse.fq.gz"
fi

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

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

fasterq-dump --split-files "SRR1265767"
gz1="$(_compress_if_exists 'SRR1265767_1' || true)"
gz2="$(_compress_if_exists 'SRR1265767_2' || true)"
gzs="$(_compress_if_exists 'SRR1265767' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KO_UNT_Rep1-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KO_UNT_Rep1-reverse.fq.gz"
fi

fasterq-dump --split-files "SRR1265768"
gz1="$(_compress_if_exists 'SRR1265768_1' || true)"
gz2="$(_compress_if_exists 'SRR1265768_2' || true)"
gzs="$(_compress_if_exists 'SRR1265768' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KO_UNT_Rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KO_UNT_Rep2-forward.fq.gz"
fi

fasterq-dump --split-files "SRR1265769"
gz1="$(_compress_if_exists 'SRR1265769_1' || true)"
gz2="$(_compress_if_exists 'SRR1265769_2' || true)"
gzs="$(_compress_if_exists 'SRR1265769' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KO_DOX_Rep1-forward.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KO_DOX_Rep1-reverse.fq.gz"
fi

fasterq-dump --split-files "SRR1265770"
gz1="$(_compress_if_exists 'SRR1265770_1' || true)"
gz2="$(_compress_if_exists 'SRR1265770_2' || true)"
gzs="$(_compress_if_exists 'SRR1265770' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "KO_DOX_Rep2-reverse.fq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "KO_DOX_Rep2-forward.fq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186241/SRR1186241"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186242/SRR1186242"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186243/SRR1186243"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186244/SRR1186244"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186245/SRR1186245.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186246/SRR1186246.2"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186247/SRR1186247"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186248/SRR1186248"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186249/SRR1186249"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186250/SRR1186250"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186251/SRR1186251.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186252/SRR1186252.2"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186253/SRR1186253"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186254/SRR1186254"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186255/SRR1186255"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/186/SRR1186256/SRR1186256.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186257/SRR1186257"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/186/SRR1186258/SRR1186258.sralite.1"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186259/SRR1186259.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186260/SRR1186260.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/265/SRR1265767/SRR1265767.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1265768/SRR1265768"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1265769/SRR1265769"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/265/SRR1265770/SRR1265770.sralite.1"

# --- Additional data files ---
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186252/SRR1186252.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186260/SRR1186260.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186259/SRR1186259.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186245/SRR1186245.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186246/SRR1186246.2"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-run-32/SRR001/1186/SRR1186251/SRR1186251.2"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186247/SRR1186247"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186249/SRR1186249"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186248/SRR1186248"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186241/SRR1186241"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186243/SRR1186243"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1265769/SRR1265769"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/265/SRR1265767/SRR1265767.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1265768/SRR1265768"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186242/SRR1186242"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186244/SRR1186244"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186250/SRR1186250"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186253/SRR1186253"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186257/SRR1186257"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/265/SRR1265770/SRR1265770.sralite.1"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/186/SRR1186256/SRR1186256.sralite.1"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-11/SRR001/186/SRR1186258/SRR1186258.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186254/SRR1186254"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR1186255/SRR1186255"

echo "Download complete. Files saved to $OUTDIR"