-
Notifications
You must be signed in to change notification settings - Fork 0
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
Mongoengine genome #71
Open
ahc87
wants to merge
5
commits into
feature/mongoengine
Choose a base branch
from
mongoengine_genome
base: feature/mongoengine
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2ac95e
Use ODM in load_genome.py
ahc87 1921ccf
Fix tests and linting suggestions
ahc87 58ad6b7
Update assembly_id key in load_regions script
ahc87 7f1f175
Use genome_id key in load_genes
ahc87 5fab26d
Remove unused MONGO_CLIENT variable
ahc87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
.. See the NOTICE file distributed with this work for additional information | ||
regarding copyright ownership. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
from configparser import NoOptionError | ||
|
||
import pymongo | ||
from mongoengine import connect | ||
|
||
from scripts.mongoengine_documents.base import ThoasDocument | ||
|
||
|
||
class MongoDbClient: | ||
''' | ||
A pymongo wrapper class to take care of configuration and collection | ||
management | ||
''' | ||
|
||
def __init__(self, config, collection_name=None): | ||
''' | ||
Note that config here is a configparser object | ||
''' | ||
self.mongo_db = MongoDbClient.connect_mongo(config) | ||
try: | ||
self.collection_name = config.get('MONGO DB', 'collection') | ||
print(f'Using MongoDB collection with name {self.collection_name} from config file') | ||
except NoOptionError as no_option_error: | ||
if not collection_name: | ||
raise IOError("Unable to find a MongoDB collection name") from no_option_error | ||
self.collection_name = collection_name | ||
print(f'Using MongoDB collection name {self.collection_name}') | ||
|
||
# We need to monkey-patch _get_collection_name so that all subclasses of ThoasDocument get written to the same | ||
# collection | ||
def _get_collection_name(): | ||
return self.collection_name | ||
ThoasDocument._get_collection_name = _get_collection_name | ||
|
||
@staticmethod | ||
def connect_mongo(config): | ||
'Get a MongoDB connection' | ||
|
||
host = config.get('MONGO DB', 'host') | ||
port = config.getint('MONGO DB', 'port') | ||
user = config.get('MONGO DB', 'user') | ||
password = config.get('MONGO DB', 'password') | ||
dbname = config.get('MONGO DB', 'db') | ||
|
||
client = connect(db=dbname, username=user, password=password, host=host, authentication_source='admin', | ||
port=port, read_preference=pymongo.ReadPreference.SECONDARY_PREFERRED) | ||
|
||
print('connected to MongoDB ' + host) | ||
return client[dbname] | ||
|
||
def collection(self): | ||
''' | ||
Get the currently set default collection to run queries against | ||
''' | ||
return self.mongo_db[self.collection_name] | ||
|
||
|
||
class FakeMongoDbClient: | ||
''' | ||
Sets up a mongomock collection for thoas code to test with | ||
''' | ||
|
||
def __init__(self): | ||
'Override default setup' | ||
conn = connect('test_db', host='mongomock://localhost') | ||
self.mongo_db = conn['test_db'] | ||
self.collection_name = 'test' | ||
|
||
def _get_collection_name(): | ||
return self.collection_name | ||
ThoasDocument._get_collection_name = _get_collection_name | ||
|
||
def collection(self): | ||
return self.mongo_db[self.collection_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
graphql_service/tests/snapshots/snap_test_slice_retrieval.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" See the NOTICE file distributed with this work for additional information | ||
regarding copyright ownership. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.""" | ||
|
||
from mongoengine import Document, StringField, EmbeddedDocumentField, EmbeddedDocument, IntField, BooleanField | ||
|
||
|
||
class ThoasDocument(Document): | ||
meta = {'allow_inheritance': True} | ||
|
||
|
||
class ExternalDB(EmbeddedDocument): | ||
name = StringField() | ||
external_db_id = StringField() | ||
description = StringField() | ||
url = StringField() | ||
release = StringField() | ||
|
||
|
||
class ExternalMethod(EmbeddedDocument): | ||
type = StringField() | ||
description = StringField() | ||
|
||
|
||
class ExternalReference(EmbeddedDocument): | ||
accession_id = StringField() | ||
name = StringField() | ||
description = StringField() | ||
assignment_method = EmbeddedDocumentField(ExternalMethod) | ||
url = StringField() | ||
source = EmbeddedDocumentField(ExternalDB) | ||
|
||
|
||
class Alphabet(EmbeddedDocument): | ||
accession_id = StringField() | ||
label = StringField() | ||
value = StringField() | ||
definition = StringField() | ||
description = StringField() | ||
|
||
|
||
class Sequence(EmbeddedDocument): | ||
alphabet = EmbeddedDocumentField(Alphabet) | ||
checksum = StringField() | ||
|
||
|
||
class Location(EmbeddedDocument): | ||
start = IntField() | ||
end = IntField() | ||
length = IntField() | ||
|
||
|
||
class Strand(EmbeddedDocument): | ||
code = StringField() | ||
value = IntField() | ||
|
||
|
||
class Slice(EmbeddedDocument): | ||
region_id = StringField() | ||
location = EmbeddedDocumentField(Location) | ||
strand = EmbeddedDocumentField(Strand) | ||
default = BooleanField() | ||
genome_id = StringField() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the usage of
"""
notice is wrong (I know the sop in confluence might be as well), but the use of the"""
will introduce some issue if ever we generate some documentation automatically. Best is to just set his text with inline comments#