Skip to content

Commit 952a2e2

Browse files
Merge branch 'auth_serve_files' of https://github.com/Clinical-Genomics/scout into auth_serve_files
2 parents f902f90 + c930233 commit 952a2e2

File tree

3 files changed

+71
-9
lines changed

3 files changed

+71
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
1111
- Rank score results now show the ranking range
1212
- cDNA and protein changes displayed on institute causatives pages
1313
- Optional SESSION_TIMEOUT_MINUTES configuration in app config files
14+
- Script to convert old OMIM case format (list of integers) to new format (list of dictionaries)
1415
- Additional check for user logged in status before serving alignment files
1516
### Changed
1617
- Verify user before redirecting to IGV alignments and sashimi plots

scout/models/case/case.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
from __future__ import absolute_import
22

33
import logging
4-
import os
54
from datetime import datetime
65

7-
from scout.constants import ANALYSIS_TYPES
8-
from scout.models import PhenotypeTerm
9-
from scout.models.panel import GenePanel
10-
11-
from . import STATUS
12-
from .individual import Individual
13-
146
logger = logging.getLogger(__name__)
157

168
individual = dict(
@@ -59,7 +51,7 @@
5951
created_at=datetime,
6052
delivery_report=str, # delivery report is a path to html file
6153
diagnosis_genes=list, # List of references to genes
62-
diagnosis_phenotypes=list, # List of references to diseases
54+
diagnosis_phenotypes=list, # List of dictionaries with OMIM disease data
6355
display_name=str, # required. This is the case name that will be shown in scout.
6456
dynamic_gene_list=list, # List of genes
6557
gene_fusion_report=str, # Path to the gene fusions report file
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
import click
5+
from pymongo import MongoClient
6+
7+
CASES_WITH_DIA = {
8+
"diagnosis_phenotypes": {"$exists": True, "$ne": []}
9+
} # MongoDB query to locate cases with any diagnosis
10+
11+
SELECT_FIELDS = {
12+
"owner": 1,
13+
"display_name": 1,
14+
"diagnosis_phenotypes": 1,
15+
} # select only a few important fields using the query above
16+
17+
18+
@click.command()
19+
@click.option("--db-uri", required=True, help="mongodb://user:password@db_url:db_port")
20+
@click.option("--db-name", required=True, help="db name")
21+
@click.option("--fix", help="Use this flag to fix the OMIM format in old cases", is_flag=True)
22+
def omim_case_fix_format(db_uri, db_name, fix):
23+
try:
24+
client = MongoClient(db_uri)
25+
db = client[db_name]
26+
# test connection
27+
click.echo("database connection info:{}".format(db))
28+
29+
cases_with_dia = list(db.case.find(CASES_WITH_DIA, SELECT_FIELDS))
30+
click.echo(f"Total number of cases with diagnosis:{len(cases_with_dia)}")
31+
32+
# Display cases with old format of diagnosis (a list of integers)
33+
cases_with_old_dia = [
34+
case for case in cases_with_dia if isinstance(case["diagnosis_phenotypes"][0], int)
35+
]
36+
click.echo(f"Total number of cases with old diagnosis format:{len(cases_with_old_dia)}")
37+
38+
for i, case in enumerate(cases_with_old_dia):
39+
click.echo(f"n:{i}\t{case['owner']}\t{case['display_name']}")
40+
old_dia = case["diagnosis_phenotypes"]
41+
new_dia = []
42+
43+
for dia_nr in old_dia:
44+
disease_term = db.disease_term.find_one({"disease_nr": dia_nr})
45+
if disease_term is None:
46+
click.echo(f"Could not find a disease term with id:{dia_nr}")
47+
continue
48+
new_dia.append(
49+
{
50+
"disease_nr": dia_nr,
51+
"disease_id": disease_term["disease_id"],
52+
"description": disease_term["description"],
53+
}
54+
)
55+
56+
if fix is False:
57+
new_dia = old_dia
58+
else:
59+
db.case.find_one_and_update(
60+
{"_id": case["_id"]}, {"$set": {"diagnosis_phenotypes": new_dia}}
61+
)
62+
click.echo(f"old dia:{old_dia}--->new dia:{new_dia}\n")
63+
64+
except Exception as err:
65+
click.echo("Error {}".format(err))
66+
67+
68+
if __name__ == "__main__":
69+
omim_case_fix_format()

0 commit comments

Comments
 (0)