 <?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.popgen.dk/angsd/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Isin</id>
	<title>angsd - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.popgen.dk/angsd/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Isin"/>
	<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php/Special:Contributions/Isin"/>
	<updated>2026-04-07T12:21:36Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3189</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3189"/>
		<updated>2023-12-08T21:25:32Z</updated>

		<summary type="html">&lt;p&gt;Isin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There has been some confusion about the versions of ANGSD.&lt;br /&gt;
&lt;br /&gt;
* Even versions are freezes from the last odd giversion&lt;br /&gt;
&lt;br /&gt;
* Odd versions are git versions. Once there has been enough commits we will increment and make a release.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
To download and use ANGSD you need to download the htslib and the angsd source folder&lt;br /&gt;
&lt;br /&gt;
You can either download the angsd0.938.tar.gz which contains both.&lt;br /&gt;
[http://popgen.dk/software/download/angsd/angsd0.938.tar.gz]&lt;br /&gt;
&lt;br /&gt;
Or you can use github for the latest version of both htslib and angsd&lt;br /&gt;
&lt;br /&gt;
Earlier versions from here: http://popgen.dk/software/download/angsd/&lt;br /&gt;
And here: https://github.com/ANGSD/angsd/releases&lt;br /&gt;
&lt;br /&gt;
=Installation=&lt;br /&gt;
Download and unpack the tarball, enter the directory and type make. Users on a mac computer, can use curl instead of wget.&lt;br /&gt;
&lt;br /&gt;
===Unix===&lt;br /&gt;
The software can be compiled using make.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://popgen.dk/software/download/angsd/angsd0.940.tar.gz&lt;br /&gt;
tar xf angsd0.940.tar.gz&lt;br /&gt;
cd htslib;make;cd ..&lt;br /&gt;
cd angsd&lt;br /&gt;
make HTSSRC=../htslib&lt;br /&gt;
cd ..&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The executable then located in '''angsd/angsd'''.&lt;br /&gt;
&lt;br /&gt;
=Install from github=&lt;br /&gt;
To install CRAM support you also need to install htslib and can be done using the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone --recursive https://github.com/samtools/htslib.git&lt;br /&gt;
git clone https://github.com/ANGSD/angsd.git &lt;br /&gt;
cd htslib;make;cd ../angsd ;make HTSSRC=../htslib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Using htslib submodule=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://github.com/ANGSD/angsd.git &lt;br /&gt;
cd angsd&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Systemwide installation of htslib=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make HTSSRC=&amp;quot;systemwide&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3188</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3188"/>
		<updated>2023-12-08T21:24:13Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* Systemwide installation of htslib? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There has been some confusion about the versions of ANGSD.&lt;br /&gt;
&lt;br /&gt;
* Even versions are freezes from the last odd giversion&lt;br /&gt;
&lt;br /&gt;
* Odd versions are git versions. Once there has been enough commits we will increment and make a release.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
To download and use ANGSD you need to download the htslib and the angsd source folder&lt;br /&gt;
&lt;br /&gt;
You can either download the angsd0.938.tar.gz which contains both.&lt;br /&gt;
[http://popgen.dk/software/download/angsd/angsd0.938.tar.gz]&lt;br /&gt;
&lt;br /&gt;
Or you can use github for the latest version of both htslib and angsd&lt;br /&gt;
&lt;br /&gt;
Earlier versions from here: http://popgen.dk/software/download/angsd/&lt;br /&gt;
And here: https://github.com/ANGSD/angsd/releases&lt;br /&gt;
&lt;br /&gt;
=Install=&lt;br /&gt;
Download and unpack the tarball, enter the directory and type make. Users on a mac computer, can use curl instead of wget.&lt;br /&gt;
&lt;br /&gt;
===Unix===&lt;br /&gt;
The software can be compiled using make.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://popgen.dk/software/download/angsd/angsd0.940.tar.gz&lt;br /&gt;
tar xf angsd0.940.tar.gz&lt;br /&gt;
cd htslib;make;cd ..&lt;br /&gt;
cd angsd&lt;br /&gt;
make HTSSRC=../htslib&lt;br /&gt;
cd ..&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The executable then located in '''angsd/angsd'''.&lt;br /&gt;
&lt;br /&gt;
=Install from github=&lt;br /&gt;
To install CRAM support you also need to install htslib and can be done using the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone --recursive https://github.com/samtools/htslib.git&lt;br /&gt;
git clone https://github.com/ANGSD/angsd.git &lt;br /&gt;
cd htslib;make;cd ../angsd ;make HTSSRC=../htslib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Systemwide installation of htslib=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make HTSSRC=&amp;quot;systemwide&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3187</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3187"/>
		<updated>2023-12-08T21:23:35Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* Systemwide installation of htslib? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There has been some confusion about the versions of ANGSD.&lt;br /&gt;
&lt;br /&gt;
* Even versions are freezes from the last odd giversion&lt;br /&gt;
&lt;br /&gt;
* Odd versions are git versions. Once there has been enough commits we will increment and make a release.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
To download and use ANGSD you need to download the htslib and the angsd source folder&lt;br /&gt;
&lt;br /&gt;
You can either download the angsd0.938.tar.gz which contains both.&lt;br /&gt;
[http://popgen.dk/software/download/angsd/angsd0.938.tar.gz]&lt;br /&gt;
&lt;br /&gt;
Or you can use github for the latest version of both htslib and angsd&lt;br /&gt;
&lt;br /&gt;
Earlier versions from here: http://popgen.dk/software/download/angsd/&lt;br /&gt;
And here: https://github.com/ANGSD/angsd/releases&lt;br /&gt;
&lt;br /&gt;
=Install=&lt;br /&gt;
Download and unpack the tarball, enter the directory and type make. Users on a mac computer, can use curl instead of wget.&lt;br /&gt;
&lt;br /&gt;
===Unix===&lt;br /&gt;
The software can be compiled using make.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://popgen.dk/software/download/angsd/angsd0.940.tar.gz&lt;br /&gt;
tar xf angsd0.940.tar.gz&lt;br /&gt;
cd htslib;make;cd ..&lt;br /&gt;
cd angsd&lt;br /&gt;
make HTSSRC=../htslib&lt;br /&gt;
cd ..&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The executable then located in '''angsd/angsd'''.&lt;br /&gt;
&lt;br /&gt;
=Install from github=&lt;br /&gt;
To install CRAM support you also need to install htslib and can be done using the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone --recursive https://github.com/samtools/htslib.git&lt;br /&gt;
git clone https://github.com/ANGSD/angsd.git &lt;br /&gt;
cd htslib;make;cd ../angsd ;make HTSSRC=../htslib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Systemwide installation of htslib?=&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
make HTSSRC=&amp;quot;systemwide&amp;quot;&lt;br /&gt;
```&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=SFS_Estimation&amp;diff=3186</id>
		<title>SFS Estimation</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=SFS_Estimation&amp;diff=3186"/>
		<updated>2023-12-08T14:22:15Z</updated>

		<summary type="html">&lt;p&gt;Isin: Minor fix: Add missing /pre&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Latest version can now do bootstrapping. Folding should now be done in realSFS and not in the saf file generation.&lt;br /&gt;
&lt;br /&gt;
=Quick Start=&lt;br /&gt;
The process of estimating the SFS and multidimensional has improved a lot in the newer versions.&lt;br /&gt;
&lt;br /&gt;
Assuming you have a bam/cram file list in the file 'file.list' and you have your ancestral state in ancestral.fasta, then the process is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#no filtering&lt;br /&gt;
./angsd -gl 1 -anc ancestral -dosaf 1&lt;br /&gt;
#or alot of filtering&lt;br /&gt;
./angsd -gl 1 -anc ancestral -dosaf 1 -baq 1 -C 50 -minMapQ 30 -minQ 20&lt;br /&gt;
&lt;br /&gt;
#this will generate 3 files&lt;br /&gt;
1) angsdput.saf.idx 2) angsdput.saf.pos.gz 3) angsdput.saf.gz&lt;br /&gt;
#these are binary files that are formally defined in https://github.com/ANGSD/angsd/blob/newsaf/doc/formats.pdf&lt;br /&gt;
&lt;br /&gt;
#To find the global SFS based on the run from above simply do&lt;br /&gt;
./realSFS angsdput.saf.idx&lt;br /&gt;
##or only use chromosome 22&lt;br /&gt;
./realSFS angsdput.saf.idx -r 22&lt;br /&gt;
&lt;br /&gt;
## or specific regions&lt;br /&gt;
./realSFS angsdput.saf.idx -r 22:100000-150000000&lt;br /&gt;
&lt;br /&gt;
##or limit to a fixed number of sites&lt;br /&gt;
./realSFS angsdput.saf.idx -r 17 -nSites 10000000&lt;br /&gt;
&lt;br /&gt;
##or you can find the 2dim sf by&lt;br /&gt;
./realSFS ceu.saf.idx yri.saf.idx&lt;br /&gt;
##NB the program will find the intersect internally. No need for multiple runs with angsd main program.&lt;br /&gt;
&lt;br /&gt;
##or you can find the 3dim sf by&lt;br /&gt;
./realSFS ceu.saf.idx yri.saf.idx MEX.saf.idx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=SFS=&lt;br /&gt;
This method will estimate the site frequency spectrum, the method is described in [[Nielsen2012]]. The theory behind the model is briefly described [[realSFSmethod|here]]&lt;br /&gt;
&lt;br /&gt;
This is a 2 step procedure first generate a &amp;quot;.saf&amp;quot; file (site allele frequency likelihood), followed by an optimization of the .saf file which will estimate the Site frequency spectrum (SFS).&lt;br /&gt;
&lt;br /&gt;
For the optimization we have implemented 2 different approaches both found in the misc folder. The diagram below shows the how the method goes from raw bam files to the SFS. &lt;br /&gt;
&lt;br /&gt;
You can also estimate a [[2d SFS Estimation| 2dsfs]] or even higher if you want to.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* NB the ancestral state needs to be supplied for the full SFS, but you can use the -fold 1 to estimate the folded SFS and then use the reference as ancestral.&lt;br /&gt;
* NB the output from the -doSaf 2 are not sample allele frequency likelihoods but sample alle posteriors.&lt;br /&gt;
And applying the realSFS to this output is therefore NOT the ML estimate of the SFS as described in the Nielsen 2012 paper,&lt;br /&gt;
but the 'Incorporating deviations from Hardy-Weinberg Equilibrium (HWE)' section of that paper.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{#mermaid:graph LR;&lt;br /&gt;
    A[sequence data] --&amp;gt; B[genotype likelihoods&amp;lt;br/&amp;gt;- SAMtools&amp;lt;br/&amp;gt;- GATK&amp;lt;br/&amp;gt;- SOAPsnp&amp;lt;br/&amp;gt;- Kim et.al]&lt;br /&gt;
    B --&amp;gt;|doSaf| C[.saf file]&lt;br /&gt;
    C --&amp;gt;|optimize realSFS| D[.saf.ml file]&lt;br /&gt;
&lt;br /&gt;
    class A sequenceData;&lt;br /&gt;
    class B genotypeLikelihoods;&lt;br /&gt;
    class C safFile;&lt;br /&gt;
    class D safMlFile;&lt;br /&gt;
&lt;br /&gt;
    classDef sequenceData fill:#FFA500;&lt;br /&gt;
    classDef genotypeLikelihoods fill:#FFFFFF;&lt;br /&gt;
    classDef safFile fill:#009FFF;&lt;br /&gt;
    classDef safMlFile fill:#FF0000;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -dosaf&lt;br /&gt;
	-&amp;gt; angsd version: 0.935-44-g02a07fc-dirty (htslib: 1.12-1-g9672589) build(Jul  8 2021 08:04:55)&lt;br /&gt;
	-&amp;gt; ./angsd -dosaf &lt;br /&gt;
	-&amp;gt; Analysis helpbox/synopsis information:&lt;br /&gt;
	-&amp;gt; Wed Aug 18 11:09:03 2021&lt;br /&gt;
	-&amp;gt; doMcall=0&lt;br /&gt;
--------------&lt;br /&gt;
abcSaf.cpp:&lt;br /&gt;
	-doSaf		0&lt;br /&gt;
	1: perform multisample GL estimation&lt;br /&gt;
	2: use an inbreeding version&lt;br /&gt;
	3: calculate genotype probabilities (use -doPost 3 instead)&lt;br /&gt;
	4: Assume genotype posteriors as input (still beta) &lt;br /&gt;
	-underFlowProtect	0&lt;br /&gt;
	-anc			(null) (ancestral fasta)&lt;br /&gt;
	-noTrans		0 (remove transitions)&lt;br /&gt;
	-pest			(null) (prior SFS)&lt;br /&gt;
	-isHap			0 (is haploid beta!)&lt;br /&gt;
	-doPost			0 (doPost 3,used for accesing saf based variables)&lt;br /&gt;
NB:&lt;br /&gt;
	  If -pest is supplied in addition to -doSaf then the output will then be posterior probability of the sample allelefrequency for each site&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
misc/realSFS&lt;br /&gt;
./realSFS afile.saf.idx [-start FNAME -P nThreads -tole tole -maxIter  -nSites ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For information and parameters concerning the realSFS subprogram go here: [[realSFS]]&lt;br /&gt;
&lt;br /&gt;
=Options=&lt;br /&gt;
;-doSaf 1: Calculate the Site allele frequency likelihood based on individual genotype likelihoods assuming HWE&lt;br /&gt;
&lt;br /&gt;
;-doSaf 2:(version above 0.503) Calculate per site posterior probabilities of the  site allele frequencies based on individual genotype likelihoods while taking into account individual inbreeding coefficients. This is implemented by Filipe G. Vieira.  You need to supply a file containing all the inbreeding coefficients. -indF. Consider if you want to either get the MAP estimate by using all sites, or get the standardized values by conditioning on the called snpsites. See bottom of this page for examples.&lt;br /&gt;
&lt;br /&gt;
;-doSaf 3: Calculate the genotype posterior probabilities for all samples forall sites, using an estimate of the sfs (sample allele frequency distribution). This needs a prior distribution of the SFS (which can be obtained from -doSaf 1/realSFS).&lt;br /&gt;
&lt;br /&gt;
;-doSaf 4: Calculate the posterior probabilities of the sample allele frequency distribution for each site based on genotype probabilities. The genotype probabilities should be provided by the using using the -beagle options. Often the genotype probabilities will be obtained by haplotype imputation. &lt;br /&gt;
&lt;br /&gt;
;-underFlowProtect [INT] &lt;br /&gt;
0: (default) no underflow protection. 1: use underflow protection. For large data sets (large number of individuals) underflow projection is needed.&lt;br /&gt;
&lt;br /&gt;
=Output file=&lt;br /&gt;
The output file from the ''-doSaf'' is described in detail in angsd/doc/formats.pdf. These binary annoying files can be printed with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
realSFS print myfile.saf.idx&lt;br /&gt;
#or&lt;br /&gt;
realSFS print mayflies.saf.idx -r chr1:10000-20000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Example==&lt;br /&gt;
A full example is shown below where we use the test data that can be found on the [[quick start]] page. In this example we use GATK genotype likelihoods.&lt;br /&gt;
&lt;br /&gt;
first generate .saf file  with 4 threads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -bam bam.filelist -doSaf 1 -out small -anc  chimpHg19.fa -GL 2 -P 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We always recommend that you filter out the bad qscore bases and meaningless mapQ reads. eg '''-minMapQ 1 -minQ 20'''. So the above analysis with these filters can be written as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -bam bam.filelist -doSaf 1 -out small -anc chimpHg19.fa -GL 2 -P 4 -minMapQ 1 -minQ 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Obtain a maximum likelihood estimate of the SFS using EM algorithm &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
misc/realSFS small.saf.idx -maxIter 100 -P 4 &amp;gt;small.sfs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SfsSmall.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
A plot of this figure are seen on the right. The jaggedness is due to the very low number of sites in this small dataset.&lt;br /&gt;
&lt;br /&gt;
=Interpretation of the output file=&lt;br /&gt;
Each row is a region of the genome (see below).&lt;br /&gt;
Each row is the expected values of the SFS.&lt;br /&gt;
==NB==&lt;br /&gt;
The generation of the .saf file contains a saf for each site, whereas the optimization requires information for a region of the genome. The optimization will therefore use large amounts of memory.&lt;br /&gt;
&lt;br /&gt;
=Folded spectra=&lt;br /&gt;
If you don't have the ancestral state, you can instead estimate the folded SFS. This is done by supplying the -anc with the reference genome and applying -fold 1 to realSFS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above example would then be&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#first generate .saf file&lt;br /&gt;
./angsd -bam bam.filelist -doSaf 1 -out smallFolded -anc  chimpHg19.fa -GL 2&lt;br /&gt;
#now try the EM optimization with 4 threads&lt;br /&gt;
misc/realSFS smallFolded.saf.idx -maxIter 100 -P 4 &amp;gt;smallFolded.sfs&lt;br /&gt;
#in R&lt;br /&gt;
sfs&amp;lt;-scan(&amp;quot;smallFolded.sfs&amp;quot;)&lt;br /&gt;
barplot(sfs[-1])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SmallFolded.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=Posterior of the per-site distributions of the sample allele frequency=&lt;br /&gt;
If you supply a prior for the SFS (which can be obtained from the -doSaf/realSFS analysis), the output of the .saf file will no longer be  site allele frequency likelihoods but instead will be the log posterior probability of the sample allele frequency for each site in logspace.&lt;br /&gt;
&lt;br /&gt;
=Format specification of binary .saf* files=&lt;br /&gt;
This can be found in the angsd/doc/formats.pdf&lt;br /&gt;
&lt;br /&gt;
* If the -fold 1 has been set, then the dimension is no longer 2*nInd+1 but nInd+1 (this is deprecated)&lt;br /&gt;
* If the -pest parameter has been supplied the output is no longer likelihoods but log posterior site allele frequencies&lt;br /&gt;
&lt;br /&gt;
=Bootstrapping=&lt;br /&gt;
We have recently added the possibility to bootstrap the SFS. Which can be very usefull for getting confidence intervals of the estimated SFS.&lt;br /&gt;
&lt;br /&gt;
This is done by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
realSFS pop.saf.idx -bootstrap 100 -P number_of_cores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The program will then get you 100 estimates of SFS, based on data that has been subsampled with replacement.&lt;br /&gt;
&lt;br /&gt;
=How to plot=&lt;br /&gt;
Assuming the we have obtained a single global sfs(only one line in the output) from '''realSFS''' program, and this is located in '''file.saf.sfs''', then we can plot the results simply like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sfs&amp;lt;-(scan(&amp;quot;small.sfs&amp;quot;)) #read in the log sfs&lt;br /&gt;
barplot(sfs[-c(1,length(sfs))]) #plot variable sites &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SfsSmall.png|thumb]]&lt;br /&gt;
We can make it more fancy like below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#function to normalize&lt;br /&gt;
norm &amp;lt;- function(x) x/sum(x)&lt;br /&gt;
#read data&lt;br /&gt;
sfs &amp;lt;- (scan(&amp;quot;small.sfs&amp;quot;))&lt;br /&gt;
#the variability as percentile&lt;br /&gt;
pvar&amp;lt;- (1-sfs[1]-sfs[length(sfs)])*100&lt;br /&gt;
#the variable categories of the sfs&lt;br /&gt;
sfs&amp;lt;-norm(sfs[-c(1,length(sfs))]) &lt;br /&gt;
barplot(sfs,legend=paste(&amp;quot;Variability:= &amp;quot;,round(pvar,3),&amp;quot;%&amp;quot;),xlab=&amp;quot;Chromosomes&amp;quot;,&lt;br /&gt;
names=1:length(sfs),ylab=&amp;quot;Proportions&amp;quot;,main=&amp;quot;mySFS plot&amp;quot;,col='blue')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SfsSmallFine.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
If your output from '''realSFS''' contains more than one line, it is because you have estimated multiple local SFS's. Then you can't use the above commands directly but should first pick a specific row.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sfs&amp;lt;-(as.numeric(read.table(&amp;quot;multiple.sfs&amp;quot;)[1,])) #first region.&lt;br /&gt;
#do the above&lt;br /&gt;
sfs&amp;lt;-(as.numeric(read.table(&amp;quot;multiple.sfs&amp;quot;)[2,])) #second region.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Which genotype likelihood model should I choose ?=&lt;br /&gt;
It depends on the data. As shown on this example [[Glcomparison]], there was a huge difference between '''-GL 1''' and '''-GL 2''' for older 1000genomes BAM files, but little difference for newer bam files.&lt;br /&gt;
=Validation=&lt;br /&gt;
The validation is based on the pre 0.900 version&lt;br /&gt;
==-doSaf 1==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd misc;&lt;br /&gt;
./supersim -outfiles test -npop 1 -nind 12 -pvar 0.9 -nsites 50000&lt;br /&gt;
echo testchr1 100000 &amp;gt;test.fai&lt;br /&gt;
../angsd -fai test.fai -glf test.glf.gz -nind 12 -doSaf 1 -issim 1&lt;br /&gt;
./realSFS angsdput.saf 24 2&amp;gt;/dev/null &amp;gt;res&lt;br /&gt;
cat res&lt;br /&gt;
31465.429798 4938.453115 2568.586388 1661.227445 1168.891114 975.302535 794.727537 632.691896 648.223566 546.293853 487.936192 417.178505 396.200026 409.813797 308.434836 371.699254 245.585920 322.293532 282.980046 292.584975 212.845183 196.682483 221.802128 236.221205 197.914673&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==-doSaf 2==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ngsSim=../ngsSim/ngsSim&lt;br /&gt;
angsd=./angsd&lt;br /&gt;
realSFS=./misc/realSFS&lt;br /&gt;
&lt;br /&gt;
$ngsSim  -npop 1 -nind 24 -nsites 1000000 -depth 4 -F 0.0 -outfiles testF0.0&lt;br /&gt;
$ngsSim  -npop 1 -nind 24 -nsites 1000000 -depth 4 -F 0.9 -outfiles testF0.9&lt;br /&gt;
&lt;br /&gt;
for i in `seq 24`;do echo 0.9;done &amp;gt;indF&lt;br /&gt;
echo testchr1 250000000 &amp;gt;test.fai&lt;br /&gt;
$angsd -fai test.fai -issim 1 -glf testF0.0.glf.gz -nind 24 -out noF -dosaf 1&lt;br /&gt;
$angsd -fai test.fai -issim 1 -glf testF0.9.glf.gz -nind 24 -out withF -dosaf 2 -domajorminor 1 -domaf 1 -indF indF&lt;br /&gt;
$angsd -fai test.fai -issim 1 -glf testF0.9.glf.gz -nind 24 -out withFsnp -dosaf 2 -domajorminor 1 -domaf 1 -indF indF -snp_pval 1e-4&lt;br /&gt;
&lt;br /&gt;
$realSFS noF.saf 48 &amp;gt;noF.sfs&lt;br /&gt;
$realSFS withF.saf 48 &amp;gt;withF.sfs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#in R&lt;br /&gt;
trueNoF&amp;lt;-scan(&amp;quot;testF0.0.frq&amp;quot;)&lt;br /&gt;
trueWithF&amp;lt;-scan(&amp;quot;testF0.9.frq&amp;quot;)&lt;br /&gt;
pdf(&amp;quot;sfsFcomparison.pdf&amp;quot;,width=14)&lt;br /&gt;
par(mfrow=c(1,2),width=14)&lt;br /&gt;
barplot(trueNoF[-1],main='true sfs F=0.0')&lt;br /&gt;
barplot(trueWithF[-1],main='true sfs F=0.9')&lt;br /&gt;
&lt;br /&gt;
estWithF&amp;lt;-scan(&amp;quot;withF.sfs&amp;quot;)&lt;br /&gt;
estNoF&amp;lt;-scan(&amp;quot;noF.sfs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
barplot(rbind(trueNoF,estNoF)[,-1],main=&amp;quot;true vs est SFS F=0 (ML) (all sites)&amp;quot;,be=T,col=1:2)&lt;br /&gt;
barplot(rbind(trueWithF,estWithF)[,-1],main='true vs est sfs=0.9 (MAP) (all sites)',be=T,col=1:2)&lt;br /&gt;
&lt;br /&gt;
readBjoint &amp;lt;- function(file=NULL,nind=10,nsites=10){&lt;br /&gt;
  ff &amp;lt;- gzfile(file,&amp;quot;rb&amp;quot;)&lt;br /&gt;
  m&amp;lt;-matrix(readBin(ff,double(),(2*nind+1)*nsites),ncol=(2*nind+1),byrow=TRUE)&lt;br /&gt;
  close(ff)&lt;br /&gt;
  return(m)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
m &amp;lt;- exp(readBjoint(&amp;quot;withF.saf&amp;quot;,nind=24,5e6))&lt;br /&gt;
barplot(rbind(trueWithF,colMeans(m))[,-1],main='true vs est sfs F=0.9 (colmean of site pp) (all sites)',be=T,col=1:2)&lt;br /&gt;
m &amp;lt;- exp(readBjoint(&amp;quot;withFsnp.saf&amp;quot;,nind=24,5e6))&lt;br /&gt;
m &amp;lt;- colMeans(m)*nrow(m)&lt;br /&gt;
##m contains SFS for absolute frequencies&lt;br /&gt;
m[1] &amp;lt;-1e6-sum(m[-1])&lt;br /&gt;
##m now contains a corrected estimate containing the zero category&lt;br /&gt;
barplot(rbind(trueWithF,norm(m))[,-1],main='true vs est sfs F=0.9 (colmean of site pp) (called snp sites)',be=T,col=1:2)&lt;br /&gt;
&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See results from above here:http://www.popgen.dk/angsd/sfsFcomparison.pdf&lt;br /&gt;
&lt;br /&gt;
=safv3 comparison=&lt;br /&gt;
Between 0.800 and 0.900 i decided to move to a better format than the raw sad files. This new format takes up half the storage and allows for easy random access and generalizes to unto 5dimensional sfs. A comparison can be found here: [[safv3]]&lt;br /&gt;
=Using NGStools=&lt;br /&gt;
See [[realSFS]] for how to convert the new safformat to the old safformat if you use NGStools.&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=SFS_Estimation&amp;diff=3185</id>
		<title>SFS Estimation</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=SFS_Estimation&amp;diff=3185"/>
		<updated>2023-12-08T14:21:30Z</updated>

		<summary type="html">&lt;p&gt;Isin: Remove old yuml diagram and replace with mermaid equivalent&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Latest version can now do bootstrapping. Folding should now be done in realSFS and not in the saf file generation.&lt;br /&gt;
&lt;br /&gt;
=Quick Start=&lt;br /&gt;
The process of estimating the SFS and multidimensional has improved a lot in the newer versions.&lt;br /&gt;
&lt;br /&gt;
Assuming you have a bam/cram file list in the file 'file.list' and you have your ancestral state in ancestral.fasta, then the process is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#no filtering&lt;br /&gt;
./angsd -gl 1 -anc ancestral -dosaf 1&lt;br /&gt;
#or alot of filtering&lt;br /&gt;
./angsd -gl 1 -anc ancestral -dosaf 1 -baq 1 -C 50 -minMapQ 30 -minQ 20&lt;br /&gt;
&lt;br /&gt;
#this will generate 3 files&lt;br /&gt;
1) angsdput.saf.idx 2) angsdput.saf.pos.gz 3) angsdput.saf.gz&lt;br /&gt;
#these are binary files that are formally defined in https://github.com/ANGSD/angsd/blob/newsaf/doc/formats.pdf&lt;br /&gt;
&lt;br /&gt;
#To find the global SFS based on the run from above simply do&lt;br /&gt;
./realSFS angsdput.saf.idx&lt;br /&gt;
##or only use chromosome 22&lt;br /&gt;
./realSFS angsdput.saf.idx -r 22&lt;br /&gt;
&lt;br /&gt;
## or specific regions&lt;br /&gt;
./realSFS angsdput.saf.idx -r 22:100000-150000000&lt;br /&gt;
&lt;br /&gt;
##or limit to a fixed number of sites&lt;br /&gt;
./realSFS angsdput.saf.idx -r 17 -nSites 10000000&lt;br /&gt;
&lt;br /&gt;
##or you can find the 2dim sf by&lt;br /&gt;
./realSFS ceu.saf.idx yri.saf.idx&lt;br /&gt;
##NB the program will find the intersect internally. No need for multiple runs with angsd main program.&lt;br /&gt;
&lt;br /&gt;
##or you can find the 3dim sf by&lt;br /&gt;
./realSFS ceu.saf.idx yri.saf.idx MEX.saf.idx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=SFS=&lt;br /&gt;
This method will estimate the site frequency spectrum, the method is described in [[Nielsen2012]]. The theory behind the model is briefly described [[realSFSmethod|here]]&lt;br /&gt;
&lt;br /&gt;
This is a 2 step procedure first generate a &amp;quot;.saf&amp;quot; file (site allele frequency likelihood), followed by an optimization of the .saf file which will estimate the Site frequency spectrum (SFS).&lt;br /&gt;
&lt;br /&gt;
For the optimization we have implemented 2 different approaches both found in the misc folder. The diagram below shows the how the method goes from raw bam files to the SFS. &lt;br /&gt;
&lt;br /&gt;
You can also estimate a [[2d SFS Estimation| 2dsfs]] or even higher if you want to.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* NB the ancestral state needs to be supplied for the full SFS, but you can use the -fold 1 to estimate the folded SFS and then use the reference as ancestral.&lt;br /&gt;
* NB the output from the -doSaf 2 are not sample allele frequency likelihoods but sample alle posteriors.&lt;br /&gt;
And applying the realSFS to this output is therefore NOT the ML estimate of the SFS as described in the Nielsen 2012 paper,&lt;br /&gt;
but the 'Incorporating deviations from Hardy-Weinberg Equilibrium (HWE)' section of that paper.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{#mermaid:graph LR;&lt;br /&gt;
    A[sequence data] --&amp;gt; B[genotype likelihoods&amp;lt;br/&amp;gt;- SAMtools&amp;lt;br/&amp;gt;- GATK&amp;lt;br/&amp;gt;- SOAPsnp&amp;lt;br/&amp;gt;- Kim et.al]&lt;br /&gt;
    B --&amp;gt;|doSaf| C[.saf file]&lt;br /&gt;
    C --&amp;gt;|optimize realSFS| D[.saf.ml file]&lt;br /&gt;
&lt;br /&gt;
    class A sequenceData;&lt;br /&gt;
    class B genotypeLikelihoods;&lt;br /&gt;
    class C safFile;&lt;br /&gt;
    class D safMlFile;&lt;br /&gt;
&lt;br /&gt;
    classDef sequenceData fill:#FFA500;&lt;br /&gt;
    classDef genotypeLikelihoods fill:#FFFFFF;&lt;br /&gt;
    classDef safFile fill:#009FFF;&lt;br /&gt;
    classDef safMlFile fill:#FF0000;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -dosaf&lt;br /&gt;
	-&amp;gt; angsd version: 0.935-44-g02a07fc-dirty (htslib: 1.12-1-g9672589) build(Jul  8 2021 08:04:55)&lt;br /&gt;
	-&amp;gt; ./angsd -dosaf &lt;br /&gt;
	-&amp;gt; Analysis helpbox/synopsis information:&lt;br /&gt;
	-&amp;gt; Wed Aug 18 11:09:03 2021&lt;br /&gt;
	-&amp;gt; doMcall=0&lt;br /&gt;
--------------&lt;br /&gt;
abcSaf.cpp:&lt;br /&gt;
	-doSaf		0&lt;br /&gt;
	1: perform multisample GL estimation&lt;br /&gt;
	2: use an inbreeding version&lt;br /&gt;
	3: calculate genotype probabilities (use -doPost 3 instead)&lt;br /&gt;
	4: Assume genotype posteriors as input (still beta) &lt;br /&gt;
	-underFlowProtect	0&lt;br /&gt;
	-anc			(null) (ancestral fasta)&lt;br /&gt;
	-noTrans		0 (remove transitions)&lt;br /&gt;
	-pest			(null) (prior SFS)&lt;br /&gt;
	-isHap			0 (is haploid beta!)&lt;br /&gt;
	-doPost			0 (doPost 3,used for accesing saf based variables)&lt;br /&gt;
NB:&lt;br /&gt;
	  If -pest is supplied in addition to -doSaf then the output will then be posterior probability of the sample allelefrequency for each site&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
misc/realSFS&lt;br /&gt;
./realSFS afile.saf.idx [-start FNAME -P nThreads -tole tole -maxIter  -nSites ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For information and parameters concerning the realSFS subprogram go here: [[realSFS]]&lt;br /&gt;
&lt;br /&gt;
=Options=&lt;br /&gt;
;-doSaf 1: Calculate the Site allele frequency likelihood based on individual genotype likelihoods assuming HWE&lt;br /&gt;
&lt;br /&gt;
;-doSaf 2:(version above 0.503) Calculate per site posterior probabilities of the  site allele frequencies based on individual genotype likelihoods while taking into account individual inbreeding coefficients. This is implemented by Filipe G. Vieira.  You need to supply a file containing all the inbreeding coefficients. -indF. Consider if you want to either get the MAP estimate by using all sites, or get the standardized values by conditioning on the called snpsites. See bottom of this page for examples.&lt;br /&gt;
&lt;br /&gt;
;-doSaf 3: Calculate the genotype posterior probabilities for all samples forall sites, using an estimate of the sfs (sample allele frequency distribution). This needs a prior distribution of the SFS (which can be obtained from -doSaf 1/realSFS).&lt;br /&gt;
&lt;br /&gt;
;-doSaf 4: Calculate the posterior probabilities of the sample allele frequency distribution for each site based on genotype probabilities. The genotype probabilities should be provided by the using using the -beagle options. Often the genotype probabilities will be obtained by haplotype imputation. &lt;br /&gt;
&lt;br /&gt;
;-underFlowProtect [INT] &lt;br /&gt;
0: (default) no underflow protection. 1: use underflow protection. For large data sets (large number of individuals) underflow projection is needed.&lt;br /&gt;
&lt;br /&gt;
=Output file=&lt;br /&gt;
The output file from the ''-doSaf'' is described in detail in angsd/doc/formats.pdf. These binary annoying files can be printed with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
realSFS print myfile.saf.idx&lt;br /&gt;
#or&lt;br /&gt;
realSFS print mayflies.saf.idx -r chr1:10000-20000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Example==&lt;br /&gt;
A full example is shown below where we use the test data that can be found on the [[quick start]] page. In this example we use GATK genotype likelihoods.&lt;br /&gt;
&lt;br /&gt;
first generate .saf file  with 4 threads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -bam bam.filelist -doSaf 1 -out small -anc  chimpHg19.fa -GL 2 -P 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We always recommend that you filter out the bad qscore bases and meaningless mapQ reads. eg '''-minMapQ 1 -minQ 20'''. So the above analysis with these filters can be written as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -bam bam.filelist -doSaf 1 -out small -anc chimpHg19.fa -GL 2 -P 4 -minMapQ 1 -minQ 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Obtain a maximum likelihood estimate of the SFS using EM algorithm &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
misc/realSFS small.saf.idx -maxIter 100 -P 4 &amp;gt;small.sfs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SfsSmall.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
A plot of this figure are seen on the right. The jaggedness is due to the very low number of sites in this small dataset.&lt;br /&gt;
&lt;br /&gt;
=Interpretation of the output file=&lt;br /&gt;
Each row is a region of the genome (see below).&lt;br /&gt;
Each row is the expected values of the SFS.&lt;br /&gt;
==NB==&lt;br /&gt;
The generation of the .saf file contains a saf for each site, whereas the optimization requires information for a region of the genome. The optimization will therefore use large amounts of memory.&lt;br /&gt;
&lt;br /&gt;
=Folded spectra=&lt;br /&gt;
If you don't have the ancestral state, you can instead estimate the folded SFS. This is done by supplying the -anc with the reference genome and applying -fold 1 to realSFS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above example would then be&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#first generate .saf file&lt;br /&gt;
./angsd -bam bam.filelist -doSaf 1 -out smallFolded -anc  chimpHg19.fa -GL 2&lt;br /&gt;
#now try the EM optimization with 4 threads&lt;br /&gt;
misc/realSFS smallFolded.saf.idx -maxIter 100 -P 4 &amp;gt;smallFolded.sfs&lt;br /&gt;
#in R&lt;br /&gt;
sfs&amp;lt;-scan(&amp;quot;smallFolded.sfs&amp;quot;)&lt;br /&gt;
barplot(sfs[-1])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SmallFolded.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=Posterior of the per-site distributions of the sample allele frequency=&lt;br /&gt;
If you supply a prior for the SFS (which can be obtained from the -doSaf/realSFS analysis), the output of the .saf file will no longer be  site allele frequency likelihoods but instead will be the log posterior probability of the sample allele frequency for each site in logspace.&lt;br /&gt;
&lt;br /&gt;
=Format specification of binary .saf* files=&lt;br /&gt;
This can be found in the angsd/doc/formats.pdf&lt;br /&gt;
&lt;br /&gt;
* If the -fold 1 has been set, then the dimension is no longer 2*nInd+1 but nInd+1 (this is deprecated)&lt;br /&gt;
* If the -pest parameter has been supplied the output is no longer likelihoods but log posterior site allele frequencies&lt;br /&gt;
&lt;br /&gt;
=Bootstrapping=&lt;br /&gt;
We have recently added the possibility to bootstrap the SFS. Which can be very usefull for getting confidence intervals of the estimated SFS.&lt;br /&gt;
&lt;br /&gt;
This is done by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
realSFS pop.saf.idx -bootstrap 100 -P number_of_cores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The program will then get you 100 estimates of SFS, based on data that has been subsampled with replacement.&lt;br /&gt;
&lt;br /&gt;
=How to plot=&lt;br /&gt;
Assuming the we have obtained a single global sfs(only one line in the output) from '''realSFS''' program, and this is located in '''file.saf.sfs''', then we can plot the results simply like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sfs&amp;lt;-(scan(&amp;quot;small.sfs&amp;quot;)) #read in the log sfs&lt;br /&gt;
barplot(sfs[-c(1,length(sfs))]) #plot variable sites &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SfsSmall.png|thumb]]&lt;br /&gt;
We can make it more fancy like below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#function to normalize&lt;br /&gt;
norm &amp;lt;- function(x) x/sum(x)&lt;br /&gt;
#read data&lt;br /&gt;
sfs &amp;lt;- (scan(&amp;quot;small.sfs&amp;quot;))&lt;br /&gt;
#the variability as percentile&lt;br /&gt;
pvar&amp;lt;- (1-sfs[1]-sfs[length(sfs)])*100&lt;br /&gt;
#the variable categories of the sfs&lt;br /&gt;
sfs&amp;lt;-norm(sfs[-c(1,length(sfs))]) &lt;br /&gt;
barplot(sfs,legend=paste(&amp;quot;Variability:= &amp;quot;,round(pvar,3),&amp;quot;%&amp;quot;),xlab=&amp;quot;Chromosomes&amp;quot;,&lt;br /&gt;
names=1:length(sfs),ylab=&amp;quot;Proportions&amp;quot;,main=&amp;quot;mySFS plot&amp;quot;,col='blue')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SfsSmallFine.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
If your output from '''realSFS''' contains more than one line, it is because you have estimated multiple local SFS's. Then you can't use the above commands directly but should first pick a specific row.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sfs&amp;lt;-(as.numeric(read.table(&amp;quot;multiple.sfs&amp;quot;)[1,])) #first region.&lt;br /&gt;
#do the above&lt;br /&gt;
sfs&amp;lt;-(as.numeric(read.table(&amp;quot;multiple.sfs&amp;quot;)[2,])) #second region.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Which genotype likelihood model should I choose ?=&lt;br /&gt;
It depends on the data. As shown on this example [[Glcomparison]], there was a huge difference between '''-GL 1''' and '''-GL 2''' for older 1000genomes BAM files, but little difference for newer bam files.&lt;br /&gt;
=Validation=&lt;br /&gt;
The validation is based on the pre 0.900 version&lt;br /&gt;
==-doSaf 1==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd misc;&lt;br /&gt;
./supersim -outfiles test -npop 1 -nind 12 -pvar 0.9 -nsites 50000&lt;br /&gt;
echo testchr1 100000 &amp;gt;test.fai&lt;br /&gt;
../angsd -fai test.fai -glf test.glf.gz -nind 12 -doSaf 1 -issim 1&lt;br /&gt;
./realSFS angsdput.saf 24 2&amp;gt;/dev/null &amp;gt;res&lt;br /&gt;
cat res&lt;br /&gt;
31465.429798 4938.453115 2568.586388 1661.227445 1168.891114 975.302535 794.727537 632.691896 648.223566 546.293853 487.936192 417.178505 396.200026 409.813797 308.434836 371.699254 245.585920 322.293532 282.980046 292.584975 212.845183 196.682483 221.802128 236.221205 197.914673&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==-doSaf 2==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ngsSim=../ngsSim/ngsSim&lt;br /&gt;
angsd=./angsd&lt;br /&gt;
realSFS=./misc/realSFS&lt;br /&gt;
&lt;br /&gt;
$ngsSim  -npop 1 -nind 24 -nsites 1000000 -depth 4 -F 0.0 -outfiles testF0.0&lt;br /&gt;
$ngsSim  -npop 1 -nind 24 -nsites 1000000 -depth 4 -F 0.9 -outfiles testF0.9&lt;br /&gt;
&lt;br /&gt;
for i in `seq 24`;do echo 0.9;done &amp;gt;indF&lt;br /&gt;
echo testchr1 250000000 &amp;gt;test.fai&lt;br /&gt;
$angsd -fai test.fai -issim 1 -glf testF0.0.glf.gz -nind 24 -out noF -dosaf 1&lt;br /&gt;
$angsd -fai test.fai -issim 1 -glf testF0.9.glf.gz -nind 24 -out withF -dosaf 2 -domajorminor 1 -domaf 1 -indF indF&lt;br /&gt;
$angsd -fai test.fai -issim 1 -glf testF0.9.glf.gz -nind 24 -out withFsnp -dosaf 2 -domajorminor 1 -domaf 1 -indF indF -snp_pval 1e-4&lt;br /&gt;
&lt;br /&gt;
$realSFS noF.saf 48 &amp;gt;noF.sfs&lt;br /&gt;
$realSFS withF.saf 48 &amp;gt;withF.sfs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#in R&lt;br /&gt;
trueNoF&amp;lt;-scan(&amp;quot;testF0.0.frq&amp;quot;)&lt;br /&gt;
trueWithF&amp;lt;-scan(&amp;quot;testF0.9.frq&amp;quot;)&lt;br /&gt;
pdf(&amp;quot;sfsFcomparison.pdf&amp;quot;,width=14)&lt;br /&gt;
par(mfrow=c(1,2),width=14)&lt;br /&gt;
barplot(trueNoF[-1],main='true sfs F=0.0')&lt;br /&gt;
barplot(trueWithF[-1],main='true sfs F=0.9')&lt;br /&gt;
&lt;br /&gt;
estWithF&amp;lt;-scan(&amp;quot;withF.sfs&amp;quot;)&lt;br /&gt;
estNoF&amp;lt;-scan(&amp;quot;noF.sfs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
barplot(rbind(trueNoF,estNoF)[,-1],main=&amp;quot;true vs est SFS F=0 (ML) (all sites)&amp;quot;,be=T,col=1:2)&lt;br /&gt;
barplot(rbind(trueWithF,estWithF)[,-1],main='true vs est sfs=0.9 (MAP) (all sites)',be=T,col=1:2)&lt;br /&gt;
&lt;br /&gt;
readBjoint &amp;lt;- function(file=NULL,nind=10,nsites=10){&lt;br /&gt;
  ff &amp;lt;- gzfile(file,&amp;quot;rb&amp;quot;)&lt;br /&gt;
  m&amp;lt;-matrix(readBin(ff,double(),(2*nind+1)*nsites),ncol=(2*nind+1),byrow=TRUE)&lt;br /&gt;
  close(ff)&lt;br /&gt;
  return(m)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
m &amp;lt;- exp(readBjoint(&amp;quot;withF.saf&amp;quot;,nind=24,5e6))&lt;br /&gt;
barplot(rbind(trueWithF,colMeans(m))[,-1],main='true vs est sfs F=0.9 (colmean of site pp) (all sites)',be=T,col=1:2)&lt;br /&gt;
m &amp;lt;- exp(readBjoint(&amp;quot;withFsnp.saf&amp;quot;,nind=24,5e6))&lt;br /&gt;
m &amp;lt;- colMeans(m)*nrow(m)&lt;br /&gt;
##m contains SFS for absolute frequencies&lt;br /&gt;
m[1] &amp;lt;-1e6-sum(m[-1])&lt;br /&gt;
##m now contains a corrected estimate containing the zero category&lt;br /&gt;
barplot(rbind(trueWithF,norm(m))[,-1],main='true vs est sfs F=0.9 (colmean of site pp) (called snp sites)',be=T,col=1:2)&lt;br /&gt;
&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See results from above here:http://www.popgen.dk/angsd/sfsFcomparison.pdf&lt;br /&gt;
&lt;br /&gt;
=safv3 comparison=&lt;br /&gt;
Between 0.800 and 0.900 i decided to move to a better format than the raw sad files. This new format takes up half the storage and allows for easy random access and generalizes to unto 5dimensional sfs. A comparison can be found here: [[safv3]]&lt;br /&gt;
=Using NGStools=&lt;br /&gt;
See [[realSFS]] for how to convert the new safformat to the old safformat if you use NGStools.&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3182</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Installation&amp;diff=3182"/>
		<updated>2023-07-04T10:56:24Z</updated>

		<summary type="html">&lt;p&gt;Isin: update to latest release&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There has been some confusion about the versions of ANGSD.&lt;br /&gt;
&lt;br /&gt;
* Even versions are freezes from the last odd giversion&lt;br /&gt;
&lt;br /&gt;
* Odd versions are git versions. Once there has been enough commits we will increment and make a release.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
To download and use ANGSD you need to download the htslib and the angsd source folder&lt;br /&gt;
&lt;br /&gt;
You can either download the angsd0.938.tar.gz which contains both.&lt;br /&gt;
[http://popgen.dk/software/download/angsd/angsd0.938.tar.gz]&lt;br /&gt;
&lt;br /&gt;
Or you can use github for the latest version of both htslib and angsd&lt;br /&gt;
&lt;br /&gt;
Earlier versions from here: http://popgen.dk/software/download/angsd/&lt;br /&gt;
And here: https://github.com/ANGSD/angsd/releases&lt;br /&gt;
&lt;br /&gt;
=Install=&lt;br /&gt;
Download and unpack the tarball, enter the directory and type make. Users on a mac computer, can use curl instead of wget.&lt;br /&gt;
&lt;br /&gt;
===Unix===&lt;br /&gt;
The software can be compiled using make.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://popgen.dk/software/download/angsd/angsd0.940.tar.gz&lt;br /&gt;
tar xf angsd0.940.tar.gz&lt;br /&gt;
cd htslib;make;cd ..&lt;br /&gt;
cd angsd&lt;br /&gt;
make HTSSRC=../htslib&lt;br /&gt;
cd ..&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The executable then located in '''angsd/angsd'''.&lt;br /&gt;
&lt;br /&gt;
=Install from github=&lt;br /&gt;
To install CRAM support you also need to install htslib and can be done using the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone --recursive https://github.com/samtools/htslib.git&lt;br /&gt;
git clone https://github.com/ANGSD/angsd.git &lt;br /&gt;
cd htslib;make;cd ../angsd ;make HTSSRC=../htslib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Systemwide installation of htslib?=&lt;br /&gt;
Then you just type make in the angsd directory&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Vcf&amp;diff=3181</id>
		<title>Vcf</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Vcf&amp;diff=3181"/>
		<updated>2023-06-21T21:53:55Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* Output files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Newer versions of angsd (master 27april2015) supports basic vcf output. This will only include gl and gp tags which can be useful for certain external programs&lt;br /&gt;
 &lt;br /&gt;
Supply&lt;br /&gt;
;-doVcf 1&lt;br /&gt;
&lt;br /&gt;
Which is simply a wrapper around -gl -dopost -domajorminor -domaf. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
A full example commandline is given below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 ./angsd -b list.list -dovcf 1 -gl 1 -dopost 1 -domajorminor 1 -domaf 1 -snp_pval 1e-6&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Output files==&lt;br /&gt;
This will generate a vcf file called angsdput.vcf.gz&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
angsdput.vcf.gz&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
##FORMAT=&amp;lt;ID=GL,Number=G,Type=Float,Description=&amp;quot;scaled Genotype Likelihoods (these are really llh eventhough they sum to one)&amp;quot;&amp;gt;&lt;br /&gt;
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	ind0	ind1	ind2	ind3	ind4	ind5	ind6	ind7	ind8	ind9	ind10	ind11	ind12	ind13	ind14	ind15	ind16	ind17	ind18	ind19	ind20	ind21	ind22	ind23	ind24	ind25	ind26	ind27	ind28	ind29	ind30	ind31	ind32&lt;br /&gt;
1	14000202	.	G	A	.	PASS	.	GL:GP	0.013409,0.986591,0.000001:0.009959,0.990038,0.000003	0.532745,0.394297,0.072957:0.333333,0.333333,0.333333	0.532745,0.394297,0.072957:0.333333,0.333333,0.333333	0.729804,0.270070,0.000126:0.666110,0.333052,0.000839	0.532745,0.394297,0.072957:0.333333,0.333333,0.333333	0.013409,0.986589,0.000003:0.009959,0.990026,0.000015	0.843814,0.156129,0.000057:0.799685,0.199918,0.000397	0.003405,0.996582,0.000013:0.002523,0.997410,0.000068	0.915318,0.084679,0.000003:0.888870,0.111106,0.000025	0.843862,0.156138,0.000000:0.800003,0.199997,0.000000	0.001243,0.728985,0.269772:0.000420,0.333191,0.666388	0.955789,0.044211,0.000000:0.941178,0.058822,0.000000	0.843860,0.156137,0.000003:0.799987,0.199993,0.000020	0.000001,0.999999,0.000000:0.000001,0.999999,0.000000	0.824856,0.152621,0.022523:0.689947,0.172484,0.137569	0.701963,0.259767,0.038270:0.526842,0.263419,0.209740	0.532745,0.394297,0.072957:0.333333,0.333333,0.333333	0.004272,0.995611,0.000117:0.003164,0.996204,0.000632	0.532745,0.394297,0.072957:0.333333,0.333333,0.333333	0.021392,0.791754,0.186854:0.008712,0.435643,0.555645	0.843681,0.156104,0.000215:0.798816,0.199700,0.001484	0.729804,0.270070,0.000126:0.666110,0.333052,0.000839	0.002698,0.996374,0.000928:0.001990,0.993012,0.004997	0.977395,0.022605,0.000000:0.969698,0.030302,0.000000	0.532745,0.394297,0.072957:0.333333,0.333333,0.333333	0.002152,0.997847,0.000002:0.001593,0.998397,0.000010	0.915213,0.084669,0.000118:0.888149,0.111016,0.000835	0.032903,0.965645,0.001452:0.024405,0.967730,0.007865	0.000006,0.999994,0.000000:0.000005,0.999995,0.000000	0.701963,0.259767,0.038270:0.526842,0.263419,0.209740	0.843846,0.156135,0.000019:0.799896,0.199971,0.000133	0.907127,0.083921,0.008952:0.835380,0.104420,0.060201	0.332066,0.644735,0.023200:0.241926,0.634652,0.123421&lt;br /&gt;
1	14000873	.	G	A	.	PASS	.	GL:GP	0.000000,0.124151,0.875849:0.000000,0.030302,0.969698	0.692531,0.305335,0.002134:0.659698,0.329846,0.010456	0.900720,0.099279,0.000000:0.888891,0.111109,0.000000	0.993158,0.006842,0.000000:0.992249,0.007751,0.000000	0.999140,0.000860,0.000000:0.999024,0.000976,0.000000	0.000091,0.994381,0.005528:0.000078,0.975325,0.024596	0.900720,0.099279,0.000000:0.888891,0.111109,0.000000	0.819369,0.180627,0.000004:0.799988,0.199993,0.000018	0.000000,0.124151,0.875849:0.000000,0.030302,0.969698	0.693938,0.305955,0.000107:0.666316,0.333155,0.000529	0.986410,0.013590,0.000000:0.984616,0.015384,0.000000	0.693919,0.305947,0.000135:0.666224,0.333109,0.000666	0.007101,0.988541,0.004358:0.006172,0.974344,0.019484	0.000000,1.000000,0.000000:0.000000,1.000000,0.000000	0.030451,0.672875,0.296674:0.013127,0.328956,0.657917	0.973184,0.026816,0.000000:0.969698,0.030302,0.000000	0.973184,0.026816,0.000000:0.969698,0.030302,0.000000	0.993158,0.006842,0.000000:0.992249,0.007751,0.000000	0.004535,0.995465,0.000000:0.004001,0.995998,0.000000	0.000395,0.693734,0.305871:0.000167,0.333276,0.666557	0.900720,0.099279,0.000000:0.888891,0.111109,0.000000	0.693965,0.305967,0.000068:0.666446,0.333220,0.000334	0.947768,0.052232,0.000000:0.941178,0.058822,0.000000	0.000000,0.220881,0.779119:0.000000,0.058822,0.941178	0.900720,0.099279,0.000000:0.888891,0.111109,0.000000	0.000000,0.017410,0.982590:0.000000,0.003891,0.996109	0.000046,0.999954,0.000000:0.000040,0.999960,0.000000	0.000001,0.999999,0.000000:0.000001,0.999999,0.000000	0.947768,0.052232,0.000000:0.941178,0.058822,0.000000	0.310721,0.689279,0.000000:0.284441,0.715559,0.000000	0.900720,0.099279,0.000000:0.888891,0.111109,0.000000	0.973184,0.026816,0.000000:0.969698,0.030302,0.000000	0.000992,0.693320,0.305688:0.000420,0.333191,0.666388&lt;br /&gt;
1	14001018	.	T	C	.	PASS	.	GL:GP	0.000000,0.069163,0.930837:0.000000,0.015384,0.984616	0.826258,0.173742,0.000000:0.800002,0.199997,0.000002	0.159620,0.840380,0.000000:0.137752,0.862248,0.000000	0.950058,0.049942,0.000000:0.941178,0.058822,0.000000	0.904865,0.095135,0.000000:0.888891,0.111109,0.000000	0.826258,0.173742,0.000000:0.800003,0.199997,0.000000	0.495544,0.416810,0.087646:0.333333,0.333333,0.333333	0.993472,0.006528,0.000000:0.992249,0.007751,0.000000	0.001055,0.703204,0.295741:0.000420,0.333191,0.666388	0.703933,0.296042,0.000025:0.666580,0.333287,0.000133	0.826258,0.173742,0.000000:0.800003,0.199997,0.000000	0.703933,0.296042,0.000025:0.666580,0.333287,0.000133	0.000420,0.703651,0.295929:0.000167,0.333276,0.666557	0.000008,0.999992,0.000000:0.000006,0.999994,0.000000	0.085860,0.913986,0.000153:0.073175,0.926086,0.000739	0.904865,0.095135,0.000000:0.888891,0.111109,0.000000	0.495544,0.416810,0.087646:0.333333,0.333333,0.333333	0.993472,0.006528,0.000000:0.992249,0.007751,0.000000	0.703731,0.295957,0.000313:0.665554,0.332774,0.001672	0.000007,0.543141,0.456852:0.000002,0.199997,0.800001	0.904865,0.095135,0.000000:0.888891,0.111109,0.000000	0.904865,0.095135,0.000000:0.888891,0.111109,0.000000	0.904865,0.095135,0.000000:0.888891,0.111109,0.000000	0.000007,0.543141,0.456852:0.000002,0.199997,0.800001	0.904865,0.095135,0.000000:0.888892,0.111108,0.000000	0.000000,0.229117,0.770883:0.000000,0.058822,0.941178	0.045152,0.954211,0.000637:0.038160,0.958794,0.003045	0.000599,0.999394,0.000006:0.000504,0.999465,0.000031	0.974389,0.025611,0.000000:0.969698,0.030302,0.000000	0.000005,0.543142,0.456853:0.000002,0.199997,0.800002	0.974389,0.025611,0.000000:0.969698,0.030302,0.000000	0.703916,0.296035,0.000050:0.666492,0.333243,0.000265	0.495544,0.416810,0.087646:0.333333,0.333333,0.333333&lt;br /&gt;
1	14001867	.	A	G	.	PASS	.	GL:GP	0.000407,0.698622,0.300971:0.000167,0.333276,0.666557	0.902773,0.097227,0.000000:0.888891,0.111109,0.000000	0.000645,0.698456,0.300899:0.000265,0.333243,0.666492	0.902773,0.097227,0.000000:0.888891,0.111109,0.000000	0.902773,0.097227,0.000000:0.888891,0.111109,0.000000	0.000006,0.998276,0.001719:0.000005,0.992066,0.007929	0.986717,0.013283,0.000000:0.984616,0.015384,0.000000	0.822776,0.177224,0.000000:0.800002,0.199997,0.000001	0.000003,0.537165,0.462832:0.000001,0.199997,0.800002	0.948903,0.051097,0.000000:0.941178,0.058822,0.000000	0.948903,0.051097,0.000000:0.941178,0.058822,0.000000	0.986717,0.013283,0.000000:0.984616,0.015384,0.000000	0.000000,0.537166,0.462833:0.000000,0.199997,0.800003	0.000060,0.999940,0.000000:0.000051,0.999949,0.000000	0.000079,0.999921,0.000000:0.000068,0.999932,0.000000	0.902773,0.097227,0.000000:0.888891,0.111109,0.000000	0.902773,0.097227,0.000000:0.888891,0.111109,0.000000	0.999159,0.000841,0.000000:0.999024,0.000976,0.000000	0.004641,0.995359,0.000000:0.004001,0.995999,0.000000	0.000645,0.698456,0.300899:0.000265,0.333243,0.666492	0.948903,0.051097,0.000000:0.941178,0.058822,0.000000	0.822774,0.177223,0.000002:0.799994,0.199995,0.000011	0.996646,0.003354,0.000000:0.996109,0.003891,0.000000	0.000000,0.008985,0.991015:0.000000,0.001949,0.998051	0.822776,0.177224,0.000000:0.800002,0.199997,0.000001	0.000000,0.367208,0.632792:0.000000,0.111109,0.888891	0.000000,0.999135,0.000865:0.000000,0.995998,0.004001	0.005821,0.994177,0.000002:0.005019,0.994970,0.000011	0.993314,0.006686,0.000000:0.992249,0.007751,0.000000	0.000000,0.999998,0.000002:0.000000,0.999992,0.000008	0.948903,0.051097,0.000000:0.941178,0.058822,0.000000	0.822776,0.177224,0.000001:0.800000,0.199997,0.000003	0.007316,0.992667,0.000017:0.006309,0.993611,0.000079&lt;br /&gt;
[capped]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Notice that the sampleID is simply an ind followed by an integer. These correspond to the samples from the `-b filelist`.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Allele_Frequencies&amp;diff=3180</id>
		<title>Allele Frequencies</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Allele_Frequencies&amp;diff=3180"/>
		<updated>2023-06-08T10:16:21Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* Output data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;keywords&amp;quot;&amp;gt; -domaf,-domaf,-domaf,-domaf,-domaf, domaf, domaf, domaf, domaf, domaf, domaf, dopost, SNP_pval &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The allele frequency is the relative frequency of an allele for a site. This can be polarized according to the major/minor, reference/non-refernce or ancestral/derived. .Therefore the choice of allele frequency estimator is closely related to choosing which alleles are segregating (see [[Inferring_Major_and_Minor_alleles]]). &lt;br /&gt;
&lt;br /&gt;
We allow for frequency estimation from different input data:&lt;br /&gt;
&lt;br /&gt;
# Genotype Likelihoods&lt;br /&gt;
# Genotype posterior probabilities&lt;br /&gt;
# Counts of bases&lt;br /&gt;
&lt;br /&gt;
The allele frequency estimator from genotype likelihoods are from this  [[suYeon | publication]], and the base counts method is from this [[Li2010 |publication]]. &lt;br /&gt;
&lt;br /&gt;
For the case of the genotype likelihood based methods we allow for deviations from Hardy-Weinberg, namely we allow for users to supply a file containing inbreeding coefficients for each individual.&lt;br /&gt;
&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 ./angsd -doMaf&lt;br /&gt;
abcFreq.cpp:&lt;br /&gt;
-doMaf	0 (Calculate persite frequencies '.mafs.gz')&lt;br /&gt;
	1: Frequency (fixed major and minor)&lt;br /&gt;
	2: Frequency (fixed major unknown minor)&lt;br /&gt;
	4: Frequency from genotype probabilities&lt;br /&gt;
	8: AlleleCounts based method (known major minor)&lt;br /&gt;
	NB. Filedumping is supressed if value is negative&lt;br /&gt;
-doPost	0	(Calculate posterior prob 3xgprob)&lt;br /&gt;
	1: Using frequency as prior&lt;br /&gt;
	2: Using uniform prior&lt;br /&gt;
	3: Using SFS as prior (still in development)&lt;br /&gt;
	4: Using reference panel as prior (still in development), requires a site file with chr pos major minor af ac an&lt;br /&gt;
Filters:&lt;br /&gt;
	-minMaf  	-1.000000	(Remove sites with MAF below)&lt;br /&gt;
	-SNP_pval	0.317311	(Remove sites with a pvalue larger)&lt;br /&gt;
	-rmSNPs 	0	(Remove infered SNPs instead of keeping them (pval &amp;gt; SNP_pval)&lt;br /&gt;
	-rmTriallelic	0.000000	(Remove sites with a pvalue lower)&lt;br /&gt;
	-forceMaf	0	(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))&lt;br /&gt;
	-skipMissing	1	(Set post to 0.33 if missing (do not use freq as prior))&lt;br /&gt;
Extras:&lt;br /&gt;
	-ref	(null)	(Filename for fasta reference)&lt;br /&gt;
	-anc	(null)	(Filename for fasta ancestral)&lt;br /&gt;
	-eps	0.001000 [Only used for -doMaf &amp;amp;8]&lt;br /&gt;
	-beagleProb	0 (Dump beagle style postprobs)&lt;br /&gt;
	-indFname	(null) (file containing individual inbreedcoeficients)&lt;br /&gt;
	-underFlowProtect	0 (file containing individual inbreedcoeficients)&lt;br /&gt;
NB These frequency estimators requires major/minor -doMajorMinor&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Allele Frequency estimation=&lt;br /&gt;
The major and minor allele is first inferred from the data or given by the user (see [[Inferring_Major_and_Minor_alleles]]). This includes information from both major and minor allele, a reference genome (for major) or an ancestral genome. &lt;br /&gt;
&lt;br /&gt;
; -doMaf [int]&lt;br /&gt;
&lt;br /&gt;
1:  Known major, and Known minor. Here both the major and minor allele is assumed to be known (inferred or given by user). The allele frequency is the obtained using based on the genotype likelihoods. The allele frequency estimator from genotype likelihoods are from this [[suYeon | publication]]  but using the EM algorithm and is briefly described [[SYKmaf|here]]. &lt;br /&gt;
&lt;br /&gt;
2:  Known major, Unknown minor. Here the major allele is assumed to be known  (inferred or given by user) however the minor allele is not determined. Instead we sum over the 3 possible minor alleles weighted by their probabilities. The allele frequency estimator from genotype likelihoods are from this [[suYeon | publication]] but using the EM algorithm and is briefly described [[SYKmaf|here]]. &lt;br /&gt;
. &lt;br /&gt;
&lt;br /&gt;
4: frequency based on genotype posterior probabilities. If genotype probabilities are used as input to ANGSD the allele frequency is estimated directly on these by [[postFreq|summing over the probabitlies]]. &lt;br /&gt;
&lt;br /&gt;
8: frequency based on base counts. This method does not rely on genotype likelihood or probabilities but instead infers the allele frequency directly on the base counts. The base counts method is from this [[Li2010 |publication]]. &lt;br /&gt;
&lt;br /&gt;
Multiple estimators can be used simultaniusly be summing up the above numbers. Thus -doMaf 7 (1+2+4) will use the first three estimators. If the allele frequencies are estimated from the genotype likelihoods then you need to infer the major and minor allele (-doMajorMinor)&lt;br /&gt;
&lt;br /&gt;
;NB using -doMaf 4 is only supported if the posteriors are supplied as external files. Since the estimation of genotype posteriors in itself requires a maf estimator.&lt;br /&gt;
&lt;br /&gt;
=Example=&lt;br /&gt;
&lt;br /&gt;
==From genotype likelihood==&lt;br /&gt;
Example for estimating the allele frequencies both while assuming known major and minor allele but also while taking the uncertaincy of the minor allele inference into account. The [[Inferring_Major_and_Minor_alleles|inference of the major and minor]] allele is done directly from the genotype likelihood&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMajorMinor 1 -doMaf 3 -bam bam.filelist -GL 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==From genotype probabilities==&lt;br /&gt;
Example of the use of a genotype probability file for example from the output from beagle. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMaf 4 -beagle beagle.file.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Estimator from base counts==&lt;br /&gt;
&lt;br /&gt;
The allele frequencies can be infered directy from the sequencing data [[Li2010|citation]].&lt;br /&gt;
This works by using &amp;quot;counts&amp;quot; of alleles, and should be invoked like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMajorMinor 2 -doMaf 8 -bam bam.filelist -doCounts 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Output data=&lt;br /&gt;
==.mafs.gz==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chromo	position	major	minor	ref	knownEM	unknownEM	nInd&lt;br /&gt;
21      9719788 T       A       0.000001        -0.000012       3&lt;br /&gt;
21      9719789 G       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719790 A       C       0.000000        -0.000004       3&lt;br /&gt;
21      9719791 G       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719792 G       A       0.000000        -0.000002       3&lt;br /&gt;
21      9719793 G       T       0.498277        41.932766       3&lt;br /&gt;
21      9719794 T       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719795 T       A       0.000000        -0.000001       3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;chromo &lt;br /&gt;
chromosome name&lt;br /&gt;
;position&lt;br /&gt;
position&lt;br /&gt;
;major &lt;br /&gt;
major allele&lt;br /&gt;
;minor &lt;br /&gt;
minor allele&lt;br /&gt;
;knownEM &lt;br /&gt;
frequency using -doMaf 1&lt;br /&gt;
;unknownEM &lt;br /&gt;
frequency using -doMaf 2&lt;br /&gt;
;phat &lt;br /&gt;
frequency using -doMaf 8&lt;br /&gt;
;nInd &lt;br /&gt;
is the number of individuals with data&lt;br /&gt;
;pK-EM&lt;br /&gt;
p-value for the frequency of (known) minor allele (-doSNPStat 1 -doMaf 1)&lt;br /&gt;
;pu-EM&lt;br /&gt;
p-value for the frequency of (unknown) minor allele (-doSNPStat 1 -doMaf 2)&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Allele_Frequencies&amp;diff=3179</id>
		<title>Allele Frequencies</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Allele_Frequencies&amp;diff=3179"/>
		<updated>2023-06-08T07:55:20Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* .mafs.gz */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;keywords&amp;quot;&amp;gt; -domaf,-domaf,-domaf,-domaf,-domaf, domaf, domaf, domaf, domaf, domaf, domaf, dopost, SNP_pval &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The allele frequency is the relative frequency of an allele for a site. This can be polarized according to the major/minor, reference/non-refernce or ancestral/derived. .Therefore the choice of allele frequency estimator is closely related to choosing which alleles are segregating (see [[Inferring_Major_and_Minor_alleles]]). &lt;br /&gt;
&lt;br /&gt;
We allow for frequency estimation from different input data:&lt;br /&gt;
&lt;br /&gt;
# Genotype Likelihoods&lt;br /&gt;
# Genotype posterior probabilities&lt;br /&gt;
# Counts of bases&lt;br /&gt;
&lt;br /&gt;
The allele frequency estimator from genotype likelihoods are from this  [[suYeon | publication]], and the base counts method is from this [[Li2010 |publication]]. &lt;br /&gt;
&lt;br /&gt;
For the case of the genotype likelihood based methods we allow for deviations from Hardy-Weinberg, namely we allow for users to supply a file containing inbreeding coefficients for each individual.&lt;br /&gt;
&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 ./angsd -doMaf&lt;br /&gt;
abcFreq.cpp:&lt;br /&gt;
-doMaf	0 (Calculate persite frequencies '.mafs.gz')&lt;br /&gt;
	1: Frequency (fixed major and minor)&lt;br /&gt;
	2: Frequency (fixed major unknown minor)&lt;br /&gt;
	4: Frequency from genotype probabilities&lt;br /&gt;
	8: AlleleCounts based method (known major minor)&lt;br /&gt;
	NB. Filedumping is supressed if value is negative&lt;br /&gt;
-doPost	0	(Calculate posterior prob 3xgprob)&lt;br /&gt;
	1: Using frequency as prior&lt;br /&gt;
	2: Using uniform prior&lt;br /&gt;
	3: Using SFS as prior (still in development)&lt;br /&gt;
	4: Using reference panel as prior (still in development), requires a site file with chr pos major minor af ac an&lt;br /&gt;
Filters:&lt;br /&gt;
	-minMaf  	-1.000000	(Remove sites with MAF below)&lt;br /&gt;
	-SNP_pval	0.317311	(Remove sites with a pvalue larger)&lt;br /&gt;
	-rmSNPs 	0	(Remove infered SNPs instead of keeping them (pval &amp;gt; SNP_pval)&lt;br /&gt;
	-rmTriallelic	0.000000	(Remove sites with a pvalue lower)&lt;br /&gt;
	-forceMaf	0	(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))&lt;br /&gt;
	-skipMissing	1	(Set post to 0.33 if missing (do not use freq as prior))&lt;br /&gt;
Extras:&lt;br /&gt;
	-ref	(null)	(Filename for fasta reference)&lt;br /&gt;
	-anc	(null)	(Filename for fasta ancestral)&lt;br /&gt;
	-eps	0.001000 [Only used for -doMaf &amp;amp;8]&lt;br /&gt;
	-beagleProb	0 (Dump beagle style postprobs)&lt;br /&gt;
	-indFname	(null) (file containing individual inbreedcoeficients)&lt;br /&gt;
	-underFlowProtect	0 (file containing individual inbreedcoeficients)&lt;br /&gt;
NB These frequency estimators requires major/minor -doMajorMinor&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Allele Frequency estimation=&lt;br /&gt;
The major and minor allele is first inferred from the data or given by the user (see [[Inferring_Major_and_Minor_alleles]]). This includes information from both major and minor allele, a reference genome (for major) or an ancestral genome. &lt;br /&gt;
&lt;br /&gt;
; -doMaf [int]&lt;br /&gt;
&lt;br /&gt;
1:  Known major, and Known minor. Here both the major and minor allele is assumed to be known (inferred or given by user). The allele frequency is the obtained using based on the genotype likelihoods. The allele frequency estimator from genotype likelihoods are from this [[suYeon | publication]]  but using the EM algorithm and is briefly described [[SYKmaf|here]]. &lt;br /&gt;
&lt;br /&gt;
2:  Known major, Unknown minor. Here the major allele is assumed to be known  (inferred or given by user) however the minor allele is not determined. Instead we sum over the 3 possible minor alleles weighted by their probabilities. The allele frequency estimator from genotype likelihoods are from this [[suYeon | publication]] but using the EM algorithm and is briefly described [[SYKmaf|here]]. &lt;br /&gt;
. &lt;br /&gt;
&lt;br /&gt;
4: frequency based on genotype posterior probabilities. If genotype probabilities are used as input to ANGSD the allele frequency is estimated directly on these by [[postFreq|summing over the probabitlies]]. &lt;br /&gt;
&lt;br /&gt;
8: frequency based on base counts. This method does not rely on genotype likelihood or probabilities but instead infers the allele frequency directly on the base counts. The base counts method is from this [[Li2010 |publication]]. &lt;br /&gt;
&lt;br /&gt;
Multiple estimators can be used simultaniusly be summing up the above numbers. Thus -doMaf 7 (1+2+4) will use the first three estimators. If the allele frequencies are estimated from the genotype likelihoods then you need to infer the major and minor allele (-doMajorMinor)&lt;br /&gt;
&lt;br /&gt;
;NB using -doMaf 4 is only supported if the posteriors are supplied as external files. Since the estimation of genotype posteriors in itself requires a maf estimator.&lt;br /&gt;
&lt;br /&gt;
=Example=&lt;br /&gt;
&lt;br /&gt;
==From genotype likelihood==&lt;br /&gt;
Example for estimating the allele frequencies both while assuming known major and minor allele but also while taking the uncertaincy of the minor allele inference into account. The [[Inferring_Major_and_Minor_alleles|inference of the major and minor]] allele is done directly from the genotype likelihood&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMajorMinor 1 -doMaf 3 -bam bam.filelist -GL 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==From genotype probabilities==&lt;br /&gt;
Example of the use of a genotype probability file for example from the output from beagle. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMaf 4 -beagle beagle.file.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Estimator from base counts==&lt;br /&gt;
&lt;br /&gt;
The allele frequencies can be infered directy from the sequencing data [[Li2010|citation]].&lt;br /&gt;
This works by using &amp;quot;counts&amp;quot; of alleles, and should be invoked like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMajorMinor 2 -doMaf 8 -bam bam.filelist -doCounts 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Output data=&lt;br /&gt;
==.mafs.gz==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chromo	position	major	minor	ref	knownEM	unknownEM	nInd&lt;br /&gt;
21      9719788 T       A       0.000001        -0.000012       3&lt;br /&gt;
21      9719789 G       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719790 A       C       0.000000        -0.000004       3&lt;br /&gt;
21      9719791 G       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719792 G       A       0.000000        -0.000002       3&lt;br /&gt;
21      9719793 G       T       0.498277        41.932766       3&lt;br /&gt;
21      9719794 T       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719795 T       A       0.000000        -0.000001       3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;chromo &lt;br /&gt;
chromosome name&lt;br /&gt;
;position&lt;br /&gt;
position&lt;br /&gt;
;major &lt;br /&gt;
major allele&lt;br /&gt;
;minor &lt;br /&gt;
minor allele&lt;br /&gt;
;knownEM &lt;br /&gt;
frequency using -doMaf 1&lt;br /&gt;
;unknownEM &lt;br /&gt;
frequency using -doMaf 2&lt;br /&gt;
;phat &lt;br /&gt;
frequency using -doMaf 8&lt;br /&gt;
;nInd &lt;br /&gt;
is the number of individuals with data&lt;br /&gt;
;pK-EM&lt;br /&gt;
probability of a site being SNP with known minor alleles (-doSNPStat 1 -doMaf 1)&lt;br /&gt;
;pu-EM&lt;br /&gt;
p-value for a site being SNP with unknown minor alleles (-doSNPStat 1 -doMaf 2)&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Allele_Frequencies&amp;diff=3178</id>
		<title>Allele Frequencies</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Allele_Frequencies&amp;diff=3178"/>
		<updated>2023-06-07T14:03:33Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* .mafs.gz */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;keywords&amp;quot;&amp;gt; -domaf,-domaf,-domaf,-domaf,-domaf, domaf, domaf, domaf, domaf, domaf, domaf, dopost, SNP_pval &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The allele frequency is the relative frequency of an allele for a site. This can be polarized according to the major/minor, reference/non-refernce or ancestral/derived. .Therefore the choice of allele frequency estimator is closely related to choosing which alleles are segregating (see [[Inferring_Major_and_Minor_alleles]]). &lt;br /&gt;
&lt;br /&gt;
We allow for frequency estimation from different input data:&lt;br /&gt;
&lt;br /&gt;
# Genotype Likelihoods&lt;br /&gt;
# Genotype posterior probabilities&lt;br /&gt;
# Counts of bases&lt;br /&gt;
&lt;br /&gt;
The allele frequency estimator from genotype likelihoods are from this  [[suYeon | publication]], and the base counts method is from this [[Li2010 |publication]]. &lt;br /&gt;
&lt;br /&gt;
For the case of the genotype likelihood based methods we allow for deviations from Hardy-Weinberg, namely we allow for users to supply a file containing inbreeding coefficients for each individual.&lt;br /&gt;
&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 ./angsd -doMaf&lt;br /&gt;
abcFreq.cpp:&lt;br /&gt;
-doMaf	0 (Calculate persite frequencies '.mafs.gz')&lt;br /&gt;
	1: Frequency (fixed major and minor)&lt;br /&gt;
	2: Frequency (fixed major unknown minor)&lt;br /&gt;
	4: Frequency from genotype probabilities&lt;br /&gt;
	8: AlleleCounts based method (known major minor)&lt;br /&gt;
	NB. Filedumping is supressed if value is negative&lt;br /&gt;
-doPost	0	(Calculate posterior prob 3xgprob)&lt;br /&gt;
	1: Using frequency as prior&lt;br /&gt;
	2: Using uniform prior&lt;br /&gt;
	3: Using SFS as prior (still in development)&lt;br /&gt;
	4: Using reference panel as prior (still in development), requires a site file with chr pos major minor af ac an&lt;br /&gt;
Filters:&lt;br /&gt;
	-minMaf  	-1.000000	(Remove sites with MAF below)&lt;br /&gt;
	-SNP_pval	0.317311	(Remove sites with a pvalue larger)&lt;br /&gt;
	-rmSNPs 	0	(Remove infered SNPs instead of keeping them (pval &amp;gt; SNP_pval)&lt;br /&gt;
	-rmTriallelic	0.000000	(Remove sites with a pvalue lower)&lt;br /&gt;
	-forceMaf	0	(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))&lt;br /&gt;
	-skipMissing	1	(Set post to 0.33 if missing (do not use freq as prior))&lt;br /&gt;
Extras:&lt;br /&gt;
	-ref	(null)	(Filename for fasta reference)&lt;br /&gt;
	-anc	(null)	(Filename for fasta ancestral)&lt;br /&gt;
	-eps	0.001000 [Only used for -doMaf &amp;amp;8]&lt;br /&gt;
	-beagleProb	0 (Dump beagle style postprobs)&lt;br /&gt;
	-indFname	(null) (file containing individual inbreedcoeficients)&lt;br /&gt;
	-underFlowProtect	0 (file containing individual inbreedcoeficients)&lt;br /&gt;
NB These frequency estimators requires major/minor -doMajorMinor&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Allele Frequency estimation=&lt;br /&gt;
The major and minor allele is first inferred from the data or given by the user (see [[Inferring_Major_and_Minor_alleles]]). This includes information from both major and minor allele, a reference genome (for major) or an ancestral genome. &lt;br /&gt;
&lt;br /&gt;
; -doMaf [int]&lt;br /&gt;
&lt;br /&gt;
1:  Known major, and Known minor. Here both the major and minor allele is assumed to be known (inferred or given by user). The allele frequency is the obtained using based on the genotype likelihoods. The allele frequency estimator from genotype likelihoods are from this [[suYeon | publication]]  but using the EM algorithm and is briefly described [[SYKmaf|here]]. &lt;br /&gt;
&lt;br /&gt;
2:  Known major, Unknown minor. Here the major allele is assumed to be known  (inferred or given by user) however the minor allele is not determined. Instead we sum over the 3 possible minor alleles weighted by their probabilities. The allele frequency estimator from genotype likelihoods are from this [[suYeon | publication]] but using the EM algorithm and is briefly described [[SYKmaf|here]]. &lt;br /&gt;
. &lt;br /&gt;
&lt;br /&gt;
4: frequency based on genotype posterior probabilities. If genotype probabilities are used as input to ANGSD the allele frequency is estimated directly on these by [[postFreq|summing over the probabitlies]]. &lt;br /&gt;
&lt;br /&gt;
8: frequency based on base counts. This method does not rely on genotype likelihood or probabilities but instead infers the allele frequency directly on the base counts. The base counts method is from this [[Li2010 |publication]]. &lt;br /&gt;
&lt;br /&gt;
Multiple estimators can be used simultaniusly be summing up the above numbers. Thus -doMaf 7 (1+2+4) will use the first three estimators. If the allele frequencies are estimated from the genotype likelihoods then you need to infer the major and minor allele (-doMajorMinor)&lt;br /&gt;
&lt;br /&gt;
;NB using -doMaf 4 is only supported if the posteriors are supplied as external files. Since the estimation of genotype posteriors in itself requires a maf estimator.&lt;br /&gt;
&lt;br /&gt;
=Example=&lt;br /&gt;
&lt;br /&gt;
==From genotype likelihood==&lt;br /&gt;
Example for estimating the allele frequencies both while assuming known major and minor allele but also while taking the uncertaincy of the minor allele inference into account. The [[Inferring_Major_and_Minor_alleles|inference of the major and minor]] allele is done directly from the genotype likelihood&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMajorMinor 1 -doMaf 3 -bam bam.filelist -GL 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==From genotype probabilities==&lt;br /&gt;
Example of the use of a genotype probability file for example from the output from beagle. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMaf 4 -beagle beagle.file.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Estimator from base counts==&lt;br /&gt;
&lt;br /&gt;
The allele frequencies can be infered directy from the sequencing data [[Li2010|citation]].&lt;br /&gt;
This works by using &amp;quot;counts&amp;quot; of alleles, and should be invoked like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -out out -doMajorMinor 2 -doMaf 8 -bam bam.filelist -doCounts 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Output data=&lt;br /&gt;
==.mafs.gz==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chromo	position	major	minor	ref	knownEM	unknownEM	nInd&lt;br /&gt;
21      9719788 T       A       0.000001        -0.000012       3&lt;br /&gt;
21      9719789 G       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719790 A       C       0.000000        -0.000004       3&lt;br /&gt;
21      9719791 G       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719792 G       A       0.000000        -0.000002       3&lt;br /&gt;
21      9719793 G       T       0.498277        41.932766       3&lt;br /&gt;
21      9719794 T       A       0.000000        -0.000001       3&lt;br /&gt;
21      9719795 T       A       0.000000        -0.000001       3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;chromo &lt;br /&gt;
chromosome name&lt;br /&gt;
;position&lt;br /&gt;
position&lt;br /&gt;
;major &lt;br /&gt;
major allele&lt;br /&gt;
;minor &lt;br /&gt;
minor allele&lt;br /&gt;
;knownEM &lt;br /&gt;
frequency using -doMaf 1&lt;br /&gt;
;unknownEM &lt;br /&gt;
frequency using -doMaf 2&lt;br /&gt;
;phat &lt;br /&gt;
frequency using -doMaf 8&lt;br /&gt;
;nInd &lt;br /&gt;
is the number of individuals with data&lt;br /&gt;
;pK-EM&lt;br /&gt;
probability of a site being SNP (using -doSNPStat 1 and -doMaf 1)&lt;br /&gt;
;pu-EM&lt;br /&gt;
probability of a site being SNP (using -doSNPStat 1 and -doMaf 2)&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Association&amp;diff=3177</id>
		<title>Association</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Association&amp;diff=3177"/>
		<updated>2023-06-07T13:32:26Z</updated>

		<summary type="html">&lt;p&gt;Isin: /* Output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Association can be performed using two approaches.&lt;br /&gt;
# Based on testing differences in allele frequencies between cases and controls, using genotype likelihoods&lt;br /&gt;
# Based on a generalized linear framework which also allows for quantitative traits and binary and for including additional covariates, using genotype posteriors. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
We recommend that users don't perform association analysis on all sites, but limit the analysis to informative sites, and in the case of alignement data (BAM), we advise that users filter away the low mapping quality reads and the low qscore bases.&lt;br /&gt;
&lt;br /&gt;
The filtering of the alignment data is described in [[Input]], and filtering based on frequencies/polymorphic sites are described [[Filters#Allele_frequencies| here]].&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
This can be done easily at the command line by adding the below commands&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
-minQ 20 -minMapQ 30 -SNP_pval 1e-6 #Use polymorphic sites with a p-value of 10^-6&lt;br /&gt;
-minQ 20 -minMapQ 30 -minMaf 0.05 #Use sites with a MAF &amp;gt;0.05&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doAsso&lt;br /&gt;
abcAsso.cpp:&lt;br /&gt;
        -doAsso 0&lt;br /&gt;
        1: Frequency Test (Known Major and Minor)&lt;br /&gt;
        2: Score Test&lt;br /&gt;
        4: Latent genotype model&lt;br /&gt;
        5: Score Test with latent genotype model - hybrid test&lt;br /&gt;
        6: Dosage regression&lt;br /&gt;
        7: Latent genotype model (wald test) - NOT PROPERLY TESTED YET!&lt;br /&gt;
  Frequency Test Options:&lt;br /&gt;
        -yBin           (null)  (File containing disease status)&lt;br /&gt;
&lt;br /&gt;
  Score, Latent, Hybrid and Dosage Test Options:&lt;br /&gt;
        -yBin           (null)  (File containing disease status)&lt;br /&gt;
        -yCount         (null)  (File containing count phenotypes)&lt;br /&gt;
        -yQuant         (null)  (File containing phenotypes)&lt;br /&gt;
        -cov            (null)  (File containing additional covariates)&lt;br /&gt;
        -sampleFile             (null)  (.sample File containing phenotypes and covariates)&lt;br /&gt;
        -whichPhe       (null)  Select which phenotypes to analyse, write phenos comma seperated ('phe1,phe2,...'), only works with a .sample file&lt;br /&gt;
        -whichCov       (null)  Select which covariates to include, write covs comma seperated ('cov1,cov2,...'), only works with a .sample file&lt;br /&gt;
        -model  1&lt;br /&gt;
        1: Additive/Log-Additive (Default)&lt;br /&gt;
        2: Dominant&lt;br /&gt;
        3: Recessive&lt;br /&gt;
&lt;br /&gt;
        -minHigh        10      (Require atleast minHigh number of high credible genotypes)&lt;br /&gt;
        -minCount       10      (Require this number of minor alleles, estimated from MAF)&lt;br /&gt;
        -assoThres      0.000001        Threshold for logistic regression&lt;br /&gt;
        -assoIter       100     Number of iterations for logistic regression&lt;br /&gt;
        -emThres        0.000100        Threshold for convergence of EM algorithm in doAsso 4 and 5&lt;br /&gt;
        -emIter 40      Number of max iterations for EM algorithm in doAsso 4 and 5&lt;br /&gt;
&lt;br /&gt;
        -doPriming      1       Prime EM algorithm with dosage derived coefficients (0: no, 1: yes - default)&lt;br /&gt;
&lt;br /&gt;
        -Pvalue 0       Prints a P-value instead of a likelihood ratio (0: no - default, 1: yes)&lt;br /&gt;
&lt;br /&gt;
  Hybrid Test Options:&lt;br /&gt;
        -hybridThres            0.050000        (p-value value threshold for when to perform latent genotype model)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Case control association using allele frequencies=&lt;br /&gt;
To test for differences in the allele frequencies,  genotype likelihood needs to be provided or [[Genotype_likelihoods_from_alignments | estimated]]. The test is an implimentation of the likelihoods ratio test for differences between cases and controls described in details in [[Kim2011]].&lt;br /&gt;
&lt;br /&gt;
;-doAsso [int] &lt;br /&gt;
'''1''': The test is performed assuming the minor allele is known. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;-yBin [Filename]&lt;br /&gt;
A file containing the case control status. 0 being the controls, 1 being the cases and -999 being missing phenotypes. The file should contain a single phenotype entry per line.&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of cases control phenotype file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
-999&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&lt;br /&gt;
create a large number of individuals by recycling the example files (500 individuals) and simulate some phentypes (case/control) using R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `seq 1 50`;do cat bam.filelist&amp;gt;&amp;gt;large.filelist;done&lt;br /&gt;
Rscript -e &amp;quot;write.table(cbind(rbinom(500,1,0.5)),'pheno.ybin',row=F,col=F)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -yBin pheno.ybin -doAsso 1 -GL 1 -out out -doMajorMinor 1 -doMaf 1 -SNP_pval 1e-6 -bam large.filelist -r 1: -P 5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that because you are reading 500 bam files it takes a little while&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
gunzip -c out.lrt0.gz | head&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Chromosome	Position	Major	Minor	Frequency	LRT&lt;br /&gt;
1	14000003	G	A	0.057070	0.016684&lt;br /&gt;
1	14000013	G	A	0.067886	0.029014&lt;br /&gt;
1	14000019	G	T	0.052904	0.569061&lt;br /&gt;
1	14000023	C	A	0.073336	0.184060&lt;br /&gt;
1	14000053	T	C	0.038903	0.604695&lt;br /&gt;
1	14000170	C	T	0.050756	0.481033&lt;br /&gt;
1	14000176	G	A	0.053157	0.424910&lt;br /&gt;
1	14000200	C	A	0.085332	0.485030&lt;br /&gt;
1	14000202	G	A	0.257132	0.025047&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The LRT is the likelihood ratio statistics which is chi square distributed with one degree of freedom. The P-value can also be obtained instead (by using -Pvalue 1). -Pvalue is accurate upto chisq values of 70, which is equvialent to P-values of 1.1102e-16.&lt;br /&gt;
&lt;br /&gt;
==Dependency Chain==&lt;br /&gt;
The method is based on estimating frequencies from genotype likelihoods. If alignment data has been supplied you need to specify the following.&lt;br /&gt;
&lt;br /&gt;
# [[Genotype_likelihoods_from_alignments | Genotype likelihood model (-GL)]].&lt;br /&gt;
#[[Inferring_Major_and_Minor_alleles  |Determine Major/Minor (-doMajorMinor)]].&lt;br /&gt;
#[[Allele_Frequency_estimation| Maf estimator (-doMaf)]].&lt;br /&gt;
&lt;br /&gt;
If you have supplied genotype likelihood files as input for angsd you can skip 1.&lt;br /&gt;
&lt;br /&gt;
=Score statistic=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is published here [[skotte2012]].&lt;br /&gt;
;-doAsso 2&lt;br /&gt;
&lt;br /&gt;
;-yBin [Filename]&lt;br /&gt;
A file containing the case control status. 0 being the controls, 1 being the cases and -999 being missing phenotypes. &lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of cases control phenotype file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
-999&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;-yQuant [Filename]&lt;br /&gt;
File containing the phenotype values.-999 being missing phenotypes. The file should contain a single phenotype entry per line.&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of quantitative phenotype file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
-999&lt;br /&gt;
2.06164722761138&lt;br /&gt;
-0.091935218675602&lt;br /&gt;
-0.287527686061831&lt;br /&gt;
-999&lt;br /&gt;
-999&lt;br /&gt;
-1.20996664036026&lt;br /&gt;
0.0188541092307412&lt;br /&gt;
-2.1122713873334&lt;br /&gt;
-999&lt;br /&gt;
-1.32920529536579&lt;br /&gt;
-1.10582299663753&lt;br /&gt;
-0.391773417823766&lt;br /&gt;
-0.501400984567535&lt;br /&gt;
-999&lt;br /&gt;
1.06014677976046&lt;br /&gt;
-1.10582299663753&lt;br /&gt;
-999&lt;br /&gt;
0.223156127557052&lt;br /&gt;
-0.189660869820135&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;-yCount [Filename]&lt;br /&gt;
A file containing the count phenotype data, for doing poission based regression. -999 being missing phenotypes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;-cov [Filename]&lt;br /&gt;
Files containing additional covariates in the analysis. Each lines should contain the additional covariates for a single individuals. Thus the number of lines should match the number of individuals and the number of coloums should match the number of additional covariates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of covariate file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
1 0 0 1 &lt;br /&gt;
1 0.1 0 0 &lt;br /&gt;
2 0 1 0 &lt;br /&gt;
2 0 1 0 &lt;br /&gt;
2 0.1 0 1 &lt;br /&gt;
1 0 0 1 &lt;br /&gt;
1 0.3 0 0 &lt;br /&gt;
2 0 0 0 &lt;br /&gt;
1 0 0 0 &lt;br /&gt;
2 0.2 0 1 &lt;br /&gt;
1 0 1 0 &lt;br /&gt;
1 0 0 0 &lt;br /&gt;
1 0.1 0 0 &lt;br /&gt;
1 0 0 0 &lt;br /&gt;
2 0 0 1 &lt;br /&gt;
2 0 0 0 &lt;br /&gt;
2 0 0 0 &lt;br /&gt;
1 0 0 1 &lt;br /&gt;
1 0.5 0 0 &lt;br /&gt;
2 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;-minHigh [int]&lt;br /&gt;
default = 10 &amp;lt;br&amp;gt;&lt;br /&gt;
This approach needs a certain amount of variability in the genotype probabilities. minHigh filters out sites that does not have at least [int] number of of homozygous major, heterozygous and homozygous minor genotypes. At least two of the three genotypes categories needs at least [int] individuals with a genotype probability above 0.9. This filter avoids the scenario where all individuals have genotypes with the same probability e.g. all are heterozygous with a high probability or all have 0.33333333 probability for all three genotypes. &lt;br /&gt;
;-minCount [int] &lt;br /&gt;
default = 10 &amp;lt;br&amp;gt;&lt;br /&gt;
The minimum expected minor alleles in the sample. This is the frequency multiplied by two times the number of individuals. Performing association on extremely low minor allele frequencies does not make sence.&lt;br /&gt;
;-model [int]&lt;br /&gt;
# Additive/Log-additive for Linear/Logistic Regression (Default).&lt;br /&gt;
# Dominant.&lt;br /&gt;
# Recessive.&lt;br /&gt;
;-fai [Filename]&lt;br /&gt;
A fasta index file (.fai). For human data either on hg19 or hg38 one can just use the file, test/hg19.fa.fai that is in the ANGSD repository and is therefore downloaded when cloning ANGSD from its github. Otherwise the .fai file can be obtained by indexing the reference genome or by using the header of a bam file.&lt;br /&gt;
;-sampleFile [Filename]&lt;br /&gt;
A .sample File containing phenotypes and covariates for doing the analysis. It is the Oxford sample information file (.sample) format described [https://www.well.ox.ac.uk/~gav/qctool_v2/documentation/sample_file_formats.html here].&lt;br /&gt;
;-whichPhe [phe1,phe2,...]&lt;br /&gt;
Use this option to select which phenotypes to analyse, write phenos comma seperated ('phe1,phe2,...'), only works with a .sample file.&lt;br /&gt;
; -whichCov [cov1,cov2,...]&lt;br /&gt;
Use this option to select which covariates to include, write covs comma seperated ('cov1,cov2,...'), only works with a .sample file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
create a large number of individuals by recycling the example files (500 individuals) and simulate some phentypes (case/control) using R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm large.filelist&lt;br /&gt;
for i in `seq 1 50`;do cat bam.filelist&amp;gt;&amp;gt;large.filelist;done&lt;br /&gt;
Rscript -e &amp;quot;write.table(cbind(rbinom(500,1,0.5)),'pheno.ybin',row=F,col=F)&amp;quot;&lt;br /&gt;
Rscript -e &amp;quot;write.table(cbind(rnorm(500)),'pheno.yquant',row=F,col=F)&amp;quot;&lt;br /&gt;
Rscript -e &amp;quot;set.seed(1);write.table(cbind(rbinom(500,1,0.5),rnorm(500)),'cov.file',row=F,col=F)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For cases control data for polymorphic sites (p-value &amp;lt; 1e-6)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -yBin pheno.ybin -doAsso 2 -GL 1 -doPost 1 -out out -doMajorMinor 1 -SNP_pval 1e-6 -doMaf 1 -bam large.filelist -P 5 -r 1:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For quantitative traits (normal distributed errors)  for polymorphic sites (p-value &amp;lt; 1e-6) and additional covariates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -yQuant pheno.yquant -doAsso 2 -cov cov.file -GL 1 -doPost 1 -out out -doMajorMinor 1 -SNP_pval 1e-6 -doMaf 1  -bam large.filelist -P 5  -r 1:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example with imputation (using BEAGLE)==&lt;br /&gt;
&lt;br /&gt;
First the polymorphic sites to be analysed needs to be selected (-doMaf 1 -SNP_pval -doMajorMinor) and the genotype likelihoods estimated (-GL 1) for use in [http://faculty.washington.edu/browning/beagle/beagle.html the Beagle software] (-doGlf 2).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -GL 1 -out input -doMajorMinor 1 -SNP_pval 1e-6 -doMaf 1  -bam large.filelist -P 5  -r 1: -doGlf 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Perform the imputation &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
java -Xmx15000m -jar beagle.jar like=input.beagle.gz out=beagleOut&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the reference fai can be obtained by indexing the reference genome or by using a bam files header &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
samtools view -H  bams/smallNA11830.mapped.ILLUMINA.bwa.CEU.low_coverage.20111114.bam | grep SN |cut -f2,3 | sed 's/SN\://g' |  sed 's/LN\://g' &amp;gt; ref.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The association can then be performed on the genotype probabilities using the score statistics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 2 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Dependency Chain==&lt;br /&gt;
The method is based on genotype probabilities. If alignment data has been supplied you need to specify the following.&lt;br /&gt;
&lt;br /&gt;
# [[Genotype_likelihoods_from_alignments | Genotype likelihood model (-GL)]].&lt;br /&gt;
#[[Inferring_Major_and_Minor_alleles  |Determine Major/Minor (-doMajorMinor)]].&lt;br /&gt;
#[[Allele_Frequency_estimation| Maf estimator (-doMaf)]].&lt;br /&gt;
#[[Genotype_calling| Calculate posterior genotype probability (-doPost)]]. If you use the score statistics -doAsso 2 then calculate the posterior using the allele frequency as prior (-doPost 1). &lt;br /&gt;
&lt;br /&gt;
If you have supplied genotype likelihoods for angsd, then you should skip 1.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have supplied genotype probabilities (as beagle output format), there are no dependencies.&lt;br /&gt;
&lt;br /&gt;
=Latent genotype model (EM algorithm)=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is employing an EM algorithm where the genotype is the introduced as a latent variable and then the likelihood is maximised using weighted least squares regression, similar to the approach in asaMap.&lt;br /&gt;
;-doAsso 4&lt;br /&gt;
&lt;br /&gt;
Otherwise works exactly like the Score Test, the only thing that has to be changed is the -doAsso flag.&lt;br /&gt;
This method has an advantage in that effect sizes are estimated and reported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example with genotype probabilities==&lt;br /&gt;
&lt;br /&gt;
It can be run thus, with a binary phenotype (can also be used for a quantitative phenotype with the -yQuant flag):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 4 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Hybrid model (Score Test + EM algorithm)=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is employing the score test first, and then if the chi-square test statistic is below a certain threshold, also apply the latent genotype model, thereby getting the effect size. The idea behind this, is that the score test is faster, as we do need to apply the EM algorithm, however using the EM algorithm gives us an effect size.&lt;br /&gt;
;-doAsso 5&lt;br /&gt;
;-hybridThres 0.05        (p-value threshold for when to perform latent genotype)&lt;br /&gt;
&lt;br /&gt;
Otherwise works exactly like the score test + latent genotype model, the only thing that has to be changed is the -doAsso flag.&lt;br /&gt;
This method has an advantage in that effect sizes are estimated and reported.&lt;br /&gt;
&lt;br /&gt;
==Example with genotype probabilities==&lt;br /&gt;
&lt;br /&gt;
It can be run thus, with a binary phenotype (can also be used for a quantitative phenotype with the -yQuant flag):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Dosage model=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is calculating the dosage or the expected genotype from the genotype probabilities, using the following formula:&lt;br /&gt;
&lt;br /&gt;
E[G|X] = p(G=1|X) + 2*p(G=2|X)&lt;br /&gt;
&lt;br /&gt;
And then doing a normal linear/logistic model with the dosages as the tested variable. This approach is almost as fast as the score test and effect sizes are also estimated.&lt;br /&gt;
&lt;br /&gt;
;-doAsso 6&lt;br /&gt;
&lt;br /&gt;
Otherwise works exactly like the score test + latent genotype model, the only thing that has to be changed is the -doAsso flag.&lt;br /&gt;
This method has an advantage in that effect sizes are estimated and reported.&lt;br /&gt;
&lt;br /&gt;
=Input File Formats=&lt;br /&gt;
All -doAsso methods can now be run with genotype probabilities stored in either a BEAGLE file [https://faculty.washington.edu/browning/beagle/beagle_3.3.2_31Oct11.pdf], a BGEN file [https://www.well.ox.ac.uk/~gav/bgen_format/] or a BCF/VCF file [https://samtools.github.io/hts-specs/VCFv4.2.pdf].&lt;br /&gt;
==BEAGLE files==&lt;br /&gt;
The BEAGLE files can be run with a binary, a count or a quantive phenotype and also with covariates. An example of a command with a binary phenotype:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle test/assotest/test.beagle -yBin test/assotest/testBin.phe -doAsso 4 -cov test.cov -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a count phenotype (using Poisson regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle test/assotest/test.beagle -yCount test/assotest/testCount.phe -doAsso 4 -cov test.cov -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a quantitative phenotype (using normal linear regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle test/assotest/test.beagle -yQuant test/assotest/testQuant.phe -doAsso 4 -cov test.cov -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==BGEN files==&lt;br /&gt;
The BGENfiles can be run with a binary, a count or a quantitative phenotype and also with covariates. Both ZLIB and ZSTD compression is supported, however one needs to add a FLAG when compiling with ZSTD (also one has to have the ZSTD library installed). &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make HTSSRC=../htslib/ WITH_ZSTD=1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also it is made according to v1.3 of the BGEN file format and only the recommended layout 2 is supported. It can also be run with a .sample file [https://www.well.ox.ac.uk/~gav/qctool/documentation/sample_file_formats.html] with both the phenotype and covariates. An example of a command with a binary phenotype:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -bgen test/assotest/test.bgen -sampleFile test/assotest/test.sample -doAsso 4 -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The column type line in the .sample will decide if a binary or normal regression model will be run, depending on the type of the phenotype (binary or quantitative).&lt;br /&gt;
&lt;br /&gt;
==BCF/VCF files==&lt;br /&gt;
The BCF/VCF files can be run with genotype probabilities, specified with the &amp;quot;GP&amp;quot; genotype field, as specified in the VCF manual. It can be run with a binary, a count or a quantitative phenotype and also with covariates. This file format does not need a .fai file. An example of a command with a binary phenotype:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -vcf-gp test/assotest/test.vcf -yBin test/assotest/testBin.phe -doAsso 4 -cov test.cov -out test.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a count phenotype (using Poisson regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -vcf-gp test/assotest/test.vcf -yCount test/assotest/testCount.phe -doAsso 4 -cov test.cov -out test.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a quantitative phenotype (using normal linear regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -vcf-gp test/assotest/test.vcf -yQuant test/assotest/testQuant.phe -doAsso 4 -cov test.cov -out test.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
==Output format==&lt;br /&gt;
The output from the association analysis is a list of files called '''prefix.lrt'''. These are tab separated plain text files, with nine columns. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Chromosome&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Position&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Major&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Minor&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Frequency&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| N*&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| LRT (or P)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| beta^&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| SE^&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| highHe*&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| highHo*&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| emIter~&lt;br /&gt;
|}&lt;br /&gt;
'''*''' Indicates that these columns are only used for the score test, latent genotype model, hybrid model and dosage model.&lt;br /&gt;
'''^''' Indicates that these columns are only used for the latent genotype model, hybrid model and dosage model.&lt;br /&gt;
'''~''' Indicates that these columns are only used for the latent genotype model and hybrid model.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Field&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Description&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Chromosome&lt;br /&gt;
|  Chromosome.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Position&lt;br /&gt;
| Physical Position.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Major&lt;br /&gt;
| The Major allele as determined by [[MajorMinor |-doMajorMinor]]. If posterior genotype files has been supplied as input, this column is not defined.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Minor&lt;br /&gt;
| The Minor allele as determined by [[MajorMinor |-doMajorMinor]]. If posterior genotype files has been supplied as input, this column is not defined.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Frequency&lt;br /&gt;
| The Minor allele frequency as determined by [[Maf|-doMaf]].&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| N*&lt;br /&gt;
| Number of individuals. That is the number of samples that have both sequencing data and phenotypic data.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| LRT (or P)&lt;br /&gt;
| The likelihood ratio statistic. This statistic is chi square distributed with one degree of freedom. Sites that fails one of the filters are given the value -999.000000. The P-value can also be obtained instead (by using -Pvalue 1), this column will have &amp;quot;P&amp;quot; as its column name the.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| beta&lt;br /&gt;
| The estimated effect size. Sites that fails one of the filters are given the value nan.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| SE&lt;br /&gt;
| The estimated standard error. Sites that fails one of the filters are given the value nan.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| high_WT/HE/HO*&lt;br /&gt;
| Number of individuals with a WE/HE/HO genotype posterior probability above 0.9. WT=major/major,HE=major/minor,HO=minor/minor.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| emIter~&lt;br /&gt;
| Number of iterations of EM algorithm for maximising likelihood.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example without effect sizes (beta):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Chromosome	Position	Major	Minor	Frequency	N	LRT	high_WT/HE/HO&lt;br /&gt;
1	14000023	C	A	0.052976	330	2.863582	250/10/0&lt;br /&gt;
1	14000072	G	T	0.020555	330	1.864555	320/10/0&lt;br /&gt;
1	14000113	A	G	0.019543	330	0.074985	320/10/0&lt;br /&gt;
1	14000202	G	A	0.270106	330	0.181530	50/90/0&lt;br /&gt;
1	14000375	T	C	0.020471	330	1.845881	320/10/0&lt;br /&gt;
1	14000851	T	C	0.016849	330	0.694058	320/10/0&lt;br /&gt;
1	14000873	G	A	0.305990	330	0.684507	140/60/10&lt;br /&gt;
1	14001008	T	C	0.018434	330	0.031631	320/10/0&lt;br /&gt;
1	14001018	T	C	0.296051	330	0.761196	110/40/10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!--=Citations=&lt;br /&gt;
For '''-doAsso 1' and '''-doAsso 3'&lt;br /&gt;
{{:Skotte2012}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example with genotype probabilities==&lt;br /&gt;
&lt;br /&gt;
It can be run thus, with a binary phenotype (can also be used for a quantitative phenotype with the -yQuant flag):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 6 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Printing mafs files==&lt;br /&gt;
&lt;br /&gt;
By default, -doAsso does not print the mafs file. To print the mafs file, use -forceMaf 1.&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	-forceMaf	0	(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Problems with inflation of p-values=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can evaluate the behavior of the tests by making a QQ plot of the LRT or P-values. There are several reasons why it might show signs of inflation&lt;br /&gt;
; -doPost (when using doAsso 2, 4, 5 or 6 without the use of posterior input -beagle&lt;br /&gt;
if you estimate the posterior genotype probability using a uniform prior (-doPost 2) then small differences in depth between sample will inflate the test statistics (see [[Skotte2012]]). Use the allele frequency as a prior (-doPost 1) &lt;br /&gt;
; -minCount/-minHigh&lt;br /&gt;
If you set this too low then it will results in inflation of the test statistics.&lt;br /&gt;
; -yQuant (when using -doAsso 2, 4, 5 or 6 with a quantitative trait)&lt;br /&gt;
If your trait is not continues or the distribution of the trait is skewed or has outliers then you will get inflation of p-values. Same rules apply as for a standard regression. Consider transforming you trait into a normal distribution&lt;br /&gt;
; Population structure&lt;br /&gt;
If you have population structure then you will have to adjust for it in the regression model (-doAssso 2, 4, 5 or 6). Consider using NGSadmix or PCAngsd and use the results as covariates. Note that the model will still have some issues because it uses the allele frequency as a prior. For the adventurous you can use PCAngsd or NGSadmix to estimate the individual allele frequencies and calculate your own genotype probabilities that take structure into account. These can then be used in angsd using the -beagle input format.&lt;br /&gt;
; low N&lt;br /&gt;
Usually a GWAS is performed on thousands of samples and we have only tested the use of the score statistics on hundreds of samples. If you have a low number of samples then try to figure out what minor allele frequency you would need in order to have some power. Also be careful with reducing -minCount/-minHigh.&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=Association&amp;diff=3176</id>
		<title>Association</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=Association&amp;diff=3176"/>
		<updated>2023-05-22T12:48:51Z</updated>

		<summary type="html">&lt;p&gt;Isin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Association can be performed using two approaches.&lt;br /&gt;
# Based on testing differences in allele frequencies between cases and controls, using genotype likelihoods&lt;br /&gt;
# Based on a generalized linear framework which also allows for quantitative traits and binary and for including additional covariates, using genotype posteriors. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
We recommend that users don't perform association analysis on all sites, but limit the analysis to informative sites, and in the case of alignement data (BAM), we advise that users filter away the low mapping quality reads and the low qscore bases.&lt;br /&gt;
&lt;br /&gt;
The filtering of the alignment data is described in [[Input]], and filtering based on frequencies/polymorphic sites are described [[Filters#Allele_frequencies| here]].&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
This can be done easily at the command line by adding the below commands&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
-minQ 20 -minMapQ 30 -SNP_pval 1e-6 #Use polymorphic sites with a p-value of 10^-6&lt;br /&gt;
-minQ 20 -minMapQ 30 -minMaf 0.05 #Use sites with a MAF &amp;gt;0.05&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=Brief Overview=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doAsso&lt;br /&gt;
abcAsso.cpp:&lt;br /&gt;
        -doAsso 0&lt;br /&gt;
        1: Frequency Test (Known Major and Minor)&lt;br /&gt;
        2: Score Test&lt;br /&gt;
        4: Latent genotype model&lt;br /&gt;
        5: Score Test with latent genotype model - hybrid test&lt;br /&gt;
        6: Dosage regression&lt;br /&gt;
        7: Latent genotype model (wald test) - NOT PROPERLY TESTED YET!&lt;br /&gt;
  Frequency Test Options:&lt;br /&gt;
        -yBin           (null)  (File containing disease status)&lt;br /&gt;
&lt;br /&gt;
  Score, Latent, Hybrid and Dosage Test Options:&lt;br /&gt;
        -yBin           (null)  (File containing disease status)&lt;br /&gt;
        -yCount         (null)  (File containing count phenotypes)&lt;br /&gt;
        -yQuant         (null)  (File containing phenotypes)&lt;br /&gt;
        -cov            (null)  (File containing additional covariates)&lt;br /&gt;
        -sampleFile             (null)  (.sample File containing phenotypes and covariates)&lt;br /&gt;
        -whichPhe       (null)  Select which phenotypes to analyse, write phenos comma seperated ('phe1,phe2,...'), only works with a .sample file&lt;br /&gt;
        -whichCov       (null)  Select which covariates to include, write covs comma seperated ('cov1,cov2,...'), only works with a .sample file&lt;br /&gt;
        -model  1&lt;br /&gt;
        1: Additive/Log-Additive (Default)&lt;br /&gt;
        2: Dominant&lt;br /&gt;
        3: Recessive&lt;br /&gt;
&lt;br /&gt;
        -minHigh        10      (Require atleast minHigh number of high credible genotypes)&lt;br /&gt;
        -minCount       10      (Require this number of minor alleles, estimated from MAF)&lt;br /&gt;
        -assoThres      0.000001        Threshold for logistic regression&lt;br /&gt;
        -assoIter       100     Number of iterations for logistic regression&lt;br /&gt;
        -emThres        0.000100        Threshold for convergence of EM algorithm in doAsso 4 and 5&lt;br /&gt;
        -emIter 40      Number of max iterations for EM algorithm in doAsso 4 and 5&lt;br /&gt;
&lt;br /&gt;
        -doPriming      1       Prime EM algorithm with dosage derived coefficients (0: no, 1: yes - default)&lt;br /&gt;
&lt;br /&gt;
        -Pvalue 0       Prints a P-value instead of a likelihood ratio (0: no - default, 1: yes)&lt;br /&gt;
&lt;br /&gt;
  Hybrid Test Options:&lt;br /&gt;
        -hybridThres            0.050000        (p-value value threshold for when to perform latent genotype model)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Case control association using allele frequencies=&lt;br /&gt;
To test for differences in the allele frequencies,  genotype likelihood needs to be provided or [[Genotype_likelihoods_from_alignments | estimated]]. The test is an implimentation of the likelihoods ratio test for differences between cases and controls described in details in [[Kim2011]].&lt;br /&gt;
&lt;br /&gt;
;-doAsso [int] &lt;br /&gt;
'''1''': The test is performed assuming the minor allele is known. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;-yBin [Filename]&lt;br /&gt;
A file containing the case control status. 0 being the controls, 1 being the cases and -999 being missing phenotypes. The file should contain a single phenotype entry per line.&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of cases control phenotype file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
-999&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&lt;br /&gt;
create a large number of individuals by recycling the example files (500 individuals) and simulate some phentypes (case/control) using R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `seq 1 50`;do cat bam.filelist&amp;gt;&amp;gt;large.filelist;done&lt;br /&gt;
Rscript -e &amp;quot;write.table(cbind(rbinom(500,1,0.5)),'pheno.ybin',row=F,col=F)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -yBin pheno.ybin -doAsso 1 -GL 1 -out out -doMajorMinor 1 -doMaf 1 -SNP_pval 1e-6 -bam large.filelist -r 1: -P 5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that because you are reading 500 bam files it takes a little while&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
gunzip -c out.lrt0.gz | head&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Chromosome	Position	Major	Minor	Frequency	LRT&lt;br /&gt;
1	14000003	G	A	0.057070	0.016684&lt;br /&gt;
1	14000013	G	A	0.067886	0.029014&lt;br /&gt;
1	14000019	G	T	0.052904	0.569061&lt;br /&gt;
1	14000023	C	A	0.073336	0.184060&lt;br /&gt;
1	14000053	T	C	0.038903	0.604695&lt;br /&gt;
1	14000170	C	T	0.050756	0.481033&lt;br /&gt;
1	14000176	G	A	0.053157	0.424910&lt;br /&gt;
1	14000200	C	A	0.085332	0.485030&lt;br /&gt;
1	14000202	G	A	0.257132	0.025047&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The LRT is the likelihood ratio statistics which is chi square distributed with one degree of freedom. The P-value can also be obtained instead (by using -Pvalue 1). -Pvalue is accurate upto chisq values of 70, which is equvialent to P-values of 1.1102e-16.&lt;br /&gt;
&lt;br /&gt;
==Dependency Chain==&lt;br /&gt;
The method is based on estimating frequencies from genotype likelihoods. If alignment data has been supplied you need to specify the following.&lt;br /&gt;
&lt;br /&gt;
# [[Genotype_likelihoods_from_alignments | Genotype likelihood model (-GL)]].&lt;br /&gt;
#[[Inferring_Major_and_Minor_alleles  |Determine Major/Minor (-doMajorMinor)]].&lt;br /&gt;
#[[Allele_Frequency_estimation| Maf estimator (-doMaf)]].&lt;br /&gt;
&lt;br /&gt;
If you have supplied genotype likelihood files as input for angsd you can skip 1.&lt;br /&gt;
&lt;br /&gt;
=Score statistic=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is published here [[skotte2012]].&lt;br /&gt;
;-doAsso 2&lt;br /&gt;
&lt;br /&gt;
;-yBin [Filename]&lt;br /&gt;
A file containing the case control status. 0 being the controls, 1 being the cases and -999 being missing phenotypes. &lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of cases control phenotype file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
-999&lt;br /&gt;
1&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;-yQuant [Filename]&lt;br /&gt;
File containing the phenotype values.-999 being missing phenotypes. The file should contain a single phenotype entry per line.&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of quantitative phenotype file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
-999&lt;br /&gt;
2.06164722761138&lt;br /&gt;
-0.091935218675602&lt;br /&gt;
-0.287527686061831&lt;br /&gt;
-999&lt;br /&gt;
-999&lt;br /&gt;
-1.20996664036026&lt;br /&gt;
0.0188541092307412&lt;br /&gt;
-2.1122713873334&lt;br /&gt;
-999&lt;br /&gt;
-1.32920529536579&lt;br /&gt;
-1.10582299663753&lt;br /&gt;
-0.391773417823766&lt;br /&gt;
-0.501400984567535&lt;br /&gt;
-999&lt;br /&gt;
1.06014677976046&lt;br /&gt;
-1.10582299663753&lt;br /&gt;
-999&lt;br /&gt;
0.223156127557052&lt;br /&gt;
-0.189660869820135&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;-yCount [Filename]&lt;br /&gt;
A file containing the count phenotype data, for doing poission based regression. -999 being missing phenotypes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;-cov [Filename]&lt;br /&gt;
Files containing additional covariates in the analysis. Each lines should contain the additional covariates for a single individuals. Thus the number of lines should match the number of individuals and the number of coloums should match the number of additional covariates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Example of covariate file&lt;br /&gt;
&amp;lt;pre class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
1 0 0 1 &lt;br /&gt;
1 0.1 0 0 &lt;br /&gt;
2 0 1 0 &lt;br /&gt;
2 0 1 0 &lt;br /&gt;
2 0.1 0 1 &lt;br /&gt;
1 0 0 1 &lt;br /&gt;
1 0.3 0 0 &lt;br /&gt;
2 0 0 0 &lt;br /&gt;
1 0 0 0 &lt;br /&gt;
2 0.2 0 1 &lt;br /&gt;
1 0 1 0 &lt;br /&gt;
1 0 0 0 &lt;br /&gt;
1 0.1 0 0 &lt;br /&gt;
1 0 0 0 &lt;br /&gt;
2 0 0 1 &lt;br /&gt;
2 0 0 0 &lt;br /&gt;
2 0 0 0 &lt;br /&gt;
1 0 0 1 &lt;br /&gt;
1 0.5 0 0 &lt;br /&gt;
2 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;-minHigh [int]&lt;br /&gt;
default = 10 &amp;lt;br&amp;gt;&lt;br /&gt;
This approach needs a certain amount of variability in the genotype probabilities. minHigh filters out sites that does not have at least [int] number of of homozygous major, heterozygous and homozygous minor genotypes. At least two of the three genotypes categories needs at least [int] individuals with a genotype probability above 0.9. This filter avoids the scenario where all individuals have genotypes with the same probability e.g. all are heterozygous with a high probability or all have 0.33333333 probability for all three genotypes. &lt;br /&gt;
;-minCount [int] &lt;br /&gt;
default = 10 &amp;lt;br&amp;gt;&lt;br /&gt;
The minimum expected minor alleles in the sample. This is the frequency multiplied by two times the number of individuals. Performing association on extremely low minor allele frequencies does not make sence.&lt;br /&gt;
;-model [int]&lt;br /&gt;
# Additive/Log-additive for Linear/Logistic Regression (Default).&lt;br /&gt;
# Dominant.&lt;br /&gt;
# Recessive.&lt;br /&gt;
;-fai [Filename]&lt;br /&gt;
A fasta index file (.fai). For human data either on hg19 or hg38 one can just use the file, test/hg19.fa.fai that is in the ANGSD repository and is therefore downloaded when cloning ANGSD from its github. Otherwise the .fai file can be obtained by indexing the reference genome or by using the header of a bam file.&lt;br /&gt;
;-sampleFile [Filename]&lt;br /&gt;
A .sample File containing phenotypes and covariates for doing the analysis. It is the Oxford sample information file (.sample) format described [https://www.well.ox.ac.uk/~gav/qctool_v2/documentation/sample_file_formats.html here].&lt;br /&gt;
;-whichPhe [phe1,phe2,...]&lt;br /&gt;
Use this option to select which phenotypes to analyse, write phenos comma seperated ('phe1,phe2,...'), only works with a .sample file.&lt;br /&gt;
; -whichCov [cov1,cov2,...]&lt;br /&gt;
Use this option to select which covariates to include, write covs comma seperated ('cov1,cov2,...'), only works with a .sample file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
create a large number of individuals by recycling the example files (500 individuals) and simulate some phentypes (case/control) using R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm large.filelist&lt;br /&gt;
for i in `seq 1 50`;do cat bam.filelist&amp;gt;&amp;gt;large.filelist;done&lt;br /&gt;
Rscript -e &amp;quot;write.table(cbind(rbinom(500,1,0.5)),'pheno.ybin',row=F,col=F)&amp;quot;&lt;br /&gt;
Rscript -e &amp;quot;write.table(cbind(rnorm(500)),'pheno.yquant',row=F,col=F)&amp;quot;&lt;br /&gt;
Rscript -e &amp;quot;set.seed(1);write.table(cbind(rbinom(500,1,0.5),rnorm(500)),'cov.file',row=F,col=F)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For cases control data for polymorphic sites (p-value &amp;lt; 1e-6)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -yBin pheno.ybin -doAsso 2 -GL 1 -doPost 1 -out out -doMajorMinor 1 -SNP_pval 1e-6 -doMaf 1 -bam large.filelist -P 5 -r 1:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For quantitative traits (normal distributed errors)  for polymorphic sites (p-value &amp;lt; 1e-6) and additional covariates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -yQuant pheno.yquant -doAsso 2 -cov cov.file -GL 1 -doPost 1 -out out -doMajorMinor 1 -SNP_pval 1e-6 -doMaf 1  -bam large.filelist -P 5  -r 1:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example with imputation (using BEAGLE)==&lt;br /&gt;
&lt;br /&gt;
First the polymorphic sites to be analysed needs to be selected (-doMaf 1 -SNP_pval -doMajorMinor) and the genotype likelihoods estimated (-GL 1) for use in [http://faculty.washington.edu/browning/beagle/beagle.html the Beagle software] (-doGlf 2).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -GL 1 -out input -doMajorMinor 1 -SNP_pval 1e-6 -doMaf 1  -bam large.filelist -P 5  -r 1: -doGlf 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Perform the imputation &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
java -Xmx15000m -jar beagle.jar like=input.beagle.gz out=beagleOut&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the reference fai can be obtained by indexing the reference genome or by using a bam files header &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
samtools view -H  bams/smallNA11830.mapped.ILLUMINA.bwa.CEU.low_coverage.20111114.bam | grep SN |cut -f2,3 | sed 's/SN\://g' |  sed 's/LN\://g' &amp;gt; ref.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The association can then be performed on the genotype probabilities using the score statistics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 2 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Dependency Chain==&lt;br /&gt;
The method is based on genotype probabilities. If alignment data has been supplied you need to specify the following.&lt;br /&gt;
&lt;br /&gt;
# [[Genotype_likelihoods_from_alignments | Genotype likelihood model (-GL)]].&lt;br /&gt;
#[[Inferring_Major_and_Minor_alleles  |Determine Major/Minor (-doMajorMinor)]].&lt;br /&gt;
#[[Allele_Frequency_estimation| Maf estimator (-doMaf)]].&lt;br /&gt;
#[[Genotype_calling| Calculate posterior genotype probability (-doPost)]]. If you use the score statistics -doAsso 2 then calculate the posterior using the allele frequency as prior (-doPost 1). &lt;br /&gt;
&lt;br /&gt;
If you have supplied genotype likelihoods for angsd, then you should skip 1.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have supplied genotype probabilities (as beagle output format), there are no dependencies.&lt;br /&gt;
&lt;br /&gt;
=Latent genotype model (EM algorithm)=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is employing an EM algorithm where the genotype is the introduced as a latent variable and then the likelihood is maximised using weighted least squares regression, similar to the approach in asaMap.&lt;br /&gt;
;-doAsso 4&lt;br /&gt;
&lt;br /&gt;
Otherwise works exactly like the Score Test, the only thing that has to be changed is the -doAsso flag.&lt;br /&gt;
This method has an advantage in that effect sizes are estimated and reported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example with genotype probabilities==&lt;br /&gt;
&lt;br /&gt;
It can be run thus, with a binary phenotype (can also be used for a quantitative phenotype with the -yQuant flag):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 4 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Hybrid model (Score Test + EM algorithm)=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is employing the score test first, and then if the chi-square test statistic is below a certain threshold, also apply the latent genotype model, thereby getting the effect size. The idea behind this, is that the score test is faster, as we do need to apply the EM algorithm, however using the EM algorithm gives us an effect size.&lt;br /&gt;
;-doAsso 5&lt;br /&gt;
;-hybridThres 0.05        (p-value threshold for when to perform latent genotype)&lt;br /&gt;
&lt;br /&gt;
Otherwise works exactly like the score test + latent genotype model, the only thing that has to be changed is the -doAsso flag.&lt;br /&gt;
This method has an advantage in that effect sizes are estimated and reported.&lt;br /&gt;
&lt;br /&gt;
==Example with genotype probabilities==&lt;br /&gt;
&lt;br /&gt;
It can be run thus, with a binary phenotype (can also be used for a quantitative phenotype with the -yQuant flag):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Dosage model=&lt;br /&gt;
To perform the test in a generalized linear framework posterior genotype probabilities must be provided or [[Genotype_calling|estimated]]. The approach is calculating the dosage or the expected genotype from the genotype probabilities, using the following formula:&lt;br /&gt;
&lt;br /&gt;
E[G|X] = p(G=1|X) + 2*p(G=2|X)&lt;br /&gt;
&lt;br /&gt;
And then doing a normal linear/logistic model with the dosages as the tested variable. This approach is almost as fast as the score test and effect sizes are also estimated.&lt;br /&gt;
&lt;br /&gt;
;-doAsso 6&lt;br /&gt;
&lt;br /&gt;
Otherwise works exactly like the score test + latent genotype model, the only thing that has to be changed is the -doAsso flag.&lt;br /&gt;
This method has an advantage in that effect sizes are estimated and reported.&lt;br /&gt;
&lt;br /&gt;
=Input File Formats=&lt;br /&gt;
All -doAsso methods can now be run with genotype probabilities stored in either a BEAGLE file [https://faculty.washington.edu/browning/beagle/beagle_3.3.2_31Oct11.pdf], a BGEN file [https://www.well.ox.ac.uk/~gav/bgen_format/] or a BCF/VCF file [https://samtools.github.io/hts-specs/VCFv4.2.pdf].&lt;br /&gt;
==BEAGLE files==&lt;br /&gt;
The BEAGLE files can be run with a binary, a count or a quantive phenotype and also with covariates. An example of a command with a binary phenotype:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle test/assotest/test.beagle -yBin test/assotest/testBin.phe -doAsso 4 -cov test.cov -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a count phenotype (using Poisson regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle test/assotest/test.beagle -yCount test/assotest/testCount.phe -doAsso 4 -cov test.cov -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a quantitative phenotype (using normal linear regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle test/assotest/test.beagle -yQuant test/assotest/testQuant.phe -doAsso 4 -cov test.cov -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==BGEN files==&lt;br /&gt;
The BGENfiles can be run with a binary, a count or a quantitative phenotype and also with covariates. Both ZLIB and ZSTD compression is supported, however one needs to add a FLAG when compiling with ZSTD (also one has to have the ZSTD library installed). &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make HTSSRC=../htslib/ WITH_ZSTD=1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also it is made according to v1.3 of the BGEN file format and only the recommended layout 2 is supported. It can also be run with a .sample file [https://www.well.ox.ac.uk/~gav/qctool/documentation/sample_file_formats.html] with both the phenotype and covariates. An example of a command with a binary phenotype:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -bgen test/assotest/test.bgen -sampleFile test/assotest/test.sample -doAsso 4 -out test.res -fai test/hg19.fa.fai&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The column type line in the .sample will decide if a binary or normal regression model will be run, depending on the type of the phenotype (binary or quantitative).&lt;br /&gt;
&lt;br /&gt;
==BCF/VCF files==&lt;br /&gt;
The BCF/VCF files can be run with genotype probabilities, specified with the &amp;quot;GP&amp;quot; genotype field, as specified in the VCF manual. It can be run with a binary, a count or a quantitative phenotype and also with covariates. This file format does not need a .fai file. An example of a command with a binary phenotype:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -vcf-gp test/assotest/test.vcf -yBin test/assotest/testBin.phe -doAsso 4 -cov test.cov -out test.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a count phenotype (using Poisson regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -vcf-gp test/assotest/test.vcf -yCount test/assotest/testCount.phe -doAsso 4 -cov test.cov -out test.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And with a quantitative phenotype (using normal linear regression):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -vcf-gp test/assotest/test.vcf -yQuant test/assotest/testQuant.phe -doAsso 4 -cov test.cov -out test.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
==Output format==&lt;br /&gt;
The output from the association analysis is a list of files called '''prefix.lrt'''. These are tab separated plain text files, with nine columns. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Chromosome&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Position&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Major&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Minor&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Frequency&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| N*&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| LRT (or P)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| beta^&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| SE^&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| highHe*&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| highHo*&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| emIter~&lt;br /&gt;
|}&lt;br /&gt;
'''*''' Indicates that these columns are only used for the score test, latent genotype model, hybrid model and dosage model.&lt;br /&gt;
'''^''' Indicates that these columns are only used for the latent genotype model, hybrid model and dosage model.&lt;br /&gt;
'''~''' Indicates that these columns are only used for the latent genotype model and hybrid model.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Field&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Description&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Chromosome&lt;br /&gt;
|  Chromosome.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Position&lt;br /&gt;
| Physical Position.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Major&lt;br /&gt;
| The Major allele as determined by [[MajorMinor |-doMajorMinor]]. If posterior genotype files has been supplied as input, this column is not defined.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Minor&lt;br /&gt;
| The Minor allele as determined by [[MajorMinor |-doMajorMinor]]. If posterior genotype files has been supplied as input, this column is not defined.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Frequency&lt;br /&gt;
| The Minor allele frequency as determined by [[Maf|-doMaf]].&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| N*&lt;br /&gt;
| Number of individuals. That is the number of samples that have both sequencing data and phenotypic data.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| LRT (or P)&lt;br /&gt;
| The likelihood ratio statistic. This statistic is chi square distributed with one degree of freedom. Sites that fails one of the filters are given the value -999.000000. The P-value can also be obtained instead (by using -Pvalue 1), this column will have &amp;quot;P&amp;quot; as its column name the.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| beta&lt;br /&gt;
| The estimated effect size. Sites that fails one of the filters are given the value nan.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| SE&lt;br /&gt;
| The estimated standard error. Sites that fails one of the filters are given the value nan.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| high_WT/HE/HO*&lt;br /&gt;
| Number of individuals with a WE/HE/HO genotype posterior probability above 0.9. WT=major/major,HE=major/minor,HO=minor/minor.&lt;br /&gt;
|- &lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| emIter~&lt;br /&gt;
| Number of iterations of EM algorithm for maximising likelihood.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example without effect sizes (beta):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Chromosome	Position	Major	Minor	Frequency	N	LRT	high_WT/HE/HO&lt;br /&gt;
1	14000023	C	A	0.052976	330	2.863582	250/10/0&lt;br /&gt;
1	14000072	G	T	0.020555	330	1.864555	320/10/0&lt;br /&gt;
1	14000113	A	G	0.019543	330	0.074985	320/10/0&lt;br /&gt;
1	14000202	G	A	0.270106	330	0.181530	50/90/0&lt;br /&gt;
1	14000375	T	C	0.020471	330	1.845881	320/10/0&lt;br /&gt;
1	14000851	T	C	0.016849	330	0.694058	320/10/0&lt;br /&gt;
1	14000873	G	A	0.305990	330	0.684507	140/60/10&lt;br /&gt;
1	14001008	T	C	0.018434	330	0.031631	320/10/0&lt;br /&gt;
1	14001018	T	C	0.296051	330	0.761196	110/40/10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!--=Citations=&lt;br /&gt;
For '''-doAsso 1' and '''-doAsso 3'&lt;br /&gt;
{{:Skotte2012}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example with genotype probabilities==&lt;br /&gt;
&lt;br /&gt;
It can be run thus, with a binary phenotype (can also be used for a quantitative phenotype with the -yQuant flag):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -doMaf 4 -beagle beagleOut.impute.beagle.gz.gprobs.gz -fai ref.fai  -yBin pheno.ybin -doAsso 6 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Problems with inflation of p-values=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can evaluate the behavior of the tests by making a QQ plot of the LRT or P-values. There are several reasons why it might show signs of inflation&lt;br /&gt;
; -doPost (when using doAsso 2, 4, 5 or 6 without the use of posterior input -beagle&lt;br /&gt;
if you estimate the posterior genotype probability using a uniform prior (-doPost 2) then small differences in depth between sample will inflate the test statistics (see [[Skotte2012]]). Use the allele frequency as a prior (-doPost 1) &lt;br /&gt;
; -minCount/-minHigh&lt;br /&gt;
If you set this too low then it will results in inflation of the test statistics.&lt;br /&gt;
; -yQuant (when using -doAsso 2, 4, 5 or 6 with a quantitative trait)&lt;br /&gt;
If your trait is not continues or the distribution of the trait is skewed or has outliers then you will get inflation of p-values. Same rules apply as for a standard regression. Consider transforming you trait into a normal distribution&lt;br /&gt;
; Population structure&lt;br /&gt;
If you have population structure then you will have to adjust for it in the regression model (-doAssso 2, 4, 5 or 6). Consider using NGSadmix or PCAngsd and use the results as covariates. Note that the model will still have some issues because it uses the allele frequency as a prior. For the adventurous you can use PCAngsd or NGSadmix to estimate the individual allele frequencies and calculate your own genotype probabilities that take structure into account. These can then be used in angsd using the -beagle input format.&lt;br /&gt;
; low N&lt;br /&gt;
Usually a GWAS is performed on thousands of samples and we have only tested the use of the score statistics on hundreds of samples. If you have a low number of samples then try to figure out what minor allele frequency you would need in order to have some power. Also be careful with reducing -minCount/-minHigh.&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/angsd/index.php?title=User:Isin&amp;diff=3168</id>
		<title>User:Isin</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/angsd/index.php?title=User:Isin&amp;diff=3168"/>
		<updated>2022-12-21T09:53:31Z</updated>

		<summary type="html">&lt;p&gt;Isin: test&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;test&lt;/div&gt;</summary>
		<author><name>Isin</name></author>
	</entry>
</feed>