<jupyter_start><jupyter_text>Forrest imaging data slice code<jupyter_code>from nipype.caching import Memory
from nipype.interfaces import fsl
from os import listdir
from os.path import isfile, join
# define run directory (by sub), create a file list to be merged (8 segments of movie)
run_dir = "/media/anakin/Ariel/ds000113/sub-02/ses-movie/func"
files = [join(run_dir, f) for f in listdir(run_dir) if isfile(join(run_dir, f)) and f[-11:-7] == 'bold']
files.sort()
#files # uncomment to check file list to be merged
# merge all segments into 1 long time course
mem = Memory(base_dir='.')
fsl_merge = mem.cache(fsl.Merge)
movie_merged = fsl_merge(dimension='t', in_files=files, tr = 2)
# use output file directory 
merged_filename = str(movie_merged.outputs)
merged_filename = merged_filename[15:-1]
merged_filename
# Splitting merged_runs to single volumes
fsl_split = mem.cache(fsl.Split)
split = fsl_split(dimension='t', in_file=merged_filename)
# use output file directory and create a list of single volumes

split_name = str(split.outputs)
split_dir = split_name[15:122] #cange according to split_name

vol_list = [f for f in listdir(split_dir) if f[:3] =='vol']

# Sanity Check - length of all data
len(vol_list)
# in order to create a 360 TR run, one must define ranges for runs
# make sure the conditions in list comprehension is accord with directories!

files = [join(split_dir, f) for f in listdir(split_dir) if isfile(join(split_dir, f)) and f[-14:-11] == 'vol']
run_merged = fsl_merge(dimension='t', in_files=files[3224:3404])
run_merged?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10745891276864729, 'fraction_numerical': 0.02402022756005057, 'mean_word_length': 5.793991416309013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '335819', 'license': 'CC0-1.0', 'n_tokens_mistral': 573, 'n_tokens_neox': 532, 'n_words': 175, 'path': 'merging_volumes-forrest.ipynb', 'repo_name': 'ArielBundy/forrest_pipeline', 'size': '1582'}