def color_pedigree(pedobj, metric='descendants', places=2, drawer='new', **kw): """ color_pedigree() forms a graph object from a pedigree object and determines the proportion of animals in a pedigree that are descendants of each animal in the pedigree. The results will be used to feed draw_colored_pedigree(). """ _dprop = {} if metric == 'descendants': _pedgraph = pyp_network.ped_to_graph(pedobj) # Walk the pedigree and compute proportion of animals in the pedigree that are # descended from each animal. for _p in pedobj.pedigree: _dcount = pyp_network.find_descendants(_pedgraph, _p.animalID, []) if len(_dcount) < 1: _dprop[_p.animalID] = 0.0 else: _dprop[_p.animalID] = round( float(len(_dcount)) / float(pedobj.metadata.num_records), places) del (_pedgraph) elif metric == 'sons': for _p in pedobj.pedigree: _dprop[_p.animalID] = float(len(_p.sons)) #print _dprop else: return 0 if drawer == 'new': new_draw_colored_pedigree(pedobj, _dprop, **kw) else: draw_colored_pedigree(pedobj, _dprop, **kw)
def color_pedigree(pedobj, metric='descendants', places=2, drawer='new', **kw): """ color_pedigree() forms a graph object from a pedigree object and determines the proportion of animals in a pedigree that are descendants of each animal in the pedigree. The results will be used to feed draw_colored_pedigree(). """ _dprop = {} if metric == 'descendants': _pedgraph = pyp_network.ped_to_graph(pedobj) # Walk the pedigree and compute proportion of animals in the pedigree that are # descended from each animal. for _p in pedobj.pedigree: _dcount = pyp_network.find_descendants(_pedgraph,_p.animalID,[]) if len(_dcount) < 1: _dprop[_p.animalID] = 0.0 else: _dprop[_p.animalID] = round(float(len(_dcount)) / float(pedobj.metadata.num_records), places) del(_pedgraph) elif metric == 'sons': for _p in pedobj.pedigree: _dprop[_p.animalID] = float(len(_p.sons)) #print _dprop else: return 0 if drawer == 'new': new_draw_colored_pedigree(pedobj, _dprop, **kw) else: draw_colored_pedigree(pedobj, _dprop, **kw)
_gfn = 'simulated_pedigree' _gt = 'Simulated Pedigree %d' % (i) pyp_graphics.draw_pedigree(example, gfilename=_gfn, gtitle=_gt, gformat='ps', garrow=0, gclusters=0) #print 'Animal\tOriginal\tSire\tDam\tSex\tGen' #for _p in example.pedigree: #print '%s\t%s\t\t%s\t%s\t%s\t%s' % ( _p.animalID, _p.originalID, _p.sireID, _p.damID, _p.sex, _p.gen ) #print example.idmap pg = pyp_network.ped_to_graph(example) pgd = networkx.is_directed_acyclic_graph(pg) print 'is_directed_acyclic_graph: %s' % (pgd) pgu = pg.to_undirected() pgc = networkx.is_connected(pgu) print 'is_connected: %s' % (pgc) pgncc = networkx.number_connected_components(pgu) print 'number_connected_components: %s' % (pgncc) ped_deg = pyp_network.get_node_degrees(pg) ped_hist = pyp_network.get_node_degree_histograms(ped_deg) print 'ped_hist:\t' for k, v in ped_hist.iteritems():
from PyPedal.pyp_utils import pyp_nice_time try: import networkx except ImportError: logging.error('The networkx module could not be imported in pyp_network. Routines using networkx functionality are not available.') if __name__=='__main__': print 'Starting pypedal.py at %s' % ( pyp_nice_time() ) print '\tLoading pedigree at %s' % ( pyp_nice_time() ) example = pyp_newclasses.loadPedigree(optionsfile='new_networkx.ini') print 'Calling pyp_network.ped_to_graph()' ng = pyp_network.ped_to_graph(example) # print 'The graph has %d nodes' % len(ng.nodes()) # print ng.nodes() # print ng.edges() # ## print 'Drawing graph madeup.ps' ## networkx.drawing.draw(ng) ## networkx.drawing.savefig("madeup.ps") ## ## print 'Drawing graph madeup.dot' ## networkx.drawing.write_dot(ng,path="madeup.dot") ## networkx.drawing.draw_nxpydot(ng) # # print 'Number of animals in pedigree: %s' % ( ng.order() ) # print ng.nodes()