-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skeletons and foldlabels for the whole brain #75
Open
PierreAuriau
wants to merge
16
commits into
main
Choose a base branch
from
full_skeleton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5be7bc4
add DeepFoldingError
PierreAuriau 32f4a55
add get_left_and_right_graph_file method
PierreAuriau 63cdc28
add F side in generate_one_transform method
PierreAuriau 3a300a4
add generate_full_foldlabel function
PierreAuriau d9c06ac
add DeepFoldingError import
PierreAuriau ba10d23
add dimension parameter
PierreAuriau c7d78a0
change place of creation empty volume
PierreAuriau 13942a1
change place of creation empty volume
PierreAuriau cdbcf2e
add generate_full_skeleton function
PierreAuriau fc235c9
add get_left_right_graph_files method
PierreAuriau b979c1f
add get_left_right_graph_files method
PierreAuriau 8e78b46
add F side in generate_one_skeleton
PierreAuriau 91dfe1b
add F side in generate_one_foldlabel
PierreAuriau 6f437ce
add F side in setup_log
PierreAuriau 01a593d
correct graph_path for F side
PierreAuriau 402fa81
change src and output filenames
PierreAuriau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,10 @@ | |
import glob | ||
import sys | ||
import re | ||
from os.path import abspath | ||
from os.path import abspath, basename, join, dirname | ||
from os.path import basename | ||
|
||
from deep_folding.brainvisa import exception_handler | ||
from deep_folding.brainvisa import exception_handler, DeepFoldingError | ||
from deep_folding.brainvisa.utils.folder import create_folder | ||
from deep_folding.brainvisa.utils.subjects import get_number_subjects,\ | ||
is_it_a_subject | ||
|
@@ -129,10 +129,11 @@ def parse_args(argv): | |
|
||
args = parser.parse_args(argv) | ||
|
||
suffix = {"R": "right", "L": "left", "F": "full"} | ||
setup_log(args, | ||
log_dir=f"{args.output_dir}", | ||
prog_name=basename(__file__), | ||
suffix='right' if args.side == 'R' else 'left') | ||
suffix=suffix[args.side]) | ||
|
||
params = vars(args) | ||
|
||
|
@@ -166,26 +167,49 @@ def __init__(self, src_dir, transform_dir, | |
def generate_one_transform(self, subject: str): | ||
"""Generates and writes ICBM2009c transform for one subject. | ||
""" | ||
graph_path = f"{self.src_dir}/{subject}*/" +\ | ||
f"{self.path_to_graph}/{self.side}*.arg" | ||
if self.side == "F": | ||
graph_path = f"{self.src_dir}/{subject}*/" + \ | ||
f"{self.path_to_graph}/?{subject}*.arg" | ||
else: | ||
graph_path = f"{self.src_dir}/{subject}*/" + \ | ||
f"{self.path_to_graph}/{self.side}{subject}*.arg" | ||
log.debug(graph_path) | ||
list_graph_file = glob.glob(graph_path) | ||
log.debug(f"list_graph_file = {list_graph_file}") | ||
if len(list_graph_file) == 0: | ||
raise RuntimeError(f"No graph file! " | ||
f"{graph_path} doesn't exist") | ||
for graph_file in list_graph_file: | ||
transform_file = self.get_transform_filename(subject, graph_file) | ||
graph = aims.read(graph_file) | ||
g_to_icbm_template = aims.GraphManip.getICBM2009cTemplateTransform( | ||
graph) | ||
aims.write(g_to_icbm_template, transform_file) | ||
if not self.bids: | ||
break | ||
try: | ||
transform_file = self.get_transform_filename(subject, graph_file) | ||
if self.side == "F": | ||
graph_file_left, graph_file_right, graph_to_remove = \ | ||
self.get_left_and_right_graph_files(graph_file, list_graph_file) | ||
list_graph_file.remove(graph_to_remove) | ||
graph_left = aims.read(graph_file_left) | ||
graph_right = aims.read(graph_file_right) | ||
g_to_icbm_template_left = aims.GraphManip.getICBM2009cTemplateTransform( | ||
graph_left) | ||
g_to_icbm_template_right = aims.GraphManip.getICBM2009cTemplateTransform( | ||
graph_right) | ||
if g_to_icbm_template_left != g_to_icbm_template_right: | ||
raise DeepFoldingError(f"Left and right transformations files are not the same: " | ||
f"{g_to_icbm_template_left} and {g_to_icbm_template_right}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mais du coup, vu que la DeepFoldingError fait que pass, ça arrête le sujet en cours ? |
||
aims.write(g_to_icbm_template_left, transform_file) | ||
else: | ||
graph = aims.read(graph_file) | ||
g_to_icbm_template = aims.GraphManip.getICBM2009cTemplateTransform( | ||
graph) | ||
aims.write(g_to_icbm_template, transform_file) | ||
if not self.bids: | ||
break | ||
except DeepFoldingError as e: | ||
log.error(f"Graph file {graph_file} : {e}") | ||
continue | ||
|
||
def get_transform_filename(self, subject, graph_file): | ||
transform_file = ( | ||
f"{self.transform_dir}/" | ||
transform_file = join( | ||
f"{self.transform_dir}", | ||
f"{self.side}transform_to_ICBM2009c_{subject}") | ||
if self.bids: | ||
session = re.search("ses-([^_/]+)", graph_file) | ||
|
@@ -200,6 +224,23 @@ def get_transform_filename(self, subject, graph_file): | |
transform_file += ".trm" | ||
return transform_file | ||
|
||
@staticmethod | ||
def get_left_and_right_graph_files(graph_file, list_graph_file): | ||
graph_name = basename(graph_file) | ||
if graph_name.startswith("L"): | ||
graph_file_left = graph_file | ||
graph_file_right = join(dirname(graph_file), f"R{graph_name[1:]}") | ||
if graph_file_right not in list_graph_file: | ||
raise DeepFoldingError(f"Right graph is missing : {graph_file_right}") | ||
graph_to_remove = graph_file_right | ||
else: | ||
graph_file_right = graph_file | ||
graph_file_left = join(dirname(graph_file), f"L{graph_name[1:]}") | ||
if graph_file_left not in list_graph_file: | ||
raise DeepFoldingError(f"Left graph is missing : {graph_file_left}") | ||
graph_to_remove = graph_file_left | ||
return graph_file_left, graph_file_right, graph_to_remove | ||
|
||
def compute(self, number_subjects): | ||
"""Loops over subjects to generate transforms to ICBM2009c from graphs. | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est normal qu'il y ait un {subject] en plus dans le path ?