diff --git a/client/src/components/Dataset/DatasetAsImage/DatasetAsImage.vue b/client/src/components/Dataset/DatasetAsImage/DatasetAsImage.vue index 5f9f2f50f39b..ff93c69d5f99 100644 --- a/client/src/components/Dataset/DatasetAsImage/DatasetAsImage.vue +++ b/client/src/components/Dataset/DatasetAsImage/DatasetAsImage.vue @@ -14,15 +14,14 @@ const { datasetPathDestination } = useDatasetPathDestination(); const props = defineProps(); -const pathDestination = computed(() => - datasetPathDestination.value(props.historyDatasetId, props.path) -); +const pathDestination = computedAsync(async () => { + return await datasetPathDestination.value(props.historyDatasetId, props.path) +}, null); const imageUrl = computed(() => { if (props.path === undefined || props.path === "undefined") { return `${getAppRoot()}dataset/display?dataset_id=${props.historyDatasetId}`; } - return pathDestination.value?.fileLink; }); diff --git a/client/src/components/Dataset/DatasetIndex/DatasetIndex.vue b/client/src/components/Dataset/DatasetIndex/DatasetIndex.vue index 5001d7f2b20a..a0e2ac3514d2 100644 --- a/client/src/components/Dataset/DatasetIndex/DatasetIndex.vue +++ b/client/src/components/Dataset/DatasetIndex/DatasetIndex.vue @@ -1,4 +1,5 @@ + + diff --git a/client/src/composables/datasetPathDestination.ts b/client/src/composables/datasetPathDestination.ts index 89f419572d1a..518f914f1cef 100644 --- a/client/src/composables/datasetPathDestination.ts +++ b/client/src/composables/datasetPathDestination.ts @@ -20,11 +20,11 @@ export function useDatasetPathDestination() { const cache = ref<{ [key: string]: PathDestinationMap }>({}); const datasetPathDestination = computed(() => { - return (dataset_id: string, path?: string) => { + return async(dataset_id: string, path?: string) => { const targetPath = path ?? "undefined"; - const pathDestination = cache.value[dataset_id]?.[targetPath]; + let pathDestination = cache.value[dataset_id]?.[targetPath]; if (!pathDestination) { - getPathDestination(dataset_id, path); + pathDestination = await getPathDestination(dataset_id, path) ?? undefined; } return pathDestination ?? null; }; @@ -36,7 +36,6 @@ export function useDatasetPathDestination() { await datasetExtraFilesStore.fetchDatasetExtFilesByDatasetId({ id: dataset_id }); datasetExtraFiles = datasetExtraFilesStore.getDatasetExtraFiles(dataset_id); } - if (datasetExtraFiles === null) { return null; } @@ -66,9 +65,7 @@ export function useDatasetPathDestination() { } pathDestination.fileLink = getCompositeDatasetLink(dataset_id, datasetEntry.path); } - set(cache.value, dataset_id, { [path]: pathDestination }); - return pathDestination; } diff --git a/client/src/entry/analysis/router.js b/client/src/entry/analysis/router.js index 011bb9ffd082..5cf4b39737c9 100644 --- a/client/src/entry/analysis/router.js +++ b/client/src/entry/analysis/router.js @@ -21,6 +21,7 @@ import ToolLanding from "components/Landing/ToolLanding"; import WorkflowLanding from "components/Landing/WorkflowLanding"; import PageDisplay from "components/PageDisplay/PageDisplay"; import PageEditor from "components/PageEditor/PageEditor"; +import ToolReport from "components/Tool/ToolReport"; import ToolSuccess from "components/Tool/ToolSuccess"; import ToolsList from "components/ToolsList/ToolsList"; import ToolsJson from "components/ToolsView/ToolsSchemaJson/ToolsJson"; @@ -239,6 +240,11 @@ export function getRouter(Galaxy) { src: `/datasets/${route.params.datasetId}/display/?preview=True`, }), }, + { + path: "datasets/:datasetId/report", + component: ToolReport, + props: true, + }, { // legacy route, potentially used by 3rd parties path: "datasets/:datasetId/show_params", diff --git a/lib/galaxy/config/sample/datatypes_conf.xml.sample b/lib/galaxy/config/sample/datatypes_conf.xml.sample index 0e026b5a7b0a..365e722689c5 100644 --- a/lib/galaxy/config/sample/datatypes_conf.xml.sample +++ b/lib/galaxy/config/sample/datatypes_conf.xml.sample @@ -575,6 +575,7 @@ + diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index 0024adea6155..23503e6c2358 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -465,6 +465,7 @@ def _serve_file_download(self, headers, data, trans, to_ext, file_size, **kwd): composite_extensions = trans.app.datatypes_registry.get_composite_extensions() composite_extensions.append("html") # for archiving composite datatypes composite_extensions.append("data_manager_json") # for downloading bundles if bundled. + composite_extensions.append("tool_markdown") if data.extension in composite_extensions: return self._archive_composite_dataset(trans, data, headers, do_action=kwd.get("do_action", "zip")) diff --git a/lib/galaxy/managers/markdown_util.py b/lib/galaxy/managers/markdown_util.py index 02545399e997..757a9980e2cc 100644 --- a/lib/galaxy/managers/markdown_util.py +++ b/lib/galaxy/managers/markdown_util.py @@ -900,7 +900,7 @@ def _remap(container, line): ) if container == "history_link": return (f"history_link(history_id={invocation.history.id})\n", False) - if container == "invocation_time": + elif container == "invocation_time": return (f"invocation_time(invocation_id={invocation.id})\n", False) ref_object_type = None output_match = re.search(OUTPUT_LABEL_PATTERN, line) @@ -953,6 +953,70 @@ def find_non_empty_group(match): return galaxy_markdown +def resolve_job_markdown(trans, job, job_markdown): + """Resolve job objects to convert tool markdown to 'internal' representation. + + Replace references to abstract workflow parts with actual galaxy object IDs corresponding + to the actual executed workflow. For instance: + + convert output=name -to- history_dataset_id= | history_dataset_collection_id= + convert input=name -to- history_dataset_id= | history_dataset_collection_id= + convert argument-less job directives to job + """ + io_dicts = job.io_dicts() + + def _remap(container, line): + if container == "history_link": + return (f"history_link(history_id={job.history.id})\n", False) + elif container == "tool_stdout": + return (f"tool_stdout(job_id={job.id})\n", False) + elif container == "tool_stderr": + return (f"tool_stderr(job_id={job.id})\n", False) + elif container == "job_parameters": + return (f"job_parameters(job_id={job.id})\n", False) + elif container == "job_metrics": + return (f"job_metrics(job_id={job.id})\n", False) + ref_object_type = None + output_match = re.search(OUTPUT_LABEL_PATTERN, line) + input_match = re.search(INPUT_LABEL_PATTERN, line) + + def find_non_empty_group(match): + for group in match.groups(): + if group: + return group + + target_match: Optional[Match] + ref_object: Optional[Any] + if output_match: + target_match = output_match + name = find_non_empty_group(target_match) + if name in io_dicts.out_data: + ref_object = io_dicts.out_data[name] + elif name in io_dicts.out_collections: + ref_object = io_dicts.out_collections[name] + else: + raise Exception("Unknown exception") + elif input_match: + target_match = input_match + name = find_non_empty_group(target_match) + ref_object = io_dicts.inp_data[name] + else: + target_match = None + ref_object = None + if ref_object: + assert target_match # tell type system, this is set when ref_object is set + if ref_object_type is None: + if ref_object.history_content_type == "dataset": + ref_object_type = "history_dataset" + else: + ref_object_type = "history_dataset_collection" + line = line.replace(target_match.group(), f"{ref_object_type}_id={ref_object.id}") + return (line, False) + + galaxy_markdown = _remap_galaxy_markdown_calls(_remap, job_markdown) + return galaxy_markdown + + def _remap_galaxy_markdown_containers(func, markdown): new_markdown = markdown diff --git a/lib/galaxy/schema/schema.py b/lib/galaxy/schema/schema.py index 0d9646316e59..4bd05d09753e 100644 --- a/lib/galaxy/schema/schema.py +++ b/lib/galaxy/schema/schema.py @@ -3846,6 +3846,13 @@ class PageDetails(PageSummary): model_config = ConfigDict(extra="allow") +class ToolReportForDataset(BaseModel): + content: Optional[str] = ContentField + generate_version: Optional[str] = GenerateVersionField + generate_time: Optional[str] = GenerateTimeField + model_config = ConfigDict(extra="allow") + + class PageSummaryList(RootModel): root: List[PageSummary] = Field( default=[], diff --git a/lib/galaxy/webapps/galaxy/api/datasets.py b/lib/galaxy/webapps/galaxy/api/datasets.py index eba6795100fd..a7dbf8130550 100644 --- a/lib/galaxy/webapps/galaxy/api/datasets.py +++ b/lib/galaxy/webapps/galaxy/api/datasets.py @@ -39,6 +39,7 @@ AsyncTaskResultSummary, DatasetAssociationRoles, DatasetSourceType, + ToolReportForDataset, ) from galaxy.util.zipstream import ZipstreamWrapper from galaxy.webapps.base.api import GalaxyFileResponse @@ -503,6 +504,17 @@ def compute_hash( ) -> AsyncTaskResultSummary: return self.service.compute_hash(trans, dataset_id, payload, hda_ldda=hda_ldda) + @router.get( + "/api/datasets/{dataset_id}/report", + summary="Return JSON content Galaxy will use to render Markdown reports", + ) + def report( + self, + dataset_id: HistoryDatasetIDPathParam, + trans=DependsOnTrans, + ) -> ToolReportForDataset: + return self.service.report(trans, dataset_id) + @router.put( "/api/datasets/{dataset_id}/object_store_id", summary="Update an object store ID for a dataset you own.", diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index e1897420f9a5..8ffce93080c7 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -280,6 +280,7 @@ def app_pair(global_conf, load_app_kwds=None, wsgi_preflight=True, **kwargs): webapp.add_client_route("/datasets/{dataset_id}/error") webapp.add_client_route("/datasets/{dataset_id}/details") webapp.add_client_route("/datasets/{dataset_id}/preview") + webapp.add_client_route("/datasets/{dataset_id}/report") webapp.add_client_route("/datasets/{dataset_id}/show_params") webapp.add_client_route("/collection/{collection_id}/edit") webapp.add_client_route("/jobs/submission/success") diff --git a/lib/galaxy/webapps/galaxy/services/datasets.py b/lib/galaxy/webapps/galaxy/services/datasets.py index 4f6fef304697..d9cca09144b6 100644 --- a/lib/galaxy/webapps/galaxy/services/datasets.py +++ b/lib/galaxy/webapps/galaxy/services/datasets.py @@ -47,6 +47,10 @@ HistoryContentsManager, ) from galaxy.managers.lddas import LDDAManager +from galaxy.managers.markdown_util import ( + ready_galaxy_markdown_for_export, + resolve_job_markdown, +) from galaxy.model.base import transaction from galaxy.objectstore.badges import BadgeDict from galaxy.schema import ( @@ -70,6 +74,7 @@ DatasetSourceType, EncodedDatasetSourceId, Model, + ToolReportForDataset, UpdateDatasetPermissionsPayload, ) from galaxy.schema.tasks import ComputeDatasetHashTaskRequest @@ -506,6 +511,18 @@ def compute_hash( result = compute_dataset_hash.delay(request=request, task_user_id=getattr(trans.user, "id", None)) return async_task_summary(result) + def report(self, trans: ProvidesHistoryContext, dataset_id: DecodedDatabaseIdField) -> ToolReportForDataset: + dataset_instance = self.hda_manager.get_accessible(dataset_id, trans.user) + self.hda_manager.ensure_dataset_on_disk(trans, dataset_instance) + file_path = trans.app.object_store.get_filename(dataset_instance.dataset) + raw_content = open(file_path).read() + internal_markdown = resolve_job_markdown(trans, dataset_instance.creating_job, raw_content) + content, extra_attributes = ready_galaxy_markdown_for_export(trans, internal_markdown) + return ToolReportForDataset( + content=content, + **extra_attributes, + ) + def drs_dataset_instance(self, object_id: str) -> Tuple[int, DatasetSourceType]: if object_id.startswith("hda-"): decoded_object_id = self.decode_id(object_id[len("hda-") :], kind="drs") diff --git a/lib/tool_shed/webapp/frontend/src/components/RepositoriesForOwner.vue b/lib/tool_shed/webapp/frontend/src/components/RepositoriesForOwner.vue index 5db3578ca516..e0e44042cd58 100644 --- a/lib/tool_shed/webapp/frontend/src/components/RepositoriesForOwner.vue +++ b/lib/tool_shed/webapp/frontend/src/components/RepositoriesForOwner.vue @@ -48,5 +48,10 @@ const rows = computed(() => { diff --git a/test/functional/tools/data/1.bed b/test/functional/tools/data/1.bed new file mode 100644 index 000000000000..eb4c30e347a1 --- /dev/null +++ b/test/functional/tools/data/1.bed @@ -0,0 +1,65 @@ +chr1 147962192 147962580 CCDS989.1_cds_0_0_chr1_147962193_r 0 - +chr1 147984545 147984630 CCDS990.1_cds_0_0_chr1_147984546_f 0 + +chr1 148078400 148078582 CCDS993.1_cds_0_0_chr1_148078401_r 0 - +chr1 148185136 148185276 CCDS996.1_cds_0_0_chr1_148185137_f 0 + +chr10 55251623 55253124 CCDS7248.1_cds_0_0_chr10_55251624_r 0 - +chr11 116124407 116124501 CCDS8374.1_cds_0_0_chr11_116124408_r 0 - +chr11 116206508 116206563 CCDS8377.1_cds_0_0_chr11_116206509_f 0 + +chr11 116211733 116212337 CCDS8378.1_cds_0_0_chr11_116211734_r 0 - +chr11 1812377 1812407 CCDS7726.1_cds_0_0_chr11_1812378_f 0 + +chr12 38440094 38440321 CCDS8736.1_cds_0_0_chr12_38440095_r 0 - +chr13 112381694 112381953 CCDS9526.1_cds_0_0_chr13_112381695_f 0 + +chr14 98710240 98712285 CCDS9949.1_cds_0_0_chr14_98710241_r 0 - +chr15 41486872 41487060 CCDS10096.1_cds_0_0_chr15_41486873_r 0 - +chr15 41673708 41673857 CCDS10097.1_cds_0_0_chr15_41673709_f 0 + +chr15 41679161 41679250 CCDS10098.1_cds_0_0_chr15_41679162_r 0 - +chr15 41826029 41826196 CCDS10101.1_cds_0_0_chr15_41826030_f 0 + +chr16 142908 143003 CCDS10397.1_cds_0_0_chr16_142909_f 0 + +chr16 179963 180135 CCDS10401.1_cds_0_0_chr16_179964_r 0 - +chr16 244413 244681 CCDS10402.1_cds_0_0_chr16_244414_f 0 + +chr16 259268 259383 CCDS10403.1_cds_0_0_chr16_259269_r 0 - +chr18 23786114 23786321 CCDS11891.1_cds_0_0_chr18_23786115_r 0 - +chr18 59406881 59407046 CCDS11985.1_cds_0_0_chr18_59406882_f 0 + +chr18 59455932 59456337 CCDS11986.1_cds_0_0_chr18_59455933_r 0 - +chr18 59600586 59600754 CCDS11988.1_cds_0_0_chr18_59600587_f 0 + +chr19 59068595 59069564 CCDS12866.1_cds_0_0_chr19_59068596_f 0 + +chr19 59236026 59236146 CCDS12872.1_cds_0_0_chr19_59236027_r 0 - +chr19 59297998 59298008 CCDS12877.1_cds_0_0_chr19_59297999_f 0 + +chr19 59302168 59302288 CCDS12878.1_cds_0_0_chr19_59302169_r 0 - +chr2 118288583 118288668 CCDS2120.1_cds_0_0_chr2_118288584_f 0 + +chr2 118394148 118394202 CCDS2121.1_cds_0_0_chr2_118394149_r 0 - +chr2 220190202 220190242 CCDS2441.1_cds_0_0_chr2_220190203_f 0 + +chr2 220229609 220230869 CCDS2443.1_cds_0_0_chr2_220229610_r 0 - +chr20 33330413 33330423 CCDS13249.1_cds_0_0_chr20_33330414_r 0 - +chr20 33513606 33513792 CCDS13255.1_cds_0_0_chr20_33513607_f 0 + +chr20 33579500 33579527 CCDS13256.1_cds_0_0_chr20_33579501_r 0 - +chr20 33593260 33593348 CCDS13257.1_cds_0_0_chr20_33593261_f 0 + +chr21 32707032 32707192 CCDS13614.1_cds_0_0_chr21_32707033_f 0 + +chr21 32869641 32870022 CCDS13615.1_cds_0_0_chr21_32869642_r 0 - +chr21 33321040 33322012 CCDS13620.1_cds_0_0_chr21_33321041_f 0 + +chr21 33744994 33745040 CCDS13625.1_cds_0_0_chr21_33744995_r 0 - +chr22 30120223 30120265 CCDS13897.1_cds_0_0_chr22_30120224_f 0 + +chr22 30160419 30160661 CCDS13898.1_cds_0_0_chr22_30160420_r 0 - +chr22 30665273 30665360 CCDS13901.1_cds_0_0_chr22_30665274_f 0 + +chr22 30939054 30939266 CCDS13903.1_cds_0_0_chr22_30939055_r 0 - +chr5 131424298 131424460 CCDS4149.1_cds_0_0_chr5_131424299_f 0 + +chr5 131556601 131556672 CCDS4151.1_cds_0_0_chr5_131556602_r 0 - +chr5 131621326 131621419 CCDS4152.1_cds_0_0_chr5_131621327_f 0 + +chr5 131847541 131847666 CCDS4155.1_cds_0_0_chr5_131847542_r 0 - +chr6 108299600 108299744 CCDS5061.1_cds_0_0_chr6_108299601_r 0 - +chr6 108594662 108594687 CCDS5063.1_cds_0_0_chr6_108594663_f 0 + +chr6 108640045 108640151 CCDS5064.1_cds_0_0_chr6_108640046_r 0 - +chr6 108722976 108723115 CCDS5067.1_cds_0_0_chr6_108722977_f 0 + +chr7 113660517 113660685 CCDS5760.1_cds_0_0_chr7_113660518_f 0 + +chr7 116512159 116512389 CCDS5771.1_cds_0_0_chr7_116512160_r 0 - +chr7 116714099 116714152 CCDS5773.1_cds_0_0_chr7_116714100_f 0 + +chr7 116945541 116945787 CCDS5774.1_cds_0_0_chr7_116945542_r 0 - +chr8 118881131 118881317 CCDS6324.1_cds_0_0_chr8_118881132_r 0 - +chr9 128764156 128764189 CCDS6914.1_cds_0_0_chr9_128764157_f 0 + +chr9 128787519 128789136 CCDS6915.1_cds_0_0_chr9_128787520_r 0 - +chr9 128882427 128882523 CCDS6917.1_cds_0_0_chr9_128882428_f 0 + +chr9 128937229 128937445 CCDS6919.1_cds_0_0_chr9_128937230_r 0 - +chrX 122745047 122745924 CCDS14606.1_cds_0_0_chrX_122745048_f 0 + +chrX 152648964 152649196 CCDS14733.1_cds_0_0_chrX_152648965_r 0 - +chrX 152691446 152691471 CCDS14735.1_cds_0_0_chrX_152691447_f 0 + +chrX 152694029 152694263 CCDS14736.1_cds_0_0_chrX_152694030_r 0 - diff --git a/test/functional/tools/data/rgWebLogo3_test.jpg b/test/functional/tools/data/rgWebLogo3_test.jpg new file mode 100644 index 000000000000..8f7e77eba67c Binary files /dev/null and b/test/functional/tools/data/rgWebLogo3_test.jpg differ diff --git a/test/functional/tools/markdown_report_extra_files.xml b/test/functional/tools/markdown_report_extra_files.xml new file mode 100644 index 000000000000..d59ffcc59fc2 --- /dev/null +++ b/test/functional/tools/markdown_report_extra_files.xml @@ -0,0 +1,45 @@ + + '$output_report.extra_files_path/test.bed'; + cp '$__tool_directory__/data/rgWebLogo3_test.jpg' '$output_report.extra_files_path/rgWebLogo3_test.jpg'; + echo "I am writing this to standard output!"; + cp '${tool_markdown}' '${output_report}'; + ]]> + + + + + + + + + + + + + + + diff --git a/test/functional/tools/markdown_report_simple.xml b/test/functional/tools/markdown_report_simple.xml new file mode 100644 index 000000000000..cc714558754e --- /dev/null +++ b/test/functional/tools/markdown_report_simple.xml @@ -0,0 +1,45 @@ + + '$output_text'; + cp '$__tool_directory__/data/1.bed' '$output_table'; + cp '${tool_markdown}' '${output_report}'; + ]]> + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/sample_tool_conf.xml b/test/functional/tools/sample_tool_conf.xml index bb9d7568f600..498d768a498b 100644 --- a/test/functional/tools/sample_tool_conf.xml +++ b/test/functional/tools/sample_tool_conf.xml @@ -232,6 +232,8 @@ + +