TITLE: SNP Calling and VCF Filtering Pipeline
AUTHORS: M Renee Bellinger

[DESCRIPTION]
<div class = "text-blocks"><div class = "text-block">SNP-calling and genotype filtering using bowtie2, samtools, bcftools, and vcftools</div><div class = "text-block"><span>This pipeline  was used for calling SNPs using GBS data obtained from Taro Leaf Blight resistant mapping population of taro, </span><span style = "font-style:italic;">Colocasia Esculenta </span><span>mapped to a taro genome assembled from 10x Genomics linked-reads and Oxford Nanopore Technology long-reads.</span></div><div class = "text-block">The genotype filtering is meant to be done in a single job submission on a linux machine (this was run using 20 cores with 120 Gb RAM and takes two to three days).</div><div class = "text-block">The file "1_SNP_calling.txt" contains steps for calling SNPs from demultiplexed GBS data and filtering vcf files (these are broken out in "Steps".</div><div class = "text-block">The file "2_genome_analysis" contains steps for running NLR-Annotator and Mummer with Nucmer algorithm to generate synteny plots. This is not broken out in steps</div></div>

[STEPS]
?. [CALL SNPS]
# copy the genome to a working folder and unzip it to be a "working copy"cp /your/path/to/genome/genome.gz genome.fasta.gzgunzip genome.fasta.gz
?. [CALL SNPS]
# index genomesamtools faidx genome.fastabowtie2-build genome.fasta genome
?. [CALL SNPS]
# Map demultiplexed GBS reads with bowtie2 or a program of your choice. Repeat this step for all demultiplexed samples# settings are -q for fastq format, -p for 20 threads, --very-sensitive-local for alignment algorithm, -x for reference, -U name of demultiplexed read file (e.g., P230.R1.fastq). -S is output file "P230.sam"bowtie2 -q -p 20 --very-sensitive-local -x genome -U P230.R1.fastq -S P230.sam
?. [CALL SNPS]
# Use samtools to convert *sam to *bam format, sort the reads, filter out unmapped reads (-F 4) to save space, and then check mapping stats# this loop will process all *sam files in your working directory# note some samtools programs use -o while others use > to collect program outputfor i in *sam;do       samtools view -bS -o $i.bam $i --threads 20       samtools sort $i.bam -o $i.sort.bam --threads 20       samtools view -h -F 4 $i.sort.bam > $i.mapped.bam       samtools flagstat $i.mapped.bam > $i.mapped.sort.statsdone;
?. [CALL SNPS]
#calculate genotype likelihoods and call variantssamtools mpileup -gu -f genome.fasta -q 20 -Q 20 --output-tags DP,AD,ADF,ADR,SP,INFO/AD *mapped.bam | bcftools call -m --output-type v -o draft_Taro.merged_q20Q20.vcf
?. [CALL SNPS]
# compress the *vcf to save spacegzip draft_Taro.merged_q20Q20.vcf
?. [Filter SNPs in *vcf file]
## I use variables for this script. Would be easier to run the file 1_SNP_calling.txt provided on page with Abstract## This step remove samples that are not part of the mapping populationA=draft_Taro.merged_q20Q20.vcf.gz vcftools --gzvcf $A --keep keep_1025_230_255.txt --recode --recode-INFO-all --out 1025_230_255
?. [Filter SNPs in *vcf file]
## Remove SNPs within 5 bases of an INDELB=1025_230_255.recode.vcfbcftools filter -g 5 $B >filter.1.vcf
?. [Filter SNPs in *vcf file]
## Remove indelsC=filter.1.vcfvcftools --vcf $C --keep keep_1025_230_255 --remove-indels --recode --recode-INFO-all --out 1025_230_255.noindel
?. [Filter SNPs in *vcf file]
## light filter for max missing 50%, minimum depth of 5 (per genotype), bi-allelic calls, minimum quality phred 20## remove samples that are not the 1025 taro leaf blight mapping populationD=1025_230_255.noindel.recode.vcfvcftools --vcf $D --max-missing 0.5 --minDP 5 --min-alleles 2 --max-alleles 2 --minQ 20 --recode --recode-INFO-all --out 1025_230_255.noindel.maxmiss.5.minDP5.2alleles.minQ20
?. [Filter SNPs in *vcf file]
## Measure missingness across individuals and create a file listing individuals missing >30% of data E=1025_230_255.noindel.maxmiss.5.minDP5.2alleles.minQ20.recode.vcfvcftools --vcf $E --missing-indv --out 30percentcat 30percent.imiss | awk '{if($5>0.3)print $1}'|grep -v INDV> remove-indv_30perc
?. [Filter SNPs in *vcf file]
## Remove individuals missing 30% data in conjunction with the light filter D=1025_230_255.noindel.recode.vcf vcftools --vcf $D --remove remove-indv_30perc --max-missing 0.5 --minDP 5 --min-alleles 2  --max-alleles 2 --minQ 20 --recode --recode-INFO-all --out 1025_230_255.noindel.maxmiss.5.minDP5.2alleles.minQ20.n86ind
?. [Filter SNPs in *vcf file]
## Measure missingness across loci and create a file "exclude_miss20p". Apply this file in step 15.F=1025_230_255.noindel.maxmiss.5.minDP5.2alleles.minQ20.n86ind.recode.vcfvcftools --vcf $F --keep keep_1025_230_255 --missing-site --out 1025_230_255.noindel.maxmiss.5.minDP5.2alleles.minQ20cat 1025_230_255.noindel.maxmiss.5.minDP5.2alleles.minQ20.lmiss|awk '{if($6>=0.20)print $1, $2}'>exclude_miss20p
?. [Filter SNPs in *vcf file]
## Apply stringent filter:## Exclude individuals missing 30% of data and loci that are missing 20% of data## some filters are redundant in case steps are run out of order## apply minimum genotypic depth of 8G=1025_230_255.noindel.recode.vcfvcftools --vcf $G --remove remove-indv_30perc --exclude-positions exclude_miss20p --max-missing 0.8 --minDP 8 --min-alleles 2 --max-alleles 2 --minQ 20 --recode --recode-INFO-all --out 1025_230_255.noindel.maxmiss.8.minDP8.2alleles.minQ20.n86
?. [Filter SNPs in *vcf file]
## Apply minor allele frequency filtervcftools --vcf 1025_230_255.noindel.maxmiss.8.minDP8.2alleles.minQ20.n86_variable_parental.recode.vcf.recode.vcf --maf 0.012 --recode --recode-INFO-all --out 1025_230_255.noindel.maxmiss.8.minDP8.2alleles.minQ20.n86_variable_parents_maf_0.012# filtered file is: 1025_230_255.noindel.maxmiss.8.minDP8.2alleles.minQ20.n86_variable_parents_maf_0.012.recode.vcf
?. ################ SNP calling ################# To set up your working environment you will need to download GBS and genome data from NCBI# Set paths to each program if they are not in your bash environment.#----------------------------------## Programs and versions used for SNP calling#----------------------------------## bowtie2v2.2.4# samtools1.4.1# bcftools-1.2 #----------------------------------## DATA FILES#----------------------------------## Short-read files that have been demultiplexed (see Guidelines)# SRX2754311 --> GBS data for Taro from Hawaii, South Pacific, Palau, and mainland Asia # SRX2754311 --> GBS data for the '1025' Taro mapping population resistant to Taro Leaf Blight# GENOME FILE# NCBI Bioproject PRJNA567267