Commit c5d4debd authored by Andrei Roibu's avatar Andrei Roibu
Browse files

finished writing tractsSum, preparing to deploy

parent 7e84c728
......@@ -19,7 +19,7 @@ def dirReader(folder_location):
None
"""
out_file = open("files2.txt", 'w')
out_file = open("files.txt", 'w')
subDirectoryList = []
for directory in os.listdir(folder_location):
......@@ -30,8 +30,6 @@ def dirReader(folder_location):
string = directory+'\n'
out_file.write(string)
subDirectoryList.append(directory)
else:
pass
return subDirectoryList
......@@ -43,7 +41,7 @@ def tractSum(folder_path):
This function also outputs the summed tract map as a Nifti (.nii.gz) file.
Args:
None
folder_location (str): A string containing the address of the required directory.
Returns:
None
......@@ -55,29 +53,43 @@ def tractSum(folder_path):
tractMapName = 'tractsNorm.nii.gz'
sum_flag = False
subDirectoryList = dirReader(folder_path)
for directory in os.listdir(folder_path):
if os.path.isdir(os.path.join(folder_location, directory)):
# test_file = open('./files.txt', 'r')
# for subDirectory in subDirectoryList():
tractedMapPath = folder_path + directory + '/' + tractMapName
tractedMapImg = nib.load(tractedMapPath)
tractedMap = tractedMapImg.get_fdata()
if not os.path.exists('/well/win/users/hsv459/functionmapper/datasets/dMRI'):
if not os.path.exists('/well/win/users/hsv459/functionmapper/datasets'):
os.mkdir('/well/win/users/hsv459/functionmapper/datasets')
os.mkdir('/well/win/users/hsv459/functionmapper/datasets/dMRI')
# the affine array stores the relationship between voxel coordinates in the image data array and coordinates in the reference space
for subDirectory in subDirectoryList:
tractedMapsPath = os.path.join('/well/win-biobank/projects/imaging/data/data3/subjectsAll/', str(subDirectory), 'dMRI/autoptx_preproc/tracts/')
tractedMapAffine = tractedMapImg.affine
sum_flag = False # This is a flat showing us if this is the first tracted to be summed
if sum_flag == False:
tractedMapSum = np.copy(tractedMap)
else:
tractedMapSum = np.sum(tractedMapSum, tractedMap)
else:
pass
for tract in os.listdir(tractedMapsPath):
if os.path.isdir(os.path.join(tractedMapsPath, tract)):
tractedMapPath = os.path.join(tractedMapsPath, tract, tractMapName)
tractedMapImg = nib.load(tractedMapPath)
tractedMapSumImg = nib.Nifti1Image(tractedMapSum, tractedMapAffine)
nib.save(tractedMapSumImg, os.path.join(folder_path, "tractsSum.nii.gz"))
tractedMap = tractedMapImg.get_fdata()
# the affine array stores the relationship between voxel coordinates in the image data array and coordinates in the reference space
tractedMapAffine = tractedMapImg.affine
if sum_flag == False:
tractedMapSum = np.copy(tractedMap)
else:
tractedMapSum = np.sum(tractedMapSum, tractedMap)
tractedMapSumPath = '/well/win/users/hsv459/functionmapper/datasets/dMRI'
tractsSumName = str(subDirectory) + ".nii.gz"
tractedMapSumImg = nib.Nifti1Image(tractedMapSum, tractedMapAffine)
nib.save(tractedMapSumImg, os.path.join(tractedMapSumPath, tractsSumName))
return None
......@@ -85,5 +97,5 @@ if __name__ == "__main__":
# dirReader("/home/andrei/directory_readear/")
folder_location = '/home/andrei/functionmapper/datasets/dMRI/23425368/'
folder_location = '/well/win-biobank/projects/imaging/data/data3/subjectsAll/'
tractSum(folder_location)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment