@@ -83,22 +83,30 @@ def get_representative_hog_for_gene(ham, hogxml_entries):
8383
8484# Create a feature "synteny" that stores a synteny graph for the current extant genome
8585def assign_extant_synteny (genome , gene_dict , ham , orient_edges ):
86- graph = nx .Graph (genome = genome )
86+ graph = nx .Graph (genome = genome )
8787 contiguity_dict = dict ()
8888 gene_keys = list (gene_dict .keys ())
89- old_contig = gene_keys [0 ][0 ]
90- hogxml_entries = gene_dict [gene_keys [0 ]]['hogxml_entries' ]
89+
90+ # find first gene with hogxml_entries, i.e. that is reported in orthoxml
91+ for first , gene_key in enumerate (gene_keys ):
92+ if 'hogxml_entries' in gene_dict [gene_key ]:
93+ break
94+ else :
95+ raise ValueError ('No gene with hogxml_entries found in genome %s' % genome .name )
96+
97+ old_contig = gene_keys [first ][0 ]
98+ hogxml_entries = gene_dict [gene_keys [first ]]['hogxml_entries' ]
9199 old_gene = get_representative_hog_for_gene (ham , hogxml_entries )
92- graph .add_node (old_gene , ** gene_dict [gene_keys [0 ]], contig = old_contig )
93- for i in range (1 , len (gene_keys )):
100+ graph .add_node (old_gene , ** gene_dict [gene_keys [first ]], contig = old_contig )
101+ for i in range (first + 1 , len (gene_keys )):
94102 contig = gene_keys [i ][0 ]
95103 if 'hogxml_entries' in gene_dict [gene_keys [i ]]:
96104 hogs_entries = gene_dict [gene_keys [i ]]['hogxml_entries' ]
97105 gene = get_representative_hog_for_gene (ham , hogs_entries )
98- graph .add_node (gene , ** gene_dict [gene_keys [i ]], contig = contig )
106+ graph .add_node (gene , ** gene_dict [gene_keys [i ]], contig = contig )
99107 if contig == old_contig :
100108 # connect genes only if they are on the same contig
101- graph .add_edge (old_gene , gene , weight = 1 , unidirectional = 0 , convergent = 0 , divergent = 0 , children = [None ], extant_descendants = [None ])
109+ graph .add_edge (old_gene , gene , weight = 1 , unidirectional = 0 , convergent = 0 , divergent = 0 , children = [None ], extant_descendants = [None ])
102110 if orient_edges :
103111 old_gene_strand = gene_dict [gene_keys [i - 1 ]]['strand' ]
104112 gene_strand = gene_dict [gene_keys [i ]]['strand' ]
0 commit comments