Skip to content

Commit

Permalink
Changes to /analysis-runner API point (#690)
Browse files Browse the repository at this point in the history
* Added ar_guid query parameter to GET /analysis-runner API point.

* Commenting out author from getAnalysisRunnerLog as it is not currently implemented.
  • Loading branch information
milo-hyben authored Feb 27, 2024
1 parent 866123c commit bd3447a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
40 changes: 25 additions & 15 deletions api/routes/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,25 @@ class AnalysisQueryModel(BaseModel):
def to_filter(self, project_id_map: dict[str, int]) -> AnalysisFilter:
"""Convert to internal analysis filter"""
return AnalysisFilter(
sample_id=GenericFilter(
in_=sample_id_transform_to_raw_list(self.sample_ids)
)
if self.sample_ids
else None,
sequencing_group_id=GenericFilter(
in_=sequencing_group_id_transform_to_raw_list(self.sequencing_group_ids)
)
if self.sequencing_group_ids
else None,
project=GenericFilter(in_=[project_id_map.get(p) for p in self.projects])
if self.projects
else None,
sample_id=(
GenericFilter(in_=sample_id_transform_to_raw_list(self.sample_ids))
if self.sample_ids
else None
),
sequencing_group_id=(
GenericFilter(
in_=sequencing_group_id_transform_to_raw_list(
self.sequencing_group_ids
)
)
if self.sequencing_group_ids
else None
),
project=(
GenericFilter(in_=[project_id_map.get(p) for p in self.projects])
if self.projects
else None
),
type=GenericFilter(eq=self.type) if self.type else None,
)

Expand Down Expand Up @@ -241,8 +247,9 @@ async def query_analyses(
@router.get('/analysis-runner', operation_id='getAnalysisRunnerLog')
async def get_analysis_runner_log(
project_names: list[str] = Query(None), # type: ignore
author: str = None,
# author: str = None, # not implemented yet, uncomment when we do
output_dir: str = None,
ar_guid: str = None,
connection: Connection = get_projectless_db_connection,
) -> list[AnalysisInternal]:
"""
Expand All @@ -257,7 +264,10 @@ async def get_analysis_runner_log(
)

results = await atable.get_analysis_runner_log(
project_ids=project_ids, author=author, output_dir=output_dir
project_ids=project_ids,
# author=author,
output_dir=output_dir,
ar_guid=ar_guid,
)
return [a.to_external() for a in results]

Expand Down
18 changes: 12 additions & 6 deletions db/python/layers/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ async def get_cram_sizes_between_range(
sample_create_dates = await sglayer.get_samples_create_date_from_sgs(
list(crams.keys())
)
by_date: dict[
SequencingGroupInternalId, list[tuple[datetime.date, int]]
] = defaultdict(list)
by_date: dict[SequencingGroupInternalId, list[tuple[datetime.date, int]]] = (
defaultdict(list)
)

for sg_id, analyses in crams.items():
if len(analyses) == 1:
Expand Down Expand Up @@ -531,7 +531,9 @@ async def get_sgs_added_by_day_by_es_indices(

return by_day

async def get_audit_logs_by_analysis_ids(self, analysis_ids: list[int]) -> dict[int, list[AuditLogInternal]]:
async def get_audit_logs_by_analysis_ids(
self, analysis_ids: list[int]
) -> dict[int, list[AuditLogInternal]]:
"""Get audit logs for analysis IDs"""
return await self.at.get_audit_log_for_analysis_ids(analysis_ids)

Expand Down Expand Up @@ -594,12 +596,16 @@ async def update_analysis(
async def get_analysis_runner_log(
self,
project_ids: list[int] = None,
author: str = None,
# author: str = None,
output_dir: str = None,
ar_guid: str = None,
) -> list[AnalysisInternal]:
"""
Get log for the analysis-runner, useful for checking this history of analysis
"""
return await self.at.get_analysis_runner_log(
project_ids, author=author, output_dir=output_dir
project_ids,
# author=author,
output_dir=output_dir,
ar_guid=ar_guid,
)
11 changes: 6 additions & 5 deletions db/python/tables/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ async def get_sample_cram_path_map_for_seqr(
async def get_analysis_runner_log(
self,
project_ids: List[int] = None,
author: str = None,
# author: str = None,
output_dir: str = None,
ar_guid: str = None,
) -> List[AnalysisInternal]:
"""
Get log for the analysis-runner, useful for checking this history of analysis
Expand All @@ -501,15 +502,15 @@ async def get_analysis_runner_log(
wheres.append('project in :project_ids')
values['project_ids'] = project_ids

if author:
wheres.append('audit_log_id = :audit_log_id')
values['audit_log_id'] = await self.audit_log_id()

if output_dir:
wheres.append('(output = :output OR output LIKE :output_like)')
values['output'] = output_dir
values['output_like'] = f'%{output_dir}'

if ar_guid:
wheres.append('JSON_EXTRACT(meta, "$.ar_guid") = :ar_guid')
values['ar_guid'] = ar_guid

wheres_str = ' AND '.join(wheres)
_query = f'SELECT * FROM analysis WHERE {wheres_str}'
rows = await self.connection.fetch_all(_query, values)
Expand Down

0 comments on commit bd3447a

Please sign in to comment.