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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE113nnn/GSE113947/suppl/GSE113947_exp.RBM20.txt.gz" -O "GSE113947_exp.RBM20.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 "SRR7092055"
gz1="$(_compress_if_exists 'SRR7092055_1' || true)"
gz2="$(_compress_if_exists 'SRR7092055_2' || true)"
gzs="$(_compress_if_exists 'SRR7092055' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_638_Del_8_1-S6_r4_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_638_Del_8_1-S6_r4_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092056"
gz1="$(_compress_if_exists 'SRR7092056_1' || true)"
gz2="$(_compress_if_exists 'SRR7092056_2' || true)"
gzs="$(_compress_if_exists 'SRR7092056' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_638_Del_8_2-S7_r4_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_638_Del_8_2-S7_r4_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092057"
gz1="$(_compress_if_exists 'SRR7092057_1' || true)"
gz2="$(_compress_if_exists 'SRR7092057_2' || true)"
gzs="$(_compress_if_exists 'SRR7092057' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_638_Del_8_3-S8_r4_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_638_Del_8_3-S8_r4_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092058"
gz1="$(_compress_if_exists 'SRR7092058_1' || true)"
gz2="$(_compress_if_exists 'SRR7092058_2' || true)"
gzs="$(_compress_if_exists 'SRR7092058' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_638_Del_8_4_S9_r4_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_638_Del_8_4_S9_r4_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092059"
gz1="$(_compress_if_exists 'SRR7092059_1' || true)"
gz2="$(_compress_if_exists 'SRR7092059_2' || true)"
gzs="$(_compress_if_exists 'SRR7092059' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Het_R636-S1_r2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Het_R636-S1_r2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092060"
gz1="$(_compress_if_exists 'SRR7092060_1' || true)"
gz2="$(_compress_if_exists 'SRR7092060_2' || true)"
gzs="$(_compress_if_exists 'SRR7092060' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Het_R636-S2_r2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Het_R636-S2_r2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092061"
gz1="$(_compress_if_exists 'SRR7092061_1' || true)"
gz2="$(_compress_if_exists 'SRR7092061_2' || true)"
gzs="$(_compress_if_exists 'SRR7092061' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Het_R636-S3_r2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Het_R636-S3_r2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092062"
gz1="$(_compress_if_exists 'SRR7092062_1' || true)"
gz2="$(_compress_if_exists 'SRR7092062_2' || true)"
gzs="$(_compress_if_exists 'SRR7092062' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Het_R636-S16_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Het_R636-S16_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092063"
gz1="$(_compress_if_exists 'SRR7092063_1' || true)"
gz2="$(_compress_if_exists 'SRR7092063_2' || true)"
gzs="$(_compress_if_exists 'SRR7092063' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Het_R636-S19_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Het_R636-S19_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092064"
gz1="$(_compress_if_exists 'SRR7092064_1' || true)"
gz2="$(_compress_if_exists 'SRR7092064_2' || true)"
gzs="$(_compress_if_exists 'SRR7092064' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Het_R636-S22_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Het_R636-S22_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092065"
gz1="$(_compress_if_exists 'SRR7092065_1' || true)"
gz2="$(_compress_if_exists 'SRR7092065_2' || true)"
gzs="$(_compress_if_exists 'SRR7092065' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Homo_R636-S17_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Homo_R636-S17_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092066"
gz1="$(_compress_if_exists 'SRR7092066_1' || true)"
gz2="$(_compress_if_exists 'SRR7092066_2' || true)"
gzs="$(_compress_if_exists 'SRR7092066' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Homo_R636-S20_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Homo_R636-S20_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092067"
gz1="$(_compress_if_exists 'SRR7092067_1' || true)"
gz2="$(_compress_if_exists 'SRR7092067_2' || true)"
gzs="$(_compress_if_exists 'SRR7092067' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_Homo_R636-S23_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_Homo_R636-S23_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092068"
gz1="$(_compress_if_exists 'SRR7092068_1' || true)"
gz2="$(_compress_if_exists 'SRR7092068_2' || true)"
gzs="$(_compress_if_exists 'SRR7092068' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S1_r2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S1_r2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092069"
gz1="$(_compress_if_exists 'SRR7092069_1' || true)"
gz2="$(_compress_if_exists 'SRR7092069_2' || true)"
gzs="$(_compress_if_exists 'SRR7092069' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S2_r2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S2_r2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092070"
gz1="$(_compress_if_exists 'SRR7092070_1' || true)"
gz2="$(_compress_if_exists 'SRR7092070_2' || true)"
gzs="$(_compress_if_exists 'SRR7092070' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S3_r2_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S3_r2_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092071"
gz1="$(_compress_if_exists 'SRR7092071_1' || true)"
gz2="$(_compress_if_exists 'SRR7092071_2' || true)"
gzs="$(_compress_if_exists 'SRR7092071' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S14_r4_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S14_r4_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092072"
gz1="$(_compress_if_exists 'SRR7092072_1' || true)"
gz2="$(_compress_if_exists 'SRR7092072_2' || true)"
gzs="$(_compress_if_exists 'SRR7092072' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S15_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S15_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092073"
gz1="$(_compress_if_exists 'SRR7092073_1' || true)"
gz2="$(_compress_if_exists 'SRR7092073_2' || true)"
gzs="$(_compress_if_exists 'SRR7092073' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S15_r4_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S15_r4_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092074"
gz1="$(_compress_if_exists 'SRR7092074_1' || true)"
gz2="$(_compress_if_exists 'SRR7092074_2' || true)"
gzs="$(_compress_if_exists 'SRR7092074' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S18_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S18_r3_R2.fastq.gz"
fi

fasterq-dump --split-files "SRR7092075"
gz1="$(_compress_if_exists 'SRR7092075_1' || true)"
gz2="$(_compress_if_exists 'SRR7092075_2' || true)"
gzs="$(_compress_if_exists 'SRR7092075' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "WTC_WT-S21_r3_R1.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "WTC_WT-S21_r3_R2.fastq.gz"
fi


# Option B: Direct download (larger .sra files)
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092055/SRR7092055"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092056/SRR7092056"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092057/SRR7092057"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092058/SRR7092058"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092059/SRR7092059"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092060/SRR7092060"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092061/SRR7092061"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092062/SRR7092062"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092063/SRR7092063"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092064/SRR7092064"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092065/SRR7092065"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092066/SRR7092066"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092067/SRR7092067"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092068/SRR7092068"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092069/SRR7092069"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092070/SRR7092070"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092071/SRR7092071"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092072/SRR7092072"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092073/SRR7092073"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092074/SRR7092074"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092075/SRR7092075"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092055/SRR7092055"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092055/SRR7092055"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092056/SRR7092056"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR007/092/SRR7092057.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092057/SRR7092057"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092058/SRR7092058"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092062/SRR7092062"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092063/SRR7092063"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092059/SRR7092059"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR007/092/SRR7092059.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092064/SRR7092064"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092060/SRR7092060"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR007/092/SRR7092061.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092061/SRR7092061"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR007/092/SRR7092065.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092065/SRR7092065"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092066/SRR7092066"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092067/SRR7092067"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092071/SRR7092071"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092072/SRR7092072"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092073/SRR7092073"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092074/SRR7092074"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092068/SRR7092068"
curl -L -O -C - "https://sra-downloadb.be-md.ncbi.nlm.nih.gov/sos5/sra-pub-zq-14/SRR007/092/SRR7092068.sralite.1"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092075/SRR7092075"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092069/SRR7092069"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR7092070/SRR7092070"

echo "Download complete. Files saved to $OUTDIR"