Skip to content
Merged
13 changes: 12 additions & 1 deletion src/mavedb/lib/experiments.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Optional

from sqlalchemy import func, or_
from sqlalchemy import func, or_, not_
from sqlalchemy.orm import Session

from mavedb.lib.logging.context import logging_context, save_to_logging_context
Expand Down Expand Up @@ -99,6 +99,17 @@ def search_experiments(
)
)

if search.meta_analysis is not None:
if not search.meta_analysis:
query = query.filter(
or_(
# Keep experiments without any score sets
not_(Experiment.score_sets.any()),
# Keep experiments where score sets exist but have no meta_analyzes_score_sets
Experiment.score_sets.any(not_(ScoreSet.meta_analyzes_score_sets.any()))
)
)

items: list[Experiment] = query.order_by(Experiment.urn, Experiment.title).all()
if not items:
items = []
Expand Down
39 changes: 0 additions & 39 deletions src/mavedb/routers/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,6 @@
)


# TODO: Rewrite this function.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets retain this function-- I think it still has utility for just listing all experiments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll modify it so that we don't need to send the weird q to it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok to just leave it as is for this PR so we can get it released. We can just handle it at some point later-- it isn't hurting anything right now.

@router.get(
"/experiments/",
status_code=200,
response_model=list[experiment.Experiment],
response_model_exclude_none=True,
)
def list_experiments(
*,
editable: Optional[bool] = None,
q: Optional[str] = None,
db: Session = Depends(deps.get_db),
user_data: Optional[UserData] = Depends(get_current_user),
) -> list[Experiment]:
"""
List experiments.
"""
query = db.query(Experiment)
if q is not None:
save_to_logging_context({"query_string": q})

if user_data is None or user_data.user is None:
logger.debug(msg="User is anonymous; Cannot list their experiments.", extra=logging_context())
return []

if len(q) > 0:
logger.debug(msg="Listing experiments for the current user.", extra=logging_context())
query = query.filter(
Experiment.created_by_id == user_data.user.id
) # .filter(Experiment.published_date is None)
# else:
# query = query.filter(Experiment.created_by_id == user.id).filter(Experiment.published_date is None)
else:
logger.debug(msg="No query string was provided; Listing all experiments.", extra=logging_context())

items = query.order_by(Experiment.urn).all()
return items


@router.post(
"/experiments/search",
status_code=200,
Expand Down
1 change: 1 addition & 0 deletions src/mavedb/view_models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ExperimentsSearch(BaseModel):
publication_identifiers: Optional[list[str]]
keywords: Optional[list[str]]
text: Optional[str]
meta_analysis: Optional[bool]


class ScoreSetsSearch(BaseModel):
Expand Down
Loading