Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Jul 1, 2024
1 parent 8635189 commit b0e7f8d
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 290 deletions.
84 changes: 60 additions & 24 deletions scripts/check_expansions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
from stranger.resources import repeats_path
from stranger.utils import parse_repeat_file, get_repeat_info


@click.command()
@click.option('-f', '--repeats-file',
type = click.Path(exists=True),
@click.option(
"-f",
"--repeats-file",
type=click.Path(exists=True),
help="Path to a file with repeat definitions. See README for explanation",
default=repeats_path,
show_default=True,
Expand All @@ -19,33 +22,66 @@ def cli(context, repeats_file):
"""Table print repeat info"""

repeat_information = {}
with open(repeats_file, 'r') as file_handle:
repeat_information = parse_repeat_file(file_handle, repeats_file_type='json')
with open(repeats_file, "r") as file_handle:
repeat_information = parse_repeat_file(file_handle, repeats_file_type="json")

if not repeat_information:
LOG.warning("Could not find any repeat info")
context.abort()

header = ["HGNCId", "LocusId", "DisplayRU", "InheritanceMode", "normal_max", "pathologic_min", "Disease", "SourceDisplay", "SourceId"]
header = [
"HGNCId",
"LocusId",
"DisplayRU",
"InheritanceMode",
"normal_max",
"pathologic_min",
"Disease",
"SourceDisplay",
"SourceId",
]
table_line = "| {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8} |"
click.echo(table_line.format(
header[0], header[1], header[2], header[3], header[4], header[5], header[6], header[7], header[8]
))
click.echo(table_line.format('-------', '-------', '-------', '-------', '-------',
'-------', '-------', '-------', '-------' ))
click.echo(
table_line.format(
header[0],
header[1],
header[2],
header[3],
header[4],
header[5],
header[6],
header[7],
header[8],
)
)
click.echo(
table_line.format(
"-------",
"-------",
"-------",
"-------",
"-------",
"-------",
"-------",
"-------",
"-------",
)
)
for entry in repeat_information:
click.echo(table_line.format(
repeat_information[entry][header[0]],
entry,
repeat_information[entry][header[2]],
repeat_information[entry][header[3]],
repeat_information[entry][header[4]],
repeat_information[entry][header[5]],
repeat_information[entry][header[6]],
repeat_information[entry][header[7]],
repeat_information[entry][header[8]],
))


if __name__=='__main__':
click.echo(
table_line.format(
repeat_information[entry][header[0]],
entry,
repeat_information[entry][header[2]],
repeat_information[entry][header[3]],
repeat_information[entry][header[4]],
repeat_information[entry][header[5]],
repeat_information[entry][header[6]],
repeat_information[entry][header[7]],
repeat_information[entry][header[8]],
)
)


if __name__ == "__main__":
cli()
44 changes: 29 additions & 15 deletions scripts/check_hgnc_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@
import requests

LOG = logging.getLogger(__name__)
LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]

import click

from stranger.resources import repeats_path
from stranger.utils import parse_repeat_file, get_repeat_info


@click.command()
@click.option('-f', '--repeats-file',
type = click.Path(exists=True),
@click.option(
"-f",
"--repeats-file",
type=click.Path(exists=True),
help="Path to a file with repeat definitions. See README for explanation",
default=repeats_path,
show_default=True,
)
@click.option('--loglevel', default='INFO', type=click.Choice(LOG_LEVELS),
help="Set the level of log output.", show_default=True)
@click.option(
"--loglevel",
default="INFO",
type=click.Choice(LOG_LEVELS),
help="Set the level of log output.",
show_default=True,
)
@click.pass_context
def cli(context, repeats_file, loglevel):
"""Table print repeat info"""
coloredlogs.install(level=loglevel)
with open(repeats_file, 'r') as file_handle:
repeat_information = parse_repeat_file(file_handle, repeats_file_type='json')

with open(repeats_file, "r") as file_handle:
repeat_information = parse_repeat_file(file_handle, repeats_file_type="json")

if not repeat_information:
LOG.warning("Could not find any repeat info")
Expand All @@ -37,10 +44,10 @@ def cli(context, repeats_file, loglevel):

for entry in repeat_information:
hgnc_id = repeat_information[entry]["HGNCId"]
locus_symbol = entry.split('_')[0]
locus_symbol = entry.split("_")[0]

url = "https://rest.genenames.org/search/hgnc_id/" + str(hgnc_id)
response = requests.get(url, headers= {"Accept":"application/json"})
response = requests.get(url, headers={"Accept": "application/json"})

if not response:
LOG.warning("Entry {} not found".format(entry))
Expand All @@ -52,17 +59,24 @@ def cli(context, repeats_file, loglevel):
LOG.warning("Entry {} not found".format(entry))

if len(response_rest["docs"]) > 1:
LOG.warning("Entry {} got {} hgnc responses - using first".format(entry,len(response_rest)))
LOG.warning(
"Entry {} got {} hgnc responses - using first".format(entry, len(response_rest))
)

symbol_from_id = response_rest['docs'][0]['symbol']
symbol_from_id = response_rest["docs"][0]["symbol"]

if symbol_from_id == locus_symbol :
if symbol_from_id == locus_symbol:
LOG.info("OK locus %s symbol %s", entry, locus_symbol)
elif symbol_from_id.lower() == locus_symbol.lower():
LOG.warning("OK locus %s symbol %s but differs in case", entry, locus_symbol)
else:
LOG.error("OOOPS locus_symbol %s and symbol %s from HGNC id %i do not match", locus_symbol, symbol_from_id, hgnc_id)
LOG.error(
"OOOPS locus_symbol %s and symbol %s from HGNC id %i do not match",
locus_symbol,
symbol_from_id,
hgnc_id,
)


if __name__=='__main__':
if __name__ == "__main__":
cli()
42 changes: 29 additions & 13 deletions scripts/compare_locus_values_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,47 @@
import requests

LOG = logging.getLogger(__name__)
LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]

import click

from stranger.resources import repeats_path
from stranger.utils import parse_repeat_file, get_repeat_info


@click.command()
@click.option('-f', '--repeats-file',
type = click.Path(exists=True),
@click.option(
"-f",
"--repeats-file",
type=click.Path(exists=True),
help="Path to a file with repeat definitions. See README for explanation",
default=repeats_path,
show_default=True,
)
@click.option('-x', '--alt-repeats-file',
type = click.Path(exists=True),
@click.option(
"-x",
"--alt-repeats-file",
type=click.Path(exists=True),
help="Path to a second file with repeat definitions. See README for explanation",
default=repeats_path,
show_default=True,
)
@click.option('--loglevel', default='INFO', type=click.Choice(LOG_LEVELS),
help="Set the level of log output.", show_default=True)
@click.option(
"--loglevel",
default="INFO",
type=click.Choice(LOG_LEVELS),
help="Set the level of log output.",
show_default=True,
)
@click.pass_context
def cli(context, repeats_file, alt_repeats_file, loglevel):
"""Test if values differ between loci for variant catalog jsons"""
coloredlogs.install(level=loglevel)
with open(repeats_file, 'r') as file_handle:
repeat_information = parse_repeat_file(file_handle, repeats_file_type='json')
with open(repeats_file, "r") as file_handle:
repeat_information = parse_repeat_file(file_handle, repeats_file_type="json")

with open(alt_repeats_file, 'r') as file_handle:
other_repeat_information = parse_repeat_file(file_handle, repeats_file_type='json')
with open(alt_repeats_file, "r") as file_handle:
other_repeat_information = parse_repeat_file(file_handle, repeats_file_type="json")

if not repeat_information or not other_repeat_information:
LOG.warning("Could not find any repeat info")
Expand All @@ -48,8 +58,14 @@ def cli(context, repeats_file, alt_repeats_file, loglevel):
LOG.warning("Entry %s field %s missing in alt file entry.", entry, key)
continue
if other_repeat_information[entry][key] != repeat_information[entry][key]:
LOG.error("Entry %s field %s differs between file: %s and alt: %s",entry, key, repeat_information[entry][key], other_repeat_information[entry][key])
LOG.error(
"Entry %s field %s differs between file: %s and alt: %s",
entry,
key,
repeat_information[entry][key],
other_repeat_information[entry][key],
)


if __name__=='__main__':
if __name__ == "__main__":
cli()
Loading

0 comments on commit b0e7f8d

Please sign in to comment.