Skip to content

Commit

Permalink
fix to ploidy issue - untested
Browse files Browse the repository at this point in the history
  • Loading branch information
mufernando committed Jan 22, 2020
1 parent dad9479 commit 3800681
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/py/stats_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
from timeit import default_timer as timer
import pandas as pd

def acs_from_ts(ts, n_pops):
def acs_from_multipop_ts(ts):
'''
This function takes a tree sequence, and returns tuple with a list of allele counts for each subpop, and an array of the positions'''
acs=[]
print("entrei nos acs")
hap = allel.HaplotypeArray(ts.genotype_matrix())
geno = hap.to_genotypes(ploidy=1)
geno = hap.to_genotypes(ploidy=2)
print("fiz hap and geno matrix")
for i in range(n_pops):
subpop_indexes = ts.samples(population=i).tolist()
# get the pop for each individual
ind_pops = np.array([i.population for i in ts.individuals()])
for i in range(len(np.unique(ind_pops))):
subpop_indexes = np.where(ind_pops==i)[0].tolist()
acs.append(geno.count_alleles(subpop=subpop_indexes))
print("ja separei os acs per subpop")
pos=np.array([s.position for s in ts.sites()])
Expand Down

1 comment on commit 3800681

@petrelharp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Please sign in to comment.