Skip to content

Commit 37d8528

Browse files
authored
Merge pull request galaxyproject#21446 from mvdbeek/sample_sheet_column_fix
[25.1] Sample sheet column fix
2 parents 3a393c2 + 2534c3e commit 37d8528

4 files changed

Lines changed: 83 additions & 0 deletions

File tree

lib/galaxy/model/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8162,6 +8162,7 @@ def copy_to_collection(
81628162
collection=collection,
81638163
element_index=self.element_index,
81648164
element_identifier=self.element_identifier,
8165+
columns=self.columns,
81658166
)
81668167
return new_element
81678168

lib/galaxy/model/deferred.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def _materialize_collection_element(
372372
element=materialized_object,
373373
element_index=element.element_index,
374374
element_identifier=element.element_identifier,
375+
columns=element.columns,
375376
)
376377
return materialized_element
377378

lib/galaxy_test/api/test_dataset_collections.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,73 @@ def test_sample_sheet_map_over_preserves_columns(self, history_id):
508508
], f"Expected [3, 'control'], got {output_elements[2]['columns']}"
509509
assert output_elements[2]["element_identifier"] == "sample3"
510510

511+
def test_copy_sample_sheet_collection(self, history_id):
512+
"""Test that copying a sample sheet collection preserves columns metadata."""
513+
# Create a sample sheet collection with columns metadata
514+
contents = [
515+
("sample1", "content1"),
516+
("sample2", "content2"),
517+
]
518+
sample_sheet_identifiers = self.dataset_collection_populator.list_identifiers(history_id, contents)
519+
payload = dict(
520+
name="original sample sheet",
521+
instance_type="history",
522+
history_id=history_id,
523+
element_identifiers=sample_sheet_identifiers,
524+
collection_type="sample_sheet",
525+
column_definitions=[
526+
{"type": "int", "name": "replicate", "optional": False},
527+
{"type": "string", "name": "condition", "optional": False},
528+
],
529+
rows={
530+
"sample1": [1, "control"],
531+
"sample2": [2, "treatment"],
532+
},
533+
)
534+
create_response = self._post("dataset_collections", payload, json=True)
535+
original_collection = self._check_create_response(create_response)
536+
original_hdca_id = original_collection["id"]
537+
538+
# Verify the original sample sheet has columns metadata
539+
original_elements = original_collection["elements"]
540+
assert len(original_elements) == 2
541+
assert original_elements[0]["columns"] == [1, "control"]
542+
assert original_elements[1]["columns"] == [2, "treatment"]
543+
544+
# Copy the collection using the new copy_collection method
545+
copy_response = self.dataset_collection_populator.copy_collection(
546+
history_id, original_hdca_id, copy_elements=True, wait=False
547+
)
548+
copied_collection = copy_response.json()
549+
550+
# Fetch the full details of the copied collection
551+
copied_collection_details = self.dataset_populator.get_history_collection_details(
552+
history_id, content_id=copied_collection["id"]
553+
)
554+
555+
# Verify the copied collection has the same columns metadata
556+
copied_elements = copied_collection_details["elements"]
557+
assert len(copied_elements) == 2, f"Expected 2 elements, got {len(copied_elements)}"
558+
559+
# Check that columns metadata was preserved for each element
560+
self._assert_has_keys(copied_elements[0], "columns")
561+
assert copied_elements[0]["columns"] == [
562+
1,
563+
"control",
564+
], f"Expected [1, 'control'], got {copied_elements[0]['columns']}"
565+
assert copied_elements[0]["element_identifier"] == "sample1"
566+
567+
self._assert_has_keys(copied_elements[1], "columns")
568+
assert copied_elements[1]["columns"] == [
569+
2,
570+
"treatment",
571+
], f"Expected [2, 'treatment'], got {copied_elements[1]['columns']}"
572+
assert copied_elements[1]["element_identifier"] == "sample2"
573+
574+
# Verify column definitions are preserved
575+
assert copied_collection_details["column_definitions"] == original_collection["column_definitions"]
576+
assert copied_collection_details["collection_type"] == "sample_sheet"
577+
511578
def test_workbook_download(self):
512579
xlsx_file = self.dataset_collection_populator.download_workbook(
513580
"sample_sheet",

lib/galaxy_test/base/populators.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,20 @@ def create_list_in_history(self, history_id: str, wait: bool = False, **kwds):
34013401
payload = self.create_list_payload(history_id, instance_type="history", **kwds)
34023402
return self.__create(payload, wait=wait)
34033403

3404+
def copy_collection(self, history_id: str, hdca_id: str, copy_elements: bool = True, wait: bool = False):
3405+
"""Copy an existing dataset collection to a history."""
3406+
payload = {
3407+
"source": "hdca",
3408+
"content": hdca_id,
3409+
"type": "dataset_collection",
3410+
"copy_elements": copy_elements,
3411+
}
3412+
copy_response = self.dataset_populator._post(
3413+
f"histories/{history_id}/contents/dataset_collections", payload, json=True
3414+
)
3415+
api_asserts.assert_status_code_is_ok(copy_response)
3416+
return copy_response
3417+
34043418
def upload_collection(self, history_id: str, collection_type, elements, wait: bool = False, **kwds):
34053419
payload = self.__create_payload_fetch(history_id, collection_type, contents=elements, **kwds)
34063420
return self.__create(payload, wait=wait)

0 commit comments

Comments
 (0)