-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from moonso/fix_obis
- Loading branch information
Showing
7 changed files
with
233 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import logging | ||
import coloredlogs | ||
import requests | ||
|
||
LOG = logging.getLogger(__name__) | ||
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), | ||
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.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') | ||
|
||
|
||
if not repeat_information: | ||
LOG.warning("Could not find any repeat info") | ||
context.abort() | ||
|
||
# print(repeat_information) | ||
|
||
# header = ["HGNCId", "LocusId", "DisplayRU", "InheritanceMode", "normal_max", "pathologic_min", "Disease", "SourceDisplay", "SourceId"] | ||
|
||
for entry in repeat_information: | ||
hgnc_id = repeat_information[entry]["HGNCId"] | ||
locus_symbol = entry.split('_')[0] | ||
|
||
url = "https://rest.genenames.org/search/hgnc_id/" + str(hgnc_id) | ||
response = requests.get(url, headers= {"Accept":"application/json"}) | ||
|
||
if not response: | ||
LOG.warning("Entry {} not found".format(entry)) | ||
# print(response.text) | ||
|
||
response_json = response.json() | ||
response_rest = response_json["response"] | ||
if len(response_rest) == 0: | ||
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))) | ||
|
||
symbol_from_id = response_rest['docs'][0]['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) | ||
|
||
|
||
if __name__=='__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import logging | ||
import coloredlogs | ||
import requests | ||
|
||
LOG = logging.getLogger(__name__) | ||
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), | ||
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), | ||
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.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(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") | ||
context.abort() | ||
|
||
for entry in repeat_information: | ||
for key in repeat_information[entry]: | ||
if entry not in other_repeat_information: | ||
LOG.info("Entry %s not found in alt file.", entry) | ||
continue | ||
if key not in other_repeat_information[entry]: | ||
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]) | ||
|
||
|
||
if __name__=='__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.