Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions edgehog/init_extant_synteny_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def get_representative_hog_for_gene(ham, hogxml_entries):
def assign_extant_synteny(genome, gene_dict, ham, orient_edges):
graph = nx.Graph(genome=genome)
contiguity_dict = dict()
gene_keys = list(gene_dict.keys())
# gffs are not necessarily sorted: order the genes by contig (in order of first appearance in the gff)
# and by genomic coordinates on the contig
contig_rank = dict()
for contig, _ in gene_dict:
contig_rank.setdefault(contig, len(contig_rank))
gene_keys = sorted(gene_dict, key=lambda key: (contig_rank[key[0]], gene_dict[key]['start'], gene_dict[key]['end']))

# find first gene with hogxml_entries, i.e. that is reported in orthoxml
for first, gene_key in enumerate(gene_keys):
Expand All @@ -110,7 +115,8 @@ def assign_extant_synteny(genome, gene_dict, ham, orient_edges):
else:
raise ValueError('No gene with hogxml_entries found in genome %s' % genome.name)

old_contig = gene_keys[first][0]
old_key = gene_keys[first]
old_contig = old_key[0]
hogxml_entries = gene_dict[gene_keys[first]]['hogxml_entries']
old_gene = get_representative_hog_for_gene(ham, hogxml_entries)
graph.add_node(old_gene, **gene_dict[gene_keys[first]], contig=old_contig)
Expand All @@ -124,7 +130,8 @@ def assign_extant_synteny(genome, gene_dict, ham, orient_edges):
# connect genes only if they are on the same contig
graph.add_edge(old_gene, gene, weight=1, unidirectional=0, convergent=0, divergent=0, children=[None], extant_descendants=[None])
if orient_edges:
old_gene_strand = gene_dict[gene_keys[i-1]]['strand']
# strand of the previous gene in the orthoxml, not of a skipped gene in between
old_gene_strand = gene_dict[old_key]['strand']
gene_strand = gene_dict[gene_keys[i]]['strand']
try:
if old_gene_strand == gene_strand:
Expand All @@ -135,7 +142,7 @@ def assign_extant_synteny(genome, gene_dict, ham, orient_edges):
graph[old_gene][gene]['divergent'] = 1
except:
pass
old_gene, old_contig = gene, contig
old_gene, old_contig, old_key = gene, contig, gene_keys[i]
# for cc in nx.connected_components(graph):
# if len(cc > 1):
# for i in range(0, len(cc)):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "edgehog"
version = "0.1.10"
version = "0.1.11"
description = "Infering ancestral synteny with hierarchical orthologous groups"
authors = [
{name="Charles Bernard", email="charles.bernard@unil.ch"},
Expand Down
3 changes: 0 additions & 3 deletions tests/test_extant_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def test_find_gff_files(tmp_path):
# features by contig and start coordinate (read_gff.py:100-117,
# init_extant_synteny_graphs.py:88).

@pytest.mark.xfail(strict=True, reason="#6: unsorted GFFs give wrong adjacencies")
def test_unsorted_gff(tmp_path):
gff = write_gff(tmp_path / "SP.gff",
gene("chr1", 100, 200, "+", "g1", "p1"),
Expand All @@ -131,7 +130,6 @@ def test_unsorted_gff(tmp_path):
assert edge_set(build_graph(gff, ["p1", "p2", "p3"])) == edges("p1-p2", "p2-p3")


@pytest.mark.xfail(strict=True, reason="#6: contigs interleaved in the GFF lose adjacencies")
def test_interleaved_contigs(tmp_path):
gff = write_gff(tmp_path / "SP.gff",
gene("chr1", 100, 200, "+", "g1", "p1"),
Expand All @@ -144,7 +142,6 @@ def test_interleaved_contigs(tmp_path):
# previous linked gene if a gene missing from the orthoXML lies in between
# (init_extant_synteny_graphs.py:111).

@pytest.mark.xfail(strict=True, reason="#7: orientation uses the strand of a skipped gene")
def test_orientation_ignores_skipped_gene(tmp_path):
gff = write_gff(tmp_path / "SP.gff",
gene("chr1", 100, 200, "+", "g1", "p1"),
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading