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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE147nnn/GSE147005/suppl/GSE147005_srsf1_acute_hko_deseq2_output.csv.gz" -O "GSE147005_srsf1_acute_hko_deseq2_output.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE147nnn/GSE147005/suppl/GSE147005_srsf1_hko_1m_deseq2_output.csv.gz" -O "GSE147005_srsf1_hko_1m_deseq2_output.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE147nnn/GSE147005/suppl/GSE147005_srsf1_hko_pn10_deseq2_output.csv.gz" -O "GSE147005_srsf1_hko_pn10_deseq2_output.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE147nnn/GSE147005/suppl/GSE147005_transcript_tpm_kallisto_table.csv.gz" -O "GSE147005_transcript_tpm_kallisto_table.csv.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 "SRR11309602"
gz1="$(_compress_if_exists 'SRR11309602_1' || true)"
gz2="$(_compress_if_exists 'SRR11309602_2' || true)"
gzs="$(_compress_if_exists 'SRR11309602' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cre_p10_1_AGTCAACA_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cre_p10_1_AGTCAACA_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309603"
gz1="$(_compress_if_exists 'SRR11309603_1' || true)"
gz2="$(_compress_if_exists 'SRR11309603_2' || true)"
gzs="$(_compress_if_exists 'SRR11309603' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cre_p10_2_AGTTCCGT_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cre_p10_2_AGTTCCGT_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309604"
gz1="$(_compress_if_exists 'SRR11309604_1' || true)"
gz2="$(_compress_if_exists 'SRR11309604_2' || true)"
gzs="$(_compress_if_exists 'SRR11309604' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "SRSF1KO_p10_1_ATGTCAGA_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "SRSF1KO_p10_1_ATGTCAGA_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309605"
gz1="$(_compress_if_exists 'SRR11309605_1' || true)"
gz2="$(_compress_if_exists 'SRR11309605_2' || true)"
gzs="$(_compress_if_exists 'SRR11309605' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "SRSF1KO_p10_2_CCGTCCCG_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "SRSF1KO_p10_2_CCGTCCCG_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309606"
gz1="$(_compress_if_exists 'SRR11309606_1' || true)"
gz2="$(_compress_if_exists 'SRR11309606_2' || true)"
gzs="$(_compress_if_exists 'SRR11309606' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cre_5wk_1_CAGATCAT_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cre_5wk_1_CAGATCAT_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309607"
gz1="$(_compress_if_exists 'SRR11309607_1' || true)"
gz2="$(_compress_if_exists 'SRR11309607_2' || true)"
gzs="$(_compress_if_exists 'SRR11309607' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Cre_5wk_2_ACTTGAAT_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Cre_5wk_2_ACTTGAAT_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309608"
gz1="$(_compress_if_exists 'SRR11309608_1' || true)"
gz2="$(_compress_if_exists 'SRR11309608_2' || true)"
gzs="$(_compress_if_exists 'SRR11309608' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "SRSF1KO_5wk_1_ACAGTGAT_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "SRSF1KO_5wk_1_ACAGTGAT_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309609"
gz1="$(_compress_if_exists 'SRR11309609_1' || true)"
gz2="$(_compress_if_exists 'SRR11309609_2' || true)"
gzs="$(_compress_if_exists 'SRR11309609' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "SRSF1KO_5wk_2_GCCAATAT_L00M_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "SRSF1KO_5wk_2_GCCAATAT_L00M_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309610"
gz1="$(_compress_if_exists 'SRR11309610_1' || true)"
gz2="$(_compress_if_exists 'SRR11309610_2' || true)"
gzs="$(_compress_if_exists 'SRR11309610' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "gfp1_GCACGGAC-GTCTCGCA_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "gfp1_GCACGGAC-GTCTCGCA_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309611"
gz1="$(_compress_if_exists 'SRR11309611_1' || true)"
gz2="$(_compress_if_exists 'SRR11309611_2' || true)"
gzs="$(_compress_if_exists 'SRR11309611' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "gfp2_GGTACCTT-AAGACGTC_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "gfp2_GGTACCTT-AAGACGTC_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309612"
gz1="$(_compress_if_exists 'SRR11309612_1' || true)"
gz2="$(_compress_if_exists 'SRR11309612_2' || true)"
gzs="$(_compress_if_exists 'SRR11309612' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "gfp3_GCAGAATT-ACCGGCCA_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "gfp3_GCAGAATT-ACCGGCCA_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309613"
gz1="$(_compress_if_exists 'SRR11309613_1' || true)"
gz2="$(_compress_if_exists 'SRR11309613_2' || true)"
gzs="$(_compress_if_exists 'SRR11309613' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "cre1_CGGCGTGA-GCGCCTGT_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "cre1_CGGCGTGA-GCGCCTGT_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309614"
gz1="$(_compress_if_exists 'SRR11309614_1' || true)"
gz2="$(_compress_if_exists 'SRR11309614_2' || true)"
gzs="$(_compress_if_exists 'SRR11309614' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "cre2_ATGTAAGT-ACTCTATG_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "cre2_ATGTAAGT-ACTCTATG_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR11309615"
gz1="$(_compress_if_exists 'SRR11309615_1' || true)"
gz2="$(_compress_if_exists 'SRR11309615_2' || true)"
gzs="$(_compress_if_exists 'SRR11309615' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "cre3_AACGTTCC-GGAGTACT_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "cre3_AACGTTCC-GGAGTACT_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/SRR11309602/SRR11309602"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309603/SRR11309603"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309604/SRR11309604"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309605/SRR11309605"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309606/SRR11309606"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309607/SRR11309607"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309608/SRR11309608"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309609/SRR11309609"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309610/SRR11309610"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309611/SRR11309611"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309612/SRR11309612"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309613/SRR11309613"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309614/SRR11309614"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309615/SRR11309615"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309613/SRR11309613"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309614/SRR11309614"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309615/SRR11309615"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309606/SRR11309606"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309607/SRR11309607"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309602/SRR11309602"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309603/SRR11309603"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309610/SRR11309610"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309611/SRR11309611"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309612/SRR11309612"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309608/SRR11309608"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309609/SRR11309609"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309604/SRR11309604"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR11309605/SRR11309605"

echo "Download complete. Files saved to $OUTDIR"