Skip to content

Commit

Permalink
harness updates to accommodate DatabaseUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaypatil96 committed Dec 27, 2024
1 parent 8af1493 commit ae220be
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
6 changes: 4 additions & 2 deletions nmdc_runtime/site/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@ def nmdc_study_to_ncbi_submission_export():

@graph
def fill_missing_data_generation_data_object_records():
study_id = get_database_updater_inputs()
database = missing_data_generation_repair(study_id)
(study_id, gold_nmdc_instrument_mapping_file_url) = get_database_updater_inputs()
gold_nmdc_instrument_map_df = get_df_from_url(gold_nmdc_instrument_mapping_file_url)

database = missing_data_generation_repair(study_id, gold_nmdc_instrument_map_df)

database_dict = nmdc_schema_object_to_dict(database)
filename = nmdc_study_id_filename(study_id)
Expand Down
48 changes: 39 additions & 9 deletions nmdc_runtime/site/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,19 +1255,49 @@ def nmdc_study_id_filename(nmdc_study_id: str) -> str:


@op(
config_schema={"nmdc_study_id": str},
out={"nmdc_study_id": Out(str)},
config_schema={
"nmdc_study_id": str,
"gold_nmdc_instrument_mapping_file_url": str,
},
out={
"nmdc_study_id": Out(str),
"gold_nmdc_instrument_mapping_file_url": Out(str),
},
)
def get_database_updater_inputs(context: OpExecutionContext) -> str:
return context.op_config["nmdc_study_id"]
def get_database_updater_inputs(context: OpExecutionContext) -> Tuple[str, str]:
return (
context.op_config["nmdc_study_id"],
context.op_config["gold_nmdc_instrument_mapping_file_url"],
)


@op(required_resource_keys={"runtime_api_user_client"})
@op(
required_resource_keys={
"runtime_api_user_client",
"runtime_api_site_client",
"gold_api_client",
}
)
def missing_data_generation_repair(
context: OpExecutionContext, nmdc_study_id: str
context: OpExecutionContext,
nmdc_study_id: str,
gold_nmdc_instrument_map_df: pd.DataFrame,
) -> nmdc.Database:
client: RuntimeApiUserClient = context.resources.runtime_api_user_client
database_updater = DatabaseUpdater(client, nmdc_study_id)
database = database_updater.get_database()
runtime_api_user_client: RuntimeApiUserClient = (
context.resources.runtime_api_user_client
)
runtime_api_site_client: RuntimeApiSiteClient = (
context.resources.runtime_api_site_client
)
gold_api_client: GoldApiClient = context.resources.gold_api_client

database_updater = DatabaseUpdater(
runtime_api_user_client,
runtime_api_site_client,
gold_api_client,
nmdc_study_id,
gold_nmdc_instrument_map_df,
)
database = database_updater.create_missing_dg_records()

return database
16 changes: 16 additions & 0 deletions nmdc_runtime/site/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,28 @@ def database_record_repair():
"password": {"env": "API_ADMIN_PASS"},
},
},
"runtime_api_site_client": {
"config": {
"base_url": {"env": "API_HOST"},
"client_id": {"env": "API_SITE_CLIENT_ID"},
"client_secret": {"env": "API_SITE_CLIENT_SECRET"},
"site_id": {"env": "API_SITE_ID"},
},
},
"gold_api_client": {
"config": {
"base_url": {"env": "GOLD_API_BASE_URL"},
"username": {"env": "GOLD_API_USERNAME"},
"password": {"env": "GOLD_API_PASSWORD"},
},
},
},
),
"ops": {
"get_database_updater_inputs": {
"config": {
"nmdc_study_id": "",
"gold_nmdc_instrument_mapping_file_url": "https://raw.githubusercontent.com/microbiomedata/nmdc-schema/refs/heads/main/assets/misc/gold_seqMethod_to_nmdc_instrument_set.tsv",
}
},
"export_json_to_drs": {"config": {"username": ""}},
Expand Down
12 changes: 12 additions & 0 deletions nmdc_runtime/site/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ def fetch_study(self, id: str) -> Union[Dict[str, Any], None]:
return None
return results[0]

def fetch_projects_by_biosample(self, biosample_id: str) -> List[Dict[str, Any]]:
id = self._normalize_id(biosample_id)
results = self.request("/projects", params={"biosampleGoldId": id})
return results

def fetch_biosample_by_biosample_id(
self, biosample_id: str
) -> List[Dict[str, Any]]:
id = self._normalize_id(biosample_id)
results = self.request("/biosamples", params={"biosampleGoldId": id})
return results


@resource(
config_schema={
Expand Down

0 comments on commit ae220be

Please sign in to comment.