Skip to content

Commit

Permalink
style: fit to PEP
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Feb 16, 2023
1 parent fc9283e commit 7acf26c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rrparser/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _add_arguments(parser):
parser.add_argument(
'--rules-dir',
default=__PACKAGE_FOLDER,
help=('Path to the rules directory (default in package directory).')
help='Path to the rules directory (default in package directory).'
)

return parser
39 changes: 21 additions & 18 deletions rrparser/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
QUOTE_NONE
)
from typing import (
Dict,
List,
Tuple
Tuple,
Literal
)
from logging import (
Logger,
Expand All @@ -38,7 +38,7 @@
)


RETRORULES_URL = 'https://zenodo.org/record/5828017/files/retrorules_rr02_rp2_hs.tar.gz'
RETRORULES_URL = 'https://zenodo.org/record/5828017/files/retrorules_rr02_rp2_hs.tar.gz'


def parse_rules(
Expand All @@ -50,14 +50,16 @@ def parse_rules(
diameters: str = '2,4,6,8,10,12,14,16',
output_format: str = 'csv',
logger: Logger = getLogger(__name__)
) -> None or str:
) -> None or str:
"""
Parse a reaction rules file and extract sub-part according 'diameters' and 'rule_type' filters.
Parameters
----------
rules_file: str
Reactions file (if not set RetroRules are considered)
rules_dir: str
Directory where to store RetroRules (if not set RetroRules are stored in the current directory)
outfile: str
Filename where to write results (if not set results are returned as a string)
input_format: str
Expand Down Expand Up @@ -93,18 +95,18 @@ def parse_rules(
# Read 'csv' as 'tsv' by specying separator
rf = read_csv(
rules_file,
sep = sep,
float_precision = 'round_trip'
sep=sep,
float_precision='round_trip'
)

# Filter rules according to 'rule_type' and 'diameters'
results = filter(rf, rule_type, diameters)

return results.to_csv(
outfile,
index = False,
sep = sep,
quoting = quoting
index=False,
sep=sep,
quoting=quoting
)


Expand Down Expand Up @@ -135,15 +137,14 @@ def filter(
"""
logger.debug(
'Args: {df}, {rt}, {dia}'.format(
df = df,
rt = rule_type,
dia = diameters
df=df,
rt=rule_type,
dia=diameters
)
)
query = 'Diameter == @diameters'
if rule_type!='all':
query += ' & `Rule usage` == @rule_usage_filter'
rule_usage_filter = ['both', rule_type]
try:
return df.query(query)
except UndefinedVariableError as e:
Expand All @@ -159,6 +160,8 @@ def fetch_retrorules(
Parameters
----------
rules_dir: str
Directory where to store RetroRules (if not set RetroRules are stored in the current directory)
logger : Logger
The logger object.
Expand Down Expand Up @@ -187,7 +190,7 @@ def check_args(
input_format: str,
output_format: str,
logger: Logger = getLogger(__name__)
) -> Tuple[List[int], str, str]:
) -> Tuple[List[int], str, Literal]:
"""
Check arguments are well-formed and format them.
Expand All @@ -213,10 +216,10 @@ def check_args(
"""
logger.debug(
'Args: {rt}, {dia}, {i_f}, {o_f}'.format(
rt = rule_type,
dia = diameters,
i_f = input_format,
o_f = output_format
rt=rule_type,
dia=diameters,
i_f=input_format,
o_f=output_format
)
)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def get_version():
'CHANGELOG.md'
),
'r'
) as f:
lines = f.readlines()
) as f1:
lines = f1.readlines()
for line in lines:
if line.startswith('##'):
from re import search
Expand Down

0 comments on commit 7acf26c

Please # to comment.