Skip to content

Commit 67ffc55

Browse files
committed
Implement CWL filename tracking...
1 parent c3600e6 commit 67ffc55

File tree

7 files changed

+53
-19
lines changed

7 files changed

+53
-19
lines changed

lib/galaxy/jobs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ def path_rewriter( path ):
13221322
dataset.set_peek( is_multi_byte=True )
13231323
else:
13241324
dataset.set_peek()
1325-
for context_key in ['name', 'info', 'dbkey']:
1325+
for context_key in ['name', 'info', 'dbkey', 'cwl_filename']:
13261326
if context_key in context:
13271327
context_value = context[context_key]
13281328
setattr(dataset, context_key, context_value)

lib/galaxy/managers/hdas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ def __init__( self, app ):
299299

300300
'annotation',
301301

302-
'api_type'
302+
'api_type',
303+
'cwl_file_name',
303304
], include_keys_from='summary' )
304305

305306
self.add_view( 'extended', [
@@ -353,7 +354,8 @@ def add_serializers( self ):
353354
# TODO: to DatasetAssociationSerializer
354355
'accessible' : lambda i, k, user=None, **c: self.manager.is_accessible( i, user ),
355356
'api_type' : lambda *a, **c: 'file',
356-
'type' : lambda *a, **c: 'file'
357+
'type' : lambda *a, **c: 'file',
358+
'cwl_file_name' : lambda i, k, **c: i.cwl_filename,
357359
})
358360

359361
def serialize( self, hda, keys, user=None, **context ):

lib/galaxy/model/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,19 @@ def has_data( self ):
20692069
"""Detects whether there is any data"""
20702070
return self.dataset.has_data()
20712071

2072+
def get_cwl_filename( self ):
2073+
return self.dataset.cwl_filename
2074+
2075+
def set_cwl_filename( self, cwl_filename ):
2076+
# This should be a write-once property intrinsic to the underlying
2077+
# dataset for pure CWL workflows. We may wish to revisit that for
2078+
# usability longer term.
2079+
if self.dataset.cwl_filename is not None:
2080+
raise Exception("Underlying dataset already has a cwlfilename set.")
2081+
self.dataset.cwl_filename = cwl_filename
2082+
2083+
cwl_filename = property( get_cwl_filename, set_cwl_filename )
2084+
20722085
def get_raw_data( self ):
20732086
"""Returns the full data. To stream it open the file_name and read/write as needed"""
20742087
return self.datatype.get_raw_data( self )

lib/galaxy/model/mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
Column( "object_store_id", TrimmedString( 255 ), index=True ),
177177
Column( "external_filename", TEXT ),
178178
Column( "_extra_files_path", TEXT ),
179+
Column( "cwl_filename", TEXT ),
179180
Column( 'file_size', Numeric( 15, 0 ) ),
180181
Column( 'total_size', Numeric( 15, 0 ) ),
181182
Column( 'uuid', UUIDType() ) )

lib/galaxy/model/migrate/versions/0138_cwl_state.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import datetime
55
import logging
66

7-
from sqlalchemy import Integer, Column, MetaData, Table
7+
from sqlalchemy import Integer, Column, MetaData, Table, TEXT
88
from galaxy.model.custom_types import JSONType
99

1010
now = datetime.datetime.utcnow
@@ -19,8 +19,12 @@ def upgrade(migrate_engine):
1919

2020
cwl_command_column = Column( "cwl_command_state", JSONType, default=True )
2121
cwl_command_version_column = Column( "cwl_command_state_version", Integer, default=True )
22+
23+
cwl_file_name = Column( "cwl_filename", TEXT, default=None, )
24+
2225
__add_column( cwl_command_column, "job", metadata )
2326
__add_column( cwl_command_version_column, "job", metadata )
27+
__add_column( cwl_file_name, "dataset", metadata )
2428

2529

2630
def downgrade(migrate_engine):
@@ -30,6 +34,8 @@ def downgrade(migrate_engine):
3034
__drop_column( "cwl_command_state", "job", metadata )
3135
__drop_column( "cwl_command_state_version", "job", metadata )
3236

37+
__drop_column( "cwl_filename", "dataset", metadata )
38+
3339

3440
def __add_column(column, table_name, metadata, **kwds):
3541
try:

lib/galaxy/tools/cwl/runtime_actions.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ def handle_outputs(job_directory=None):
2727

2828
def handle_output_location(output, target_path):
2929
output_path = ref_resolver.uri_file_path(output["location"])
30-
if output["class"] != "File":
31-
open("galaxy.json", "w").write(json.dump({
32-
"dataset_id": job_proxy.output_id(output_name),
33-
"type": "dataset",
34-
"ext": "expression.json",
35-
}))
30+
with open("galaxy.json", "a+") as f:
31+
if output["class"] != "File":
32+
json.dump({
33+
"dataset_id": job_proxy.output_id(output_name),
34+
"type": "dataset",
35+
"ext": "expression.json",
36+
}, f)
37+
else:
38+
json.dump({
39+
"dataset_id": job_proxy.output_id(output_name),
40+
"type": "dataset",
41+
"cwl_filename": output["basename"],
42+
}, f)
43+
f.write("\n")
44+
3645
shutil.move(output_path, target_path)
3746
for secondary_file in output.get("secondaryFiles", []):
3847
# TODO: handle nested files...

test/api/test_tools_cwl.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@ def _get_job_stdout(self, job_id):
135135

136136
@skip_without_tool( "cat3-tool" )
137137
def test_cat3( self ):
138-
history_id = self.dataset_populator.new_history()
139-
hda1 = _dataset_to_param( self.dataset_populator.new_dataset( history_id, content='1\t2\t3' ) )
140-
inputs = {
141-
"f1": hda1,
142-
}
143-
response = self._run( "cat3-tool", history_id, inputs, assert_ok=True )
144-
output1 = response[ "outputs" ][ 0 ]
145-
output1_content = self.dataset_populator.get_history_dataset_content( history_id, dataset=output1 )
146-
assert output1_content == "1\t2\t3\n", output1_content
138+
with self.dataset_populator.test_history() as history_id:
139+
hda1 = _dataset_to_param( self.dataset_populator.new_dataset( history_id, content='1\t2\t3' ) )
140+
inputs = {
141+
"f1": hda1,
142+
}
143+
response = self._run( "cat3-tool", history_id, inputs, assert_ok=True )
144+
output1 = response[ "outputs" ][ 0 ]
145+
output1_details = self.dataset_populator.get_history_dataset_details( history_id, dataset=output1 )
146+
assert "cwl_file_name" in output1_details, output1_details.keys()
147+
assert output1_details["cwl_file_name"] == "output.txt", output1_details["cwl_file_name"]
148+
output1_content = self.dataset_populator.get_history_dataset_content( history_id, dataset=output1 )
149+
assert output1_content == "1\t2\t3\n", output1_content
147150

148151
@skip_without_tool( "sorttool" )
149152
def test_sorttool( self ):

0 commit comments

Comments
 (0)