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

Updated stacky with new metadata manager #509

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_library_from_library_id(library_id: Union[int | str]) -> Dict:
if isinstance(library_id, str):
# We have an internal id, convert to int
params = {
"internal_id": library_id
"library_id": library_id
}
else:
endpoint = f"{endpoint}/{library_id}"
Expand Down Expand Up @@ -94,6 +94,28 @@ def get_library_workflow(library_id: str) -> Union[str | None]:
return library.get("workflow")


def get_library_project_owner(library_id: str) -> Union[str | None]:
"""
Given a library id, collect the library project owner
:param library_id:
:return:
"""
library = get_library_from_library_id(library_id)

return library.get("project_owner")
Copy link
Member

@williamputraintan williamputraintan Aug 21, 2024

Choose a reason for hiding this comment

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

On the casing end, I suppose this get will take value directly from the results JSON? (From #502) the metadata now has a middleware to translate snake_case to camelCase aligning with other microservices, so this might not get project_owner properly.

In terms of query params, the API may still support snake_case filters, but would recommend using the camelCase if you can as this is what the Swagger documents it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this is the same for library_id/Id and subject_id/Id too?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the response will be in camelCase



def get_library_project_name(library_id: str) -> Union[str | None]:
"""
Given a library id, collect the library workflow
:param library_id:
:return:
"""
library = get_library_from_library_id(library_id)

return library.get("project_name")


def get_all_libraries() -> List[Dict]:
"""
Collect all libraries from the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_specimen_from_specimen_id(specimen_id: Union[str, int]) -> Dict:
if isinstance(specimen_id, str):
# We have an internal id, convert to int
params = {
"internal_id": specimen_id
"specimen_id": specimen_id
}
else:
endpoint = f"{endpoint}/{specimen_id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_subject_from_subject_id(subject_id: Union[str, int]) -> Dict:
if isinstance(subject_id, str):
# We have an internal id, convert to int
params = {
"internal_id": subject_id
"subject_id": subject_id
}
else:
endpoint = f"{endpoint}/{subject_id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

def generate_subject_event_data_object_from_subject(subject_obj: Dict, instrument_run_id: str) -> Dict:
return {
"id": subject_obj.get("id"),
"event_data": {
"instrumentRunId": instrument_run_id,
"subject": {
"id": subject_obj.get("id"),
"internalId": subject_obj.get("internal_id")
"orcabusId": subject_obj.get("orcabus_id"),
"subjectId": subject_obj.get("subject_id")
}
}
}
Expand Down Expand Up @@ -66,7 +65,7 @@ def get_library_bclconvert_rows(library_obj: Dict, bclconvert_data: List[Dict])
"""
return list(
filter(
lambda bclconvert_row: bclconvert_row.get("sample_id") == library_obj.get("internal_id"),
lambda bclconvert_row: bclconvert_row.get("sample_id") == library_obj.get("library_id"),
bclconvert_data
)
)
Expand All @@ -90,21 +89,23 @@ def generate_library_event_data_object_from_library_specimen_and_subject(
"""

library_event_obj = {
"id": library_obj.get("id"),
"internalId": library_obj.get("internal_id"),
"orcabusId": library_obj.get("orcabus_id"),
"libraryId": library_obj.get("library_id"),
"phenotype": library_obj.get("phenotype", None),
"workflow": library_obj.get("workflow", None),
"quality": library_obj.get("quality", None),
"type": library_obj.get("type", None),
"assay": library_obj.get("assay", None),
"coverage": library_obj.get("coverage", None),
"projectOwner": library_obj.get("project_owner", None),
"projectName": library_obj.get("project_name", None),
"specimen": {
"id": specimen_obj.get("id"),
"internalId": specimen_obj.get("internal_id")
"orcabusId": specimen_obj.get("orcabus_id"),
"specimenId": specimen_obj.get("specimen_id")
},
"subject": {
"id": subject_obj.get("id"),
"internalId": subject_obj.get("internal_id")
"orcabusId": subject_obj.get("orcabus_id"),
"subjectId": subject_obj.get("subject_id")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
"Type": "Map",
"ItemsPath": "$.generate_event_objects_step.subject_event_data_list",
"ItemSelector": {
"subject_id.$": "$$.Map.Item.Value.event_data.subject.internalId",
"subject_metadata_db_id.$": "$$.Map.Item.Value.id",
"subject_id.$": "$$.Map.Item.Value.event_data.subject.subjectId",
"subject_orcabus_id.$": "$$.Map.Item.Value.subject.orcabusId",
"subject_event_data.$": "$$.Map.Item.Value.event_data",
"instrument_run_id.$": "$$.Map.Item.Value.event_data.instrumentRunId"
},
Expand Down Expand Up @@ -228,10 +228,10 @@
"id_type": {
"S": "${__subject_table_partition_name__}"
},
"metadata_db_id": {
"N.$": "States.Format('{}', $.subject_metadata_db_id)"
"orcabus_id": {
"S.$": "$.subject_orcabus_id"
},
"internal_id": {
"subject_id": {
"S.$": "$.subject_id"
},
"instrument_run_id_set": {
Expand Down Expand Up @@ -298,8 +298,8 @@
"Type": "Map",
"ItemsPath": "$.generate_event_objects_step.library_event_data_list",
"ItemSelector": {
"library_id.$": "$$.Map.Item.Value.event_data.library.internalId",
"library_metadata_db_id.$": "$$.Map.Item.Value.id",
"library_id.$": "$$.Map.Item.Value.event_data.library.libraryId",
"library_orcabus_id.$": "$$.Map.Item.Value.library.orcabusId",
"library_event_data.$": "$$.Map.Item.Value.event_data",
"instrument_run_id.$": "$$.Map.Item.Value.event_data.instrumentRunId"
},
Expand Down Expand Up @@ -370,11 +370,11 @@
"id_type": {
"S": "${__library_table_partition_name__}"
},
"metadata_db_id": {
"N.$": "States.Format('{}', $.library_metadata_db_id)"
"orcabus_id": {
"S.$": "$.library_orcabus_id"
},
"internal_id": {
"S.$": "$.library_event_data.library.internalId"
"library_id": {
"S.$": "$.library_event_data.library.libraryId"
},
"instrument_run_id_set": {
"SS.$": "States.Array($.instrument_run_id)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ItemSelector": {
"bclconvert_data_row.$": "$$.Map.Item.Value",
"instrument_run_id.$": "$.input_payload_data.instrumentRunId",
"library_id.$": "$.input_payload_data.library.internalId"
"library_id.$": "$.input_payload_data.library.libraryId"
},
"ItemProcessor": {
"ProcessorConfig": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"UpdateExpression": "ADD library_set :library_set, fastq_list_row_id_set :fastq_list_row_id_set",
"ExpressionAttributeValues": {
":library_set": {
"SS.$": "States.Array($.input_payload_data.library.internalId)"
"SS.$": "States.Array($.input_payload_data.library.libraryId)"
},
":fastq_list_row_id_set": {
"SS.$": "$.bclconvert_and_fastq_list_row_id_inputs[*].fastq_list_row_id"
Expand All @@ -84,16 +84,16 @@
"TableName": "${__table_name__}",
"Item": {
"id": {
"S.$": "$.input_payload_data.library.internalId"
"S.$": "$.input_payload_data.library.libraryId"
},
"id_type": {
"S": "${__library_partition_name__}"
},
"metadata_db_id": {
"N.$": "States.Format('{}', $.input_payload_data.library.id)"
"orcabus_id": {
"S.$": "$.input_payload_data.library.orcabusId"
},
"internal_id": {
"S.$": "$.input_payload_data.library.internalId"
"library_id": {
"S.$": "$.input_payload_data.library.libraryId"
},
"fastq_list_row_id_set": {
"SS.$": "$.bclconvert_and_fastq_list_row_id_inputs[*].fastq_list_row_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"ResultPath": "$.get_fastq_list_row_ids_step",
"ResultSelector": {
"internal_id.$": "$.Item.internal_id.S",
"library_id.$": "$.Item.library_id.S",
"fastq_list_row_id_list.$": "$.Item.fastq_list_row_id_set.SS"
},
"Next": "For each FastqListRowID"
Expand Down Expand Up @@ -186,7 +186,7 @@
}
],
"ResultSelector": {
"sample_id.$": "$[0].get_fastq_list_row_ids_step.internal_id",
"sample_id.$": "$[0].get_fastq_list_row_ids_step.library_id",
"samplesheet.$": "$[0].generate_samplesheet_step.samplesheet",
"fastq_list_rows.$": "$[0].get_fastq_list_row_values_step.fastq_list_rows",
"fastq_list_row_ids.$": "$[0].get_fastq_list_row_ids_step.fastq_list_row_id_list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ItemSelector": {
"bclconvert_data_row.$": "$$.Map.Item.Value",
"instrument_run_id.$": "$.input_payload_data.instrumentRunId",
"library_id.$": "$.input_payload_data.library.internalId"
"library_id.$": "$.input_payload_data.library.libraryId"
},
"ItemProcessor": {
"ProcessorConfig": {
Expand Down Expand Up @@ -62,7 +62,7 @@
"UpdateExpression": "ADD library_set :library_set, fastq_list_row_id_set :fastq_list_row_id_set",
"ExpressionAttributeValues": {
":library_set": {
"SS.$": "States.Array($.input_payload_data.library.internalId)"
"SS.$": "States.Array($.input_payload_data.library.libraryId)"
},
":fastq_list_row_id_set": {
"SS.$": "$.bclconvert_and_fastq_list_row_id_inputs[*].fastq_list_row_id"
Expand All @@ -83,16 +83,16 @@
"TableName": "${__table_name__}",
"Item": {
"id": {
"S.$": "$.input_payload_data.library.internalId"
"S.$": "$.input_payload_data.library.libraryId"
},
"id_type": {
"S": "${__library_partition_name__}"
},
"metadata_db_id": {
"N.$": "States.Format('{}', $.input_payload_data.library.id)"
"orcabus_id": {
"S.$": "$.input_payload_data.library.orcabusId"
},
"internal_id": {
"S.$": "$.input_payload_data.library.internalId"
"library_id": {
"S.$": "$.input_payload_data.library.libraryId"
},
"sample_type": {
"S.$": "$.input_payload_data.library.type"
Expand All @@ -114,7 +114,7 @@
"ItemsPath": "$.bclconvert_and_fastq_list_row_id_inputs",
"ItemSelector": {
"fastq_list_row_id.$": "$$.Map.Item.Value.fastq_list_row_id",
"library_id.$": "$.input_payload_data.library.internalId",
"library_id.$": "$.input_payload_data.library.libraryId",
"instrument_run_id.$": "$.input_payload_data.instrumentRunId"
},
"ItemProcessor": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"Next": "For each FastqListRowID",
"ResultPath": "$.get_fastq_list_row_ids_step",
"ResultSelector": {
"internal_id.$": "$.Item.internal_id.S",
"library_id.$": "$.Item.library_id.S",
"sample_type.$": "$.Item.sample_type.S",
"fastq_list_row_id_list.$": "$.Item.fastq_list_row_id_set.SS"
}
Expand All @@ -62,7 +62,7 @@
"ItemSelector": {
"fastq_list_row_id.$": "$$.Map.Item.Value",
"sample_type.$": "$.get_fastq_list_row_ids_step.sample_type",
"library_id.$": "$.get_fastq_list_row_ids_step.internal_id",
"library_id.$": "$.get_fastq_list_row_ids_step.library_id",
"instrument_run_id.$": "$.instrument_run_id"
},
"ItemProcessor": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Parameters": {
"TableName": "${__table_name__}",
"Key": {
"id.$": "$.payload_data.subject.internalId",
"id.$": "$.payload_data.subject.subjectId",
"id_type": "${__subject_partition_name__}"
}
},
Expand Down Expand Up @@ -44,10 +44,10 @@
"Parameters": {
"TableName": "${__table_name__}",
"Item": {
"id.$": "$.payload_data.subject.internalId",
"id.$": "$.payload_data.subject.subjectId",
"id_type": "${__subject_partition_name__}",
"metadata_db_id": {
"N.$": "States.Format('{}', $.payload_data.subject.id)"
"orcabus_id": {
"S.$": "$.payload_data.subject.orcabusId"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Parameters": {
"TableName": "${__table_name__}",
"Key": {
"id.$": "$.payload_data.library.internalId",
"id.$": "$.payload_data.library.libraryId",
"id_type": "${__library_partition_name__}"
}
},
Expand All @@ -34,13 +34,13 @@
"Parameters": {
"TableName": "${__table_name__}",
"Key": {
"id.$": "$.payload_data.library.subject.internalId",
"id.$": "$.payload_data.library.subject.subjectId",
"id_type": "${__subject_partition_name__}"
},
"UpdateExpression": "ADD library_set :library_set",
"ExpressionAttributeValues": {
":library_set": {
"SS.$": "States.Array($.payload_data.library.internalId)"
"SS.$": "States.Array($.payload_data.library.libraryId)"
}
}
},
Expand Down Expand Up @@ -70,10 +70,10 @@
"Parameters": {
"TableName": "${__table_name__}",
"Item": {
"id.$": "$.payload_data.library.internalId",
"id.$": "$.payload_data.library.libraryId",
"id_type": "${__library_partition_name__}",
"metadata_db_id": {
"N.$": "States.Format('{}', $.payload_data.library.id)"
"orcabus_id": {
"S.$": "$.payload_data.library.orcabusId"
},
"phenotype": {
"S.$": "$.payload_data.library.phenotype"
Expand All @@ -88,7 +88,7 @@
"S.$": "$.payload_data.library.assay"
},
"subject_id": {
"S.$": "$.payload_data.library.subject.internalId"
"S.$": "$.payload_data.library.subject.subjectId"
}
}
},
Expand All @@ -112,7 +112,7 @@
"ItemSelector": {
"bclconvert_data_row.$": "$$.Map.Item.Value",
"instrument_run_id.$": "$.payload_data.instrumentRunId",
"library_id.$": "$.payload_data.library.internalId"
"library_id.$": "$.payload_data.library.libraryId"
},
"ItemProcessor": {
"ProcessorConfig": {
Expand Down
Loading