diff --git a/tools/xnatutils/macros.xml b/tools/xnatutils/macros.xml
index 5157a33a..14dc73cc 100644
--- a/tools/xnatutils/macros.xml
+++ b/tools/xnatutils/macros.xml
@@ -14,4 +14,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/xnatutils/test-data/e4.60005.nii.gz b/tools/xnatutils/test-data/e4.60005.nii.gz
new file mode 100644
index 00000000..de73e4d0
Binary files /dev/null and b/tools/xnatutils/test-data/e4.60005.nii.gz differ
diff --git a/tools/xnatutils/test-data/e5_60005_nii.gz b/tools/xnatutils/test-data/e5_60005_nii.gz
new file mode 100644
index 00000000..10a87927
Binary files /dev/null and b/tools/xnatutils/test-data/e5_60005_nii.gz differ
diff --git a/tools/xnatutils/test-data/xnat_get.log b/tools/xnatutils/test-data/xnat_get.log
new file mode 100644
index 00000000..c665235d
--- /dev/null
+++ b/tools/xnatutils/test-data/xnat_get.log
@@ -0,0 +1,2 @@
+Downloading subject01_MT01: 1-t1w-NIFTI
+Downloading subject02_MR01: 1-t1w-NIFTI
diff --git a/tools/xnatutils/test-data/xnat_ls_project.log b/tools/xnatutils/test-data/xnat_ls_project.log
new file mode 100644
index 00000000..f85f41c8
--- /dev/null
+++ b/tools/xnatutils/test-data/xnat_ls_project.log
@@ -0,0 +1,2 @@
+subject01
+subject02
diff --git a/tools/xnatutils/test-data/xnat_ls_project_scan.log b/tools/xnatutils/test-data/xnat_ls_project_scan.log
new file mode 100644
index 00000000..1874e440
--- /dev/null
+++ b/tools/xnatutils/test-data/xnat_ls_project_scan.log
@@ -0,0 +1,2 @@
+t1w
+t1w
diff --git a/tools/xnatutils/test-data/xnat_ls_project_session.log b/tools/xnatutils/test-data/xnat_ls_project_session.log
new file mode 100644
index 00000000..387e713c
--- /dev/null
+++ b/tools/xnatutils/test-data/xnat_ls_project_session.log
@@ -0,0 +1,2 @@
+subject01_MR01
+subject02_MR01
diff --git a/tools/xnatutils/test-data/xnat_put.log b/tools/xnatutils/test-data/xnat_put.log
new file mode 100644
index 00000000..b1a57091
--- /dev/null
+++ b/tools/xnatutils/test-data/xnat_put.log
@@ -0,0 +1 @@
+Invalid status for response from XNATSession for url http://10.1.1.32:8080/data/archive/projects/OPENNEURO_T1W/subjects/Xnat4Tests_S00001/experiments/Xnat4Tests_E00001/scans/t1w/resources/NIFTI_GZ (status 404, accepted status: [200, 201])
diff --git a/tools/xnatutils/test-data/xnat_rename.log b/tools/xnatutils/test-data/xnat_rename.log
new file mode 100644
index 00000000..886a12b3
--- /dev/null
+++ b/tools/xnatutils/test-data/xnat_rename.log
@@ -0,0 +1 @@
+Successfully renamed 'subject01_MT01' to 'subject01_MR01'
diff --git a/tools/xnatutils/test-data/zstat1.nii.gz b/tools/xnatutils/test-data/zstat1.nii.gz
new file mode 100644
index 00000000..10a87927
Binary files /dev/null and b/tools/xnatutils/test-data/zstat1.nii.gz differ
diff --git a/tools/xnatutils/xnatutils.xml b/tools/xnatutils/xnatutils.xml
index 9e87063c..38874f45 100644
--- a/tools/xnatutils/xnatutils.xml
+++ b/tools/xnatutils/xnatutils.xml
@@ -15,44 +15,116 @@ export XNAT_PASS=$xnat_pass &&
#if $operation.ops_list == "list":
#if $operation.project_option.project == "default":
- xnat-ls --server $xnat_url >> '$log' 2>&1
+ xnat-ls --server $xnat_url >> '$list_log' 2>&1
#else
- #if $operation.project_option.datatype_selector != 'session':
- xnat-ls --server $xnat_url
- --project $operation.project_option.project_id
- -d $operation.project_option.datatype_choice >> '$log' 2>&1
+ #if $operation.project_option.project_id !='':
+ xnat-ls --server $xnat_url
+ --project $operation.project_option.project_id
+ #if $operation.project_option.subject_id !='':
+ --subject $operation.project_option.subject_id
+ #end if
+ --datatype $operation.project_option.datatype_choice
+ #if $operation.project_option.return_attr:
+ #if $operation.project_option.datatype_choice == 'scan':
+ --return_attr type
+ #elif $operation.project_option.datatype_choice == 'subject' or $operation.project_option.datatype_choice == 'session':
+ --return_attr id
+ #end if
+ #end if
+ #if $operation.project_option.datatype_choice == 'session' and $operation.project_option.datatype_selector.include_scan !='':
+ --with_scans $operation.project_option.datatype_selector.include_scan
+ #end if
+ #if $operation.project_option.datatype_choice == 'session' and $operation.project_option.datatype_selector.exclude_scan !='':
+ --without_scans $operation.project_option.datatype_selector.exclude_scan
+ #end if
+ #if $operation.project_option.before_date !='':
+ --before $operation.project_option.before_date
+ #end if
+ #if $operation.project_option.after_date !='':
+ --after $operation.project_option.after_date
+ #end if
+ >> '$list_log' 2>&1
#else
- #if $operation.project_option.datatype_selector.include_scan =='' and $operation.project_option.datatype_selector.exclude_scan =='':
- xnat-ls --server $xnat_url
- --project $operation.project_option.project_id
- -d $operation.project_option.datatype_choice >> '$log' 2>&1
- #elif $operation.project_option.datatype_selector.include_scan !='' and $operation.project_option.datatype_selector.exclude_scan =='':
- xnat-ls --server $xnat_url
- --project $operation.project_option.project_id
- -d $operation.project_option.datatype_choice
- --with_scans $operation.project_option.datatype_selector.include_scan >> '$log' 2>&1
- #elif $operation.project_option.datatype_selector.include_scan =='' and $operation.project_option.datatype_selector.exclude_scan !='':
- xnat-ls --server $xnat_url
- --project $operation.project_option.project_id
- -d $operation.project_option.datatype_choice
- --without_scans $operation.project_option.datatype_selector.exclude_scan >> '$log' 2>&1
- #else
- xnat-ls --server $xnat_url
- --project $operation.project_option.project_id
- -d $operation.project_option.datatype_choice
- --with_scans $operation.project_option.datatype_selector.include_scan
- --without_scans $operation.project_option.datatype_selector.exclude_scan >> '$log' 2>&1
- #end if
+ echo "Project ID is missing" >> '$list_log' 2>&1
#end if
#end if
#elif $operation.ops_list == "get":
- mkdir -p output &&
- xnat-get --server $xnat_url
- --scans $operation.scans
+ #if $operation.input_option.input_type == 'use_xml':
+ xnat-get --server $xnat_url $operation.input_option.xml_file >> '$get_log' 2>&1
+ #else
+ #if $operation.input_option.session !='':
+ echo '$operation.input_option.session' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.scans !='':
+ echo '$operation.input_option.scans' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.scan_option.with_scans !='':
+ echo '$operation.input_option.scan_option.with_scans' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.convert_type.to_type !='':
+ echo '$operation.input_option.convert_type.to_type' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.converter_option.converter !='':
+ echo '$operation.input_option.converter_option.converter' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.before_date !='':
+ echo '$operation.input_option.opt.before_date' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.after_date !='':
+ echo '$operation.input_option.opt.after_date' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.project_id !='':
+ echo '$operation.input_option.opt.project_id' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.subject_id !='':
+ echo '$operation.input_option.opt.subject_id' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.resource_name !='':
+ echo '$operation.input_option.opt.subject_id' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.dont_match_scan_id:
+ echo '$operation.input_option.opt.dont_match_scan_id' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.opt.strip_name :
+ echo '$operation.input_option.opt.strip_name' >> '$get_log' &&
+ #end if
+ #if $operation.input_option.method !=''
+ echo '$operation.input_option.method' >> '$get_log' 2>&1
+ #end if
+ #end if
#elif $operation.ops_list == "put":
- echo "TODO - put" >> '$log'
+ #import re
+ #if $operation.upload_file.ext.endswith(".gz")
+ #set file_identifier=re.sub('[^\s\w\-]', '_', str($operation.upload_file.element_identifier)) + '.gz'
+ ln -s '$operation.upload_file' '${file_identifier}' &&
+ #else
+ #set file_identifier=re.sub('[^\s\w\-]', '_', str($operation.upload_file.element_identifier))
+ ln -s '$operation.upload_file' '${file_identifier}' &&
+ #end if
+
+ xnat-put --server $xnat_url
+ $operation.session_name
+ $operation.scan_name
+ '${file_identifier}'
+ --method $operation.method
+ $operation.dataset_option.overwrite
+ $operation.dataset_option.create_session
+ #if $operation.dataset_option.resource_name !='':
+ --resource_name $operation.dataset_option.resource_name
+ #end if
+ #if $operation.id_option.project_id !='':
+ --project_id
+ #end if
+ #if $operation.id_option.subject_id !='':
+ --subject_id
+ #end if
+ #if $operation.id_option.scan_id != '':
+ --scan_id
+ #end if
+ >> '$put_log' 2>&1
#elif $operation.ops_list == "rename":
- xnat-rename --server $xnat_url $operation.old_session_name $operation.new_session_name >> '$log' 2>&1
+ xnat-rename --server $xnat_url
+ $operation.old_session_name $operation.new_session_name >> '$rename_log' 2>&1
#end if
]]>
@@ -66,73 +138,54 @@ export XNAT_PASS=$xnat_pass &&
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
@@ -148,27 +201,129 @@ export XNAT_PASS=$xnat_pass &&
-
+
+ operation['ops_list'] == 'list'
+
+
+ operation['ops_list'] == 'get'
+
+
+ operation['ops_list'] == 'put'
+
+
+ operation['ops_list'] == 'rename'
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
**What it does**
- Xnat-utils is a collection of scripts for conveniently up/downloading and listing data on/from XNAT
+ Xnat-utils is a collection of scripts for conveniently up/downloading and listing data on/from XNAT server.
+
+**Usage**
+ Four commands are wrapped for Galaxy operation.
+
+- ``xnat-ls``: list projects/subjects/sessions/scans
+- ``xnat-get``: download scans and resources
+- ``xnat-put``: upload scans and resources (requires write privileges to project)
+- ``xnat-rename``: renames an XNAT session
+
+
+**How to connect to XNAT server**
+
+To interact with XNAT server from Galaxy you need to set up your XNAT login credential in Galaxy user preference.
+
+1. Obtain your username and password from XNAT
+
+2. In Galaxy, add XNAT server url, username and password to "XNAT Server and Account" field in User > Preferences > Manage Information. Your XNAT login credential can be different from your Galaxy login credential.
+
**Remarks**
- This tool leverages Xnatutils (https://github.com/Australian-Imaging-Service/xnatutils)
- to query and retrieve files on Australia Image Service Server.
+ Xnatutils_ is used to query and retrieve files on Australia Image Service (AIS_) Server.
+
+.. _AIS: https://ardc.edu.au/project/australian-imaging-service-ais/
+.. _Xnatutils: https://github.com/Australian-Imaging-Service/xnatutils
+
+
+ 10.47486/PL102
+