In [4]:
from scitran_client import ScitranClient, query, Projects, Acquisitions, Sessions, Files
client = ScitranClient('scitran')
We can assemble queries by building filters like below. We're looking for sessions in the project called vwfa
, so we query for sessions and filter by the associated project. After we find the sessions we're interested in, we query for T1-weighted nifti files that are associated with those sessions.
In [7]:
sessions = client.search(query(Sessions).filter(Projects.label.match('vwfa')))
files = client.search(query(Files).filter(
Files.type.match('nifti'),
Acquisitions.measurement.match('anatomy_t1w'),
Acquisitions.session.in_(session['_id'] for session in sessions),
))
In [8]:
# Let's analyze the first file.
example_file = files[0]
import os
# fsl-bet looks for files in the nifti subdirectory
nifti_dir = os.path.join(client.gear_in_dir, 'nifti')
if not os.path.exists(nifti_dir):
os.mkdir(nifti_dir)
example_file_path = client.download_all_file_search_results([example_file], dest_dir=nifti_dir)[0]
In [9]:
session_id = example_file['_source']['acquisition']['session']
# We let fsl-bet find the input file by having an empty string for a command.
client.run_gear_and_upload_analysis('testing fsl-bet local run', 'scitran/fsl-bet', session_id, '')
In [16]:
import nibabel as nib
import scipy.misc
img = nib.load(example_file_path)
scipy.misc.toimage(img.get_data()[100, :, :]).save('before.png')
output_file_path = os.path.join(client.gear_out_dir, '11353_3_1_brain-extracted.nii.gz')
img = nib.load(output_file_path)
scipy.misc.toimage(img.get_data()[100, :, :]).save('after.png')