<commit_before>#include "genotype.h"

const std::vector<char> Genotype::alleles = {'A','T','G','C'};

Genotype::Genotype(std::string gtstr) : gt(), ploidy(0) {
	for(auto it = gtstr.begin(); it != gtstr.end(); ++it){
		++gt[*it];
		ploidy+=1;
	}
}

Genotype::Genotype(std::map<char,int> gt) : gt(gt), ploidy(0) {
	for(auto it = gt.begin(); it!= gt.end(); ++it){
		ploidy += it->second;
	}
}

int Genotype::numbase(char n){
	return gt[n];
}

int Genotype::numnotbase(char n){
	return ploidy - gt[n];
}

int Genotype::getploidy(){
	return ploidy;
}

//check out http://genome.sph.umich.edu/wiki/Relationship_between_Ploidy,_Alleles_and_Genotypes
void Genotype::enumerate_gts(std::vector<Genotype> &v, int stopallele, unsigned int ploidy, std::string genotype){
	if (genotype.length() == ploidy){
		v.push_back(Genotype(genotype));
	}
	else{
		for (int i = 0; i < stopallele; ++i){
			std::string s(1,alleles[i]);
			s.append(genotype);
			enumerate_gts(v,i+1, ploidy, s);
		}
	}
}

double Genotype::p_finite_alleles(char ref, double ref_weight, double theta, std::map<char,double> pi){
	double p = 1.0;
	for (auto it = gt.begin(); it != gt.end(); ++it){
		char allele = it->first;
		int count = it->second;
		double w = (ref == allele ? ref_weight : 0);
		for (int i = 0; i < count; ++i){
			p *= (w + theta * pi[allele] + i);
		}
	}
}

std::vector<Genotype> Genotype::enumerate_gts(int ploidy){
	std::vector<Genotype> v;
	enumerate_gts(v,alleles.size(),ploidy,std::string());
	return v;
}

std::string Genotype::to_string() const{
	std::string s;
	for(auto it = gt.begin(); it != gt.end(); ++it){
		s.append(it->second,it->first);
	}
	return s;
}

std::ostream& operator<<(std::ostream& os, const Genotype gt){
	return os << gt.to_string();
}


<commit_msg>add probability of gt under finite alleles model<commit_after>#include "genotype.h"

const std::vector<char> Genotype::alleles = {'A','T','G','C'};

Genotype::Genotype(std::string gtstr) : gt(), ploidy(0) {
	for(auto it = gtstr.begin(); it != gtstr.end(); ++it){
		++gt[*it];
		ploidy+=1;
	}
}

Genotype::Genotype(std::map<char,int> gt) : gt(gt), ploidy(0) {
	for(auto it = gt.begin(); it!= gt.end(); ++it){
		ploidy += it->second;
	}
}

int Genotype::numbase(char n){
	return gt[n];
}

int Genotype::numnotbase(char n){
	return ploidy - gt[n];
}

int Genotype::getploidy(){
	return ploidy;
}

//check out http://genome.sph.umich.edu/wiki/Relationship_between_Ploidy,_Alleles_and_Genotypes
void Genotype::enumerate_gts(std::vector<Genotype> &v, int stopallele, unsigned int ploidy, std::string genotype){
	if (genotype.length() == ploidy){
		v.push_back(Genotype(genotype));
	}
	else{
		for (int i = 0; i < stopallele; ++i){
			std::string s(1,alleles[i]);
			s.append(genotype);
			enumerate_gts(v,i+1, ploidy, s);
		}
	}
}

double Genotype::p_finite_alleles(char ref, double ref_weight, double theta, std::map<char,double> pi){
	double p = std::tgamma(ploidy + 1);
	int numalleles = 0;
	for (auto it = gt.begin(); it != gt.end(); ++it){
		char allele = it->first;
		int count = it->second;
		double w = (ref == allele ? ref_weight : 0);
		for (int i = 0; i < count; ++i){
			p *= (w + theta * pi[allele] + i) / (w + theta + numalleles);
			numalleles++;
		}
		p /= std::tgamma(count + 1)
	}
	return p;
}

std::vector<Genotype> Genotype::enumerate_gts(int ploidy){
	std::vector<Genotype> v;
	enumerate_gts(v,alleles.size(),ploidy,std::string());
	return v;
}

std::string Genotype::to_string() const{
	std::string s;
	for(auto it = gt.begin(); it != gt.end(); ++it){
		s.append(it->second,it->first);
	}
	return s;
}

std::ostream& operator<<(std::ostream& os, const Genotype gt){
	return os << gt.to_string();
}



{'fraction_non_alphanumeric': 0.20321438300190683, 'fraction_numerical': 0.005720512122037592, 'mean_word_length': 4.755485893416928, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '285188', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1519, 'n_words': 320}