mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
Add tool for exporting individual files to Galaxy.
Stolen wholesale from EU. Trying to make it a bit more general though.
This commit is contained in:
@@ -23,7 +23,8 @@
|
||||
<tool file="data_source/hbvar.xml" />
|
||||
</section>
|
||||
<section id="send" name="Send Data">
|
||||
<tool file="cloud/send.xml" />
|
||||
<tool file="data_export/send.xml" />
|
||||
<tool file="data_export/export_remote.xml" />
|
||||
</section>
|
||||
<section id="collection_operations" name="Collection Operations">
|
||||
<tool file="${model_tools_path}/unzip_collection.xml" />
|
||||
|
||||
@@ -126,6 +126,7 @@ GALAXY_LIB_TOOLS_UNVERSIONED = [
|
||||
"send_to_cloud",
|
||||
"__DATA_FETCH__",
|
||||
"directory_uri",
|
||||
"export_remote",
|
||||
# Legacy tools bundled with Galaxy.
|
||||
"laj_1",
|
||||
"gff2bed1",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<toolbox tool_path="${tool_conf_dir}" is_shed_conf="false">
|
||||
<tool file="upload.xml"/>
|
||||
<tool file="export_remote.xml"/>
|
||||
<section id="test" name="Test Section">
|
||||
<tool file="multi_data_optional.xml" />
|
||||
<tool file="paths_as_file.xml" />
|
||||
|
||||
@@ -135,6 +135,37 @@ class RemoteFilesIntegrationTestCase(ConfiguresRemoteFilesIntegrationTestCase):
|
||||
with open(os.path.join(ftp_dir, 'helloworld')) as f:
|
||||
assert 'hello world!\n' == f.read()
|
||||
|
||||
def test_export_remote_tool_default(self):
|
||||
dataset_populator = self.dataset_populator
|
||||
ftp_dir = self.user_ftp_dir
|
||||
_write_file_fixtures(self.root, ftp_dir)
|
||||
with dataset_populator.test_history() as history_id:
|
||||
dataset = dataset_populator.new_dataset(history_id, content="example content", wait=True, name="foo")
|
||||
infile = {
|
||||
"src": "hda",
|
||||
"id": dataset["id"]
|
||||
}
|
||||
inputs = {
|
||||
"d_uri": "gxftp://",
|
||||
"export_type|export_type_selector": "datasets_auto",
|
||||
"export_type|infiles": [infile],
|
||||
}
|
||||
response = dataset_populator.run_tool("export_remote", inputs, history_id)
|
||||
response.raise_for_status()
|
||||
with open(os.path.join(ftp_dir, 'foo.txt')) as f:
|
||||
assert 'example content\n' == f.read()
|
||||
|
||||
inputs = {
|
||||
"d_uri": "gxftp://",
|
||||
"export_type|export_type_selector": "datasets_named",
|
||||
"export_type|datasets_0|infile": infile,
|
||||
"export_type|datasets_0|name": "my_cool_name.txt",
|
||||
}
|
||||
response = dataset_populator.run_tool("export_remote", inputs, history_id)
|
||||
response.raise_for_status()
|
||||
with open(os.path.join(ftp_dir, 'my_cool_name.txt')) as f:
|
||||
assert 'example content\n' == f.read()
|
||||
|
||||
def _assert_index_empty(self, index):
|
||||
assert len(index) == 0
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from galaxy.files import ConfiguredFileSources
|
||||
|
||||
|
||||
def get_file_sources(file_sources_path):
|
||||
assert os.path.exists(file_sources_path), "file sources path [%s] does not exist" % file_sources_path
|
||||
with open(file_sources_path, "r") as f:
|
||||
file_sources_as_dict = json.load(f)
|
||||
file_sources = ConfiguredFileSources.from_dict(file_sources_as_dict)
|
||||
return file_sources
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
args = _parser().parse_args(argv)
|
||||
exit_code = 0
|
||||
file_sources = get_file_sources(args.file_sources)
|
||||
directory_uri = args.directory_uri
|
||||
counter = 0
|
||||
for real_data_path, name in zip(args.infiles, args.names):
|
||||
if directory_uri.endswith("/"):
|
||||
target_uri = directory_uri + name
|
||||
else:
|
||||
target_uri = directory_uri + "/" + name
|
||||
file_source_path = file_sources.get_file_source_path(target_uri)
|
||||
if os.path.exists(file_source_path.path):
|
||||
print(f'Error: File "{file_source_path.path}" already exists. Skipping.')
|
||||
exit_code = 1
|
||||
continue
|
||||
file_source = file_source_path.file_source
|
||||
file_source.write_from(file_source_path.path, real_data_path)
|
||||
counter += 1
|
||||
print(f"'{counter}' out of '{len(args.infiles)}' files have been exported.\n")
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def _parser():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--directory-uri', type=str,
|
||||
help='directory target URI')
|
||||
parser.add_argument('--file-sources', type=str, help='file sources json')
|
||||
parser.add_argument('--infiles', type=str, nargs='*', required=True)
|
||||
parser.add_argument('--names', type=str, nargs='*', required=True)
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,60 @@
|
||||
<tool id="export_remote" name="Export datasets" version="0.1.0">
|
||||
<description>to remote files source</description>
|
||||
<command><![CDATA[
|
||||
python '$__tool_directory__/export_remote.py'
|
||||
--file-sources '$file_sources'
|
||||
--directory-uri '$d_uri'
|
||||
#if $export_type.export_type_selector == "datasets_auto"
|
||||
--infiles
|
||||
#for $filepath in $export_type.infiles:
|
||||
'$filepath'
|
||||
#end for
|
||||
--names
|
||||
#for $name in $export_type.infiles:
|
||||
#if $name.ext == 'vcf_bgzip':
|
||||
#set file_ext = 'vcf.bz'
|
||||
#else:
|
||||
#set file_ext = $name.ext
|
||||
#end if
|
||||
'${name.element_identifier}.${file_ext}'
|
||||
#end for
|
||||
#else
|
||||
--infiles
|
||||
#for $dataset in $export_type.datasets:
|
||||
'$dataset.infile'
|
||||
#end for
|
||||
--names
|
||||
#for $dataset in $export_type.datasets:
|
||||
'$dataset.name'
|
||||
#end for
|
||||
#end if
|
||||
> '$out'
|
||||
]]></command>
|
||||
<inputs>
|
||||
<conditional name="export_type">
|
||||
<param name="export_type_selector" type="select" label="What would you like to export?">
|
||||
<option value="datasets_auto" selected="True">Datasets using their Galaxy name and extension.</option>
|
||||
<option value="datasets_named">Datasets using specified name.</option>
|
||||
<!-- Allow more options - e.g. HTML, collections preserving their structure... -->
|
||||
</param>
|
||||
<when value="datasets_auto">
|
||||
<param name="infiles" type="data" format="txt,binary" multiple="true" label="Choose your datasets"/>
|
||||
</when>
|
||||
<when value="datasets_named">
|
||||
<repeat name="datasets" title="Dataset">
|
||||
<param type="data" name="infile" label="Input dataset" />
|
||||
<param type="text" name="name" label="Name" />
|
||||
</repeat>
|
||||
</when>
|
||||
</conditional>
|
||||
<param type="directory_uri" name="d_uri" label="Directory URI" />
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out" format="txt" label="Export logs"/>
|
||||
</outputs>
|
||||
<configfiles>
|
||||
<file_sources name="file_sources" />
|
||||
</configfiles>
|
||||
<tests>
|
||||
</tests>
|
||||
</tool>
|
||||
Reference in New Issue
Block a user