Skip to content

Commit

Permalink
add meta-query command
Browse files Browse the repository at this point in the history
  • Loading branch information
gmauro committed Oct 21, 2024
1 parent 415ef70 commit a9dc526
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gwasstudio/cli/metadata/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import cloup

from gwasstudio.mongo.models import EnhancedDataProfile

help_doc = """
Metadata query
"""


@cloup.command("meta_query", no_args_is_help=True, help=help_doc)
@cloup.option(
"--key",
default=None,
help="query key",
)
@cloup.option(
"--value",
default=None,
help="query value",
)
def meta_query(key, value):
obj = EnhancedDataProfile()
objs = obj.query(**{key: value})
print(objs)
pass
2 changes: 2 additions & 0 deletions gwasstudio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# from gwasstudio.cli.export import export
from gwasstudio.cli.info import info
from gwasstudio.cli.metadata.ingest import meta_ingest
from gwasstudio.cli.metadata.query import meta_query
from gwasstudio.cli.metadata.view import meta_view

# from gwasstudio.cli.ingest import ingest
Expand Down Expand Up @@ -92,6 +93,7 @@ def main():
# cli_init.add_command(ingest)
cli_init.add_command(meta_ingest)
cli_init.add_command(meta_view)
cli_init.add_command(meta_query)
logger.info("{} started".format(__appname__.capitalize()))
cli_init(obj={})

Expand Down
16 changes: 16 additions & 0 deletions gwasstudio/mongo/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ def view(self):
logger.debug(detail)
return detail

def query(self, **kwargs):
"""
:param kwargs:
:return:
"""
docs = []
if len(kwargs) > 0:
with self.mec:
if "trait_desc" in kwargs.keys():
docs = self.klass.objects(trait_desc__contains=kwargs.get("trait_desc")).as_pymongo()
else:
docs = self.klass.objects(**kwargs).as_pymongo()
logger.debug("found {} documents".format(len(docs)))
return docs

def modify(self, **kwargs):
"""
Perform an atomic update of the document in the database and
Expand Down

0 comments on commit a9dc526

Please sign in to comment.