Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to the mongodb using the new method #459

Merged
merged 1 commit into from
Apr 10, 2018
Merged
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
22 changes: 14 additions & 8 deletions backend/beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,33 @@ def get(self):
] #
})

def connect_mongo(dataset):
client = pymongo.MongoClient(host=settings.mongo_host, port=settings.mongo_port)

auth_db = client['exac-user']
auth_db.authenticate(settings.mongo_user, settings.mongo_password)

return client[dataset]


def lookupAllele(chrom, pos, referenceAllele, allele, reference, dataset): #pylint: disable=too-many-arguments, unused-argument
"""CHeck if an allele is present in the database
Args:
chrom: The chromosome, format matches [1-22XY]
pos: Coordinate within a chromosome. Position is a number and is 0-based
allele: Any string of nucleotides A,C,T,G
alternate: Any string of nucleotides A,C,T,G
reference: The human reference build that was used (currently unused)
reference: The human reference build that was used
dataset: Dataset to look in (currently used to select Mongo database)
Returns:
The string 'true' if the allele was found, otherwise the string 'false'
"""
client = pymongo.MongoClient(host=settings.mongo_host, port=settings.mongo_port)
if reference == 'hg19':
reference = 'GRChg37'

# The name of the dataset in the database is exac as required by the
# exac browser we are using.
if dataset == 'SweGen':
dataset = 'exac'
dataset = "exac-{}-{}".format(dataset.lower(), reference)

mdb = client[dataset]
mdb.authenticate(settings.mongo_user, settings.mongo_password)
mdb = connect_mongo(dataset)

# Beacon is 0-based, our database is 1-based in coords.
pos += 1
Expand Down