def muti_bundle_registration(paths_file, pts=12): """ muti-bundle registration and consolidation Parameters ---------- paths_file: list; muti_bundle file path pts: each streamline is divided into sections Return ------ new header: include id of each streamline that comes from different subjects registration and consolidation bundle """ fas = Fasciculus(paths_file[0]) # print fas.get_header() bundle_header = {'fasciculus_id': None} sub1 = fas.get_data() bundle_header['fasciculus_id'] = len(sub1) * [ int(paths_file[0].split('/')[9]) ] sub2 = Fasciculus(paths_file[1]).get_data() subj2_aligned = bundle_registration(sub1, sub2, pts=pts) bundle = fas.fib_merge(sub1, subj2_aligned) bundle_header['fasciculus_id'] += ( len(bundle) - len(sub1)) * [int(paths_file[1].split('/')[9])] # print bundle_header # print len(bundle) for index in range(len(paths_file))[2:]: # print paths_file[index] sub = Fasciculus(paths_file[index]).get_data() sub_aligned = bundle_registration(sub1, sub, pts=pts) lenth = len(bundle) bundle = fas.fib_merge(bundle, sub_aligned) bundle_header['fasciculus_id'] += ( len(bundle) - lenth) * [int(paths_file[index].split('/')[9])] fas.update_header(bundle_header) fas.set_data(nibas.ArraySequence(bundle)) return fas
def cc_seg_pipeline(tck_path, mask, geo_path, thr=5., roi_id=None, step=0): """ Extract occipital streamlines and separate hemisphere streamlines Parameters ---------- tck_path: list; streamline file path (.tck) mask: surface mask (xh.aparc.annot) geo_path: geometry data path (subject_id.L.white.native.surf.gii) thr: distance of streamline terminus to surface Return ------ occipital streamlines """ # load data fasciculus = Fasciculus(tck_path) # extract streamlines from left to right hemisphere fibselection = FibSelection(fasciculus) L_temp_need0 = fibselection.endpoint_dissimilarity() fasciculus.set_data(L_temp_need0) L_temp_need1 = fibselection.single_point_mid_sag() fasciculus.set_data(L_temp_need1) del L_temp_need0, L_temp_need1 gc.collect() # separation of lr_seed fib fib = fasciculus.hemi_fib_separation() # choose the mask: Occipital mask_fib = [] for i in range(len(fib)): vertices, colortable, label = nib.freesurfer.read_annot(mask[i]) gii_data = nib.load(geo_path[i]).darrays coords, faces = gii_data[0].data, gii_data[1].data label_value = np.array(len(coords) * [0]) if not roi_id: label_value[vertices == 11] = 11 # lateraloccipital label_value[vertices == 13] = 13 # lingual label_value[vertices == 5] = 5 # cuneus label_value[vertices == 21] = 21 # pericalcarine else: for value in roi_id: label_value[vertices == value] = value # extract fib using mask streamlines = fib[i] streamlines = fasciculus.sort_streamlines(streamlines) if i == 0: s0 = [s[0] for s in streamlines] else: s0 = [s[-1] for s in streamlines] stream_terminus = np.array(s0) dist = cdist(coords[label_value > 0], stream_terminus) stream_index = np.array(len(streamlines) * [False]) for j in range(len(dist[:])): temp_index = np.array(dist[j] <= thr) stream_index += temp_index rois_streamlines = streamlines[stream_index] mask_fib.append(rois_streamlines) # lr fib merge fib_merge = fasciculus.fib_merge(mask_fib[0], mask_fib[1]) del mask_fib gc.collect() fib_hemi = fasciculus.separation_fib_to_hemi(fib_merge) del fib_merge gc.collect() return fib_hemi