Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 62 additions & 64 deletions MobiDetailsApp/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ def litvar():
# print(article)
if article['authors'][0]:
pmid = int(article['pmid'])
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': ''}
Comment on lines -94 to +103
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function litvar refactored with the following changes:

return render_template(
'ajax/litvar.html',
urls=md_utilities.urls,
Expand All @@ -118,9 +118,8 @@ def litvar():

@bp.route('/litvar2', methods=['POST'])
def litvar2():
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]
Comment on lines -121 to +122
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function litvar2 refactored with the following changes:

# if re.search(r'^rs\d+$', request.form['rsid']):
header = md_utilities.api_agent
# rsid = request.form['rsid']
Expand Down Expand Up @@ -186,21 +185,20 @@ def litvar2():
if 'authors' in article and \
len(article['authors']) > 0:
pmid = int(article['pmid'])
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['pmids']:
pmid = int(pubmed_id)
pubmed_info[pmid] = {}
pubmed_info[pmid]['title'] = ''
pubmed_info[pmid] = {'title': ''}
if not pubmed_info:
for pubmed_id in litvar_data['pmids']:
pmid = int(pubmed_id)
pubmed_info[pmid] = {}
pubmed_info[pmid]['title'] = ''
pubmed_info[pmid] = {'title': ''}
# get litvar direct link of rsid
litvar_sensor_url = "{0}{1}".format(
md_utilities.urls['ncbi_litvar_apiv2_sensor'], rsid
Expand Down Expand Up @@ -256,9 +254,9 @@ def defgen():
match_varid = re.search(r'^(\d+)$', request.form['vfid'])
if match_varid and \
match_genome:
variant_id = match_varid.group(1)
variant_id = match_varid[1]
# genome = request.form['genome']
genome = match_genome.group(1)
genome = match_genome[1]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function defgen refactored with the following changes:

db = get_db()
curs = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
# get all variant_features and gene info
Expand All @@ -274,19 +272,28 @@ def defgen():
(variant_id, genome)
)
vf = curs.fetchone()
file_content = "GENE;VARIANT;A_ENREGISTRER;ETAT;RESULTAT;VARIANT_P;\
rsid = 'rs{0}'.format(vf['dbsnp_id']) if vf['dbsnp_id'] else ''
file_content = (
"GENE;VARIANT;A_ENREGISTRER;ETAT;RESULTAT;VARIANT_P;\
VARIANT_C;ENST;NM;POSITION_GENOMIQUE;CLASSESUR5;CLASSESUR3;COSMIC;RS;\
REFERENCES;CONSEQUENCES;COMMENTAIRE;CHROMOSOME;GENOME_REFERENCE;\
NOMENCLATURE_HGVS;LOCALISATION;SEQUENCE_REF;LOCUS;ALLELE1;ALLELE2\r\n"
rsid = ''
if vf['dbsnp_id']:
rsid = 'rs{0}'.format(vf['dbsnp_id'])
file_content += "{0};{1}:c.{2};;;;p.{3};c.{2};{4};{1};{5};\
+ "{0};{1}:c.{2};;;;p.{3};c.{2};{4};{1};{5};\
;;;{6};;{7};;chr{8};{9};chr{8}:g.{10};{11} {12};;;;\r\n".format(
vf['gene_symbol'], vf['refseq'],
vf['c_name'], vf['p_name'], vf['enst'], vf['pos'],
rsid, vf['prot_type'], vf['chr'], genome,
vf['g_name'], vf['start_segment_type'], vf['start_segment_number']
vf['gene_symbol'],
vf['refseq'],
vf['c_name'],
vf['p_name'],
vf['enst'],
vf['pos'],
rsid,
vf['prot_type'],
vf['chr'],
genome,
vf['g_name'],
vf['start_segment_type'],
vf['start_segment_number'],
)
)
# print(file_content)
app_path = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -309,12 +316,9 @@ def defgen():
md_utilities.send_error_email(
md_utilities.prepare_email_html(
'MobiDetails Ajax error',
'<p>DefGen file generation failed in {} (no variant_id)</p>'
.format(
os.path.basename(__file__)
)
f'<p>DefGen file generation failed in {os.path.basename(__file__)} (no variant_id)</p>',
),
'[MobiDetails - Ajax Error]'
'[MobiDetails - Ajax Error]',
)
return """
<div class="w3-blue w3-ripple w3-padding-16 w3-large w3-center" style="width:100%">
Expand Down Expand Up @@ -343,12 +347,12 @@ def intervar():
match_ref and \
match_alt and \
match_gene_symbol:
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]
Comment on lines -346 to +355
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function intervar refactored with the following changes:

This removes the following comments ( why? ):

# print(obj)

header = md_utilities.api_agent
if len(ref) > 1 or len(alt) > 1:
return 'No wintervar for indels'
Expand Down Expand Up @@ -396,17 +400,12 @@ def intervar():
headers=header
).data.decode('utf-8')
)
i = 0
for obj in intervar_list:
for i, obj in enumerate(intervar_list):
# some housekeeping to get proper strings
obj = obj.replace('{', '').replace('}', '')
obj = '{{{}}}'.format(obj)
intervar_list[i] = obj
i += 1
intervar_data = []
for obj in intervar_list:
# print(obj)
intervar_data.append(json.loads(obj))
intervar_data = [json.loads(obj) for obj in intervar_list]
except Exception as e:
md_utilities.send_error_email(
md_utilities.prepare_email_html(
Expand Down Expand Up @@ -465,31 +464,30 @@ def intervar():
key,
md_utilities.acmg_criteria[key]
)
if intervar_acmg is not None:
db = get_db()
curs = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute(
"""
if intervar_acmg is None:
return "<span>No wintervar class</span>"
db = get_db()
curs = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute(
"""
SELECT html_code
FROM valid_class
WHERE acmg_translation = %s
""",
(intervar_acmg.lower(),)
)
res = curs.fetchone()
close_db()
return """
(intervar_acmg.lower(),)
)
res = curs.fetchone()
close_db()
return """
<span style='color:{0};'>{1}</span>
<span> with the following criteria:</span><br /><br />
<div class='w3-row-padding w3-center'>{2}</div><br />
<div id='acmg_info'></div>
""".format(
res['html_code'],
intervar_acmg,
intervar_criteria
)
else:
return "<span>No wintervar class</span>"
res['html_code'],
intervar_acmg,
intervar_criteria
)
else:
md_utilities.send_error_email(
md_utilities.prepare_email_html(
Expand Down
73 changes: 41 additions & 32 deletions MobiDetailsApp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def check_api_key(api_key=None):

@bp.route('/api/service/vv_instance', methods=['GET'])
def check_vv_instance():
vv_url = md_utilities.get_vv_api_url()
if vv_url:
if vv_url := md_utilities.get_vv_api_url():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_vv_instance refactored with the following changes:

if vv_url == md_utilities.urls['variant_validator_api']:
return jsonify(
variant_validator_instance='Running genuine VV server',
Expand All @@ -76,47 +75,57 @@ def api_variant_exists(variant_ghgvs=None):
return jsonify(mobidetails_error='No variant submitted')
variant_regexp = md_utilities.regexp['variant']
chrom_regexp = md_utilities.regexp['ncbi_chrom']
match_variant_ghgvs = re.search(rf'^({chrom_regexp}):g\.({variant_regexp})$', urllib.parse.unquote(variant_ghgvs))
# match_object = re.search(r'^([Nn][Cc]_0000\d{2}\.\d{1,2}):g\.(.+)$', urllib.parse.unquote(variant_ghgvs))
if match_variant_ghgvs:
db = get_db()
chrom, genome_version = md_utilities.get_common_chr_name(db, match_variant_ghgvs.group(1))
if chrom and \
if not (
match_variant_ghgvs := re.search(
rf'^({chrom_regexp}):g\.({variant_regexp})$',
urllib.parse.unquote(variant_ghgvs),
)
):
return jsonify(mobidetails_error='Malformed query, please check your input')
db = get_db()
chrom, genome_version = md_utilities.get_common_chr_name(
db, match_variant_ghgvs[1]
)
if chrom and \
genome_version:
pattern = match_variant_ghgvs.group(2)
curs = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute(
"""
pattern = match_variant_ghgvs[2]
curs = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute(
"""
SELECT feature_id
FROM variant
WHERE chr = %s
AND g_name = %s
AND genome_version = %s
""",
(chrom, pattern, genome_version)
)
res = curs.fetchone()
if res is not None:
close_db()
return jsonify(
mobidetails_id=res['feature_id'],
url='{0}{1}'.format(
request.host_url[:-1],
url_for(
'api.variant',
variant_id=res['feature_id'],
caller='browser'
)
(chrom, pattern, genome_version)
)
res = curs.fetchone()
if res is not None:
close_db()
return jsonify(
mobidetails_id=res['feature_id'],
url='{0}{1}'.format(
request.host_url[:-1],
url_for(
'api.variant',
variant_id=res['feature_id'],
caller='browser'
)
)
else:
close_db()
checked_var_ghgvs = '{0}:g.{1}'.format(match_variant_ghgvs.group(1), match_variant_ghgvs.group(2))
return jsonify(mobidetails_warning='The variant {} does not exist yet in MD'.format(checked_var_ghgvs))
)
else:
return jsonify(mobidetails_error='The chromosome {} does not exist in MD'.format(match_variant_ghgvs.group(1)))
close_db()
checked_var_ghgvs = '{0}:g.{1}'.format(
match_variant_ghgvs[1], match_variant_ghgvs[2]
)
return jsonify(
mobidetails_warning=f'The variant {checked_var_ghgvs} does not exist yet in MD'
)
else:
return jsonify(mobidetails_error='Malformed query, please check your input')
return jsonify(
mobidetails_error=f'The chromosome {match_variant_ghgvs[1]} does not exist in MD'
)
Comment on lines -79 to +128
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function api_variant_exists refactored with the following changes:

This removes the following comments ( why? ):

# match_object = re.search(r'^([Nn][Cc]_0000\d{2}\.\d{1,2}):g\.(.+)$', urllib.parse.unquote(variant_ghgvs))


# -------------------------------------------------------------------
# api - variant
Expand Down
Loading