Skip to content

Commit

Permalink
a few minor code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Aug 1, 2024
1 parent d49dd5d commit fbd029c
Show file tree
Hide file tree
Showing 51 changed files with 33 additions and 103 deletions.
1 change: 0 additions & 1 deletion ppanggolin/RGP/genomicIsland.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
6 changes: 2 additions & 4 deletions ppanggolin/RGP/rgp_cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down Expand Up @@ -101,8 +100,7 @@ def genes(self):
Return iterable of genes from all RGPs that are identical in families
"""
for rgp in self.rgps:
for gene in rgp.genes:
yield gene
yield from rgp.genes
@property
def spots(self) -> Set[Spot]:
"""
Expand Down Expand Up @@ -283,7 +281,7 @@ def add_info_to_identical_rgps(rgp_graph: nx.Graph, identical_rgps_objects: List
name=identical_rgp_obj.name,
families_count=len(identical_rgp_obj.families),
identical_rgp_count=len(identical_rgp_obj.rgps),
identical_rgp_names=';'.join([i_rgp.name for i_rgp in identical_rgp_obj.rgps]),
identical_rgp_names=';'.join(i_rgp.name for i_rgp in identical_rgp_obj.rgps),
identical_rgp_genomes=';'.join({i_rgp.organism.name for i_rgp in identical_rgp_obj.rgps}),
identical_rgp_contig_border_count=len(
[True for i_rgp in identical_rgp_obj.rgps if i_rgp.is_contig_border]),
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/align/alignOnPang.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import time
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/annotate/annotate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/annotate/synta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/cluster/cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/context/searchGeneContext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
4 changes: 1 addition & 3 deletions ppanggolin/edge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding: utf8

# default libraries
from collections import defaultdict
Expand Down Expand Up @@ -50,8 +49,7 @@ def organisms(self) -> Generator[Organism, None, None]:
:return: Generator with organisms as the key and an iterable of the gene pairs as value
"""
for organism in self._organisms.keys():
yield organism
yield from self._organisms.keys()

@property
def number_of_organisms(self) -> int:
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/figures/draw_spot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8


# default libraries
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/figures/drawing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/figures/tile_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
4 changes: 1 addition & 3 deletions ppanggolin/formats/readBinaries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down Expand Up @@ -152,8 +151,7 @@ def read_chunks(table: tables.Table, column: str = None, chunk: int = 10000):
:param chunk:
"""
for i in range(0, table.nrows, chunk):
for row in table.read(start=i, stop=i + chunk, field=column):
yield row
yield from table.read(start=i, stop=i + chunk, field=column)


def read_genedata(h5f: tables.File) -> Dict[int, Genedata]:
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/writeAnnotations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/writeBinaries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/writeFlatGenomes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/writeFlatMetadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/writeFlatPangenome.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
3 changes: 1 addition & 2 deletions ppanggolin/formats/writeMSA.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down Expand Up @@ -123,7 +122,7 @@ def write_fasta_families(family: GeneFamily, tmpdir: tempfile.TemporaryDirectory

# get genes that are present in only one copy for our family in each organism.
single_copy_genes = []
for _, genes in family.get_org_dict().items():
for genes in family.get_org_dict().values():
if len(genes) == 1:
single_copy_genes.extend(genes)

Expand Down
3 changes: 1 addition & 2 deletions ppanggolin/formats/writeMetadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down Expand Up @@ -58,7 +57,7 @@ def write_metadata_status(pangenome: Pangenome, h5f: tables.File, status_group:
metadata_group._v_attrs.modules = True
metasources_group._v_attrs.modules = metasources["modules"]

return True if any(metadata_group._v_attrs._f_list()) else False
return any(metadata_group._v_attrs._f_list())


def write_metadata_group(h5f: tables.File, metatype: str) -> tables.Group:
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/writeSequences.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/formats/write_proksee.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import json
Expand Down
24 changes: 7 additions & 17 deletions ppanggolin/geneFamily.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding: utf8

# default libraries
from __future__ import annotations
Expand Down Expand Up @@ -259,26 +258,23 @@ def edges(self) -> Generator[Edge, None, None]:
:return: Edges of the gene family
"""
for edge in self._edges_getter.values():
yield edge
yield from self._edges_getter.values()

@property
def neighbors(self) -> Generator[GeneFamily, None, None]:
"""Returns all the GeneFamilies that are linked with an edge
:return: Neighbors
"""
for neighbor in self._edges_getter.keys():
yield neighbor
yield from self._edges_getter.keys()

@property
def genes(self):
"""Return all the genes belonging to the family
:return: Generator of genes
"""
for gene in self._genes_getter.values():
yield gene
yield from self._genes_getter.values()

@property
def organisms(self) -> Generator[Organism, None, None]:
Expand All @@ -288,17 +284,15 @@ def organisms(self) -> Generator[Organism, None, None]:
"""
if len(self._genePerOrg) == 0:
_ = self.get_org_dict()
for org in self._genePerOrg.keys():
yield org
yield from self._genePerOrg.keys()

@property
def spots(self) -> Generator[Spot, None, None]:
"""Return all the spots belonging to the family
:return: Generator of spots
"""
for spot in self._spots:
yield spot
yield from self._spots

@property
def module(self) -> Module:
Expand Down Expand Up @@ -446,8 +440,7 @@ def get_genes_per_org(self, org: Organism) -> Generator[Gene, None, None]:
_ = self.get_org_dict()
if org not in self._genePerOrg:
raise KeyError(f"Genome does not have the gene family: {self.name}")
for gene in self._genePerOrg[org]:
yield gene
yield from self._genePerOrg[org]


def is_single_copy(self, dup_margin: float, exclude_fragment: bool) -> bool:
Expand All @@ -459,10 +452,7 @@ def is_single_copy(self, dup_margin: float, exclude_fragment: bool) -> bool:
:return: A boolean indicating whether the gene family is single copy.
"""

if self.duplication_ratio(exclude_fragment) < dup_margin:
return True
else:
return False
return self.duplication_ratio(exclude_fragment) < dup_margin

def duplication_ratio(self, exclude_fragment: bool) -> bool:
"""
Expand Down
3 changes: 1 addition & 2 deletions ppanggolin/genome.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding: utf8

from __future__ import annotations
import logging
Expand Down Expand Up @@ -230,7 +229,7 @@ def string_coordinates(self) -> str:
"""
Return a string representation of the coordinates
"""
return ','.join([f'{start}..{stop}' for start, stop in self.coordinates])
return ','.join(f'{start}..{stop}' for start, stop in self.coordinates)

def start_relative_to(self, gene):
"""
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/graph/makeGraph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/info/info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import sys
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/meta/meta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
8 changes: 3 additions & 5 deletions ppanggolin/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding: utf8

# default libraries
import logging
Expand Down Expand Up @@ -119,8 +118,7 @@ def metadata(self) -> Generator[Metadata, None, None]:
"""

for meta_dict in self._metadata_getter.values():
for metadata in meta_dict.values():
yield metadata
yield from meta_dict.values()

@property
def sources(self) -> Generator[str, None, None]:
Expand Down Expand Up @@ -260,7 +258,7 @@ def has_metadata(self) -> bool:
:return: True if it has metadata else False
"""

return True if self.number_of_metadata > 0 else False
return self.number_of_metadata > 0

def has_source(self, source: str) -> bool:
"""Check if the source is in the metadata feature
Expand All @@ -269,4 +267,4 @@ def has_source(self, source: str) -> bool:
:return: True if the source is in the metadata feature else False
"""
return True if source in self._metadata_getter else False
return source in self._metadata_getter
1 change: 0 additions & 1 deletion ppanggolin/metrics/fluidity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/metrics/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/mod/module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down
3 changes: 1 addition & 2 deletions ppanggolin/nem/partition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import logging
Expand Down Expand Up @@ -166,7 +165,7 @@ def run_partitioning(nem_dir_path: Path, nb_org: int, beta: float = 2.5, free_di
partitions_list[i] = "S_" # SHELL in case of doubt gene families is attributed to shell
else:
partitions_list[i] = parti[positions_max_prob.pop()]
except IOError:
except OSError:
logging.getLogger("PPanGGOLiN").debug(
"partitioning did not work (the number of genomes used is probably too low), "
"see logs here to obtain more details " + nem_dir_path.as_posix() + "/nem_file_" +
Expand Down
1 change: 0 additions & 1 deletion ppanggolin/nem/rarefaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# coding:utf-8

# default libraries
import argparse
Expand Down
Loading

0 comments on commit fbd029c

Please sign in to comment.