Skip to content
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

[TEST][REF] Move and test functions related to creating scans.tsv for AIBL #1390

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

AliceJoubert
Copy link
Contributor

@AliceJoubert AliceJoubert commented Nov 22, 2024

Close #1352, #1353

@AliceJoubert AliceJoubert self-assigned this Nov 22, 2024
@AliceJoubert AliceJoubert marked this pull request as ready for review December 3, 2024 15:23
Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AliceJoubert !

I made a first pass with small comments and suggestions.
Looks good to me but I will take a closer look next week.

write_scans_tsv(bids_path, scans_dict)


def _flutemeta_badline(line: List[str]) -> Optional[List[str]]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes I also forget about it, but since we are in the Python 3.9+ world, we can use builtins for type hints. I don't think we need to update all signatures in an industrial way, but slowly make the code evolve to use new typing syntax.

Suggested change
def _flutemeta_badline(line: List[str]) -> Optional[List[str]]:
def _flutemeta_badline(line: list[str]) -> Optional[list[str]]:


def _flutemeta_badline(line: List[str]) -> Optional[List[str]]:
# Fix for malformed flutemeta file in AIBL (see #796).
# Some flutemeta lines contain a non-coded string value at the second-to-last position. This value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you turn this into a docstring ?

write_scans_tsv(bids_path, scans_dict)


def _flutemeta_badline(line: List[str]) -> Optional[List[str]]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename to start with an action verb, _handle_flutemeta_badline maybe ?

write_sessions_tsv
"""

from clinica.iotools.bids_utils import _get_pet_tracer_from_filename
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably means that we need to make this function public...


supported_modalities = ("anat", "dwi", "func", "pet")

for sub in scans_dict.keys():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It costs only 4 characters and it helps our brains:

Suggested change
for sub in scans_dict.keys():
for subject in scans_dict.keys():

supported_modalities = ("anat", "dwi", "func", "pet")

for sub in scans_dict.keys():
for session in scans_dict[sub].keys():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same of previous for loop.

Suggested change
for session in scans_dict[sub].keys():
for session in scans_dict[sub]:

scans_df = pd.DataFrame()
tsv_file = bids_dir / sub / session / f"{sub}_{session}_scans.tsv"
tsv_file.unlink(missing_ok=True)
for mod in (bids_dir / sub / session).glob("*"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea about names and simplify by replacing the following if condition by a list filter:

Suggested change
for mod in (bids_dir / sub / session).glob("*"):
for modality in [mod for mod in (bids_dir / subject / session).glob("*") if mod.name in supported_modalities]:

return scans_dict


def write_scans_tsv(bids_dir: Path, scans_dict: dict) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either these are private, or __all__ needs to be updated to reflect the new public objects of this module, right ? It basically depends if you are using these functions outside of this module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REF][TEST] AIBL-to-BIDS : add tests for creating scans.tsv functions
2 participants