// File: auton1[P]viterbi/entry_filters.cpp
// Function: entry::filter_sites_by_frequency_and_call_rate(double, double, double, double, double)
void entry::filter_sites_by_frequency_and_call_rate(double min_maf, double max_maf, double min_non_ref_af, double max_non_ref_af, double min_site_call_rate)
{
	// Filter sites so that all allele frequencies are between limits
	if (passed_filters == false)
		return;

	if ((min_maf <= 0.0) && (max_maf >= 1.0) && (min_site_call_rate <= 0) && (min_non_ref_af <= 0.0) && (max_non_ref_af >= 1.0))
		return;

	unsigned int N_alleles;
	unsigned int N_non_missing_chr;
	parse_basic_entry(true);
	parse_genotype_entries(true);

	if (GT_idx == -1)
		LOG.error("Require Genotypes in variant file to filter by frequency and/or call rate");

	N_alleles = get_N_alleles();

	vector<int> allele_counts;
	get_allele_counts(allele_counts, N_non_missing_chr);

	double freq, folded_freq;
	double maf=numeric_limits<double>::max();
	for (unsigned int ui=0; ui<N_alleles; ui++)
	{
		freq = allele_counts[ui] / (double)N_non_missing_chr;
		folded_freq = min(freq, 1.0 - freq);

		maf = min(maf, folded_freq);
		if ((ui > 0) && ((freq < min_non_ref_af) || (freq > max_non_ref_af)))
			passed_filters = false;
	}

	if ((maf < min_maf) || (maf > max_maf))
		passed_filters = false;

	double call_rate = N_non_missing_chr / double(get_N_chr());

	if (call_rate < min_site_call_rate)
		passed_filters = false;
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movsd %xmm0, 0xe8(%rsp)
movsd %xmm1, 0xe0(%rsp)
movsd %xmm2, 0xd8(%rsp)
movsd %xmm3, 0xd0(%rsp)
movsd %xmm4, 0xc8(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x38(%rsp)
movb 0xc(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5dd8b
jmp 0x5e0be
xorps %xmm0, %xmm0
ucomisd 0xe8(%rsp), %xmm0
jb 0x5dde8
movsd 0xe0(%rsp), %xmm0
movsd 0x1626e(%rip), %xmm1    # 0x74018
ucomisd %xmm1, %xmm0
jb 0x5dde8
xorps %xmm0, %xmm0
ucomisd 0xc8(%rsp), %xmm0
jb 0x5dde8
xorps %xmm0, %xmm0
ucomisd 0xd8(%rsp), %xmm0
jb 0x5dde8
movsd 0xd0(%rsp), %xmm0
movsd 0x1623b(%rip), %xmm1    # 0x74018
ucomisd %xmm1, %xmm0
jb 0x5dde8
jmp 0x5e0be
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq *0x10(%rax)
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
xorl %r8d, %r8d
movl %r8d, %edx
movl %r8d, %ecx
callq *0x28(%rax)
movq 0x38(%rsp), %rax
cmpl $-0x1, 0x630(%rax)
jne 0x5ded4
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x69f0
movq 0x30(%rsp), %rdx
leaq 0x17ee5(%rip), %rsi     # 0x75d2a
leaq 0xa0(%rsp), %rdi
callq 0x67c0
jmp 0x5de54
leaq 0x357a5(%rip), %rdi     # 0x93600
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
callq 0x712f0
jmp 0x5de6f
leaq 0xa0(%rsp), %rdi
callq 0x6b50
leaq 0x9f(%rsp), %rdi
callq 0x65f0
jmp 0x5ded4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x5dec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x6b50
leaq 0x9f(%rsp), %rdi
callq 0x65f0
jmp 0x5e0c6
movq 0x38(%rsp), %rdi
callq 0x4c290
movl %eax, 0xc4(%rsp)
leaq 0x70(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xea00
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x4c3c0
jmp 0x5df0d
callq 0xf250
movsd %xmm0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0xc4(%rsp), %eax
jae 0x5e02a
movl 0x54(%rsp), %eax
movl %eax, %esi
leaq 0x70(%rsp), %rdi
callq 0xecf0
cvtsi2sdl (%rax), %xmm0
movl 0xc0(%rsp), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm1
movsd 0x160af(%rip), %xmm0    # 0x74018
subsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x5f2c0
movq %rax, 0x20(%rsp)
jmp 0x5df89
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x5f2c0
movq %rax, 0x18(%rsp)
jmp 0x5dfae
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
cmpl $0x0, 0x54(%rsp)
jbe 0x5e018
movsd 0x68(%rsp), %xmm1
movsd 0xd8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5dfea
movsd 0x68(%rsp), %xmm0
ucomisd 0xd0(%rsp), %xmm0
jbe 0x5e018
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
jmp 0x5e018
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0xed70
jmp 0x5e0c6
jmp 0x5e01a
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x5df20
movsd 0x58(%rsp), %xmm1
movsd 0xe8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5e050
movsd 0x58(%rsp), %xmm0
ucomisd 0xe0(%rsp), %xmm0
jbe 0x5e059
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
movq 0x38(%rsp), %rdi
movl 0xc0(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x4c2f0
movl %eax, 0x14(%rsp)
jmp 0x5e07b
movsd 0x8(%rsp), %xmm0
movl 0x14(%rsp), %eax
movl %eax, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5e0b4
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
leaq 0x70(%rsp), %rdi
callq 0xed70
addq $0xf8, %rsp
retq
movq 0x90(%rsp), %rdi
callq 0x69e0
nopw %cs:(%rax,%rax)