Skip to content

Commit

Permalink
Use env var to read MongoDB password
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Todor <todormihai@gmail.com>
  • Loading branch information
mihaitodor committed Dec 19, 2024
1 parent d48deba commit eef9381
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
utilities/FASTA
utilities/mongo_utilities.py
/data
secrets.env
20 changes: 12 additions & 8 deletions app/common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import os
import re
from collections import OrderedDict
from datetime import datetime
from itertools import groupby
from threading import Lock
from uuid import uuid4

import pyliftover
import requests
from datetime import datetime
import pymongo
import requests
from flask import abort
from itertools import groupby
import re

# MongoDB Client URIs
FHIR_genomics_data_client_uri = "mongodb+srv://download:download@cluster0.8ianr.mongodb.net/FHIRGenomicsData"
utilities_data_client_uri = "mongodb+srv://download:download@cluster0.8ianr.mongodb.net/UtilitiesData"
FHIR_genomics_data_client_uri = f"mongodb+srv://readonly:{os.getenv('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/FHIRGenomicsData"
utilities_data_client_uri = f"mongodb+srv://readonly:{os.getenv('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/UtilitiesData"

# MongoDB Clients
client = pymongo.MongoClient(FHIR_genomics_data_client_uri)
Expand Down Expand Up @@ -620,9 +622,11 @@ def create_fhir_variant_resource(record, ref_seq, subject):
inner_end = record['END'] - abs(record['CIEND'][0])
outer_end = record['END'] + abs(record['CIEND'][1])

resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81301-4", "display": "Variant outer start-end"}]}, "valueRange": {"low": {"value": outer_start}, "high": {"value": outer_end}}})
resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81301-4", "display": "Variant outer start-end"}]},
"valueRange": {"low": {"value": outer_start}, "high": {"value": outer_end}}})

resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81302-2", "display": "Variant inner start-end"}]}, "valueRange": {"low": {"value": inner_start}, "high": {"value": inner_end}}})
resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81302-2", "display": "Variant inner start-end"}]},
"valueRange": {"low": {"value": inner_start}, "high": {"value": inner_end}}})

# Variant population allele frequency
if 'popAlleleFreq' in record:
Expand Down
2 changes: 2 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from app import create_app

load_dotenv()
# Load secrets from secrets.env file if available
load_dotenv("secrets.env")

app = create_app()

Expand Down
6 changes: 4 additions & 2 deletions utilities/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from enum import Enum
import os
import re
from enum import Enum

import pandas as pd
import pymongo

utilities_data_client_uri = "mongodb+srv://download:download@cluster0.8ianr.mongodb.net/UtilitiesData"
utilities_data_client_uri = f"mongodb+srv://readonly:{os.getenv('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/UtilitiesData"
utilities_client = pymongo.MongoClient(utilities_data_client_uri)
utilities_db = utilities_client.UtilitiesData
transcript_data = utilities_db.Transcripts
Expand Down

0 comments on commit eef9381

Please sign in to comment.