<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.popgen.dk/software/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Thorfinn</id>
	<title>software - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.popgen.dk/software/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Thorfinn"/>
	<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php/Special:Contributions/Thorfinn"/>
	<updated>2026-04-30T14:19:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1466</id>
		<title>NgsAdmixTutorial</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1466"/>
		<updated>2022-06-06T22:59:21Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* The output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We will go through a simple and more complex example on how to use NGSadmix with visualization of the data.&lt;br /&gt;
&lt;br /&gt;
User need to to add -printInfo 1 in order to get information about sites retained for analysis.&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix - very small data set==&lt;br /&gt;
&lt;br /&gt;
In our first example, we will infer admixture proportions for low depth NGS data using a small dataset from 30 human samples.&lt;br /&gt;
&lt;br /&gt;
===Set paths to software===&lt;br /&gt;
Every time you open a new terminal window, set directories to all required programs and the data you will use depending on where you installed them&lt;br /&gt;
&lt;br /&gt;
Set the path to NGSadmix, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NGSADMIX=~/Software/NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test the link&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $NGSADMIX&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create directories===&lt;br /&gt;
Create the directories that will be used for working:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Results&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd ..&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set the paths to your local directories===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;IN_DIR=Demo/Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;OUT_DIR=Demo/Results&amp;lt;/code&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Test the links&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The test data===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use a very reduced data set.&lt;br /&gt;
&lt;br /&gt;
*10 individuals from each population: 10 from Nigeria (YRI), 10 from Japan (JPT) and 10 with European Ancestry (CEU). &lt;br /&gt;
*a very reduced genome 30 x 100k random regions across the autosomes&lt;br /&gt;
*each individual is sequenced at 2-6X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Europeans (mostly of British ancestry)&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;East Asian - Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;West African - Nigerian Yoruba individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can either download the beagle input files or create them yourself from bam files. Therefore you should choose either 'Download the beagle genotype likelihood input file' or 'Create the the beagle genotype likelihood input file using ANGSD'.&lt;br /&gt;
====Download the beagle genotype likelihood input file====&lt;br /&gt;
NGSadmix uses Genotype Likelihoods (GLs) in .beagle format as input. The input file has been created for you.&lt;br /&gt;
A file with the information about the population is also provided.&lt;br /&gt;
 &lt;br /&gt;
