Skip to content

Commit

Permalink
Add graph title
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Apr 28, 2024
1 parent 2dd51d4 commit a12ce37
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions jcvi/compara/pedigree.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ def _check(self):
self[s] = Sample(s, None, None)
self.terminal_nodes = terminal_nodes

def to_graph(self, inbreeding_dict: Dict[str, SampleInbreeding]) -> nx.DiGraph:
def to_graph(
self, inbreeding_dict: Dict[str, SampleInbreeding], title: str = ""
) -> nx.DiGraph:
"""
Convert the pedigree to a graph.
"""
graph_styles = {"splines": "curved"}
edge_styles = {"color": "lightslategray", "arrowhead": "none"}
graph_styles = {"labelloc": "b", "label": title, "splines": "curved"}
edge_styles = {"arrowhead": "none", "color": "lightslategray"}
G = nx.DiGraph(**graph_styles)
for s in self:
dad, mom = self[s].dad, self[s].mom
Expand Down Expand Up @@ -238,6 +240,7 @@ def pedigree(args):
p = OptionParser(pedigree.__doc__)
p.add_option("--ploidy", default=2, type="int", help="Ploidy")
p.add_option("--N", default=10000, type="int", help="Number of samples")
p.add_option("--title", default="", help="Title of the graph")
opts, args = p.parse_args(args)

if len(args) != 1:
Expand All @@ -250,7 +253,7 @@ def pedigree(args):
for _, v in inb.items():
print(v)

G = ped.to_graph(inb)
G = ped.to_graph(inb, title=opts.title)
dotfile = f"{pedfile}.dot"
nx.nx_agraph.write_dot(G, dotfile)
pdf_file = dotfile + ".pdf"
Expand Down

0 comments on commit a12ce37

Please sign in to comment.