diff --git a/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py b/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py index b9ba25476d54e007f44ddeecb455f1b76f9acc1f..9e5625dc19693537afdd6d5ce5f1062c0e35939f 100644 --- a/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py +++ b/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py @@ -16,7 +16,7 @@ with open('../test/test1.json', 'r') as f: #import our function for converting a folder of segmentations to points from coordinate_extraction import FolderToAtlasSpace, FolderToAtlasSpaceMultiThreaded -from read_and_write import SaveDataframeasCSV, WritePointsToMeshview +from read_and_write import SaveDataframeasCSV, WritePointsToMeshview, FilesinDirectory from counting_and_load import PixelCountPerRegion, labelPoints startTime = datetime.now() @@ -36,7 +36,7 @@ data, header = nrrd.read(input["volume_path"]) #now we can get the labels for each point labels = labelPoints(points, data, scale_factor=2.5) -#save points to a meshview json +#save points to a meshview jsonv WritePointsToMeshview(points, labels, input["points_json_path"], label_df) df_counts_per_label_name = PixelCountPerRegion(labels, input["label_path"]) @@ -50,4 +50,13 @@ print(f"overall time taken was: {time_taken}") #get centroids and areas returns a list of objects and the center coordinate. #we need to deform the center coordinate according to visualign deformations¨ #we need to then transform the coordinate into atlas space -#and then save labels like before. \ No newline at end of file +#and then save labels like before. + + + + + +# Create a list of flat file names from a directory: + +#flatfiles = FilesinDirectory('../test_data/ttA_2877_NOP_atlasmaps') +#print(flatfiles) \ No newline at end of file diff --git a/PyNutil/load_workflow.py b/PyNutil/load_workflow.py index ccacb26c3b4568a5fe5d962a90f1751df693279e..7960ac88d745ac3a08d5da56f41f74f749352be1 100644 --- a/PyNutil/load_workflow.py +++ b/PyNutil/load_workflow.py @@ -20,4 +20,15 @@ values = image_arr[coordsx, coordsy] # assign x,y coords from image_array into v lbidx = labelfile['idx'].values allen_id_image = lbidx[values.astype(int)] # assign allen IDs into image array -plt.imshow(allen_id_image) \ No newline at end of file +plt.imshow(allen_id_image) + + +# Count area per unique label +# Scale up to size of corresponding segmentation +# calculate segmentation value per slice +# divide segmentation value per idx per slice by area per idx per slice +# output reports +# also do for whole brain + +#Also to do: +# fix position of clear label in label files diff --git a/PyNutil/read_and_write.py b/PyNutil/read_and_write.py index 7d11ea19b00e992681d06a407684f28e8cecf597..a701ebf2455fb092a3bb60b2f4a3c65810f6233c 100644 --- a/PyNutil/read_and_write.py +++ b/PyNutil/read_and_write.py @@ -3,6 +3,7 @@ import numpy as np import struct import pandas as pd import matplotlib.pyplot as plt +import os #related to read and write @@ -88,3 +89,17 @@ def LabeltoArray(label_path, image_array): allen_id_image = lbidx[values.astype(int)] # assign allen IDs into image array return allen_id_image + +def FilesinDirectory(directory): + """return list of flat file names in a directory""" + list_of_files = [] + for file in os.scandir(directory): + if file.path.endswith(".flat") and file.is_file: + #print(filename.path) + #newfilename, file_ext = os.path.splitext(filename) + #print(newfilename) + filename = os.path.basename(file) + newfilename, file_ext = os.path.splitext(filename) + list_of_files.append(newfilename) + return list_of_files + diff --git a/PyNutil/testing.py b/PyNutil/testing.py deleted file mode 100644 index e38dda5a57586fa65a287e6cc173990a4a449e4f..0000000000000000000000000000000000000000 --- a/PyNutil/testing.py +++ /dev/null @@ -1,23 +0,0 @@ - -import subprocess -import sys -import os -import glob - -directory = ('../test') - -""" -for filename in os.scandir(directory): - if filename.is_file: - print(filename.path) -""" - -directory = ('../test') - -for filename in os.scandir(directory): - if filename.path.endswith(".json") and filename.is_file: - print(filename.path) - - - - diff --git a/PyNutil/testing_sharon.py b/PyNutil/testing_sharon.py new file mode 100644 index 0000000000000000000000000000000000000000..0a4b18838196fd11d7234a8609c859c5cca3561a --- /dev/null +++ b/PyNutil/testing_sharon.py @@ -0,0 +1,43 @@ + +import subprocess +import sys +import os +import glob + +dir = ('../test_data/ttA_2877_NOP_atlasmaps') +"""fetch file names in a directory""" + +def FilesinDirectory(directory): + for file in os.scandir(directory): + if file.path.endswith(".flat") and file.is_file: + #print(filename.path) + #newfilename, file_ext = os.path.splitext(filename) + #print(newfilename) + filename = os.path.basename(file) + newfilename, file_ext = os.path.splitext(filename) + return newfilename + +#Question: how to return multiple file names into a list? + + +files = [] +newfiles = files.append(FilesinDirectory('../test_data/ttA_2877_NOP_atlasmaps')) +print(files) + + + + + +import os + +# file name with extension +file_name = os.path.basename('../test_data/ttA_2877_NOP_atlasmaps') + +print(file_name) + +# file name without extension +print(os.path.splitext(file_name)[0]) + + + +