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

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

# --- GEO supplementary files ---
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE271nnn/GSE271650/suppl/GSE271650_lps_results_df_wt_lps_vs_ko_lps.csv.gz" -O "GSE271650_lps_results_df_wt_lps_vs_ko_lps.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE271nnn/GSE271650/suppl/GSE271650_veh_ko_lps_ko_vs_ko_lps.csv.gz" -O "GSE271650_veh_ko_lps_ko_vs_ko_lps.csv.gz"
wget -nc "ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE271nnn/GSE271650/suppl/GSE271650_veh_wt_lps_results_df_wt_vs_wt_lps.csv.gz" -O "GSE271650_veh_wt_lps_results_df_wt_vs_wt_lps.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 "SRR29727661"
gz1="$(_compress_if_exists 'SRR29727661_1' || true)"
gz2="$(_compress_if_exists 'SRR29727661_2' || true)"
gzs="$(_compress_if_exists 'SRR29727661' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "N14_2-2447633_S4_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "N14_2-2447633_S4_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727662"
gz1="$(_compress_if_exists 'SRR29727662_1' || true)"
gz2="$(_compress_if_exists 'SRR29727662_2' || true)"
gzs="$(_compress_if_exists 'SRR29727662' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "M13_2-2447632_S3_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "M13_2-2447632_S3_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727663"
gz1="$(_compress_if_exists 'SRR29727663_1' || true)"
gz2="$(_compress_if_exists 'SRR29727663_2' || true)"
gzs="$(_compress_if_exists 'SRR29727663' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Zhou_F6_2-2322701_S6_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Zhou_F6_2-2322701_S6_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727664"
gz1="$(_compress_if_exists 'SRR29727664_1' || true)"
gz2="$(_compress_if_exists 'SRR29727664_2' || true)"
gzs="$(_compress_if_exists 'SRR29727664' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Zhou_E5_2-2322650_S5_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Zhou_E5_2-2322650_S5_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727665"
gz1="$(_compress_if_exists 'SRR29727665_1' || true)"
gz2="$(_compress_if_exists 'SRR29727665_2' || true)"
gzs="$(_compress_if_exists 'SRR29727665' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Zhou_D4_2-2322649_S4_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Zhou_D4_2-2322649_S4_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727666"
gz1="$(_compress_if_exists 'SRR29727666_1' || true)"
gz2="$(_compress_if_exists 'SRR29727666_2' || true)"
gzs="$(_compress_if_exists 'SRR29727666' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "L12_2-2447631_S2_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "L12_2-2447631_S2_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727667"
gz1="$(_compress_if_exists 'SRR29727667_1' || true)"
gz2="$(_compress_if_exists 'SRR29727667_2' || true)"
gzs="$(_compress_if_exists 'SRR29727667' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "K11_2-2447630_S1_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "K11_2-2447630_S1_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727668"
gz1="$(_compress_if_exists 'SRR29727668_1' || true)"
gz2="$(_compress_if_exists 'SRR29727668_2' || true)"
gzs="$(_compress_if_exists 'SRR29727668' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Zhou_C3_2-2322648_S3_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Zhou_C3_2-2322648_S3_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727669"
gz1="$(_compress_if_exists 'SRR29727669_1' || true)"
gz2="$(_compress_if_exists 'SRR29727669_2' || true)"
gzs="$(_compress_if_exists 'SRR29727669' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Zhou_B2_2-2322647_S2_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Zhou_B2_2-2322647_S2_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727670"
gz1="$(_compress_if_exists 'SRR29727670_1' || true)"
gz2="$(_compress_if_exists 'SRR29727670_2' || true)"
gzs="$(_compress_if_exists 'SRR29727670' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Zhou_A1_2-2322646_S1_L001_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Zhou_A1_2-2322646_S1_L001_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727671"
gz1="$(_compress_if_exists 'SRR29727671_1' || true)"
gz2="$(_compress_if_exists 'SRR29727671_2' || true)"
gzs="$(_compress_if_exists 'SRR29727671' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample8_2-2136362_S8_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample8_2-2136362_S8_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727672"
gz1="$(_compress_if_exists 'SRR29727672_1' || true)"
gz2="$(_compress_if_exists 'SRR29727672_2' || true)"
gzs="$(_compress_if_exists 'SRR29727672' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample6_2-2136360_S6_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample6_2-2136360_S6_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727673"
gz1="$(_compress_if_exists 'SRR29727673_1' || true)"
gz2="$(_compress_if_exists 'SRR29727673_2' || true)"
gzs="$(_compress_if_exists 'SRR29727673' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample4_2-2136358_S4_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample4_2-2136358_S4_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727674"
gz1="$(_compress_if_exists 'SRR29727674_1' || true)"
gz2="$(_compress_if_exists 'SRR29727674_2' || true)"
gzs="$(_compress_if_exists 'SRR29727674' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample2_2-2136356_S2_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample2_2-2136356_S2_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727675"
gz1="$(_compress_if_exists 'SRR29727675_1' || true)"
gz2="$(_compress_if_exists 'SRR29727675_2' || true)"
gzs="$(_compress_if_exists 'SRR29727675' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample7_2-2136361_S7_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample7_2-2136361_S7_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727676"
gz1="$(_compress_if_exists 'SRR29727676_1' || true)"
gz2="$(_compress_if_exists 'SRR29727676_2' || true)"
gzs="$(_compress_if_exists 'SRR29727676' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample5_2-2136359_S5_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample5_2-2136359_S5_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727677"
gz1="$(_compress_if_exists 'SRR29727677_1' || true)"
gz2="$(_compress_if_exists 'SRR29727677_2' || true)"
gzs="$(_compress_if_exists 'SRR29727677' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample3_2-2136357_S3_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample3_2-2136357_S3_L002_R2_001.fastq.gz"
fi

fasterq-dump --split-files "SRR29727678"
gz1="$(_compress_if_exists 'SRR29727678_1' || true)"
gz2="$(_compress_if_exists 'SRR29727678_2' || true)"
gzs="$(_compress_if_exists 'SRR29727678' || true)"
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz1" ]; then
  mv -f "$gz1" "Yang_Zhou_sample1_2-2136355_S1_L002_R1_001.fastq.gz"
fi
if [ "$RENAME_SRA_TO_ORIGINAL" = "1" ] && [ -n "$gz2" ]; then
  mv -f "$gz2" "Yang_Zhou_sample1_2-2136355_S1_L002_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/SRR29727661/SRR29727661"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727662/SRR29727662"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727663/SRR29727663"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727664/SRR29727664"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727665/SRR29727665"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727666/SRR29727666"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727667/SRR29727667"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727668/SRR29727668"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727669/SRR29727669"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727670/SRR29727670"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727671/SRR29727671"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727672/SRR29727672"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727673/SRR29727673"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727674/SRR29727674"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727675/SRR29727675"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727676/SRR29727676"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727677/SRR29727677"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727678/SRR29727678"

# --- Additional data files ---
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727667/SRR29727667"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727666/SRR29727666"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727662/SRR29727662"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727661/SRR29727661"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727678/SRR29727678"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727674/SRR29727674"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727677/SRR29727677"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727673/SRR29727673"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727676/SRR29727676"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727672/SRR29727672"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727675/SRR29727675"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727671/SRR29727671"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727670/SRR29727670"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727669/SRR29727669"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727668/SRR29727668"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727665/SRR29727665"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727664/SRR29727664"
curl -L -O -C - "https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR29727663/SRR29727663"

echo "Download complete. Files saved to $OUTDIR"