Conversation
| pubmed_info[pmid] = {} | ||
| pubmed_info[pmid]['title'] = article['title'] | ||
| pubmed_info[pmid]['journal'] = article['journal'] | ||
| pubmed_info[pmid]['year'] = article['year'] | ||
| pubmed_info[pmid]['author'] = article['authors'][0] | ||
| pubmed_info[pmid] = { | ||
| 'title': article['title'], | ||
| 'journal': article['journal'], | ||
| 'year': article['year'], | ||
| 'author': article['authors'][0], | ||
| } | ||
| except Exception: | ||
| for pubmed_id in litvar_data[0]['pmids']: | ||
| pmid = int(pubmed_id) | ||
| pubmed_info[pmid] = {} | ||
| pubmed_info[pmid]['title'] = '' | ||
| pubmed_info[pmid] = {'title': ''} |
There was a problem hiding this comment.
Function litvar refactored with the following changes:
- Merge dictionary assignment with declaration [×5] (
merge-dict-assign)
| match_rsid = re.search(r'^(rs\d+)$', request.form['rsid']) | ||
| if match_rsid: | ||
| rsid = match_rsid.group(1) | ||
| if match_rsid := re.search(r'^(rs\d+)$', request.form['rsid']): | ||
| rsid = match_rsid[1] |
There was a problem hiding this comment.
Function litvar2 refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups) - Merge dictionary assignment with declaration [×6] (
merge-dict-assign)
| variant_id = match_varid[1] | ||
| # genome = request.form['genome'] | ||
| genome = match_genome.group(1) | ||
| genome = match_genome[1] |
There was a problem hiding this comment.
Function defgen refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups) - Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace call to format with f-string (
use-fstring-for-formatting) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace if statement with if expression (
assign-if-exp) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign)
| genome = match_genome.group(1) | ||
| chrom = match_nochr_chrom.group(1) | ||
| pos = match_pos.group(1) | ||
| ref = match_ref.group(1) | ||
| alt = match_alt.group(1) | ||
| gene = match_gene_symbol.group(1) | ||
| genome = match_genome[1] | ||
| chrom = match_nochr_chrom[1] | ||
| pos = match_pos[1] | ||
| ref = match_ref[1] | ||
| alt = match_alt[1] | ||
| gene = match_gene_symbol[1] |
There was a problem hiding this comment.
Function intervar refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects [×6] (
use-getitem-for-re-match-groups) - Replace manual loop counter with call to enumerate (
convert-to-enumerate) - Convert for loop into list comprehension (
list-comprehension) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
This removes the following comments ( why? ):
# print(obj)
| def check_vv_instance(): | ||
| vv_url = md_utilities.get_vv_api_url() | ||
| if vv_url: | ||
| if vv_url := md_utilities.get_vv_api_url(): |
There was a problem hiding this comment.
Function check_vv_instance refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| external_tools['ClinGenSpecificationRegistry'][ | ||
| 'version' | ||
| ] = f'v{clingen_version}' | ||
| external_tools['OncoKBGenes']['version'] = f'v{oncokb_genes_version}' |
There was a problem hiding this comment.
Lines 190-198 refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting)
MobiDetailsApp/md_utilities.py
Outdated
| match_obj = re.search(r'^(.+d[eu][lp])[ATCG]+$', variant) | ||
| if match_obj: | ||
| variant = match_obj.group(1) | ||
| else: | ||
| match_obj = re.search(r'^(.+del)[ATCG]+(ins[ACTG])$', variant) | ||
| if match_obj: | ||
| variant = match_obj.group(1) + match_obj.group(2) | ||
| if match_obj := re.search(r'^(.+d[eu][lp])[ATCG]+$', variant): | ||
| variant = match_obj[1] | ||
| elif match_obj := re.search(r'^(.+del)[ATCG]+(ins[ACTG])$', variant): | ||
| variant = match_obj[1] + match_obj[2] |
There was a problem hiding this comment.
Function clean_var_name refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| match_object = re.search(r'^(\w{3})(\d+)(\w{3}|[X\*=])$', var) | ||
| if match_object: | ||
| if re.search('d[ue][pl]', match_object.group(3)): | ||
| return three2one[match_object.group(1).capitalize()] + \ | ||
| match_object.group(2) + \ | ||
| match_object.group(3) | ||
| if match_object := re.search(r'^(\w{3})(\d+)(\w{3}|[X\*=])$', var): | ||
| if re.search('d[ue][pl]', match_object[3]): | ||
| return ( | ||
| three2one[match_object[1].capitalize()] | ||
| + match_object[2] | ||
| + match_object[3] | ||
| ) | ||
| else: | ||
| return three2one[match_object.group(1).capitalize()] + \ | ||
| match_object.group(2) + \ | ||
| three2one[match_object.group(3).capitalize()] | ||
| match_object = re.search(r'^(\w{3})(\d+_)(\w{3})(\d+.+)$', var) | ||
| if match_object: | ||
| return three2one[match_object.group(1)].capitalize() + \ | ||
| match_object.group(2) + \ | ||
| three2one[match_object.group(3)].capitalize() + \ | ||
| match_object.group(4) | ||
| match_object = re.search(r'^(\w{3})(\d+)\w{3}fsTer\d+$', var) | ||
| if match_object: | ||
| return three2one[match_object.group(1)].capitalize() + \ | ||
| match_object.group(2) + \ | ||
| 'fs' | ||
| return ( | ||
| three2one[match_object[1].capitalize()] | ||
| + match_object[2] | ||
| + three2one[match_object[3].capitalize()] | ||
| ) | ||
| if match_object := re.search(r'^(\w{3})(\d+_)(\w{3})(\d+.+)$', var): | ||
| return ( | ||
| three2one[match_object[1]].capitalize() | ||
| + match_object[2] | ||
| + three2one[match_object[3]].capitalize() | ||
| + match_object[4] | ||
| ) | ||
| if match_object := re.search(r'^(\w{3})(\d+)\w{3}fsTer\d+$', var): | ||
| return three2one[match_object[1]].capitalize() + match_object[2] + 'fs' |
There was a problem hiding this comment.
Function three2one_fct refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×13] (
use-getitem-for-re-match-groups)
| match_object = re.search(r'^(\w{1})(\d+)([\w\*=]{1})$', var) | ||
| if match_object: | ||
| return one2three[match_object.group(1).capitalize()] + \ | ||
| match_object.group(2) + \ | ||
| one2three[match_object.group(3).capitalize()] | ||
| match_object = re.search(r'^(\w{1})(\d+)(d[ue][pl])$', var) | ||
| if match_object: | ||
| return one2three[match_object.group(1).capitalize()] + \ | ||
| match_object.group(2) + \ | ||
| match_object.group(3) | ||
| match_object = re.search(r'^(\w{1})(\d+_)(\w{1})(\d+.+)$', var) | ||
| if match_object: | ||
| return one2three[match_object.group(1).capitalize()] + \ | ||
| match_object.group(2) + \ | ||
| one2three[match_object.group(3).capitalize()] + \ | ||
| match_object.group(4) | ||
| if match_object := re.search(r'^(\w{1})(\d+)([\w\*=]{1})$', var): | ||
| return ( | ||
| one2three[match_object[1].capitalize()] | ||
| + match_object[2] | ||
| + one2three[match_object[3].capitalize()] | ||
| ) | ||
| if match_object := re.search(r'^(\w{1})(\d+)(d[ue][pl])$', var): | ||
| return ( | ||
| one2three[match_object[1].capitalize()] | ||
| + match_object[2] | ||
| + match_object[3] | ||
| ) | ||
| if match_object := re.search(r'^(\w{1})(\d+_)(\w{1})(\d+.+)$', var): | ||
| return ( | ||
| one2three[match_object[1].capitalize()] | ||
| + match_object[2] | ||
| + one2three[match_object[3].capitalize()] | ||
| + match_object[4] | ||
| ) |
There was a problem hiding this comment.
Function one2three_fct refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×10] (
use-getitem-for-re-match-groups)
| short_chr = get_short_chr_name(chr_name) | ||
| if short_chr: | ||
| if short_chr := get_short_chr_name(chr_name): |
There was a problem hiding this comment.
Function get_ncbi_chr_name refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression)
This removes the following comments ( why? ):
# print(ncbi_name)
| res = curs.fetchone() | ||
| if res: | ||
| if res := curs.fetchone(): |
There was a problem hiding this comment.
Function get_common_chr_name refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| if re.search(rf'^[Cc][Hh][Rr]({nochr_captured_regexp})$', chr_name): | ||
| return True | ||
| return False | ||
| return bool(re.search(rf'^[Cc][Hh][Rr]({nochr_captured_regexp})$', chr_name)) |
There was a problem hiding this comment.
Function is_valid_full_chr refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity)
| return match_obj.group(1) | ||
| return match_obj[1] |
There was a problem hiding this comment.
Function get_short_chr_name refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups)
| if re.search(rf'^({nochr_captured_regexp})$', chr_name): | ||
| return True | ||
| return False | ||
| return bool(re.search(rf'^({nochr_captured_regexp})$', chr_name)) |
There was a problem hiding this comment.
Function is_valid_chr refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity)
| if re.search(r'^[Nn][Cc]_0000\d{2}\.\d{1,2}$', chr_name): | ||
| return True | ||
| return False | ||
| return bool(re.search(r'^[Nn][Cc]_0000\d{2}\.\d{1,2}$', chr_name)) |
There was a problem hiding this comment.
Function is_valid_ncbi_chr refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity)
| return 'Match failed in {}'.format(text) | ||
| return f'Match failed in {text}' |
There was a problem hiding this comment.
Function get_value_from_tabix_file refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| match_obj = re.search(r'^([A-Z][a-z]{2})(\d+)([A-Z][a-z]{2})$', p_name) | ||
| if match_obj: | ||
| return three2one[match_obj.group(1)], match_obj.group(2), three2one[match_obj.group(3)] | ||
| if match_obj := re.search( | ||
| r'^([A-Z][a-z]{2})(\d+)([A-Z][a-z]{2})$', p_name | ||
| ): | ||
| return three2one[match_obj[1]], match_obj[2], three2one[match_obj[3]] |
There was a problem hiding this comment.
Function decompose_missense refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups)
| score = re.split( | ||
| '{}'.format(sep), dbnsfp_record[score_index] | ||
| )[transcript_index] | ||
| score = re.split(f'{sep}', dbnsfp_record[score_index])[transcript_index] | ||
| if pred_index != score_index: | ||
| pred = predictors_translations[translation_mode][ | ||
| re.split( | ||
| '{}'.format(sep), | ||
| dbnsfp_record[pred_index] | ||
| )[transcript_index] | ||
| re.split(f'{sep}', dbnsfp_record[pred_index])[transcript_index] |
There was a problem hiding this comment.
Function getdbNSFP_results refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| # returns most deleterious score of predictors | ||
| # when not found in desired transcript | ||
| j = 0 | ||
| k = 0 | ||
| best_score = threshold | ||
| for score in re.split(';', score): | ||
| for j, score in enumerate(re.split(';', score)): | ||
| if direction == 'lt': | ||
| if score != '.' and \ | ||
| float(score) < float(best_score): | ||
| best_score = score | ||
| k = j | ||
| else: | ||
| if score != '.' and \ | ||
| elif score != '.' and \ | ||
| float(score) > float(best_score): | ||
| best_score = score | ||
| k = j | ||
| j += 1 | ||
| best_score = score | ||
| k = j |
There was a problem hiding this comment.
Function get_most_other_deleterious_pred refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
This removes the following comments ( why? ):
# when not found in desired transcript
# returns most deleterious score of predictors
| value = float(val) | ||
| if predictor == 'sift': | ||
| value = 1-(float(val)) | ||
| value = 1-(float(val)) if predictor == 'sift' else float(val) |
There was a problem hiding this comment.
Function get_preditor_single_threshold_color refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| return match_object.group(1) | ||
| else: | ||
| match_object = re.search(r'_(\d+)[di]', g_name) | ||
| if match_object is not None: | ||
| return match_object.group(1) | ||
| else: | ||
| # case of single nt dels ins dup | ||
| match_object = re.search(r'^(\d+)[d]', g_name) | ||
| if match_object is not None: | ||
| return match_object.group(1) | ||
| return None | ||
| return match_object[1] | ||
| match_object = re.search(r'_(\d+)[di]', g_name) | ||
| if match_object is not None: | ||
| return match_object[1] | ||
| # case of single nt dels ins dup | ||
| match_object = re.search(r'^(\d+)[d]', g_name) | ||
| return match_object[1] if match_object is not None else None |
There was a problem hiding this comment.
Function compute_pos_end refactored with the following changes:
- Swap if/else branches [×4] (
swap-if-else-branches) - Remove unnecessary else after guard condition [×2] (
remove-unnecessary-else) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| return match_object.group(1), match_object.group(2) | ||
| else: | ||
| match_object = re.search(r'^(\d+)[ATGC]>', name) | ||
| if match_object is not None: | ||
| return match_object.group(1), match_object.group(1) | ||
| else: | ||
| # single nt del or delins | ||
| match_object = re.search(r'^(\d+)[d]', name) | ||
| if match_object is not None: | ||
| return match_object.group(1), match_object.group(1) | ||
| else: | ||
| return match_object[1], match_object[2] | ||
| match_object = re.search(r'^(\d+)[ATGC]>', name) | ||
| if match_object is not None: | ||
| return match_object[1], match_object[1] | ||
| # single nt del or delins | ||
| match_object = re.search(r'^(\d+)[d]', name) | ||
| if match_object is not None: | ||
| return match_object[1], match_object[1] | ||
| # case where NM wt disagree with genomic wt | ||
| if re.search(r'^\d+=', name): | ||
| return '-1', '-1' | ||
| return None, None | ||
| return ('-1', '-1') if re.search(r'^\d+=', name) else (None, None) |
There was a problem hiding this comment.
Function compute_start_end_pos refactored with the following changes:
- Swap if/else branches [×6] (
swap-if-else-branches) - Remove unnecessary else after guard condition [×3] (
remove-unnecessary-else) - Replace m.group(x) with m[x] for re.Match objects [×6] (
use-getitem-for-re-match-groups) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| begin_txt = 'VariantValidator error: ' | ||
| if var == '': | ||
| begin_txt = '' | ||
| begin_txt = '' if var == '' else 'VariantValidator error: ' |
There was a problem hiding this comment.
Function danger_panel refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| # to print general info do not send var neither id_var | ||
| # Newly created variant: | ||
| c = 'c.' | ||
| if re.search(r'N[MR]_', var): | ||
| c = '' | ||
| c = '' if re.search(r'N[MR]_', var) else 'c.' |
There was a problem hiding this comment.
Function info_panel refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# Newly created variant:
# to print general info do not send var neither id_var
| if checked_url: | ||
| return checked_url | ||
| else: | ||
| if not checked_url: | ||
| checked_url = test_vv_api_url( | ||
| urls['variant_validator_api_hello'], | ||
| urls['variant_validator_api'] | ||
| ) | ||
| return checked_url | ||
| return checked_url | ||
| else: | ||
| # the other way around | ||
| checked_url = test_vv_api_url( | ||
| urls['variant_validator_api_hello'], | ||
| urls['variant_validator_api'] | ||
| ) | ||
| if checked_url: | ||
| if checked_url := test_vv_api_url( | ||
| urls['variant_validator_api_hello'], urls['variant_validator_api'] | ||
| ): | ||
| return checked_url | ||
| if checked_url := test_vv_api_url( | ||
| urls['variant_validator_api_hello_backup'], | ||
| urls['variant_validator_api_backup'], | ||
| ): | ||
| return checked_url | ||
| else: | ||
| checked_url = test_vv_api_url( | ||
| urls['variant_validator_api_hello_backup'], | ||
| urls['variant_validator_api_backup'] | ||
| ) | ||
| if checked_url: | ||
| return checked_url | ||
| else: |
There was a problem hiding this comment.
Function get_vv_api_url refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body) - Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
This removes the following comments ( why? ):
# the other way around
| list_name, | ||
| ) | ||
| ).status_code == http_code | ||
| assert client.get(f'/auth/variant_list/{list_name}').status_code == http_code |
There was a problem hiding this comment.
Function test_variant_list refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| for name in res: | ||
| print(name[0]) | ||
| assert client.get('/gene/{}'.format(name[0])).status_code == 200 | ||
| assert client.get(f'/gene/{name[0]}').status_code == 200 |
There was a problem hiding this comment.
Function test_gene_page refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| print(response.headers['Location'] + 'http://localhost/{}'.format(url)) | ||
| assert 'http://localhost/{}'.format(url) == response.headers['Location'] | ||
| print(response.headers['Location'] + f'http://localhost/{url}') | ||
| assert f'http://localhost/{url}' == response.headers['Location'] |
There was a problem hiding this comment.
Function test_search_engine refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| for variant_id in res: | ||
| print(variant_id[0]) | ||
| assert client.get('/api/variant/{}/browser/'.format(variant_id[0])).status_code == 200 | ||
| assert client.get(f'/api/variant/{variant_id[0]}/browser/').status_code == 200 |
There was a problem hiding this comment.
Function test_variant_page refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| def test_format_mirs(record, result): | ||
| totest = md_utilities.format_mirs(record) | ||
| print('-{}'.format(totest)) | ||
| print(f'-{totest}') |
There was a problem hiding this comment.
Function test_format_mirs refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!