Mini-pipeline: Gene–Temperature Association Scan
(One German pop with individual “temperature-sensitivity” phenotypes + one Spanish pop without the phenotype)
Below is a lean, reproducible path that starts with a multi-sample VCF and a .csv containing
sample_id, population(GER/ESP), lat, lon, temp_sens and ends with a ranked list of candidate temperature-associated loci.
0. Folder map
proj/
├── data/ (raw VCF, metadata.csv)
├── work/ (filtered files)
├── baypass/ (pop-level GEA)
└── results/ (plots, tables, reports)
1. QC & format conversion (shell)
# 1.1 Filter for biallelic SNPs, depth, missingness, MAF
bcftools view -m2 -M2 -v snps data/raw.vcf |
bcftools filter -e 'FMT/DP<8' |
vcftools --vcf - --max-missing 0.9 --maf 0.05 \
--recode --stdout > work/filtered.vcf
# 1.2 Convert to PLINK binary
plink --vcf work/filtered.vcf --make-bed --out work/filtered
2. Basic population structure check
# PCA on all samples
plink --bfile work/filtered --pca 20 --out work/pca
Plot in R (ggplot2) to make sure GER and ESP separate but Germans don’t show big internal structure.
3. Individual-level GWAS inside Germans (temperature-sensitivity)
# 3.1 Keep only German samples
grep ",GER," data/metadata.csv | cut -d"," -f1 > work/german.list
plink --bfile work/filtered --keep work/german.list --make-bed --out work/ger
# 3.2 Prepare phenotype file (1 column = temp_sens, same sample order as .fam)
cut -d"," -f1,5 data/metadata.csv | grep ",GER," | \
sort -k1,1 > work/ger_temp.txt # sample_id temp_sens
# Merge with .fam order (or use --pheno-name if PLINK2)
# 3.3 Linear (or logistic) regression with top PCs as covariates
plink --bfile work/ger --pheno work/ger_temp.txt \
--covar work/pca.eigenvec --covar-number 1-3 \
--linear --adjust --out results/gwas_ger
For mixed-model correction → GEMMA or GCTA-mlma:
gemma -bfile work/ger -k work/ger.cXX.txt \
-lmm 4 -pheno work/ger_temp_only.txt \
-o gwas_ger_gemma
Deliverable: Manhattan/QQ plots (qqman), list of SNPs with FDR < 0.05.
4. Population-level GEA (GER vs ESP) with BayPass
Reason: only 2 pops → BayPass’s core model (STD) can still estimate XtX (Fst-like) and test correlation with a population covariate (e.g. mean annual temperature or mean temp-sens if you have Spanish measurements later).
4.1 Build allele-count matrix
# Convert VCF to BayPass counts
vcftools --vcf work/filtered.vcf --keep work/german.list \
--counts2 | awk '{print $5","$6}' > baypass/ger.count
grep ",ESP," data/metadata.csv | cut -d"," -f1 > work/spain.list
vcftools --vcf work/filtered.vcf --keep work/spain.list \
--counts2 | awk '{print $5","$6}' > baypass/esp.count
# paste GER and ESP side-by-side
paste -d" " baypass/ger.count baypass/esp.count > baypass/genos.txt
4.2 Run BayPass
# population covariate = mean annual temperature difference (°C)
echo "10.0 16.2" > baypass/cov.txt # GER, ESP
baypass -npop 2 -gfile baypass/genos.txt \
-efile baypass/cov.txt -outprefix baypass/out
Outputs
• out_summary_pi_xtx.out (XtX: differentiation).
• out_summary_beta_params.out (regression of allele freq vs covariate, gives BF).
Pick SNPs with XtX > 99th percentile and BF > 10 → strong GEA.
5. Merge & interpret
- Overlap SNPs from step 3 (individual GWAS) and step 4 (BayPass).
- Extract allele frequencies
plink --bfile work/filtered --freq --within data/pop.clst --out results/afreq
- Annotate with SnpEff or VEP
snpEff -v yourGenome results/candidate_snps.vcf > results/annotated.vcf
6. R notebook skeleton
library(data.table); library(qqman); library(ggplot2)
# GWAS result
gwas <- fread("results/gwas_ger.assoc.linear")
manhattan(gwas, chr="CHR", bp="BP", p="P", snp="SNP")
# BayPass
bay <- fread("baypass/out_summary_beta_params.out")
sig_bay <- bay[BETA_BF > 10]
# Overlap
cand <- merge(gwas[P < 1e-5], sig_bay, by="SNP")
fwrite(cand, "results/candidate_overlap.tsv")
# Plot allele freq GER vs ESP
af <- fread("results/afreq.frq.strat") # PLINK output
af_wide <- dcast(af, SNP ~ POP, value.var="MAF")
ggplot(af_wide[SNP %in% cand$SNP], aes(GER, ESP)) +
geom_point() + geom_abline(slope=1, linetype=2)
7. Deliverables
| File | Purpose |
|---|
| results/gwas_ger.assoc.linear | Per-SNP GWAS in Germans |
| baypass/out_summary*.out | Population-level GEA stats |
| results/candidate_overlap.tsv | High-confidence temperature loci |
| R markdown / html | Plots + methods section |
8. Caveats & tips
• With only one population carrying the phenotype, individual-level GWAS is the main driver; BayPass mainly confirms differentiation.
• Check power: N_GER ≥ ~50 recommended.
• Correct for relatedness (GEMMA) to avoid false positives.
• Spanish data can later supply phenotypes; if so, rerun GWAS jointly with LMM.
• Always inspect QQ plots and genomic inflation (λ).
That’s it—a compact path from VCF + metadata to candidate temperature-associated loci using standard, free tools and a sprinkle of R. 🚀