From d43c2d3ecfa6f6b2dafd7848b53943ad890a968d Mon Sep 17 00:00:00 2001 From: JeanMainguy Date: Tue, 19 Dec 2023 18:22:31 +0100 Subject: [PATCH] mv call of metadata_sources out of loops to be faster --- ppanggolin/formats/writeFlatPangenome.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ppanggolin/formats/writeFlatPangenome.py b/ppanggolin/formats/writeFlatPangenome.py index 6d6b0451..6bba6539 100644 --- a/ppanggolin/formats/writeFlatPangenome.py +++ b/ppanggolin/formats/writeFlatPangenome.py @@ -238,6 +238,8 @@ def write_gexf_nodes(gexf: TextIO, light: bool = True, soft_core: False = 0.95): 'cloud': 'a="0" b="255" g="222" r="121"'} if not light: index = pan.get_org_index() + + pan_metadata_sources = pan.metadata_sources("families") for fam in pan.gene_families: name = Counter() @@ -276,7 +278,7 @@ def write_gexf_nodes(gexf: TextIO, light: bool = True, soft_core: False = 0.95): gexf.write(f' \n') shift = 14 source_fields = {m.source: m.fields for f in pan.gene_families if len(list(f.metadata)) > 0 for m in f.metadata} - for source_metadata_families in pan.metadata_sources("families"): + for source_metadata_families in pan_metadata_sources: to_concat = defaultdict(list) for m in fam.metadata: if m.source == source_metadata_families: @@ -307,7 +309,7 @@ def write_gexf_edges(gexf: TextIO, light: bool = True): edgeids = 0 index = pan.get_org_index() shift = 14 - + metadata_count = len(pan.metadata_sources("families")) for edge in pan.edges: gexf.write(f' \n') @@ -316,8 +318,7 @@ def write_gexf_edges(gexf: TextIO, light: bool = True): gexf.write(f' \n') if not light: for org, genes_pairs in edge.get_organisms_dict().items(): - gexf.write( - f' \n') + gexf.write(f' \n') gexf.write(' \n') gexf.write(' \n') edgeids += 1