def hapinitial(allele): #Edge counts are used. Count of edge/Total count for all edges. for i in G.out_edges(1, data=True): if i[2]['allele'] == allele: return sum(G.node[i[1]]['frequency'])/sum(G.node[1]['frequency'])
import math import numpy as np import itertools from v3 import G, glevel #ll is number of levels in the graph ll = len(glevel) -1 print "ll" print ll #Set the genotype GT = [('?','?'),(1,1),(1,2),(1,2)] #Create n the list of the number of edges in each level n = [G.out_degree(1)] #m is the list of matrices of forward probabilities at each level m = [np.zeros(shape=(n[0],n[0]))] #Append matrices to list m for i in range(ll-1): #Sum n for each level n.append(G.out_degree(glevel[i]+1)) for j in range(glevel[i]+2, glevel[i+1]+1): n[i+1] += G.out_degree(j) #Append zero-filled matrix to list m m.append(np.zeros(shape=(n[i+1],n[i+1]))) #Haploid initial state probabilities. allele: allele number.