Download the files and move them to your input folder (for example, $IN_DIR):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1input.gz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1pop.info&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1input.gz $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1pop.info $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the the beagle genotype likelihood input file using ANGSD====&lt;br /&gt;
first set the path to ANGSD  (change ~/github/angsd/ to the path on your system)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ANGSD=~/github/angsd/angsd &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
test that you have the rigth path and that ANGSD is installed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; $ANGSD&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download small BAM files and extract files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; wget http://popgen.dk/software/download/NGSadmix/data/smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; tar xf smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make a list with the bam file names&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;find smallerbams/ |  grep bam$ &amp;gt; all.files&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
calculate genotype likelihoods for polymorphic sites using ANGSD (see ANGSD website for further information)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ANGSD -bam all.files -GL 2 -doMajorMinor 1 -doMaf 1 -SNP_pval 2e-6 -minMapQ 30 -minQ 20 -minInd 25 -minMaf 0.05 -doGlf 2 -out $IN_DIR/Demo1input.gz -P 5 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
create population information file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; paste -d &amp;quot; &amp;quot; &amp;lt;( cut -f 5 -d&amp;quot;.&amp;quot; all.files ) &amp;lt;(cut -f 1 -d&amp;quot;.&amp;quot; all.files | xargs -n1 basename) &amp;gt; $IN_DIR/Demo1pop.info &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View population information file ====&lt;br /&gt;
&lt;br /&gt;
To view a summary of the population information file, cut the first column, sort and count:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $IN_DIR/Demo1pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets make a population label file and place it in the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cut -f1 -d&amp;quot; &amp;quot; $IN_DIR/Demo1pop.info  &amp;gt; $OUT_DIR/poplabel &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View the genotype likelihood beagle file ====&lt;br /&gt;
&lt;br /&gt;
*In general, the first three columns of a beagle file contain marker name and the two alleles, allele1 and allele2, present in the locus (in beagle A=0, C=1, G=2, T=3). All following columns contain genotype likelihoods (three columns for each individual: first GL for homozygote for allele1, then GL for heterozygote and then GL for homozygote for allele2). Note that the GL values sum to one per site for each individual. This is just a normalization of the genotype likelihoods in order to avoid underflow problems in the beagle software, but it does not mean that they are genotype probabilities. &lt;br /&gt;
&lt;br /&gt;
*In order to see the first 10 columns and 10 lines of the input file, type:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | head -n 10 | cut -f 1-10 | column -t&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Use this command to count the number of lines of the input file. The number of lines, indicates the number of loci for which there are GLs plus one (as the command includes the count of the header line):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | wc -l&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Let’s analyze the input file ===&lt;br /&gt;
To run an analysis of the GLs with NGSadmix, assuming the number of ancestral populations is K=3, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo1input.gz -K 3 -minMaf 0.05 -seed 1 -o $OUT_DIR/Demo1NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
=== The output ===&lt;br /&gt;
&lt;br /&gt;
The analysis performed by NGSadmix produces 4 files:&lt;br /&gt;
&lt;br /&gt;
*'''Log likelihood of the estimates'''&lt;br /&gt;
A .log file that summarizes the run.&lt;br /&gt;
&lt;br /&gt;
Let’s take a look at the log file to determine the log likelihood of the estimates achieved by NGSadmix which is called the “best like” in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cat $OUT_DIR/Demo1NGSadmix.log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated allele frequency'''&lt;br /&gt;
&lt;br /&gt;
::A zipped .fopt file, that contains an estimate of the allele frequency in each of the 3 assumed ancestral populations (there is a line for each locus).&lt;br /&gt;
&lt;br /&gt;
::We can use this file to obtain the estimated allele frequency of the first 5 SNPs (one per line) of the three assumed ancestral populations, by typing the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;zcat $OUT_DIR/Demo1NGSadmix.fopt.gz | head -n 5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated admixture proportions'''&lt;br /&gt;
::A .qopt file, that contains an estimate of the individual's ancestry proportion from each of the three assumed ancestral populations (there is a line for each individual).&lt;br /&gt;
&lt;br /&gt;
::To obtain the estimated admixture proportions for the first 5 individuals, type the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 Demo1NGSadmix.qopt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plot the results in R ===&lt;br /&gt;
&lt;br /&gt;
Follow these instructions to make a simple plot of the estimated admixture proportions for all individuals in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Get ID and pop info for each individual&lt;br /&gt;
pop&amp;lt;-scan(&amp;quot;poplabel&amp;quot;,what=&amp;quot;theFuck&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Read inferred admixture proportions file&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo1NGSadmix.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Plot them (ordered by population)&lt;br /&gt;
ord = order(pop)&lt;br /&gt;
par(mar=c(7,4,1,1))&lt;br /&gt;
barplot(t(q)[,ord],col=c(2,1,3),names=pop[ord],las=2,ylab=&amp;quot;Demo1 Admixture proportions&amp;quot;,cex.names=0.75)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The y-axis of the plot show the admixture proportions and the individuals in the samples are plotted in the x-axis. &lt;br /&gt;
&lt;br /&gt;
Each color represents a different ancestral population.&lt;br /&gt;
&lt;br /&gt;
The proportion of each color shows the different admixture of the individuals for each ancestral population. &lt;br /&gt;
&lt;br /&gt;
The plot is sorted by the population of origin of each individual in the sample, and therefore, it shows blocks with prevalence of a certain color, which represents the population to which each individual belongs.&lt;br /&gt;
&lt;br /&gt;
NB As you could tell from the number of loci included in the analysis, the above analysis is based on data from very few loci (actually we on purpose only analyzed data from a small part of the genome to make sure the analysis ran fast).&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix with admixed populations==&lt;br /&gt;
&lt;br /&gt;
Now that you know how to make input data to NGSadmix, how to run NGSadmix and what the output looks like, let's try to look at a more realistic size dataset. More specifically let's try to run NGSadmix on 50000 sites from the 1000 genomes project from the following populations:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;ASW&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;HapMap African Americans from SW US&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;European individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CHB&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Han Chinese in Beijing&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Yoruba individuals from Nigeria&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;MXL&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Mexican individuals from LA California&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
:&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The input file Demo2input.gz with genotype likelihoods from 100 individuals in .beagle format, and a file with population info are given.&lt;br /&gt;
''Note: please make sure you have created and set up the working directories as indicated in the previous tutorial.''&lt;br /&gt;
&lt;br /&gt;
===Download Files===&lt;br /&gt;
Download and copy the files to your input folder (for example, $IN_DIR)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2input.gz&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2pop.info&lt;br /&gt;
mv Demo2input.gz $IN_DIR&lt;br /&gt;
mv Demo2pop.info $OUT_DIR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
make sure you are back in your original folder (not the $OUT_DIR folder)&lt;br /&gt;
&lt;br /&gt;
===Take a quick look at the population data===&lt;br /&gt;
make a summary by cutting the first column, sorting and counting&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $OUT_DIR/Demo2pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run NGSadmix===&lt;br /&gt;
Run an analysis of the data with NGSadmix with K=3 (-K 3), using 1 cpu (-P 1), using only SNPs with minor allele frequency above 0.05 (-minMaf 0.05), set the seed set to 21 (-seed 21), and set the prefix of the output files to Demo2NGSadmixK3. For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 3 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Plot=== &lt;br /&gt;
Plot the estimated admixture proportions by running the following code in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK3.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=3&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that like in the previous example, the order of the individuals in the plot is not the same as in the .qopt file. Instead, to provide a better overview, the individuals have been ordered according to their population labels.&lt;br /&gt;
&lt;br /&gt;
===Choose a differnt K===&lt;br /&gt;
Try to run NGSadmix with K=4 and compare the plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 4 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK4.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=4&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1465</id>
		<title>NgsAdmixTutorial</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1465"/>
		<updated>2022-06-06T22:59:03Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* The output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We will go through a simple and more complex example on how to use NGSadmix with visualization of the data.&lt;br /&gt;
&lt;br /&gt;
User need to to add -printInfo 1 in order to get information about sites retained for analysis.&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix - very small data set==&lt;br /&gt;
&lt;br /&gt;
In our first example, we will infer admixture proportions for low depth NGS data using a small dataset from 30 human samples.&lt;br /&gt;
&lt;br /&gt;
===Set paths to software===&lt;br /&gt;
Every time you open a new terminal window, set directories to all required programs and the data you will use depending on where you installed them&lt;br /&gt;
&lt;br /&gt;
Set the path to NGSadmix, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NGSADMIX=~/Software/NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test the link&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $NGSADMIX&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create directories===&lt;br /&gt;
Create the directories that will be used for working:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Results&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd ..&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set the paths to your local directories===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;IN_DIR=Demo/Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;OUT_DIR=Demo/Results&amp;lt;/code&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Test the links&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The test data===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use a very reduced data set.&lt;br /&gt;
&lt;br /&gt;
*10 individuals from each population: 10 from Nigeria (YRI), 10 from Japan (JPT) and 10 with European Ancestry (CEU). &lt;br /&gt;
*a very reduced genome 30 x 100k random regions across the autosomes&lt;br /&gt;
*each individual is sequenced at 2-6X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Europeans (mostly of British ancestry)&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;East Asian - Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;West African - Nigerian Yoruba individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can either download the beagle input files or create them yourself from bam files. Therefore you should choose either 'Download the beagle genotype likelihood input file' or 'Create the the beagle genotype likelihood input file using ANGSD'.&lt;br /&gt;
====Download the beagle genotype likelihood input file====&lt;br /&gt;
NGSadmix uses Genotype Likelihoods (GLs) in .beagle format as input. The input file has been created for you.&lt;br /&gt;
A file with the information about the population is also provided.&lt;br /&gt;
 &lt;br /&gt;
Download the files and move them to your input folder (for example, $IN_DIR):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1input.gz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1pop.info&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1input.gz $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1pop.info $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the the beagle genotype likelihood input file using ANGSD====&lt;br /&gt;
first set the path to ANGSD  (change ~/github/angsd/ to the path on your system)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ANGSD=~/github/angsd/angsd &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
test that you have the rigth path and that ANGSD is installed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; $ANGSD&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download small BAM files and extract files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; wget http://popgen.dk/software/download/NGSadmix/data/smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; tar xf smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make a list with the bam file names&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;find smallerbams/ |  grep bam$ &amp;gt; all.files&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
calculate genotype likelihoods for polymorphic sites using ANGSD (see ANGSD website for further information)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ANGSD -bam all.files -GL 2 -doMajorMinor 1 -doMaf 1 -SNP_pval 2e-6 -minMapQ 30 -minQ 20 -minInd 25 -minMaf 0.05 -doGlf 2 -out $IN_DIR/Demo1input.gz -P 5 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
create population information file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; paste -d &amp;quot; &amp;quot; &amp;lt;( cut -f 5 -d&amp;quot;.&amp;quot; all.files ) &amp;lt;(cut -f 1 -d&amp;quot;.&amp;quot; all.files | xargs -n1 basename) &amp;gt; $IN_DIR/Demo1pop.info &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View population information file ====&lt;br /&gt;
&lt;br /&gt;
To view a summary of the population information file, cut the first column, sort and count:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $IN_DIR/Demo1pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets make a population label file and place it in the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cut -f1 -d&amp;quot; &amp;quot; $IN_DIR/Demo1pop.info  &amp;gt; $OUT_DIR/poplabel &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View the genotype likelihood beagle file ====&lt;br /&gt;
&lt;br /&gt;
*In general, the first three columns of a beagle file contain marker name and the two alleles, allele1 and allele2, present in the locus (in beagle A=0, C=1, G=2, T=3). All following columns contain genotype likelihoods (three columns for each individual: first GL for homozygote for allele1, then GL for heterozygote and then GL for homozygote for allele2). Note that the GL values sum to one per site for each individual. This is just a normalization of the genotype likelihoods in order to avoid underflow problems in the beagle software, but it does not mean that they are genotype probabilities. &lt;br /&gt;
&lt;br /&gt;
*In order to see the first 10 columns and 10 lines of the input file, type:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | head -n 10 | cut -f 1-10 | column -t&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Use this command to count the number of lines of the input file. The number of lines, indicates the number of loci for which there are GLs plus one (as the command includes the count of the header line):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | wc -l&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Let’s analyze the input file ===&lt;br /&gt;
To run an analysis of the GLs with NGSadmix, assuming the number of ancestral populations is K=3, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo1input.gz -K 3 -minMaf 0.05 -seed 1 -o $OUT_DIR/Demo1NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
=== The output ===&lt;br /&gt;
&lt;br /&gt;
The analysis performed by NGSadmix produces 4 files:&lt;br /&gt;
&lt;br /&gt;
*'''Log likelihood of the estimates'''&lt;br /&gt;
A .log file that summarizes the run.&lt;br /&gt;
&lt;br /&gt;
Let’s take a look at the log file to determine the log likelihood of the estimates achieved by NGSadmix which is called the “best like” in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cat $OUT_DIR/Demo1NGSadmix.log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated allele frequency'''&lt;br /&gt;
&lt;br /&gt;
::A zipped .fopt file, that contains an estimate of the allele frequency in each of the 3 assumed ancestral populations (there is a line for each locus).&lt;br /&gt;
&lt;br /&gt;
::We can use this file to obtain the estimated allele frequency of the first 5 SNPs (one per line) of the three assumed ancestral populations, by typing the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;zcat $OUT_DIR/Demo1NGSadmix.fopt.gz | head -n 5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated admixture proportions'''&lt;br /&gt;
::A .qopt file, that contains an estimate of the individual's ancestry proportion from each of the three assumed ancestral populations (there is a line for each individual).&lt;br /&gt;
&lt;br /&gt;
::To obtain the estimated admixture proportions for the first 5 individuals, type the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 Demo1NGSadmix.qopt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#*'''DemoNGSadmix.filter''' if the filter was used, it will show the sites that were left out.&lt;br /&gt;
#&lt;br /&gt;
#::To see the header file, type:&lt;br /&gt;
#&lt;br /&gt;
#::&amp;lt;code&amp;gt;head -n 5 $OUT_DIR/Demo1NGSadmix.filter&amp;lt;/code&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#::no lines means that all where used&lt;br /&gt;
&lt;br /&gt;
=== Plot the results in R ===&lt;br /&gt;
&lt;br /&gt;
Follow these instructions to make a simple plot of the estimated admixture proportions for all individuals in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Get ID and pop info for each individual&lt;br /&gt;
pop&amp;lt;-scan(&amp;quot;poplabel&amp;quot;,what=&amp;quot;theFuck&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Read inferred admixture proportions file&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo1NGSadmix.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Plot them (ordered by population)&lt;br /&gt;
ord = order(pop)&lt;br /&gt;
par(mar=c(7,4,1,1))&lt;br /&gt;
barplot(t(q)[,ord],col=c(2,1,3),names=pop[ord],las=2,ylab=&amp;quot;Demo1 Admixture proportions&amp;quot;,cex.names=0.75)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The y-axis of the plot show the admixture proportions and the individuals in the samples are plotted in the x-axis. &lt;br /&gt;
&lt;br /&gt;
Each color represents a different ancestral population.&lt;br /&gt;
&lt;br /&gt;
The proportion of each color shows the different admixture of the individuals for each ancestral population. &lt;br /&gt;
&lt;br /&gt;
The plot is sorted by the population of origin of each individual in the sample, and therefore, it shows blocks with prevalence of a certain color, which represents the population to which each individual belongs.&lt;br /&gt;
&lt;br /&gt;
NB As you could tell from the number of loci included in the analysis, the above analysis is based on data from very few loci (actually we on purpose only analyzed data from a small part of the genome to make sure the analysis ran fast).&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix with admixed populations==&lt;br /&gt;
&lt;br /&gt;
Now that you know how to make input data to NGSadmix, how to run NGSadmix and what the output looks like, let's try to look at a more realistic size dataset. More specifically let's try to run NGSadmix on 50000 sites from the 1000 genomes project from the following populations:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;ASW&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;HapMap African Americans from SW US&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;European individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CHB&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Han Chinese in Beijing&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Yoruba individuals from Nigeria&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;MXL&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Mexican individuals from LA California&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
:&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The input file Demo2input.gz with genotype likelihoods from 100 individuals in .beagle format, and a file with population info are given.&lt;br /&gt;
''Note: please make sure you have created and set up the working directories as indicated in the previous tutorial.''&lt;br /&gt;
&lt;br /&gt;
===Download Files===&lt;br /&gt;
Download and copy the files to your input folder (for example, $IN_DIR)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2input.gz&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2pop.info&lt;br /&gt;
mv Demo2input.gz $IN_DIR&lt;br /&gt;
mv Demo2pop.info $OUT_DIR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
make sure you are back in your original folder (not the $OUT_DIR folder)&lt;br /&gt;
&lt;br /&gt;
===Take a quick look at the population data===&lt;br /&gt;
make a summary by cutting the first column, sorting and counting&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $OUT_DIR/Demo2pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run NGSadmix===&lt;br /&gt;
Run an analysis of the data with NGSadmix with K=3 (-K 3), using 1 cpu (-P 1), using only SNPs with minor allele frequency above 0.05 (-minMaf 0.05), set the seed set to 21 (-seed 21), and set the prefix of the output files to Demo2NGSadmixK3. For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 3 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Plot=== &lt;br /&gt;
Plot the estimated admixture proportions by running the following code in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK3.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=3&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that like in the previous example, the order of the individuals in the plot is not the same as in the .qopt file. Instead, to provide a better overview, the individuals have been ordered according to their population labels.&lt;br /&gt;
&lt;br /&gt;
===Choose a differnt K===&lt;br /&gt;
Try to run NGSadmix with K=4 and compare the plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 4 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK4.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=4&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1464</id>
		<title>NgsAdmixTutorial</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1464"/>
		<updated>2022-06-06T22:55:35Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* The test data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We will go through a simple and more complex example on how to use NGSadmix with visualization of the data.&lt;br /&gt;
&lt;br /&gt;
User need to to add -printInfo 1 in order to get information about sites retained for analysis.&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix - very small data set==&lt;br /&gt;
&lt;br /&gt;
In our first example, we will infer admixture proportions for low depth NGS data using a small dataset from 30 human samples.&lt;br /&gt;
&lt;br /&gt;
===Set paths to software===&lt;br /&gt;
Every time you open a new terminal window, set directories to all required programs and the data you will use depending on where you installed them&lt;br /&gt;
&lt;br /&gt;
Set the path to NGSadmix, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NGSADMIX=~/Software/NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test the link&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $NGSADMIX&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create directories===&lt;br /&gt;
Create the directories that will be used for working:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Results&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd ..&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set the paths to your local directories===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;IN_DIR=Demo/Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;OUT_DIR=Demo/Results&amp;lt;/code&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Test the links&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The test data===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use a very reduced data set.&lt;br /&gt;
&lt;br /&gt;
*10 individuals from each population: 10 from Nigeria (YRI), 10 from Japan (JPT) and 10 with European Ancestry (CEU). &lt;br /&gt;
*a very reduced genome 30 x 100k random regions across the autosomes&lt;br /&gt;
*each individual is sequenced at 2-6X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Europeans (mostly of British ancestry)&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;East Asian - Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;West African - Nigerian Yoruba individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can either download the beagle input files or create them yourself from bam files. Therefore you should choose either 'Download the beagle genotype likelihood input file' or 'Create the the beagle genotype likelihood input file using ANGSD'.&lt;br /&gt;
====Download the beagle genotype likelihood input file====&lt;br /&gt;
NGSadmix uses Genotype Likelihoods (GLs) in .beagle format as input. The input file has been created for you.&lt;br /&gt;
A file with the information about the population is also provided.&lt;br /&gt;
 &lt;br /&gt;
Download the files and move them to your input folder (for example, $IN_DIR):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1input.gz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1pop.info&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1input.gz $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1pop.info $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the the beagle genotype likelihood input file using ANGSD====&lt;br /&gt;
first set the path to ANGSD  (change ~/github/angsd/ to the path on your system)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ANGSD=~/github/angsd/angsd &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
test that you have the rigth path and that ANGSD is installed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; $ANGSD&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download small BAM files and extract files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; wget http://popgen.dk/software/download/NGSadmix/data/smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; tar xf smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make a list with the bam file names&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;find smallerbams/ |  grep bam$ &amp;gt; all.files&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
calculate genotype likelihoods for polymorphic sites using ANGSD (see ANGSD website for further information)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ANGSD -bam all.files -GL 2 -doMajorMinor 1 -doMaf 1 -SNP_pval 2e-6 -minMapQ 30 -minQ 20 -minInd 25 -minMaf 0.05 -doGlf 2 -out $IN_DIR/Demo1input.gz -P 5 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
create population information file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; paste -d &amp;quot; &amp;quot; &amp;lt;( cut -f 5 -d&amp;quot;.&amp;quot; all.files ) &amp;lt;(cut -f 1 -d&amp;quot;.&amp;quot; all.files | xargs -n1 basename) &amp;gt; $IN_DIR/Demo1pop.info &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View population information file ====&lt;br /&gt;
&lt;br /&gt;
To view a summary of the population information file, cut the first column, sort and count:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $IN_DIR/Demo1pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets make a population label file and place it in the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cut -f1 -d&amp;quot; &amp;quot; $IN_DIR/Demo1pop.info  &amp;gt; $OUT_DIR/poplabel &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View the genotype likelihood beagle file ====&lt;br /&gt;
&lt;br /&gt;
*In general, the first three columns of a beagle file contain marker name and the two alleles, allele1 and allele2, present in the locus (in beagle A=0, C=1, G=2, T=3). All following columns contain genotype likelihoods (three columns for each individual: first GL for homozygote for allele1, then GL for heterozygote and then GL for homozygote for allele2). Note that the GL values sum to one per site for each individual. This is just a normalization of the genotype likelihoods in order to avoid underflow problems in the beagle software, but it does not mean that they are genotype probabilities. &lt;br /&gt;
&lt;br /&gt;
*In order to see the first 10 columns and 10 lines of the input file, type:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | head -n 10 | cut -f 1-10 | column -t&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Use this command to count the number of lines of the input file. The number of lines, indicates the number of loci for which there are GLs plus one (as the command includes the count of the header line):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | wc -l&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Let’s analyze the input file ===&lt;br /&gt;
To run an analysis of the GLs with NGSadmix, assuming the number of ancestral populations is K=3, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo1input.gz -K 3 -minMaf 0.05 -seed 1 -o $OUT_DIR/Demo1NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
=== The output ===&lt;br /&gt;
&lt;br /&gt;
The analysis performed by NGSadmix produces 4 files:&lt;br /&gt;
&lt;br /&gt;
*'''Log likelihood of the estimates'''&lt;br /&gt;
A .log file that summarizes the run.&lt;br /&gt;
&lt;br /&gt;
Let’s take a look at the log file to determine the log likelihood of the estimates achieved by NGSadmix which is called the “best like” in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cat $OUT_DIR/Demo1NGSadmix.log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated allele frequency'''&lt;br /&gt;
&lt;br /&gt;
::A zipped .fopt file, that contains an estimate of the allele frequency in each of the 3 assumed ancestral populations (there is a line for each locus).&lt;br /&gt;
&lt;br /&gt;
::We can use this file to obtain the estimated allele frequency of the first 5 SNPs (one per line) of the three assumed ancestral populations, by typing the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;zcat $OUT_DIR/Demo1NGSadmix.fopt.gz | head -n 5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated admixture proportions'''&lt;br /&gt;
::A .qopt file, that contains an estimate of the individual's ancestry proportion from each of the three assumed ancestral populations (there is a line for each individual).&lt;br /&gt;
&lt;br /&gt;
::To obtain the estimated admixture proportions for the first 5 individuals, type the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 Demo1NGSadmix.qopt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''DemoNGSadmix.filter''' if the filter was used, it will show the sites that were left out.&lt;br /&gt;
&lt;br /&gt;
::To see the header file, type:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 $OUT_DIR/Demo1NGSadmix.filter&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::no lines means that all where used&lt;br /&gt;
&lt;br /&gt;
=== Plot the results in R ===&lt;br /&gt;
&lt;br /&gt;
Follow these instructions to make a simple plot of the estimated admixture proportions for all individuals in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Get ID and pop info for each individual&lt;br /&gt;
pop&amp;lt;-scan(&amp;quot;poplabel&amp;quot;,what=&amp;quot;theFuck&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Read inferred admixture proportions file&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo1NGSadmix.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Plot them (ordered by population)&lt;br /&gt;
ord = order(pop)&lt;br /&gt;
par(mar=c(7,4,1,1))&lt;br /&gt;
barplot(t(q)[,ord],col=c(2,1,3),names=pop[ord],las=2,ylab=&amp;quot;Demo1 Admixture proportions&amp;quot;,cex.names=0.75)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The y-axis of the plot show the admixture proportions and the individuals in the samples are plotted in the x-axis. &lt;br /&gt;
&lt;br /&gt;
Each color represents a different ancestral population.&lt;br /&gt;
&lt;br /&gt;
The proportion of each color shows the different admixture of the individuals for each ancestral population. &lt;br /&gt;
&lt;br /&gt;
The plot is sorted by the population of origin of each individual in the sample, and therefore, it shows blocks with prevalence of a certain color, which represents the population to which each individual belongs.&lt;br /&gt;
&lt;br /&gt;
NB As you could tell from the number of loci included in the analysis, the above analysis is based on data from very few loci (actually we on purpose only analyzed data from a small part of the genome to make sure the analysis ran fast).&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix with admixed populations==&lt;br /&gt;
&lt;br /&gt;
Now that you know how to make input data to NGSadmix, how to run NGSadmix and what the output looks like, let's try to look at a more realistic size dataset. More specifically let's try to run NGSadmix on 50000 sites from the 1000 genomes project from the following populations:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;ASW&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;HapMap African Americans from SW US&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;European individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CHB&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Han Chinese in Beijing&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Yoruba individuals from Nigeria&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;MXL&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Mexican individuals from LA California&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
:&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The input file Demo2input.gz with genotype likelihoods from 100 individuals in .beagle format, and a file with population info are given.&lt;br /&gt;
''Note: please make sure you have created and set up the working directories as indicated in the previous tutorial.''&lt;br /&gt;
&lt;br /&gt;
===Download Files===&lt;br /&gt;
Download and copy the files to your input folder (for example, $IN_DIR)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2input.gz&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2pop.info&lt;br /&gt;
mv Demo2input.gz $IN_DIR&lt;br /&gt;
mv Demo2pop.info $OUT_DIR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
make sure you are back in your original folder (not the $OUT_DIR folder)&lt;br /&gt;
&lt;br /&gt;
===Take a quick look at the population data===&lt;br /&gt;
make a summary by cutting the first column, sorting and counting&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $OUT_DIR/Demo2pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run NGSadmix===&lt;br /&gt;
Run an analysis of the data with NGSadmix with K=3 (-K 3), using 1 cpu (-P 1), using only SNPs with minor allele frequency above 0.05 (-minMaf 0.05), set the seed set to 21 (-seed 21), and set the prefix of the output files to Demo2NGSadmixK3. For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 3 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Plot=== &lt;br /&gt;
Plot the estimated admixture proportions by running the following code in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK3.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=3&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that like in the previous example, the order of the individuals in the plot is not the same as in the .qopt file. Instead, to provide a better overview, the individuals have been ordered according to their population labels.&lt;br /&gt;
&lt;br /&gt;
===Choose a differnt K===&lt;br /&gt;
Try to run NGSadmix with K=4 and compare the plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 4 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK4.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=4&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1463</id>
		<title>NgsAdmixTutorial</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1463"/>
		<updated>2022-06-06T22:49:51Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Create directories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We will go through a simple and more complex example on how to use NGSadmix with visualization of the data.&lt;br /&gt;
&lt;br /&gt;
User need to to add -printInfo 1 in order to get information about sites retained for analysis.&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix - very small data set==&lt;br /&gt;
&lt;br /&gt;
In our first example, we will infer admixture proportions for low depth NGS data using a small dataset from 30 human samples.&lt;br /&gt;
&lt;br /&gt;
===Set paths to software===&lt;br /&gt;
Every time you open a new terminal window, set directories to all required programs and the data you will use depending on where you installed them&lt;br /&gt;
&lt;br /&gt;
Set the path to NGSadmix, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NGSADMIX=~/Software/NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test the link&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $NGSADMIX&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create directories===&lt;br /&gt;
Create the directories that will be used for working:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Results&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd ..&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set the paths to your local directories===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;IN_DIR=Demo/Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;OUT_DIR=Demo/Results&amp;lt;/code&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Test the links&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The test data===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use a very reduced data set.&lt;br /&gt;
&lt;br /&gt;
*10 individuals from each population: 10 from Nigeria (YRI), 10 from Japan (JPT) and 10 with European Ancestry (CEU). &lt;br /&gt;
*a very reduced genome 30 x 100k random regions across the autosomes&lt;br /&gt;
*each individual is sequenced at 2-6X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Europeans (mostly of British ancestry)&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;East Asian - Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;West African - Nigerian Yoruba individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can either download the beagle input files or create them yourself from bam files&lt;br /&gt;
====Download the beagle genotype likelihood input file====&lt;br /&gt;
NGSadmix uses Genotype Likelihoods (GLs) in .beagle format as input. The input file has been created for you.&lt;br /&gt;
A file with the information about the population is also provided.&lt;br /&gt;
 &lt;br /&gt;
Download the files and move them to your input folder (for example, $IN_DIR):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1input.gz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1pop.info&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1input.gz $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1pop.info $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the the beagle genotype likelihood input file using ANGSD====&lt;br /&gt;
first set the path to ANGSD  (change ~/github/angsd/ to the path on your system)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ANGSD=~/github/angsd/angsd &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
test that you have the rigth path and that ANGSD is installed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; $ANGSD&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download small BAM files and extract files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; wget http://popgen.dk/software/download/NGSadmix/data/smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; tar xf smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make a list with the bam file names&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;find smallerbams/ |  grep bam$ &amp;gt; all.files&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
calculate genotype likelihoods for polymorphic sites using ANGSD (see ANGSD website for further information)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ANGSD -bam all.files -GL 2 -doMajorMinor 1 -doMaf 1 -SNP_pval 2e-6 -minMapQ 30 -minQ 20 -minInd 25 -minMaf 0.05 -doGlf 2 -out $IN_DIR/Demo1input.gz -P 5 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
create population information file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; paste -d &amp;quot; &amp;quot; &amp;lt;( cut -f 5 -d&amp;quot;.&amp;quot; all.files ) &amp;lt;(cut -f 1 -d&amp;quot;.&amp;quot; all.files | xargs -n1 basename) &amp;gt; $IN_DIR/Demo1pop.info &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View population information file ====&lt;br /&gt;
&lt;br /&gt;
To view a summary of the population information file, cut the first column, sort and count:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $IN_DIR/Demo1pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets make a population label file and place it in the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cut -f1 -d&amp;quot; &amp;quot; $IN_DIR/Demo1pop.info  &amp;gt; $OUT_DIR/poplabel &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View the genotype likelihood beagle file ====&lt;br /&gt;
&lt;br /&gt;
*In general, the first three columns of a beagle file contain marker name and the two alleles, allele1 and allele2, present in the locus (in beagle A=0, C=1, G=2, T=3). All following columns contain genotype likelihoods (three columns for each individual: first GL for homozygote for allele1, then GL for heterozygote and then GL for homozygote for allele2). Note that the GL values sum to one per site for each individual. This is just a normalization of the genotype likelihoods in order to avoid underflow problems in the beagle software, but it does not mean that they are genotype probabilities. &lt;br /&gt;
&lt;br /&gt;
*In order to see the first 10 columns and 10 lines of the input file, type:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | head -n 10 | cut -f 1-10 | column -t&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Use this command to count the number of lines of the input file. The number of lines, indicates the number of loci for which there are GLs plus one (as the command includes the count of the header line):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | wc -l&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Let’s analyze the input file ===&lt;br /&gt;
To run an analysis of the GLs with NGSadmix, assuming the number of ancestral populations is K=3, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo1input.gz -K 3 -minMaf 0.05 -seed 1 -o $OUT_DIR/Demo1NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
=== The output ===&lt;br /&gt;
&lt;br /&gt;
The analysis performed by NGSadmix produces 4 files:&lt;br /&gt;
&lt;br /&gt;
*'''Log likelihood of the estimates'''&lt;br /&gt;
A .log file that summarizes the run.&lt;br /&gt;
&lt;br /&gt;
Let’s take a look at the log file to determine the log likelihood of the estimates achieved by NGSadmix which is called the “best like” in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cat $OUT_DIR/Demo1NGSadmix.log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated allele frequency'''&lt;br /&gt;
&lt;br /&gt;
::A zipped .fopt file, that contains an estimate of the allele frequency in each of the 3 assumed ancestral populations (there is a line for each locus).&lt;br /&gt;
&lt;br /&gt;
::We can use this file to obtain the estimated allele frequency of the first 5 SNPs (one per line) of the three assumed ancestral populations, by typing the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;zcat $OUT_DIR/Demo1NGSadmix.fopt.gz | head -n 5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated admixture proportions'''&lt;br /&gt;
::A .qopt file, that contains an estimate of the individual's ancestry proportion from each of the three assumed ancestral populations (there is a line for each individual).&lt;br /&gt;
&lt;br /&gt;
::To obtain the estimated admixture proportions for the first 5 individuals, type the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 Demo1NGSadmix.qopt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''DemoNGSadmix.filter''' if the filter was used, it will show the sites that were left out.&lt;br /&gt;
&lt;br /&gt;
::To see the header file, type:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 $OUT_DIR/Demo1NGSadmix.filter&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::no lines means that all where used&lt;br /&gt;
&lt;br /&gt;
=== Plot the results in R ===&lt;br /&gt;
&lt;br /&gt;
Follow these instructions to make a simple plot of the estimated admixture proportions for all individuals in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Get ID and pop info for each individual&lt;br /&gt;
pop&amp;lt;-scan(&amp;quot;poplabel&amp;quot;,what=&amp;quot;theFuck&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Read inferred admixture proportions file&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo1NGSadmix.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Plot them (ordered by population)&lt;br /&gt;
ord = order(pop)&lt;br /&gt;
par(mar=c(7,4,1,1))&lt;br /&gt;
barplot(t(q)[,ord],col=c(2,1,3),names=pop[ord],las=2,ylab=&amp;quot;Demo1 Admixture proportions&amp;quot;,cex.names=0.75)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The y-axis of the plot show the admixture proportions and the individuals in the samples are plotted in the x-axis. &lt;br /&gt;
&lt;br /&gt;
Each color represents a different ancestral population.&lt;br /&gt;
&lt;br /&gt;
The proportion of each color shows the different admixture of the individuals for each ancestral population. &lt;br /&gt;
&lt;br /&gt;
The plot is sorted by the population of origin of each individual in the sample, and therefore, it shows blocks with prevalence of a certain color, which represents the population to which each individual belongs.&lt;br /&gt;
&lt;br /&gt;
NB As you could tell from the number of loci included in the analysis, the above analysis is based on data from very few loci (actually we on purpose only analyzed data from a small part of the genome to make sure the analysis ran fast).&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix with admixed populations==&lt;br /&gt;
&lt;br /&gt;
Now that you know how to make input data to NGSadmix, how to run NGSadmix and what the output looks like, let's try to look at a more realistic size dataset. More specifically let's try to run NGSadmix on 50000 sites from the 1000 genomes project from the following populations:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;ASW&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;HapMap African Americans from SW US&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;European individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CHB&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Han Chinese in Beijing&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Yoruba individuals from Nigeria&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;MXL&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Mexican individuals from LA California&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
:&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The input file Demo2input.gz with genotype likelihoods from 100 individuals in .beagle format, and a file with population info are given.&lt;br /&gt;
''Note: please make sure you have created and set up the working directories as indicated in the previous tutorial.''&lt;br /&gt;
&lt;br /&gt;
===Download Files===&lt;br /&gt;
Download and copy the files to your input folder (for example, $IN_DIR)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2input.gz&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2pop.info&lt;br /&gt;
mv Demo2input.gz $IN_DIR&lt;br /&gt;
mv Demo2pop.info $OUT_DIR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
make sure you are back in your original folder (not the $OUT_DIR folder)&lt;br /&gt;
&lt;br /&gt;
===Take a quick look at the population data===&lt;br /&gt;
make a summary by cutting the first column, sorting and counting&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $OUT_DIR/Demo2pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run NGSadmix===&lt;br /&gt;
Run an analysis of the data with NGSadmix with K=3 (-K 3), using 1 cpu (-P 1), using only SNPs with minor allele frequency above 0.05 (-minMaf 0.05), set the seed set to 21 (-seed 21), and set the prefix of the output files to Demo2NGSadmixK3. For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 3 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Plot=== &lt;br /&gt;
Plot the estimated admixture proportions by running the following code in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK3.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=3&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that like in the previous example, the order of the individuals in the plot is not the same as in the .qopt file. Instead, to provide a better overview, the individuals have been ordered according to their population labels.&lt;br /&gt;
&lt;br /&gt;
===Choose a differnt K===&lt;br /&gt;
Try to run NGSadmix with K=4 and compare the plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 4 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK4.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=4&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1441</id>
		<title>NgsAdmixTutorial</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsAdmixTutorial&amp;diff=1441"/>
		<updated>2020-05-02T03:18:26Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We will go through a simple and more complex example on how to use NGSadmix with visualization of the data.&lt;br /&gt;
&lt;br /&gt;
User need to to add -printInfo 1 in order to get information about sites retained for analysis.&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix - very small data set==&lt;br /&gt;
&lt;br /&gt;
In our first example, we will infer admixture proportions for low depth NGS data using a small dataset from 30 human samples.&lt;br /&gt;
&lt;br /&gt;
===Set paths to software===&lt;br /&gt;
Every time you open a new terminal window, set directories to all required programs and the data you will use depending on where you installed them&lt;br /&gt;
&lt;br /&gt;
Set the path to NGSadmix, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NGSADMIX=~/Software/NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test the link&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $NGSADMIX&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create directories===&lt;br /&gt;
Create the directories that will be used for working:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd Demo&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir Results&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set the paths to your local directories===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;IN_DIR=Demo/Data&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;OUT_DIR=Demo/Results&amp;lt;/code&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Test the links&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ls $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The test data===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use a very reduced data set.&lt;br /&gt;
&lt;br /&gt;
*10 individuals from each population: 10 from Nigeria (YRI), 10 from Japan (JPT) and 10 with European Ancestry (CEU). &lt;br /&gt;
*a very reduced genome 30 x 100k random regions across the autosomes&lt;br /&gt;
*each individual is sequenced at 2-6X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Europeans (mostly of British ancestry)&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;East Asian - Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;West African - Nigerian Yoruba individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can either download the beagle input files or create them yourself from bam files&lt;br /&gt;
====Download the beagle genotype likelihood input file====&lt;br /&gt;
NGSadmix uses Genotype Likelihoods (GLs) in .beagle format as input. The input file has been created for you.&lt;br /&gt;
A file with the information about the population is also provided.&lt;br /&gt;
 &lt;br /&gt;
Download the files and move them to your input folder (for example, $IN_DIR):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1input.gz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wget popgen.dk/software/download/NGSadmix/data/Demo1pop.info&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1input.gz $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mv Demo1pop.info $IN_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the the beagle genotype likelihood input file using ANGSD====&lt;br /&gt;
first set the path to ANGSD  (change ~/github/angsd/ to the path on your system)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ANGSD=~/github/angsd/angsd &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
test that you have the rigth path and that ANGSD is installed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; $ANGSD&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download small BAM files and extract files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; wget http://popgen.dk/software/download/NGSadmix/data/smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; tar xf smallerbams.tar &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make a list with the bam file names&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;find smallerbams/ |  grep bam$ &amp;gt; all.files&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
calculate genotype likelihoods for polymorphic sites using ANGSD (see ANGSD website for further information)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ANGSD -bam all.files -GL 2 -doMajorMinor 1 -doMaf 1 -SNP_pval 2e-6 -minMapQ 30 -minQ 20 -minInd 25 -minMaf 0.05 -doGlf 2 -out $IN_DIR/Demo1input.gz -P 5 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
create population information file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; paste -d &amp;quot; &amp;quot; &amp;lt;( cut -f 5 -d&amp;quot;.&amp;quot; all.files ) &amp;lt;(cut -f 1 -d&amp;quot;.&amp;quot; all.files | xargs -n1 basename) &amp;gt; $IN_DIR/Demo1pop.info &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View population information file ====&lt;br /&gt;
&lt;br /&gt;
To view a summary of the population information file, cut the first column, sort and count:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $IN_DIR/Demo1pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets make a population label file and place it in the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cut -f1 -d&amp;quot; &amp;quot; $IN_DIR/Demo1pop.info  &amp;gt; $OUT_DIR/poplabel &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== View the genotype likelihood beagle file ====&lt;br /&gt;
&lt;br /&gt;
*In general, the first three columns of a beagle file contain marker name and the two alleles, allele1 and allele2, present in the locus (in beagle A=0, C=1, G=2, T=3). All following columns contain genotype likelihoods (three columns for each individual: first GL for homozygote for allele1, then GL for heterozygote and then GL for homozygote for allele2). Note that the GL values sum to one per site for each individual. This is just a normalization of the genotype likelihoods in order to avoid underflow problems in the beagle software, but it does not mean that they are genotype probabilities. &lt;br /&gt;
&lt;br /&gt;
*In order to see the first 10 columns and 10 lines of the input file, type:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | head -n 10 | cut -f 1-10 | column -t&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Use this command to count the number of lines of the input file. The number of lines, indicates the number of loci for which there are GLs plus one (as the command includes the count of the header line):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;gunzip -c $IN_DIR/Demo1input.gz | wc -l&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Let’s analyze the input file ===&lt;br /&gt;
To run an analysis of the GLs with NGSadmix, assuming the number of ancestral populations is K=3, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo1input.gz -K 3 -minMaf 0.05 -seed 1 -o $OUT_DIR/Demo1NGSadmix&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
=== The output ===&lt;br /&gt;
&lt;br /&gt;
The analysis performed by NGSadmix produces 4 files:&lt;br /&gt;
&lt;br /&gt;
*'''Log likelihood of the estimates'''&lt;br /&gt;
A .log file that summarizes the run.&lt;br /&gt;
&lt;br /&gt;
Let’s take a look at the log file to determine the log likelihood of the estimates achieved by NGSadmix which is called the “best like” in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cat $OUT_DIR/Demo1NGSadmix.log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated allele frequency'''&lt;br /&gt;
&lt;br /&gt;
::A zipped .fopt file, that contains an estimate of the allele frequency in each of the 3 assumed ancestral populations (there is a line for each locus).&lt;br /&gt;
&lt;br /&gt;
::We can use this file to obtain the estimated allele frequency of the first 5 SNPs (one per line) of the three assumed ancestral populations, by typing the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;zcat $OUT_DIR/Demo1NGSadmix.fopt.gz | head -n 5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Estimated admixture proportions'''&lt;br /&gt;
::A .qopt file, that contains an estimate of the individual's ancestry proportion from each of the three assumed ancestral populations (there is a line for each individual).&lt;br /&gt;
&lt;br /&gt;
::To obtain the estimated admixture proportions for the first 5 individuals, type the following command:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 Demo1NGSadmix.qopt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''DemoNGSadmix.filter''' if the filter was used, it will show the sites that were left out.&lt;br /&gt;
&lt;br /&gt;
::To see the header file, type:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;head -n 5 $OUT_DIR/Demo1NGSadmix.filter&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::no lines means that all where used&lt;br /&gt;
&lt;br /&gt;
=== Plot the results in R ===&lt;br /&gt;
&lt;br /&gt;
Follow these instructions to make a simple plot of the estimated admixture proportions for all individuals in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Get ID and pop info for each individual&lt;br /&gt;
pop&amp;lt;-scan(&amp;quot;poplabel&amp;quot;,what=&amp;quot;theFuck&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Read inferred admixture proportions file&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo1NGSadmix.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Plot them (ordered by population)&lt;br /&gt;
ord = order(pop)&lt;br /&gt;
par(mar=c(7,4,1,1))&lt;br /&gt;
barplot(t(q)[,ord],col=c(2,1,3),names=pop[ord],las=2,ylab=&amp;quot;Demo1 Admixture proportions&amp;quot;,cex.names=0.75)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The y-axis of the plot show the admixture proportions and the individuals in the samples are plotted in the x-axis. &lt;br /&gt;
&lt;br /&gt;
Each color represents a different ancestral population.&lt;br /&gt;
&lt;br /&gt;
The proportion of each color shows the different admixture of the individuals for each ancestral population. &lt;br /&gt;
&lt;br /&gt;
The plot is sorted by the population of origin of each individual in the sample, and therefore, it shows blocks with prevalence of a certain color, which represents the population to which each individual belongs.&lt;br /&gt;
&lt;br /&gt;
NB As you could tell from the number of loci included in the analysis, the above analysis is based on data from very few loci (actually we on purpose only analyzed data from a small part of the genome to make sure the analysis ran fast).&lt;br /&gt;
&lt;br /&gt;
==Example of NGSadmix with admixed populations==&lt;br /&gt;
&lt;br /&gt;
Now that you know how to make input data to NGSadmix, how to run NGSadmix and what the output looks like, let's try to look at a more realistic size dataset. More specifically let's try to run NGSadmix on 50000 sites from the 1000 genomes project from the following populations:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;table class=&amp;quot;muse-table&amp;quot; border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;ASW&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;HapMap African Americans from SW US&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CEU&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;European individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;CHB&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Han Chinese in Beijing&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;JPT&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Japanese individuals&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;YRI&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Yoruba individuals from Nigeria&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;MXL&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td&amp;gt;Mexican individuals from LA California&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
:&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The input file Demo2input.gz with genotype likelihoods from 100 individuals in .beagle format, and a file with population info are given.&lt;br /&gt;
''Note: please make sure you have created and set up the working directories as indicated in the previous tutorial.''&lt;br /&gt;
&lt;br /&gt;
===Download Files===&lt;br /&gt;
Download and copy the files to your input folder (for example, $IN_DIR)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2input.gz&lt;br /&gt;
wget popgen.dk/software/download/NGSadmix/data/Demo2pop.info&lt;br /&gt;
mv Demo2input.gz $IN_DIR&lt;br /&gt;
mv Demo2pop.info $OUT_DIR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
make sure you are back in your original folder (not the $OUT_DIR folder)&lt;br /&gt;
&lt;br /&gt;
===Take a quick look at the population data===&lt;br /&gt;
make a summary by cutting the first column, sorting and counting&lt;br /&gt;
&amp;lt;code&amp;gt;cut -f 1 -d &amp;quot; &amp;quot; $OUT_DIR/Demo2pop.info | sort | uniq -c&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run NGSadmix===&lt;br /&gt;
Run an analysis of the data with NGSadmix with K=3 (-K 3), using 1 cpu (-P 1), using only SNPs with minor allele frequency above 0.05 (-minMaf 0.05), set the seed set to 21 (-seed 21), and set the prefix of the output files to Demo2NGSadmixK3. For a reference on the parameters that can be used to run NGSadmix, please go to [http://www.popgen.dk/software/index.php/NgsAdmixv2#Parameters]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 3 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Plot=== &lt;br /&gt;
Plot the estimated admixture proportions by running the following code in R:&lt;br /&gt;
&lt;br /&gt;
Make sure you stand on the output directory&lt;br /&gt;
&amp;lt;code&amp;gt;cd $OUT_DIR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK3.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=3&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that like in the previous example, the order of the individuals in the plot is not the same as in the .qopt file. Instead, to provide a better overview, the individuals have been ordered according to their population labels.&lt;br /&gt;
&lt;br /&gt;
===Choose a differnt K===&lt;br /&gt;
Try to run NGSadmix with K=4 and compare the plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$NGSADMIX -likes $IN_DIR/Demo2input.gz -K 4 -P 1 -minMaf 0.05 -seed 21 -o $OUT_DIR/Demo2NGSadmixK4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type “R” in the terminal and press enter and paste the following code into R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# read population labels and estimated admixture proportions&lt;br /&gt;
pop&amp;lt;-read.table(&amp;quot;Demo2pop.info&amp;quot;,as.is=T)&lt;br /&gt;
q&amp;lt;-read.table(&amp;quot;Demo2NGSadmixK4.qopt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# order according to population&lt;br /&gt;
ord&amp;lt;-order(pop[,1])&lt;br /&gt;
barplot(t(q)[,ord],col=2:10,space=0,border=NA,xlab=&amp;quot;Individuals&amp;quot;,ylab=&amp;quot;Demo2 Admixture proportions for K=4&amp;quot;)&lt;br /&gt;
text(tapply(1:nrow(pop),pop[ord,1],mean),-0.05,unique(pop[ord,1]),xpd=T)&lt;br /&gt;
abline(v=cumsum(sapply(unique(pop[ord,1]),function(x){sum(pop[ord,1]==x)})),col=1,lwd=1.2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=873</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=873"/>
		<updated>2018-10-05T13:59:09Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= NEW VERSION = &lt;br /&gt;
For the NEW version of ngsRelate that coestimates relatedness and inbreeding go to this link https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= OLD VERSION = &lt;br /&gt;
For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=872</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=872"/>
		<updated>2018-10-05T13:58:33Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: Replaced content with &amp;quot;For the NEW version of ngsRelate that coestimates relatedness and inbreeding go to this link https://github.com/ANGSD/NgsRelate For the old version please use this link: h...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For the NEW version of ngsRelate that coestimates relatedness and inbreeding go to this link https://github.com/ANGSD/NgsRelate&lt;br /&gt;
For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=871</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=871"/>
		<updated>2018-10-03T12:48:00Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are examples of how NgsRelate can be used to coestimate relatedness and inbreeding from NGS data. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. &lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only VCF/BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
Method (v1) is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=870</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=870"/>
		<updated>2018-10-03T12:46:54Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 3: using frequencies from 1000genomes vcf files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are examples of how NgsRelate can be used to coestimate relatedness and inbreeding from NGS data. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. &lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only VCF/BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=869</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=869"/>
		<updated>2018-10-03T12:46:26Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are examples of how NgsRelate can be used to coestimate relatedness and inbreeding from NGS data. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. &lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only VCF/BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=868</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=868"/>
		<updated>2018-10-03T12:45:56Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are examples of how NgsRelate can be used to coestimate relatedness and inbreeding from NGS data. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only VCF/BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=867</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=867"/>
		<updated>2018-10-03T12:44:24Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 0: using only BCF files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only VCF/BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=866</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=866"/>
		<updated>2018-10-03T12:43:56Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=865</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=865"/>
		<updated>2018-10-03T12:42:11Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This pages refers to the new v2 of ngsRelate which coestimates relatedness and inbreeding. For the old version please use this link: http://www.popgen.dk/software/index.php?title=NgsRelate&amp;amp;oldid=694&lt;br /&gt;
&lt;br /&gt;
=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=864</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=864"/>
		<updated>2018-10-03T12:39:45Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
= [http://www.popgen.dk/angsd ANGSD] =&lt;br /&gt;
Analysis of Next Generation Sequencing Data&lt;br /&gt;
&lt;br /&gt;
&amp;lt;classdiagram type=&amp;quot;dir:LR&amp;quot;&amp;gt;&lt;br /&gt;
[sequence data]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype;likelihoods]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
[sequence files|bam files;SOAP files{bg:orange}]-&amp;gt;[sequence data]&lt;br /&gt;
[glf files|glfv3;soapSNP{bg:orange}]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype prob|beagle output{bg:orange}]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
&amp;lt;/classdiagram&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= [[NgsAdmix]] =&lt;br /&gt;
[[File:NgsAdmix.png|thumb|NGSadmix]]&lt;br /&gt;
Infer the ancestry proportions from low depth NGS data. The principal is the same as other softwares such as FRAPPE and ADMIXTURE however, ngsAdmix also works when you have uncertainty in your data. This makes it ideal for medium and low depth sequencing data where many genotypes cannot be called without introducing errors or ascertainment bias.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= [[NgsRelate]] =&lt;br /&gt;
A software package for inferring relatedness and inbreeding between pairs of individuals from NGS data. This is a new version.&lt;br /&gt;
&lt;br /&gt;
= [[Relate]]=&lt;br /&gt;
[[File:relate.png|thumb|left|Relate. Infered IBD sharing across a chromosome for a sib pair estimated using affy 500k data]]&lt;br /&gt;
&lt;br /&gt;
This method estimates the probability of sharing alleles identity by descent (IBD) across the genome and can also be used for mapping disease loci using distantly related individuals. To accommodate LD the methods need SNP for several individuals in order to estimate the allele frequencies and the pairwise LD. The method return the posterior probabilities of the IBD states across the genome and the overall IBD sharing.&lt;br /&gt;
&lt;br /&gt;
= [[RelateAdmix]] =&lt;br /&gt;
A software package for inferring relatedness between pairs of individuals even if the individuals are admixed.&lt;br /&gt;
&lt;br /&gt;
= [[BAMSE]] =&lt;br /&gt;
&lt;br /&gt;
= [[CATS]] =&lt;br /&gt;
&lt;br /&gt;
[[File:catsFig2.png|thumb|left|joint power of a non-symetric two stage GWA design]]&lt;br /&gt;
R package for power estimation for a two-stage genome-wide association design. This is a modification of the code from Skol et al 2006, nat genet. so that the relative risk, case-control ratios and allele frequencies are allowed to vary between stages.&lt;br /&gt;
&lt;br /&gt;
= [[LDadmix]] = &lt;br /&gt;
= [[R scripts]] =&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=863</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=863"/>
		<updated>2018-10-03T12:38:23Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* fastNGSadmix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
= [http://www.popgen.dk/angsd ANGSD] =&lt;br /&gt;
Analysis of Next Generation Sequencing Data&lt;br /&gt;
&lt;br /&gt;
&amp;lt;classdiagram type=&amp;quot;dir:LR&amp;quot;&amp;gt;&lt;br /&gt;
[sequence data]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype;likelihoods]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
[sequence files|bam files;SOAP files{bg:orange}]-&amp;gt;[sequence data]&lt;br /&gt;
[glf files|glfv3;soapSNP{bg:orange}]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype prob|beagle output{bg:orange}]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
&amp;lt;/classdiagram&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= [[NgsAdmix]] =&lt;br /&gt;
[[File:NgsAdmix.png|thumb|NGSadmix]]&lt;br /&gt;
Infer the ancestry proportions from low depth NGS data. The principal is the same as other softwares such as FRAPPE and ADMIXTURE however, ngsAdmix also works when you have uncertainty in your data. This makes it ideal for medium and low depth sequencing data where many genotypes cannot be called without introducing errors or ascertainment bias.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= [[NgsRelate] ggg] =&lt;br /&gt;
A software package for inferring relatedness and inbreeding between pairs of individuals from NGS data.&lt;br /&gt;
&lt;br /&gt;
= [[NgsRelate]] =&lt;br /&gt;
A software package for inferring relatedness and inbreeding between pairs of individuals from NGS data.&lt;br /&gt;
&lt;br /&gt;
= [[Relate]]=&lt;br /&gt;
[[File:relate.png|thumb|left|Relate. Infered IBD sharing across a chromosome for a sib pair estimated using affy 500k data]]&lt;br /&gt;
&lt;br /&gt;
This method estimates the probability of sharing alleles identity by descent (IBD) across the genome and can also be used for mapping disease loci using distantly related individuals. To accommodate LD the methods need SNP for several individuals in order to estimate the allele frequencies and the pairwise LD. The method return the posterior probabilities of the IBD states across the genome and the overall IBD sharing.&lt;br /&gt;
&lt;br /&gt;
= [[RelateAdmix]] =&lt;br /&gt;
A software package for inferring relatedness between pairs of individuals even if the individuals are admixed.&lt;br /&gt;
&lt;br /&gt;
= [[BAMSE]] =&lt;br /&gt;
&lt;br /&gt;
= [[CATS]] =&lt;br /&gt;
&lt;br /&gt;
[[File:catsFig2.png|thumb|left|joint power of a non-symetric two stage GWA design]]&lt;br /&gt;
R package for power estimation for a two-stage genome-wide association design. This is a modification of the code from Skol et al 2006, nat genet. so that the relative risk, case-control ratios and allele frequencies are allowed to vary between stages.&lt;br /&gt;
&lt;br /&gt;
= [[LDadmix]] = &lt;br /&gt;
= [[R scripts]] =&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=862</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=862"/>
		<updated>2018-10-03T12:36:55Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* NgsRelate */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
= [http://www.popgen.dk/angsd ANGSD] =&lt;br /&gt;
Analysis of Next Generation Sequencing Data&lt;br /&gt;
&lt;br /&gt;
&amp;lt;classdiagram type=&amp;quot;dir:LR&amp;quot;&amp;gt;&lt;br /&gt;
[sequence data]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype;likelihoods]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
[sequence files|bam files;SOAP files{bg:orange}]-&amp;gt;[sequence data]&lt;br /&gt;
[glf files|glfv3;soapSNP{bg:orange}]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype prob|beagle output{bg:orange}]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
&amp;lt;/classdiagram&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= [[NgsAdmix]] =&lt;br /&gt;
[[File:NgsAdmix.png|thumb|NGSadmix]]&lt;br /&gt;
Infer the ancestry proportions from low depth NGS data. The principal is the same as other softwares such as FRAPPE and ADMIXTURE however, ngsAdmix also works when you have uncertainty in your data. This makes it ideal for medium and low depth sequencing data where many genotypes cannot be called without introducing errors or ascertainment bias.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= [[NgsRelate] ggg] =&lt;br /&gt;
A software package for inferring relatedness and inbreeding between pairs of individuals from NGS data.&lt;br /&gt;
&lt;br /&gt;
= [[fastNGSadmix]] =&lt;br /&gt;
Infers the ancestry proportions from NGS data of a single indivudal, even with low-depth NGS data. It is based on ngsAdmix, however it uses a referenece panel of population specific frequencies, and works when you have uncertainty in your data. This makes it ideal for quick and easy analyses of medium and low depth sequencing data samples where many genotypes cannot be called without introducing errors or ascertainment bias. There is also a PCA method for doing PCA of a NGS sample, where population structure is taken into into account.&lt;br /&gt;
&lt;br /&gt;
= [[Relate]]=&lt;br /&gt;
[[File:relate.png|thumb|left|Relate. Infered IBD sharing across a chromosome for a sib pair estimated using affy 500k data]]&lt;br /&gt;
&lt;br /&gt;
This method estimates the probability of sharing alleles identity by descent (IBD) across the genome and can also be used for mapping disease loci using distantly related individuals. To accommodate LD the methods need SNP for several individuals in order to estimate the allele frequencies and the pairwise LD. The method return the posterior probabilities of the IBD states across the genome and the overall IBD sharing.&lt;br /&gt;
&lt;br /&gt;
= [[RelateAdmix]] =&lt;br /&gt;
A software package for inferring relatedness between pairs of individuals even if the individuals are admixed.&lt;br /&gt;
&lt;br /&gt;
= [[BAMSE]] =&lt;br /&gt;
&lt;br /&gt;
= [[CATS]] =&lt;br /&gt;
&lt;br /&gt;
[[File:catsFig2.png|thumb|left|joint power of a non-symetric two stage GWA design]]&lt;br /&gt;
R package for power estimation for a two-stage genome-wide association design. This is a modification of the code from Skol et al 2006, nat genet. so that the relative risk, case-control ratios and allele frequencies are allowed to vary between stages.&lt;br /&gt;
&lt;br /&gt;
= [[LDadmix]] = &lt;br /&gt;
= [[R scripts]] =&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=861</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=Main_Page&amp;diff=861"/>
		<updated>2018-10-03T12:36:16Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
= [http://www.popgen.dk/angsd ANGSD] =&lt;br /&gt;
Analysis of Next Generation Sequencing Data&lt;br /&gt;
&lt;br /&gt;
&amp;lt;classdiagram type=&amp;quot;dir:LR&amp;quot;&amp;gt;&lt;br /&gt;
[sequence data]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype;likelihoods]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
[sequence files|bam files;SOAP files{bg:orange}]-&amp;gt;[sequence data]&lt;br /&gt;
[glf files|glfv3;soapSNP{bg:orange}]-&amp;gt;[genotype;likelihoods]&lt;br /&gt;
[genotype prob|beagle output{bg:orange}]-&amp;gt;[genotype;probabilities]&lt;br /&gt;
&amp;lt;/classdiagram&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= [[NgsAdmix]] =&lt;br /&gt;
[[File:NgsAdmix.png|thumb|NGSadmix]]&lt;br /&gt;
Infer the ancestry proportions from low depth NGS data. The principal is the same as other softwares such as FRAPPE and ADMIXTURE however, ngsAdmix also works when you have uncertainty in your data. This makes it ideal for medium and low depth sequencing data where many genotypes cannot be called without introducing errors or ascertainment bias.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= [[NgsRelate]] =&lt;br /&gt;
A software package for inferring relatedness between pairs of individuals from NGS data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= [[fastNGSadmix]] =&lt;br /&gt;
Infers the ancestry proportions from NGS data of a single indivudal, even with low-depth NGS data. It is based on ngsAdmix, however it uses a referenece panel of population specific frequencies, and works when you have uncertainty in your data. This makes it ideal for quick and easy analyses of medium and low depth sequencing data samples where many genotypes cannot be called without introducing errors or ascertainment bias. There is also a PCA method for doing PCA of a NGS sample, where population structure is taken into into account.&lt;br /&gt;
&lt;br /&gt;
= [[Relate]]=&lt;br /&gt;
[[File:relate.png|thumb|left|Relate. Infered IBD sharing across a chromosome for a sib pair estimated using affy 500k data]]&lt;br /&gt;
&lt;br /&gt;
This method estimates the probability of sharing alleles identity by descent (IBD) across the genome and can also be used for mapping disease loci using distantly related individuals. To accommodate LD the methods need SNP for several individuals in order to estimate the allele frequencies and the pairwise LD. The method return the posterior probabilities of the IBD states across the genome and the overall IBD sharing.&lt;br /&gt;
&lt;br /&gt;
= [[RelateAdmix]] =&lt;br /&gt;
A software package for inferring relatedness between pairs of individuals even if the individuals are admixed.&lt;br /&gt;
&lt;br /&gt;
= [[BAMSE]] =&lt;br /&gt;
&lt;br /&gt;
= [[CATS]] =&lt;br /&gt;
&lt;br /&gt;
[[File:catsFig2.png|thumb|left|joint power of a non-symetric two stage GWA design]]&lt;br /&gt;
R package for power estimation for a two-stage genome-wide association design. This is a modification of the code from Skol et al 2006, nat genet. so that the relative risk, case-control ratios and allele frequencies are allowed to vary between stages.&lt;br /&gt;
&lt;br /&gt;
= [[LDadmix]] = &lt;br /&gt;
= [[R scripts]] =&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=845</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=845"/>
		<updated>2018-07-30T09:39:58Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 0: using only NGS data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=844</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=844"/>
		<updated>2018-07-30T09:39:41Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 1: using only NGS data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using only NGS data==&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=843</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=843"/>
		<updated>2018-07-30T09:39:17Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: Undo revision 842 by Thorfinn (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=842</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=842"/>
		<updated>2018-07-30T09:38:55Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 1: using only NGS data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 0: using BCF files==&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=841</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=841"/>
		<updated>2018-07-30T09:35:53Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* How to download and install */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/SAMtools/htslib&lt;br /&gt;
&lt;br /&gt;
git clone https://github.com/ANGSD/ngsRelate&lt;br /&gt;
&lt;br /&gt;
cd htslib/;make;cd ../ngsRelate;make HTSSRC=../htslib/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=813</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=813"/>
		<updated>2018-01-12T10:30:16Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* How to download and install */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/76b03fad2da1db3148759ccdce1ab6508c2e00bd/ngsRelate.cpp &amp;gt;ngsRelate.cpp&lt;br /&gt;
g++ ngsRelate.cpp -O3 -lz -o ngsRelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=812</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=812"/>
		<updated>2018-01-08T11:54:04Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* How to download and install */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://github.com/ANGSD/NgsRelate/blob/76b03fad2da1db3148759ccdce1ab6508c2e00bd/ngsRelate.cpp &amp;gt;ngsRelate.cpp&lt;br /&gt;
g++ ngsRelate.cpp -O3 -lz -o ngsRelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt; newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/newres.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotype likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 -domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (numbered from 0, so 0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
'''NEW''':  Note that if you want you also input a file with the IDs of the individuals (on ID per line) in the same order as in the file 'filelist' used to make the genotype likelihoods. If you do the output will also contain these IDs and not just the numbers of the samples  (one can actually just use that exact file, however the IDs then tend to be a bit long). This can be done with the optional flag -z followed by the filename.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq  &amp;gt;newres&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;newres&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
NEW: Example of output of analysis of two samples run without the optional -z:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the same analysis run with the optional flag -z followed by name of file with IDs (where the first two IDs are S1 and S42):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a	b	ida	idb	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	S1	S42	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat newres&lt;br /&gt;
a	b	nSites	k0	        k1   	        k2	        loglh	        nIter	coverage&lt;br /&gt;
0	1	1128677	0.673213	0.326774	0.000013	-1710940.769938	19	0.813930&lt;br /&gt;
0	2	1121594	0.448790	0.548298	0.002912	-1666189.356801	25	0.808822&lt;br /&gt;
0	3	1131917	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
0	4	1135509	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
0	5	1043719	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
1	2	1118945	0.006249	0.993750	0.000001	-1580989.961356	13	0.806912&lt;br /&gt;
1	3	1129152	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
1	4	1132778	1.000000	0.000000	0.000000	-1744055.210286	-1	0.816887&lt;br /&gt;
1	5	1041298	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
2	3	1122253	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
2	4	1125729	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
2	5	1035731	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
3	4	1136091	0.566552	0.433054	0.000393	-1743752.158759	36	0.819276&lt;br /&gt;
3	5	1046456	0.265831	0.482954	0.251214	-1467343.087558	11	0.754637&lt;br /&gt;
4	5	1047977	0.004653	0.995347	0.000000	-1473415.049864	94	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first two columns contain the information of about what two individuals was used for the analysis. The third column contains information about how many sites were used in the analysis. The following three columns are the maximum likelihood (ML) estimates of the relatedness coefficients. The seventh column is the log of the likelihood of the ML estimate. The eigth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the ninth column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For OLD versions of the program (from before June 28 2017): &lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
Important recent changes:&lt;br /&gt;
&lt;br /&gt;
#We have made -s 1 default (flips all allele frequencies from freq to 1-freq), since this is needed in almost all analyses. If you do not want the frequencies flipped then simply run the program with -s 0&lt;br /&gt;
#The output format has been changed to a more R friendly format (no &amp;quot;:&amp;quot; and parenthesis) &lt;br /&gt;
#The option -z has been added so one can get the sample IDs printed in the output (if one run the program with -z idfilename)&lt;br /&gt;
#We have fixed -m 1 so the estimates can no longer be negative&lt;br /&gt;
&lt;br /&gt;
See github for the full change log.&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=563</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=563"/>
		<updated>2017-01-30T13:16:26Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* How to download and install */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;ngsRelate.cpp&lt;br /&gt;
g++ ngsRelate.cpp -O3 -lz -o ngsRelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=562</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=562"/>
		<updated>2017-01-27T11:10:51Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* How to download and install */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ ngsRelate.cpp -O3 -lz -o ngsRelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=561</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=561"/>
		<updated>2017-01-16T11:54:54Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 3: using frequencies from 1000genomes vcf files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
#Then we extract and match the freqs from the reference population with the sites where we had data. The parser expects a header, so make a dummy file&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;header&amp;quot; |gzip -c &amp;gt;new&lt;br /&gt;
cat EUR_AF/ALL.frq.gz &amp;gt;&amp;gt;new &lt;br /&gt;
ngsRelate extract_freq new angsdput.glf.pos.gz &amp;gt;myfreq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=556</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=556"/>
		<updated>2017-01-03T12:49:35Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq_bim angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=555</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=555"/>
		<updated>2016-12-27T07:33:24Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 3: using frequencies from 1000genomes vcf files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=554</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=554"/>
		<updated>2016-12-27T07:32:39Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 3: using frequencies from 1000genomes vcf files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
We want to run ngsRelate using population frequencies from europe. We will extract the frequencies from the 1000genomes project vcf.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Assuming that we have perchr called: ALL.chr*.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
#We dump output in EUR_AF/*.frq&lt;br /&gt;
#We only use diallelic sites, we extract CHROM,POS,REF,ALT,EUR_AF tags from the vcf&lt;br /&gt;
#We then pulled out the unique sites.&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
    IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
    echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
##We merge into one file&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
#we extract the first 4 columns, which is the sites input for angsd&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 3 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=553</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=553"/>
		<updated>2016-12-27T07:27:46Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 3: using frequencies from 1000genomes vcf files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for f in `seq 1 22`&lt;br /&gt;
do&lt;br /&gt;
    IF=/storage/data_shared/callsets/1000genomes/phase3/vcf/ALL.chr${f}.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz&lt;br /&gt;
    echo &amp;quot;bcftools view  -m2 -M2 -v snps ${IF} | bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%EUR_AF\n' |awk '{if(\$5&amp;gt;0) print \$0 }'|sort -S 50% -u -k1,2 &amp;gt;EUR_AF/${f}.frq&amp;quot;&lt;br /&gt;
done|parallel&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
cat EUR_AF/1.frq &amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
for i in `seq 2 22`&lt;br /&gt;
do&lt;br /&gt;
    cat EUR_AF/${i}.frq &amp;gt;&amp;gt;EUR_AF/ALL.frq&lt;br /&gt;
done&lt;br /&gt;
gzip EUR_AF/ALL.frq&lt;br /&gt;
&lt;br /&gt;
gunzip -c EUR_AF/ALL.frq.gz |cut -f1-4 |gzip -c &amp;gt;EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
./angsd/angsd sites index EUR_AF/sites.txt.gz&lt;br /&gt;
&lt;br /&gt;
 ./angsd/angsd -b list -gl 1 -domajorminor 3 -C 50 -ref /storage/data_shared/reference_genomes/hs37d5/hs37d5.fa -doglf 2 -minmapq 30 -minq 20 -sites EUR_AF/sites.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=552</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=552"/>
		<updated>2016-12-27T07:25:26Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
zcat angsdput.mafs.gz | cut -f5 |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
== Run example 3: using frequencies from 1000genomes vcf files==&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=531</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=531"/>
		<updated>2015-08-31T08:06:41Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Brief description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
Method is published here: http://bioinformatics.oxfordjournals.org/content/early/2015/08/29/bioinformatics.btv509.abstract&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=523</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=523"/>
		<updated>2015-08-04T17:39:15Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals from low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods instead of called genotypes. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the examples below. For more information about ANGSD see here: http://popgen.dk/angsd/index.php/Quick_Start.&lt;br /&gt;
&lt;br /&gt;
=How to download and install=&lt;br /&gt;
The source code for NgsRelate is deposited on github: https://github.com/ANGSD/NgsRelate. On a linux or mac system with curl and g++ installed NgsRelate can be downloaded and installed as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Run examples=&lt;br /&gt;
Below are two examples of how NgsRelate can be used to estimate relatedness from NGS data. Note that to be able to run all steps of the examples you need to have the programs ANGSD and PLINK installed and you also need to download large data files from both HapMap3 and 1000 Genomes webpages. Furthermore, the examples take several hours to run all in all. They are therefore just meant as illustrations of how NgsRelate can be run. '''If you want to quickly try out NgsRelate, e.g. to check if your installation works, you can download the final input data for NgsRelate used in the very last command in run example 2 here: http://www.popgen.dk/ida/NgsRelateExampleData/web/input/. Using that data you can try out NgsRelate by running that last command, i.e.''' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output should be a file called res that contains relatedness estimates for all pairs between 6 individuals. A copy of this file can be found here http://www.popgen.dk/ida/NgsRelateExampleData/web/output/.&lt;br /&gt;
&lt;br /&gt;
== Run example 1: using only NGS data==&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files; one line per BAN/CRAM file. Then we can use ANGSD to estimate frequencies and calculate genotype likelihoods while doing SNP calling and in the end produce the the input files needed for the NgsRelate program as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### First we generate a file with allele frequencies (angsdput.mafs.gz) and a file with genotpe likelihoods (angsdput.glf.gz).&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
&lt;br /&gt;
### Then we extract the frequency column from the allele frequency file and remove the header (to make it in the format NgsRelate needs)&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have these files we can use NgsRelate to estimate relatedness between any pairs of individuals. E.g. if we want to estimate relatedness between the first two individuals (0 and 1) we can do it using the following command: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify the name of our file with genotype likelihoods after the option &amp;quot;-g&amp;quot;, the number of individuals in the file after the option &amp;quot;-n&amp;quot;, the name of the file with allele frequencies after the option &amp;quot;-f&amp;quot; and the number of the two individuals after the options &amp;quot;-a&amp;quot; and &amp;quot;-b&amp;quot; . If -a and -b are not specified NgsRelate will loop through all pairs of individuals in the input file.&lt;br /&gt;
&lt;br /&gt;
== Run example 2: using NGS data with population frequencies estimated from genetic data from PLINK files ==&lt;br /&gt;
In this example we show how you can estimate relatedness between a number of individuals which you have NGS data from (in bam files) using genetic data from PLINK files for frequency estimation. &lt;br /&gt;
Assume the individuals we want to estimate relatedness from are from the population called LWK and assume we have files with genetic data from individuals from LWK as well as other populations in binary PLINK format (e.g. hapmap3_r2_b36_fwd.consensus.qc.polyHg19.*) and a file, LWK.fam, with the IDs of the LWK individuals in this dataset. Then using PLINK we can produce allele frequency information in a format that NgsRelate can use as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract individuals from LWK from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for this population&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Afterwards we can use ANGSD to calculate genotype likelihoods for the sites for which we have frequency info for as follows:     &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the chr,pos,major,minor information about the sites we have frequency info from into a file &lt;br /&gt;
### (so we can extract data from these sites from the NGS data files) &lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index this file for angsd&lt;br /&gt;
./angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### calculate genotype likelihoods for the six individuals for the sites we have frequency info on based on the bam files &lt;br /&gt;
### (assuming the paths to the bam files are listed in the file 'list'):&lt;br /&gt;
./angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
### this generates the output files angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we can use NgsRelate to estimate relatedness for the six individuals from which we have NGS data in bam files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract the frequencies and sync it to the angsd output&lt;br /&gt;
./ngsrelate extract_freq angsdput.glf.pos.gz hapmap3Hg19LWK.bim LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
### run ngsrelate &lt;br /&gt;
./ngsrelate  -g angsdput.glf.gz -n 6 -f freq -s 1 &amp;gt;res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final relatedness estimates will then be available in the file called &amp;quot;res&amp;quot; which can be found here: http://www.popgen.dk/ida/NgsRelateExampleData/web/output/. Note that we here used the option -s 1 to flip the allele frequencies (i.e. set them to 1 minus the frequencies in the freq file).&lt;br /&gt;
&lt;br /&gt;
=Output format=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat res&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contains the information of about which individuals was used for the analysis. The next three columns are the maximum likelihood (ML) estimate of the relatedness coefficients. The fifth column is the log of the likelihood of the ML estimate. The sixth column is the number of iterations of the maximization algorithm that was used to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and where the minor allele frequency (MAF) above the threshold (default is 0.05 but the user may specify a different threshold). Note that in some cases nIter is -1. This indicates that values on the boundary of the parameter space had a higher likelihood than the values achieved using the EM-algorithm (ML methods sometimes have trouble finding the ML estimate when it is on the boundary of the parameter space, and we therefore test the boundary values explicitly and output these if these have the highest likelihood).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
NgsAdmix takes two files as input: a file with genotype likelihoods and a file with frequencies for the sites there are genotype likelihoods for. &lt;br /&gt;
The genotype likelihood file needs to contain a line for each site with 3 values for each individual (one log transformed genotype likelihood for each of the 3 possible genotypes encoded as 'double's) and it needs to be in binary format and gz compressed.&lt;br /&gt;
The frequency file needs to contain a line per site with the allele frequency of the site in it.&lt;br /&gt;
&lt;br /&gt;
= Help and additional options =&lt;br /&gt;
To get help and a list of all options simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;br /&gt;
&lt;br /&gt;
=Bugs/Improvements=&lt;br /&gt;
-Make better output message if files doesn't exists when using the extract_freq option&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=457</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=457"/>
		<updated>2015-06-23T17:38:50Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract population from huge binary plink file&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
&lt;br /&gt;
### calculate frequencies for the subpopulation&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&lt;br /&gt;
### we are only interested in the output from the snpsites with the seq data. so we extract the chr,pos,major,minor&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
### index the file for angsd&lt;br /&gt;
angsd sites index forAngsd.txt&lt;br /&gt;
&lt;br /&gt;
##assuming 'list' contains path to bams&lt;br /&gt;
angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
#this generates an angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&lt;br /&gt;
#extract the frequencies and sync it to the angsd output&lt;br /&gt;
 ./NgsRelate/a.out extract_freq angsdput.glf.pos.gz files/hapmap3Hg19LWK.bim files/LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
#run ngsrelate&lt;br /&gt;
ngsrelate  -g angsdput.glf.gz -n 6 -f freq &amp;gt;resi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output  with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat resi&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=456</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=456"/>
		<updated>2015-06-23T17:34:24Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
### find sites from plink files&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
### index the file&lt;br /&gt;
angsd sites index forAngsd.txt&lt;br /&gt;
##assuming 'list' contains path to bams&lt;br /&gt;
angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
#this generates an angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&lt;br /&gt;
#extract the frequencies and sync it to the angsd output&lt;br /&gt;
 ./NgsRelate/a.out extract_freq angsdput.glf.pos.gz files/hapmap3Hg19LWK.bim files/LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
#run ngsrelate&lt;br /&gt;
ngsrelate  -g angsdput.glf.gz -n 6 -f freq &amp;gt;resi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output  with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat resi&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=455</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=455"/>
		<updated>2015-06-23T17:33:02Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
### find sites from plink files&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
### index the file&lt;br /&gt;
angsd sites index forAngsd.txt&lt;br /&gt;
##assuming 'list' contains path to bams&lt;br /&gt;
angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
#this generates an angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&lt;br /&gt;
 ./NgsRelate/a.out extract_freq angsdput.glf.pos.gz files/hapmap3Hg19LWK.bim files/LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output of with two samples&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of output  with 6 samples:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat resi&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.675337	0.322079	0.002584	-1710946.832375	10	0.813930&lt;br /&gt;
(0,2)	0.458841	0.526377	0.014782	-1666215.528333	10	0.808822&lt;br /&gt;
(0,3)	1.000000	0.000000	0.000000	-1743992.363193	-1	0.816266&lt;br /&gt;
(0,4)	1.000000	0.000000	0.000000	-1759202.971213	-1	0.818856&lt;br /&gt;
(0,5)	1.000000	0.000000	0.000000	-1550475.615322	-1	0.752663&lt;br /&gt;
(1,2)	0.007111	0.991020	0.001868	-1580995.130867	10	0.806912&lt;br /&gt;
(1,3)	1.000000	0.000000	0.000000	-1728859.988212	-1	0.814272&lt;br /&gt;
(1,4)	1.000001	-0.000001	0.000000	-1744055.203870	9	0.816887&lt;br /&gt;
(1,5)	1.000000	0.000000	0.000000	-1536858.187440	-1	0.750917&lt;br /&gt;
(2,3)	1.000000	0.000000	0.000000	-1705157.832621	-1	0.809297&lt;br /&gt;
(2,4)	1.000000	0.000000	0.000000	-1719681.338365	-1	0.811804&lt;br /&gt;
(2,5)	1.000000	0.000000	0.000000	-1517388.260612	-1	0.746903&lt;br /&gt;
(3,4)	0.547602	0.439423	0.012975	-1743899.789842	10	0.819276&lt;br /&gt;
(3,5)	0.265819	0.482953	0.251228	-1467343.087647	10	0.754637&lt;br /&gt;
(4,5)	0.004655	0.995345	-0.000000	-1473415.049411	8	0.755734&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=454</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=454"/>
		<updated>2015-06-23T15:42:33Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
### find sites from plink files&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
### index the file&lt;br /&gt;
angsd sites index forAngsd.txt&lt;br /&gt;
##assuming 'list' contains path to bams&lt;br /&gt;
angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 2 -minMapQ 30 -minQ 20&lt;br /&gt;
#this generates an angsdput.glf.gz and a angsdput.glf.pos.gz.&lt;br /&gt;
&lt;br /&gt;
 ./NgsRelate/a.out extract_freq angsdput.glf.pos.gz files/hapmap3Hg19LWK.bim files/LWKsub.frq &amp;gt;freq&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=453</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=453"/>
		<updated>2015-06-23T15:26:50Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
### find sites from plink files&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
### index the file&lt;br /&gt;
angsd sites index forAngsd.txt&lt;br /&gt;
##assuming 'list' contains path to bams&lt;br /&gt;
angsd -gl 1 -doglf 3 -sites forAngsd.txt -b list -domajorminor 3 -P 10 -minMapQ 30 -minQ 20&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=452</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=452"/>
		<updated>2015-06-23T12:32:00Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
### find sites from plink files&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
### index the file&lt;br /&gt;
angsd sites index forAngsd.txt&lt;br /&gt;
##assuming &lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=451</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=451"/>
		<updated>2015-06-23T12:30:39Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
### find sites from plink files&lt;br /&gt;
cut -f1,4-6  hapmap3Hg19LWK.bim &amp;gt;forAngsd.txt&lt;br /&gt;
##assuming &lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=450</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=450"/>
		<updated>2015-06-23T12:27:04Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using NGS data with plink population frequencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### extract plink&lt;br /&gt;
plink --bfile hapmap3_r2_b36_fwd.consensus.qc.polyHg19 --keep LWK.fam  --make-bed --out hapmap3Hg19LWK --noweb&lt;br /&gt;
### calculate frequencies&lt;br /&gt;
plink --bfile  hapmap3Hg19LWK --freq --noweb --out LWKsub&lt;br /&gt;
&lt;br /&gt;
##assuming &lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=449</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=449"/>
		<updated>2015-06-23T12:15:15Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using only NGS data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using NGS data with plink population frequencies=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=448</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=448"/>
		<updated>2015-06-23T10:55:12Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Run example using only NGS data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=447</id>
		<title>NgsRelate</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=NgsRelate&amp;diff=447"/>
		<updated>2015-06-20T15:05:01Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: /* Download and Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Brief description=&lt;br /&gt;
This page contains information about the program called NgsRelate, which can be used to infer relatedness coefficients for pairs of individuals for low coverage Next Generation Sequencing (NGS) data by using genotype likelihoods. To be able to infer the relatedness you will need to know the population frequencies and have genotype likelihoods. This can be obtained e.g. using the program ANGSD as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
=Download and Installation=&lt;br /&gt;
Primary repository is github. https://github.com/ANGSD/NgsRelate&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/ANGSD/NgsRelate/master/NgsRelate.cpp &amp;gt;NgsRelate.cpp&lt;br /&gt;
g++ NgsRelate.cpp -O3 -lz -o ngsrelate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Run example using only NGS data=&lt;br /&gt;
Assume we have file containing paths to 100 BAM/CRAM files, then we can use ANGSD to estimate frequencies calculate genotype likelihoods while doing SNP calling and dumping the input files needed for the NgsRelate program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./angsd -b filelist -gl 1 -domajorminor 1 -snp_pval 1e-6 - domaf 1 -minmaf 0.05 -doGlf 3&lt;br /&gt;
#this generates an angsdput.mafs.gz and a angsdput.glf.gz.&lt;br /&gt;
#we will need to extract the frequency column from the mafs file and remove the header&lt;br /&gt;
cut -f5 angsdput.mafs.gz |sed 1d &amp;gt;freq&lt;br /&gt;
./ngsrelate -g angsdput.glf.gz -n 100 -f freq -a 0 -b 1 &amp;gt;gl.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we specify that our binary genotype likelihood file contains 100 samples, and that we want to run the analysis for the first two samples -a 0 -b 1.&lt;br /&gt;
If no -a and -b are specified it will loop through all pairs&lt;br /&gt;
&lt;br /&gt;
=Output=&lt;br /&gt;
Example of output&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pair	k0	k1	k2	loglh	nIter	coverage&lt;br /&gt;
(0,1)	0.673213	0.326774	0.000013	-1710940.769941	19	0.814658&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first column contain the individuals that was used for the analysis . The next three columns are the estimated relatedness coefficient. The fifth column is the log of the likelihood of the MLE. The sixth column is the number of iterations required to find the MLE, and finally the seventh column is fraction of non-missing sites, i.e. the fraction of sites where data was available for both individuals, and the minor allele frequency (MAF) above the threshold (default is 0.05 but may also user specified).&lt;br /&gt;
&lt;br /&gt;
= Input file format =&lt;br /&gt;
The input files are binary gz compressed, log like ratios encoded as double. 3 values per sample.&lt;br /&gt;
The freq file is allowed to be gz compressed.&lt;br /&gt;
&lt;br /&gt;
= Citing and references =&lt;br /&gt;
&lt;br /&gt;
= Changelog =&lt;br /&gt;
See github for log&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=446</id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=446"/>
		<updated>2015-06-20T07:07:03Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Main&lt;br /&gt;
* ANGSD&lt;br /&gt;
** http://popgen.dk/wiki|Website&lt;br /&gt;
* NgsRelate&lt;br /&gt;
**http://www.popgen.dk/software/index.php/NgsRelate | Website&lt;br /&gt;
* Relate&lt;br /&gt;
** Relate|Local IBD relatedness&lt;br /&gt;
** Relate#Download_and_Installation|Download&lt;br /&gt;
** Relate#Manual|Manual&lt;br /&gt;
** Relate#Citation|citation&lt;br /&gt;
** Relate#Change_log|Log&lt;br /&gt;
* BAMSE&lt;br /&gt;
** BAMSE| Bayesian Association of multiple SNPs&lt;br /&gt;
* CATS&lt;br /&gt;
** CATS|power for two stage GWAS&lt;br /&gt;
* NGSadmix&lt;br /&gt;
**ngsAdmix|Population Structure for NGS data&lt;br /&gt;
** NgsAdmix#Installation|Download&lt;br /&gt;
** NgsAdmix#Run_example | Example&lt;br /&gt;
** NgsAdmix#Input_Files| Input files&lt;br /&gt;
** NgsAdmix#citation|Citation&lt;br /&gt;
** NgsAdmix#log|Log&lt;br /&gt;
* fastNGSadmix&lt;br /&gt;
** fastNgsAdmix#Installation|Download&lt;br /&gt;
** fastNgsAdmix#Run_example | Example&lt;br /&gt;
** fastNgsAdmix#Input_Files| Input files&lt;br /&gt;
** fastNgsAdmix#citation|Citation&lt;br /&gt;
** fastNgsAdmix#log|Log&lt;br /&gt;
* relateAdmix&lt;br /&gt;
** relateAdmix|Relatedness estimation for admixed individuals&lt;br /&gt;
** relateAdmix#Installation|Download&lt;br /&gt;
** relateAdmix#Run_example | Example&lt;br /&gt;
* LDadmix&lt;br /&gt;
* R scripts&lt;br /&gt;
** Rscripts| various R scripts&lt;br /&gt;
* navigation&lt;br /&gt;
** mainpage|Software&lt;br /&gt;
** http://popgen.dk|Popgen.dk&lt;br /&gt;
** http://popgen.dk/wiki|ANGSD&lt;br /&gt;
* SEARCH&lt;br /&gt;
* TOOLBOX&lt;br /&gt;
* LANGUAGES&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=445</id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=445"/>
		<updated>2015-06-20T07:05:51Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Main&lt;br /&gt;
* ANGSD&lt;br /&gt;
** http://popgen.dk/wiki|website&lt;br /&gt;
* NgsRelate&lt;br /&gt;
**http://www.popgen.dk/software/index.php/NgsRelate#Download_and_Installation |Download&lt;br /&gt;
* Relate&lt;br /&gt;
** Relate|Local IBD relatedness&lt;br /&gt;
** Relate#Download_and_Installation|Download&lt;br /&gt;
** Relate#Manual|Manual&lt;br /&gt;
** Relate#Citation|citation&lt;br /&gt;
** Relate#Change_log|Log&lt;br /&gt;
* BAMSE&lt;br /&gt;
** BAMSE| Bayesian Association of multiple SNPs&lt;br /&gt;
* CATS&lt;br /&gt;
** CATS|power for two stage GWAS&lt;br /&gt;
* NGSadmix&lt;br /&gt;
**ngsAdmix|Population Structure for NGS data&lt;br /&gt;
** NgsAdmix#Installation|Download&lt;br /&gt;
** NgsAdmix#Run_example | Example&lt;br /&gt;
** NgsAdmix#Input_Files| Input files&lt;br /&gt;
** NgsAdmix#citation|Citation&lt;br /&gt;
** NgsAdmix#log|Log&lt;br /&gt;
* fastNGSadmix&lt;br /&gt;
** fastNgsAdmix#Installation|Download&lt;br /&gt;
** fastNgsAdmix#Run_example | Example&lt;br /&gt;
** fastNgsAdmix#Input_Files| Input files&lt;br /&gt;
** fastNgsAdmix#citation|Citation&lt;br /&gt;
** fastNgsAdmix#log|Log&lt;br /&gt;
* relateAdmix&lt;br /&gt;
** relateAdmix|Relatedness estimation for admixed individuals&lt;br /&gt;
** relateAdmix#Installation|Download&lt;br /&gt;
** relateAdmix#Run_example | Example&lt;br /&gt;
* LDadmix&lt;br /&gt;
* R scripts&lt;br /&gt;
** Rscripts| various R scripts&lt;br /&gt;
* navigation&lt;br /&gt;
** mainpage|Software&lt;br /&gt;
** http://popgen.dk|Popgen.dk&lt;br /&gt;
** http://popgen.dk/wiki|ANGSD&lt;br /&gt;
* SEARCH&lt;br /&gt;
* TOOLBOX&lt;br /&gt;
* LANGUAGES&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=444</id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=444"/>
		<updated>2015-06-20T07:04:17Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Main&lt;br /&gt;
* ANGSD&lt;br /&gt;
** http://popgen.dk/wiki|website&lt;br /&gt;
* NgsRelate&lt;br /&gt;
* Relate&lt;br /&gt;
** Relate|Local IBD relatedness&lt;br /&gt;
** Relate#Download_and_Installation|Download&lt;br /&gt;
** Relate#Manual|Manual&lt;br /&gt;
** Relate#Citation|citation&lt;br /&gt;
** Relate#Change_log|Log&lt;br /&gt;
* BAMSE&lt;br /&gt;
** BAMSE| Bayesian Association of multiple SNPs&lt;br /&gt;
* CATS&lt;br /&gt;
** CATS|power for two stage GWAS&lt;br /&gt;
* NGSadmix&lt;br /&gt;
**ngsAdmix|Population Structure for NGS data&lt;br /&gt;
** NgsAdmix#Installation|Download&lt;br /&gt;
** NgsAdmix#Run_example | Example&lt;br /&gt;
** NgsAdmix#Input_Files| Input files&lt;br /&gt;
** NgsAdmix#citation|Citation&lt;br /&gt;
** NgsAdmix#log|Log&lt;br /&gt;
* fastNGSadmix&lt;br /&gt;
** fastNgsAdmix#Installation|Download&lt;br /&gt;
** fastNgsAdmix#Run_example | Example&lt;br /&gt;
** fastNgsAdmix#Input_Files| Input files&lt;br /&gt;
** fastNgsAdmix#citation|Citation&lt;br /&gt;
** fastNgsAdmix#log|Log&lt;br /&gt;
* relateAdmix&lt;br /&gt;
** relateAdmix|Relatedness estimation for admixed individuals&lt;br /&gt;
** relateAdmix#Installation|Download&lt;br /&gt;
** relateAdmix#Run_example | Example&lt;br /&gt;
* LDadmix&lt;br /&gt;
* R scripts&lt;br /&gt;
** Rscripts| various R scripts&lt;br /&gt;
* navigation&lt;br /&gt;
** mainpage|Software&lt;br /&gt;
** http://popgen.dk|Popgen.dk&lt;br /&gt;
** http://popgen.dk/wiki|ANGSD&lt;br /&gt;
* SEARCH&lt;br /&gt;
* TOOLBOX&lt;br /&gt;
* LANGUAGES&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
	<entry>
		<id>https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=442</id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href="https://www.popgen.dk/software/index.php?title=MediaWiki:Sidebar&amp;diff=442"/>
		<updated>2015-06-19T22:05:03Z</updated>

		<summary type="html">&lt;p&gt;Thorfinn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Main&lt;br /&gt;
* ANGSD&lt;br /&gt;
** http://popgen.dk/wiki|website&lt;br /&gt;
* NgsRelate | NgsRelate&lt;br /&gt;
* Relate&lt;br /&gt;
** Relate|Local IBD relatedness&lt;br /&gt;
** Relate#Download_and_Installation|Download&lt;br /&gt;
** Relate#Manual|Manual&lt;br /&gt;
** Relate#Citation|citation&lt;br /&gt;
** Relate#Change_log|Log&lt;br /&gt;
* BAMSE&lt;br /&gt;
** BAMSE| Bayesian Association of multiple SNPs&lt;br /&gt;
* CATS&lt;br /&gt;
** CATS|power for two stage GWAS&lt;br /&gt;
* NGSadmix&lt;br /&gt;
**ngsAdmix|Population Structure for NGS data&lt;br /&gt;
** NgsAdmix#Installation|Download&lt;br /&gt;
** NgsAdmix#Run_example | Example&lt;br /&gt;
** NgsAdmix#Input_Files| Input files&lt;br /&gt;
** NgsAdmix#citation|Citation&lt;br /&gt;
** NgsAdmix#log|Log&lt;br /&gt;
* fastNGSadmix&lt;br /&gt;
** fastNgsAdmix#Installation|Download&lt;br /&gt;
** fastNgsAdmix#Run_example | Example&lt;br /&gt;
** fastNgsAdmix#Input_Files| Input files&lt;br /&gt;
** fastNgsAdmix#citation|Citation&lt;br /&gt;
** fastNgsAdmix#log|Log&lt;br /&gt;
* relateAdmix&lt;br /&gt;
** relateAdmix|Relatedness estimation for admixed individuals&lt;br /&gt;
** relateAdmix#Installation|Download&lt;br /&gt;
** relateAdmix#Run_example | Example&lt;br /&gt;
* LDadmix&lt;br /&gt;
* R scripts&lt;br /&gt;
** Rscripts| various R scripts&lt;br /&gt;
* navigation&lt;br /&gt;
** mainpage|Software&lt;br /&gt;
** http://popgen.dk|Popgen.dk&lt;br /&gt;
** http://popgen.dk/wiki|ANGSD&lt;br /&gt;
* SEARCH&lt;br /&gt;
* TOOLBOX&lt;br /&gt;
* LANGUAGES&lt;/div&gt;</summary>
		<author><name>Thorfinn</name></author>
	</entry>
</feed>