Esempio n. 1
0
def genDiploid(numberofalleles=0):
	"""
	 
	"""
	alleles = numberofalleles
	diploid = (xayastats.diceroll(1,alleles), xayastats.diceroll(1,alleles))
	return diploid # return dipoid as a two item tuple
Esempio n. 2
0
def createRandomDirectedNetwork(nodes=0, edges=0):
    '''Given a number of nodes and edges, generate a random directed graph
    in XAYA format, where each edge is randomly generated. Arcs from a node,
    back into that node are disallowed in the current version. 
    Last modified, Sept, 29, 2009. 
    '''
    #Create an empty network data structure
    network = {}
    #If either nodes or edges are 0/negative, return an empty graph
    if (nodes <=0) or (edges <= 0):
        return network
    # Check that edges < nodes * (nodes-1) -- i.e. a complete graph minus self-arcs
    if edges >  nodes * (nodes - 1):
        return network
    
    #Use while loop to determine when sufficient edges produced
    while countNetworkEdges(network) < edges:
    
        #Generate a node value
        nodevalue = xayastats.diceroll(1,nodes)
        #Generate an Edge value
        edgevalue = xayastats.diceroll(1,nodes)
        #Check for self-loops. If self loop return to top of While 
        if nodevalue != edgevalue:
            #If node does not already exist, add it and value
            if not network.has_key(nodevalue):
                network[nodevalue] = [edgevalue]
            else:
                #Check if value already in an arc, and if not, add it. 
                if edgevalue not in network[nodevalue]:
                    network[nodevalue].append(edgevalue)
    #reversednetwork = xayacore.reverseGraph(network)-- not working as expected
    #undirectednetwork = xayacore.unionGraphs(network, reversednetwork) --nwaexpcted
    return network
Esempio n. 3
0
def genHaploid(numberofalleles= 0):
	"""
	Given a number of sex alleles, randomly generate a haploid genotype.
	"""
	#Set internal variable from parameters
	alleles = numberofalleles
	# Randomly generate haploid
	haploid = xayastats.diceroll(1, alleles)
	return (haploid) # return haploid as a 1 item tuple
Esempio n. 4
0
def NOTWORKINGcreateRandomUndirectedNetwork(nodes=0, edges=0):
    '''Given a number of nodes and edges, generate a random undirected graph
    (as pairs of edges in a directed graph) where each edge is randomly generated,
    sampling is without replacement -- so no edge is generated twice. 
    '''
    #Create an empty network data structure
    network = {}
    #Set EdgeCounter to 0
    edgecounter = 0
    # Start Node and Edge Generation loop
    while edgecounter < edges:
        #Generate a node value
        nodevalue = xayastats.diceroll(1,nodes)
        #Generate an Edge value
        edgevalue = xayastats.diceroll(1,nodes)
        # Check if network has node and edge values already -- bidirectional
        # Check forward order
        alreadyin = 0
        if network.has_key(nodevalue):
            if edgevalue in network[nodevalue]:
                alreadyin = 1
        # Check Reverse Order
        if network.has_key(edgevalue):
            if nodevalue in network[edgevalue]:
                alreadyin = 1
        # If arc does not exist already
        if alreadyin != 1:
            #If node does not already exist, add it and value and iterate counter
            if not network.has_key(nodevalue):
                network[nodevalue] = [edgevalue]
                edgecounter = edgecounter + 1
            # Otherwise add the value and iterate counter
            else: network[nodevalue].append(edgevalue)
            edgecounter = edgecounter + 1
        
    else: return network