#!/bin/bash
# ===========================================================
# Batch run HOMER findMotifs.pl for all .txt files in gene_data/
# Step 1: Remove the first line (column name) from each file
# Step 2: Run findMotifs.pl with parameters
# Each result saved to *_LPSMotifResults/ folder
# ===========================================================

FOLDER="gene_data"

cd "$FOLDER" || { echo "❌ Folder $FOLDER not found!"; exit 1; }

for txtfile in *.txt; do
    [ -e "$txtfile" ] || continue   # skip if no txt file found

    prefix=$(basename "$txtfile" .txt)
    cleanfile="${prefix}_noheader.txt"
    outdir="${prefix}_LPSMotifResults"

    echo ">>> Processing $txtfile ..."

    # Remove the first line (column header)
    tail -n +2 "$txtfile" > "$cleanfile"

    # Run HOMER motif finding
    findMotifs.pl "$cleanfile" human "$outdir" -start -500 -end 500 -p 4

    echo ">>> Finished: results in $outdir/"
    echo
done

echo "✅ All motif analyses completed successfully!"

