folded version
parent
598fb21351
commit
0e25049a58
|
|
@ -11,31 +11,40 @@ import sys
|
||||||
|
|
||||||
# default folded SFS
|
# default folded SFS
|
||||||
folded = True
|
folded = True
|
||||||
|
diploid = True
|
||||||
|
|
||||||
|
# PARAM : Nb of indiv
|
||||||
|
n = int(sys.argv[2])
|
||||||
|
|
||||||
|
if diploid and not folded:
|
||||||
|
n *= 2
|
||||||
|
|
||||||
|
SFS_values = dict.fromkeys(range(n),0)
|
||||||
|
|
||||||
|
|
||||||
with gzip.open(sys.argv[1], "rb") as inputgz:
|
with gzip.open(sys.argv[1], "rb") as inputgz:
|
||||||
line = inputgz.readline()
|
line = inputgz.readline()
|
||||||
genotypes = []
|
genotypes = []
|
||||||
SFS_values = {}
|
#SFS_values = {}
|
||||||
while line:
|
while line:
|
||||||
line = line.decode('utf-8').strip()
|
line = line.decode('utf-8').strip()
|
||||||
if not line.startswith("##") and not line.startswith("#"):
|
if not line.startswith("##") and not line.startswith("#"):
|
||||||
FORMAT = line.split("\t")[8:9]
|
FORMAT = line.split("\t")[8:9]
|
||||||
SAMPLES = line.split("\t")[9:]
|
SAMPLES = line.split("\t")[9:]
|
||||||
snp_genotypes = []
|
snp_genotypes = []
|
||||||
|
allele_counts = {}
|
||||||
for sample in SAMPLES:
|
for sample in SAMPLES:
|
||||||
# for UNPHASED data
|
# for UNPHASED data
|
||||||
smpl_genotype = [int(a) for a in sample.split(':')[0].split('/') if a != '.']
|
smpl_genotype = [int(a) for a in sample.split(':')[0].split('/') if a != '.']
|
||||||
#if not folded:
|
nb_alleles = set(smpl_genotype)
|
||||||
|
snp_genotypes += smpl_genotype
|
||||||
print(smpl_genotype)
|
for k in set(snp_genotypes):
|
||||||
nb_alleles = len(set(smpl_genotype))
|
allele_counts[snp_genotypes.count(k)] = k
|
||||||
snp_genotypes.append(nb_alleles)
|
if folded :
|
||||||
print(snp_genotypes)
|
for count in allele_counts.keys():
|
||||||
nb_derived_allele = len([val for val in snp_genotypes if val != 0])
|
if count <= len(snp_genotypes)/2 :
|
||||||
print("nb derived allele", nb_derived_allele)
|
SFS_values[count-1] += 1
|
||||||
if nb_derived_allele not in SFS_values.keys():
|
|
||||||
SFS_values[nb_derived_allele] = 1
|
|
||||||
else:
|
else:
|
||||||
SFS_values[nb_derived_allele] += 1
|
SFS_values[len(snp_genotypes)-count] += 1
|
||||||
line = inputgz.readline()
|
line = inputgz.readline()
|
||||||
print(SFS_values)
|
print(SFS_values)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue